use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class PsiUtil method appendName.
private static boolean appendName(GrCodeReferenceElement referenceElement, StringBuilder builder) {
String refName = referenceElement.getReferenceName();
if (refName == null)
return false;
GrCodeReferenceElement qualifier = referenceElement.getQualifier();
if (qualifier != null) {
appendName(qualifier, builder);
builder.append(".");
}
builder.append(refName);
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GrTypeDefinitionStub method getBaseClassReference.
@Nullable
public GrCodeReferenceElement getBaseClassReference() {
String baseClassName = getBaseClassName();
if (baseClassName == null)
return null;
GrCodeReferenceElement reference = SoftReference.dereference(myStubBaseReference);
if (reference == null) {
reference = GroovyPsiElementFactory.getInstance(getProject()).createReferenceElementFromText(baseClassName, getPsi());
myStubBaseReference = new SoftReference<>(reference);
}
return reference;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class ResolveUtil method resolveAnnotation.
@Nullable
public static PsiClass resolveAnnotation(PsiElement insideAnnotation) {
final GrAnnotation annotation = PsiTreeUtil.getParentOfType(insideAnnotation, GrAnnotation.class, false);
if (annotation == null)
return null;
final GrCodeReferenceElement reference = annotation.getClassReference();
final GroovyResolveResult result = reference.advancedResolve();
final PsiElement element = result.getElement();
if (element instanceof PsiClass && ((PsiClass) element).isAnnotationType())
return (PsiClass) element;
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GrMainCompletionProvider method completeStaticMembers.
static StaticMemberProcessor completeStaticMembers(CompletionParameters parameters) {
final PsiElement position = parameters.getPosition();
final PsiElement originalPosition = parameters.getOriginalPosition();
final StaticMemberProcessor processor = new StaticMemberProcessor(position) {
@NotNull
@Override
protected LookupElement createLookupElement(@NotNull PsiMember member, @NotNull PsiClass containingClass, boolean shouldImport) {
shouldImport |= originalPosition != null && PsiTreeUtil.isAncestor(containingClass, originalPosition, false);
return createGlobalMemberElement(member, containingClass, shouldImport);
}
@Override
protected LookupElement createLookupElement(@NotNull List<PsiMethod> overloads, @NotNull PsiClass containingClass, boolean shouldImport) {
shouldImport |= originalPosition != null && PsiTreeUtil.isAncestor(containingClass, originalPosition, false);
return new JavaGlobalMemberLookupElement(overloads, containingClass, QualifiedMethodInsertHandler.INSTANCE, StaticImportInsertHandler.INSTANCE, shouldImport);
}
@Override
protected boolean isAccessible(PsiMember member) {
boolean result = super.isAccessible(member);
if (!result && member instanceof GrField) {
GrAccessorMethod[] getters = ((GrField) member).getGetters();
return getters.length > 0 && super.isAccessible(getters[0]);
}
return result;
}
};
final PsiFile file = position.getContainingFile();
if (file instanceof GroovyFile) {
for (GrImportStatement statement : ((GroovyFile) file).getImportStatements()) {
if (statement.isStatic()) {
GrCodeReferenceElement importReference = statement.getImportReference();
if (importReference != null) {
if (!statement.isOnDemand()) {
importReference = importReference.getQualifier();
}
if (importReference != null) {
final PsiElement target = importReference.resolve();
if (target instanceof PsiClass) {
processor.importMembersOf((PsiClass) target);
}
}
}
}
}
}
return processor;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GroovyClassNameInsertHandler method findNewExpression.
@Nullable
private static GrNewExpression findNewExpression(@Nullable PsiElement position) {
if (position == null)
return null;
final PsiElement reference = position.getParent();
if (!(reference instanceof GrCodeReferenceElement))
return null;
PsiElement parent = reference.getParent();
while (parent instanceof GrCodeReferenceElement) parent = parent.getParent();
if (parent instanceof GrAnonymousClassDefinition)
parent = parent.getParent();
return parent instanceof GrNewExpression ? (GrNewExpression) parent : null;
}
Aggregations