use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.
the class NewInstanceOfSingletonInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitNewExpression(@NotNull GrNewExpression newExpression) {
if (newExpression.getArrayDeclaration() != null)
return;
GrCodeReferenceElement refElement = newExpression.getReferenceElement();
if (refElement == null)
return;
PsiElement resolved = refElement.resolve();
if (!(resolved instanceof GrTypeDefinition))
return;
PsiAnnotation annotation = AnnotationUtil.findAnnotation((GrTypeDefinition) resolved, GROOVY_LANG_SINGLETON);
if (annotation == null)
return;
registerError(newExpression, GroovyInspectionBundle.message("new.instance.of.singleton"), ContainerUtil.ar(new ReplaceWithInstanceAccessFix()), ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
};
}
use of com.intellij.psi.PsiAnnotation 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 com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.
the class GrAnnotationArgumentListImpl method addInternal.
@Override
public ASTNode addInternal(ASTNode first, ASTNode last, ASTNode anchor, Boolean before) {
if (first.getElementType() == GroovyElementTypes.ANNOTATION_MEMBER_VALUE_PAIR && last.getElementType() == GroovyElementTypes.ANNOTATION_MEMBER_VALUE_PAIR) {
ASTNode lparenth = getNode().getFirstChildNode();
ASTNode rparenth = getNode().getLastChildNode();
if (lparenth == null) {
getNode().addLeaf(GroovyTokenTypes.mLPAREN, "(", null);
}
if (rparenth == null) {
getNode().addLeaf(GroovyTokenTypes.mRPAREN, ")", null);
}
final PsiNameValuePair[] nodes = getAttributes();
if (nodes.length == 1) {
final PsiNameValuePair pair = nodes[0];
if (pair.getName() == null) {
final String text = pair.getValue().getText();
try {
final PsiAnnotation annotation = GroovyPsiElementFactory.getInstance(getProject()).createAnnotationFromText("@AAA(value = " + text + ")");
getNode().replaceChild(pair.getNode(), annotation.getParameterList().getAttributes()[0].getNode());
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
}
if (anchor == null && before != null) {
anchor = before.booleanValue() ? getNode().getLastChildNode() : getNode().getFirstChildNode();
}
}
return super.addInternal(first, last, anchor, before);
}
use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.
the class AnnotationAttributeCompletionResultProcessor method process.
public void process(@NotNull Consumer<LookupElement> consumer, @NotNull PrefixMatcher matcher) {
GrCodeReferenceElement ref = myAnnotation.getClassReference();
PsiElement resolved = ref.resolve();
if (resolved instanceof PsiClass) {
final PsiAnnotation annotationCollector = GrAnnotationCollector.findAnnotationCollector((PsiClass) resolved);
if (annotationCollector != null) {
final ArrayList<GrAnnotation> annotations = ContainerUtil.newArrayList();
GrAnnotationCollector.collectAnnotations(annotations, myAnnotation, annotationCollector);
Set<String> usedNames = ContainerUtil.newHashSet();
for (GrAnnotation annotation : annotations) {
final PsiElement resolvedAliased = annotation.getClassReference().resolve();
if (resolvedAliased instanceof PsiClass && ((PsiClass) resolvedAliased).isAnnotationType()) {
for (PsiMethod method : ((PsiClass) resolvedAliased).getMethods()) {
if (usedNames.add(method.getName())) {
for (LookupElement element : GroovyCompletionUtil.createLookupElements(new GroovyResolveResultImpl(method, true), false, matcher, null)) {
consumer.consume(element);
}
}
}
}
}
} else if (((PsiClass) resolved).isAnnotationType()) {
for (PsiMethod method : ((PsiClass) resolved).getMethods()) {
for (LookupElement element : GroovyCompletionUtil.createLookupElements(new GroovyResolveResultImpl(method, true), false, matcher, null)) {
consumer.consume(element);
}
}
}
}
}
use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.
the class ExternalBuilderStrategySupport method applyTransformation.
@Override
public void applyTransformation(@NotNull TransformationContext context) {
PsiAnnotation annotation = PsiImplUtil.getAnnotation(context.getCodeClass(), BUILDER_FQN);
if (!isApplicable(annotation, EXTERNAL_STRATEGY_NAME))
return;
final PsiClass constructedClass = GrAnnotationUtil.inferClassAttribute(annotation, "forClass");
if (constructedClass == null || "groovy.transform.Undefined.CLASS".equals(constructedClass.getQualifiedName()))
return;
if (constructedClass instanceof GrTypeDefinition) {
for (GrField field : ((GrTypeDefinition) constructedClass).getCodeFields()) {
context.addMethod(DefaultBuilderStrategySupport.createFieldSetter(context.getCodeClass(), field, annotation));
}
} else {
for (PsiMethod setter : PropertyUtil.getAllProperties(constructedClass, true, false).values()) {
final PsiMethod builderSetter = createFieldSetter(context.getCodeClass(), setter, annotation);
if (builderSetter != null)
context.addMethod(builderSetter);
}
}
context.addMethod(createBuildMethod(annotation, createType(constructedClass)));
}
Aggregations