Search in sources :

Example 6 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project android by JetBrains.

the class AndroidResolveHelperTest method testIntDefResolution.

public void testIntDefResolution() {
    @Language("JAVA") String text = "package p1.p2;\n" + "\n" + "import java.lang.annotation.Retention;\n" + "import java.lang.annotation.RetentionPolicy;\n" + "\n" + "public class Foo {\n" + "    public static final int INVISIBLE = 0x00000004;\n" + "    public static final int VISIBLE = 0x00000000;\n" + "    public static final int GONE = 0x00000008;\n" + "\n" + "    @android.support.annotation.IntDef({VISIBLE, INVISIBLE, GONE})\n" + "    @Retention(RetentionPolicy.SOURCE)\n" + "    public @interface Visibility {}\n" + "\n" + "    @Foo.Visibility\n" + "    private int mVisibility;  \n" + "\n" + "    public void setVisibility(@Foo.Visibility int v) {\n" + "        mVis<caret>ibility = v;\n" + "    }\n" + "}\n";
    PsiElement element = getPsiElement(text);
    assertNotNull(element);
    PsiAnnotation annotation = AndroidResolveHelper.getAnnotationForLocal(element, "v");
    assertNotNull(annotation);
    assertEquals(SdkConstants.INT_DEF_ANNOTATION, annotation.getQualifiedName());
    AndroidResolveHelper.IntDefResolution result = AndroidResolveHelper.resolveIntDef(annotation);
    assertFalse(result.canBeOred);
    Map<Integer, String> map = result.valuesMap;
    assertNotNull(map);
    assertEquals(3, map.size());
    assertEquals("INVISIBLE", map.get(4));
    assertEquals("VISIBLE", map.get(0));
    assertEquals("GONE", map.get(8));
}
Also used : Language(org.intellij.lang.annotations.Language) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.

the class GrAliasAnnotationChecker method checkArgumentList.

@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
    final PsiAnnotation annotationCollector = GrAnnotationCollector.findAnnotationCollector(annotation);
    if (annotationCollector == null) {
        return false;
    }
    final ArrayList<GrAnnotation> annotations = ContainerUtil.newArrayList();
    final Set<String> usedAttributes = GrAnnotationCollector.collectAnnotations(annotations, annotation, annotationCollector);
    AliasedAnnotationHolder aliasedHolder = new AliasedAnnotationHolder(holder, annotation);
    AnnotationChecker checker = new AnnotationChecker(aliasedHolder);
    for (GrAnnotation aliased : annotations) {
        checker.checkAnnotationArgumentList(aliased);
    }
    final GrAnnotationNameValuePair[] attributes = annotation.getParameterList().getAttributes();
    final String aliasQName = annotation.getQualifiedName();
    if (attributes.length == 1 && attributes[0].getNameIdentifierGroovy() == null && !usedAttributes.contains("value")) {
        holder.createErrorAnnotation(attributes[0], GroovyBundle.message("at.interface.0.does.not.contain.attribute", aliasQName, "value"));
    }
    for (GrAnnotationNameValuePair pair : attributes) {
        final PsiElement nameIdentifier = pair.getNameIdentifierGroovy();
        if (nameIdentifier != null && !usedAttributes.contains(pair.getName())) {
            holder.createErrorAnnotation(nameIdentifier, GroovyBundle.message("at.interface.0.does.not.contain.attribute", aliasQName, pair.getName()));
        }
    }
    return true;
}
Also used : GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) GrAnnotationNameValuePair(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.

the class GroovySuppressableInspectionTool method getInspectionIdsSuppressedInAnnotation.

@NotNull
private static Collection<String> getInspectionIdsSuppressedInAnnotation(final GrModifierList modifierList) {
    if (modifierList == null) {
        return Collections.emptyList();
    }
    PsiAnnotation annotation = modifierList.findAnnotation(BatchSuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
    if (annotation == null) {
        return Collections.emptyList();
    }
    final GrAnnotationMemberValue attributeValue = (GrAnnotationMemberValue) annotation.findAttributeValue(null);
    Collection<String> result = new ArrayList<>();
    if (attributeValue instanceof GrAnnotationArrayInitializer) {
        for (GrAnnotationMemberValue annotationMemberValue : ((GrAnnotationArrayInitializer) attributeValue).getInitializers()) {
            final String id = getInspectionIdSuppressedInAnnotationAttribute(annotationMemberValue);
            if (id != null) {
                result.add(id);
            }
        }
    } else {
        final String id = getInspectionIdSuppressedInAnnotationAttribute(attributeValue);
        if (id != null) {
            result.add(id);
        }
    }
    return result;
}
Also used : GrAnnotationMemberValue(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue) ArrayList(java.util.ArrayList) PsiAnnotation(com.intellij.psi.PsiAnnotation) GrAnnotationArrayInitializer(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.

the class SimpleBuilderStrategySupport method applyTransformation.

@Override
public void applyTransformation(@NotNull TransformationContext context) {
    GrTypeDefinition typeDefinition = context.getCodeClass();
    final PsiAnnotation annotation = PsiImplUtil.getAnnotation(typeDefinition, BUILDER_FQN);
    if (!isApplicable(annotation, SIMPLE_STRATEGY_NAME))
        return;
    for (GrField field : typeDefinition.getCodeFields()) {
        context.addMethod(createFieldSetter(typeDefinition, field, annotation));
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 10 with PsiAnnotation

use of com.intellij.psi.PsiAnnotation in project intellij-plugins by JetBrains.

the class CucumberJavaMethodUsageSearcher method processQuery.

@Override
public void processQuery(@NotNull final MethodReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
    SearchScope scope = p.getEffectiveSearchScope();
    if (!(scope instanceof GlobalSearchScope)) {
        return;
    }
    final PsiMethod method = p.getMethod();
    final PsiAnnotation stepAnnotation = CucumberJavaUtil.getCucumberStepAnnotation(method);
    final String regexp = stepAnnotation != null ? CucumberJavaUtil.getPatternFromStepDefinition(stepAnnotation) : null;
    if (regexp == null) {
        return;
    }
    final String word = CucumberUtil.getTheBiggestWordToSearchByIndex(regexp);
    if (StringUtil.isEmpty(word)) {
        return;
    }
    final GlobalSearchScope restrictedScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope) scope, GherkinFileType.INSTANCE);
    ReferencesSearch.search(new ReferencesSearch.SearchParameters(method, restrictedScope, false, p.getOptimizer())).forEach(consumer);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiMethod(com.intellij.psi.PsiMethod) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Aggregations

PsiAnnotation (com.intellij.psi.PsiAnnotation)61 PsiModifierList (com.intellij.psi.PsiModifierList)18 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)14 PsiMethod (com.intellij.psi.PsiMethod)14 NotNull (org.jetbrains.annotations.NotNull)13 Project (com.intellij.openapi.project.Project)12 PsiClass (com.intellij.psi.PsiClass)11 PsiElement (com.intellij.psi.PsiElement)9 MockProblemDescriptor (com.intellij.testFramework.MockProblemDescriptor)6 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)5 PsiParameter (com.intellij.psi.PsiParameter)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5 Nullable (org.jetbrains.annotations.Nullable)5 PsiParameterList (com.intellij.psi.PsiParameterList)4 TestSize (com.google.idea.blaze.base.dependencies.TestSize)3 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)3 PsiNameValuePair (com.intellij.psi.PsiNameValuePair)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Nullable (javax.annotation.Nullable)3