diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2013-01-08 11:11:20 -0800 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2013-01-08 11:11:20 -0800 |
commit | b56ea2a18f232d79481e778085fd64e8ae486fc3 (patch) | |
tree | 44e1f6eb4864a45033f865b74fe783e3d784dd6a /java/java-psi-impl/src/com/intellij/psi/impl/source/PsiReferenceListImpl.java | |
download | idea-b56ea2a18f232d79481e778085fd64e8ae486fc3.tar.gz |
Snapshot of commit d5ec1d5018ed24f1b4f32b1d09df6dbd7e2fc425
from branch master of git://git.jetbrains.org/idea/community.git
Diffstat (limited to 'java/java-psi-impl/src/com/intellij/psi/impl/source/PsiReferenceListImpl.java')
-rw-r--r-- | java/java-psi-impl/src/com/intellij/psi/impl/source/PsiReferenceListImpl.java | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiReferenceListImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiReferenceListImpl.java new file mode 100644 index 000000000000..2eff5acd41ed --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiReferenceListImpl.java @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.impl.source; + +import com.intellij.lang.ASTNode; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.psi.*; +import com.intellij.psi.impl.java.stubs.PsiClassReferenceListStub; +import com.intellij.psi.impl.source.tree.JavaElementType; +import com.intellij.psi.stubs.IStubElementType; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.TokenSet; +import org.jetbrains.annotations.NotNull; + +public final class PsiReferenceListImpl extends JavaStubPsiElement<PsiClassReferenceListStub> implements PsiReferenceList { + private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.PsiReferenceListImpl"); + private static final TokenSet REFERENCE_BIT_SET = TokenSet.create(Constants.JAVA_CODE_REFERENCE); + + public PsiReferenceListImpl(final PsiClassReferenceListStub stub, final IStubElementType nodeType) { + super(stub, nodeType); + } + + public PsiReferenceListImpl(final ASTNode node) { + super(node); + } + + @Override + @NotNull + public PsiJavaCodeReferenceElement[] getReferenceElements() { + return calcTreeElement().getChildrenAsPsiElements(REFERENCE_BIT_SET, PsiJavaCodeReferenceElement.ARRAY_FACTORY); + } + + @Override + @NotNull + public PsiClassType[] getReferencedTypes() { + final PsiClassReferenceListStub stub = getStub(); + if (stub != null) { + return stub.getReferencedTypes(); + } + + final PsiJavaCodeReferenceElement[] refs = getReferenceElements(); + final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); + PsiClassType[] types = new PsiClassType[refs.length]; + for (int i = 0; i < types.length; i++) { + types[i] = factory.createType(refs[i]); + } + + return types; + } + + @Override + public Role getRole() { + final IElementType tt = getElementType(); + + if (tt == JavaElementType.EXTENDS_LIST) { + return Role.EXTENDS_LIST; + } + else if (tt == JavaElementType.IMPLEMENTS_LIST) { + return Role.IMPLEMENTS_LIST; + } + else if (tt == JavaElementType.THROWS_LIST) { + return Role.THROWS_LIST; + } + else if (tt == JavaElementType.EXTENDS_BOUND_LIST) { + return Role.EXTENDS_BOUNDS_LIST; + } + else { + LOG.error("Unknown element type:" + tt); + return null; + } + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof JavaElementVisitor) { + ((JavaElementVisitor)visitor).visitReferenceList(this); + } + else { + visitor.visitElement(this); + } + } + + public String toString() { + return "PsiReferenceList"; + } +} |