use of com.intellij.psi.PsiAnnotation in project android by JetBrains.
the class AndroidResolveHelperTest method testResolution.
private void testResolution(String text) {
PsiElement element = getPsiElement(text);
assertNotNull(element);
PsiAnnotation annotation = AndroidResolveHelper.getAnnotationForLocal(element, "color");
assertNotNull(annotation);
assertEquals(ResourceEvaluator.COLOR_INT_ANNOTATION, annotation.getQualifiedName());
}
use of com.intellij.psi.PsiAnnotation in project android by JetBrains.
the class AnnotationsRendererTest method createFakeAnnotation.
@NotNull
private static PsiAnnotation createFakeAnnotation(String fqcn) {
PsiAnnotation annotation = mock(PsiAnnotation.class);
when(annotation.getQualifiedName()).thenReturn(fqcn);
return annotation;
}
use of com.intellij.psi.PsiAnnotation in project android by JetBrains.
the class AndroidResolveHelperTest method testColorInt.
public void testColorInt() {
@Language("JAVA") String text = "package p1.p2;\n" + "\n" + "public class Foo {\n" + " @android.support.annotation.ColorInt int mColor;\n" + " \n" + " public void setColor(@android.support.annotation.ColorInt int c) {\n" + " mColor = <caret>c;\n" + " }\n" + "}\n";
PsiElement element = getPsiElement(text);
assertNotNull(element);
PsiAnnotation annotation = AndroidResolveHelper.getAnnotationForLocal(element, "c");
assertNotNull(annotation);
assertEquals(ResourceEvaluator.COLOR_INT_ANNOTATION, annotation.getQualifiedName());
annotation = AndroidResolveHelper.getAnnotationForField(element, "p1.p2.Foo", "mColor");
assertNotNull(annotation);
assertEquals(ResourceEvaluator.COLOR_INT_ANNOTATION, annotation.getQualifiedName());
}
use of com.intellij.psi.PsiAnnotation in project intellij-plugins by JetBrains.
the class CucumberJavaStepDefinitionSearch method execute.
@Override
public boolean execute(@NotNull final ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
final PsiElement myElement = queryParameters.getElementToSearch();
if (!(myElement instanceof PsiMethod)) {
return true;
}
final PsiMethod method = (PsiMethod) myElement;
Boolean isStepDefinition = ReadAction.compute(() -> CucumberJavaUtil.isStepDefinition(method));
if (!isStepDefinition) {
return true;
}
final PsiAnnotation stepAnnotation = ReadAction.compute(() -> CucumberJavaUtil.getCucumberStepAnnotation(method));
final String regexp = CucumberJavaUtil.getPatternFromStepDefinition(stepAnnotation);
if (regexp == null) {
return true;
}
return CucumberUtil.findGherkinReferencesToElement(myElement, regexp, consumer, queryParameters.getEffectiveSearchScope());
}
use of com.intellij.psi.PsiAnnotation in project intellij-community by JetBrains.
the class DelegatesToInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitAnnotation(@NotNull GrAnnotation annotation) {
checkTarget(annotation);
checkDelegatesTo(annotation);
}
private void checkTarget(GrAnnotation annotation) {
if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET.equals(annotation.getQualifiedName()))
return;
final PsiElement owner = annotation.getParent().getParent();
if (!(owner instanceof GrParameter))
return;
final boolean isTargetDeclared = annotation.findDeclaredAttributeValue("value") != null;
String targetName = GrAnnotationUtil.inferStringAttribute(annotation, "value");
final GrParameterList parameterList = DefaultGroovyMethods.asType(owner.getParent(), GrParameterList.class);
for (GrParameter parameter : parameterList.getParameters()) {
final PsiAnnotation delegatesTo = parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO);
if (delegatesTo != null) {
if (isTargetDeclared) {
final String curTarget = GrAnnotationUtil.inferStringAttribute(delegatesTo, "target");
if (curTarget != null && curTarget.equals(targetName)) {
//target is used
return;
}
} else {
if (delegatesTo.findDeclaredAttributeValue("target") == null && delegatesTo.findDeclaredAttributeValue("value") == null) {
// target is used
return;
}
}
}
}
registerError(annotation.getClassReference(), GroovyInspectionBundle.message("target.annotation.is.unused"), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
private void checkDelegatesTo(GrAnnotation annotation) {
if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO.equals(annotation.getQualifiedName()))
return;
final PsiElement owner = annotation.getParent().getParent();
if (!(owner instanceof GrParameter))
return;
final PsiAnnotationMemberValue targetPair = annotation.findDeclaredAttributeValue("target");
if (targetPair == null)
return;
String targetName = GrAnnotationUtil.inferStringAttribute(annotation, "target");
final GrParameterList parameterList = DefaultGroovyMethods.asType(owner.getParent(), GrParameterList.class);
for (GrParameter parameter : parameterList.getParameters()) {
final PsiAnnotation target = parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET);
if (target != null) {
final String curTarget = GrAnnotationUtil.inferStringAttribute(target, "value");
if (curTarget != null && curTarget.equals(targetName)) {
//target is used
return;
}
}
}
registerError(targetPair, GroovyInspectionBundle.message("target.0.does.not.exist", targetName != null ? targetName : "?"), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
};
}
Aggregations