IDEA-117584 more stubs for annotations. Optimization for argument searching

This commit is contained in:
Max Medvedev
2013-12-09 18:59:00 +04:00
parent 9afba6b56e
commit 98be3a370a
@@ -23,6 +23,7 @@ import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.light.LightClassReference;
import com.intellij.psi.meta.PsiMetaData;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.PairFunction;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -82,10 +83,6 @@ public class GrAnnotationImpl extends GrStubElementBase<GrAnnotationStub> implem
@NotNull
public GrAnnotationArgumentList getParameterList() {
final GrAnnotationStub stub = getStub();
if (stub != null) {
return stub.getPsiElement().getParameterList();
}
return findNotNullChildByClass(GrAnnotationArgumentList.class);
}
@@ -105,29 +102,44 @@ public class GrAnnotationImpl extends GrStubElementBase<GrAnnotationStub> implem
@Nullable
public PsiJavaCodeReferenceElement getNameReferenceElement() {
final GrAnnotationStub stub = getStub();
if (stub != null) {
return stub.getPsiElement().getNameReferenceElement();
}
final GroovyResolveResult resolveResult = resolveWithStub();
final GroovyResolveResult resolveResult = getClassReference().advancedResolve();
final PsiElement resolved = resolveResult.getElement();
if (!(resolved instanceof PsiClass)) return null;
if (resolved instanceof PsiClass) {
return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass)resolved, resolveResult.getSubstitutor());
}
else {
return null;
}
return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass)resolved, resolveResult.getSubstitutor());
}
@NotNull
private GroovyResolveResult resolveWithStub() {
final GrAnnotationStub stub = getStub();
final GrCodeReferenceElement reference = stub != null ? stub.getPsiElement().getClassReference() : getClassReference();
return reference.advancedResolve();
}
@Nullable
public PsiAnnotationMemberValue findAttributeValue(@Nullable String attributeName) {
final GrAnnotationStub stub = getStub();
if (stub != null) {
final GrAnnotation stubbedPsi = stub.getPsiElement();
final PsiAnnotationMemberValue value = PsiImplUtil.findAttributeValue(stubbedPsi, attributeName);
if (value == null || !PsiTreeUtil.isAncestor(stubbedPsi, value, true)) { // if value is a default value we can use it
return value;
}
}
return PsiImplUtil.findAttributeValue(this, attributeName);
}
@Nullable
public PsiAnnotationMemberValue findDeclaredAttributeValue(@NonNls final String attributeName) {
final GrAnnotationStub stub = getStub();
if (stub != null) {
final GrAnnotation stubbedPsi = stub.getPsiElement();
final PsiAnnotationMemberValue value = PsiImplUtil.findDeclaredAttributeValue(stubbedPsi, attributeName);
if (value == null) {
return null;
}
}
return PsiImplUtil.findDeclaredAttributeValue(this, attributeName);
}