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));
}
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;
}
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;
}
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));
}
}
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);
}
Aggregations