use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrAliasAnnotationChecker method checkApplicability.
@Override
public boolean checkApplicability(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
final ArrayList<GrAnnotation> aliasedAnnotations = getAliasedAnnotations(annotation);
if (aliasedAnnotations == null) {
return false;
}
AliasedAnnotationHolder aliasedHolder = new AliasedAnnotationHolder(holder, annotation);
AnnotationChecker checker = new AnnotationChecker(aliasedHolder);
for (GrAnnotation aliased : aliasedAnnotations) {
checker.checkApplicability(aliased, annotation.getOwner());
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrAliasAnnotationChecker method getAliasedAnnotations.
@Nullable
private static ArrayList<GrAnnotation> getAliasedAnnotations(GrAnnotation annotation) {
final PsiAnnotation annotationCollector = GrAnnotationCollector.findAnnotationCollector(annotation);
if (annotationCollector == null)
return null;
final ArrayList<GrAnnotation> aliasedAnnotations = ContainerUtil.newArrayList();
GrAnnotationCollector.collectAnnotations(aliasedAnnotations, annotation, annotationCollector);
return aliasedAnnotations;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrabDependencies method isAvailable.
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!isCorrectModule(file))
return false;
int offset = editor.getCaretModel().getOffset();
final GrAnnotation anno = PsiTreeUtil.findElementOfClassAtOffset(file, offset, GrAnnotation.class, false);
if (anno != null && isGrabAnnotation(anno)) {
return true;
}
PsiElement at = file.findElementAt(offset);
if (at != null && isUnresolvedRefName(at) && findGrab(file) != null) {
return true;
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrClassImplUtil method processDeclarations.
public static boolean processDeclarations(@NotNull GrTypeDefinition grType, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
if (place instanceof GrCodeReferenceElement && lastParent instanceof GrModifierList) {
final PsiElement possibleAnnotation = PsiTreeUtil.skipParentsOfType(place, GrCodeReferenceElement.class);
if (possibleAnnotation instanceof GrAnnotation && possibleAnnotation.getParent() == lastParent) {
//don't process class members while resolving annotation which annotates current class
return true;
}
}
for (final PsiTypeParameter typeParameter : grType.getTypeParameters()) {
if (!ResolveUtil.processElement(processor, typeParameter, state))
return false;
}
NameHint nameHint = processor.getHint(NameHint.KEY);
String name = nameHint == null ? null : nameHint.getName(state);
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
final PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject());
boolean processInstanceMethods = (ResolveUtil.shouldProcessMethods(classHint) || ResolveUtil.shouldProcessProperties(classHint)) && shouldProcessInstanceMembers(grType, lastParent);
LanguageLevel level = PsiUtil.getLanguageLevel(place);
if (ResolveUtil.shouldProcessProperties(classHint)) {
Map<String, CandidateInfo> fieldsMap = CollectClassMembersUtil.getAllFields(grType);
if (name != null) {
CandidateInfo fieldInfo = fieldsMap.get(name);
if (fieldInfo != null) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, fieldInfo)) {
return false;
}
} else if (grType.isTrait() && lastParent != null) {
PsiField field = findFieldByName(grType, name, false, true);
if (field != null && field.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
return false;
}
}
}
} else {
for (CandidateInfo info : fieldsMap.values()) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, info)) {
return false;
}
}
if (grType.isTrait() && lastParent != null) {
for (PsiField field : CollectClassMembersUtil.getFields(grType, true)) {
if (field.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
return false;
}
}
}
}
}
}
if (ResolveUtil.shouldProcessMethods(classHint)) {
Map<String, List<CandidateInfo>> methodsMap = CollectClassMembersUtil.getAllMethods(grType, true);
boolean isPlaceGroovy = place.getLanguage() == GroovyLanguage.INSTANCE;
if (name == null) {
for (List<CandidateInfo> list : methodsMap.values()) {
for (CandidateInfo info : list) {
if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
return false;
}
}
}
} else {
List<CandidateInfo> byName = methodsMap.get(name);
if (byName != null) {
for (CandidateInfo info : byName) {
if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
return false;
}
}
}
}
}
final GrTypeDefinitionBody body = grType.getBody();
if (body != null) {
if (ResolveUtil.shouldProcessClasses(classHint)) {
for (PsiClass innerClass : getInnerClassesForResolve(grType, lastParent, place)) {
if (name != null && !name.equals(innerClass.getName()))
continue;
if (!processor.execute(innerClass, state))
return false;
}
}
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation 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;
}
Aggregations