use of com.intellij.psi.PsiAnnotation in project android by JetBrains.
the class AndroidLintAnimatorKeepInspection method getQuickFixes.
@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
return new AndroidLintQuickFix[] { new AndroidLintQuickFix() {
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
if (!ObjectAnimatorDetector.isAddKeepErrorMessage(message, TextFormat.RAW)) {
return;
}
PsiModifierListOwner container = PsiTreeUtil.getParentOfType(startElement, PsiModifierListOwner.class);
if (container == null) {
return;
}
if (!FileModificationService.getInstance().preparePsiElementForWrite(container)) {
return;
}
final PsiModifierList modifierList = container.getModifierList();
if (modifierList != null) {
PsiAnnotation annotation = AnnotationUtil.findAnnotation(container, KEEP_ANNOTATION);
if (annotation == null) {
Project project = startElement.getProject();
new AddAnnotationFix(KEEP_ANNOTATION, container).invoke(project, null, container.getContainingFile());
}
}
}
@Override
public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
return true;
}
@NotNull
@Override
public String getName() {
return "Annotate with @Keep";
}
} };
}
use of com.intellij.psi.PsiAnnotation in project intellij by bazelbuild.
the class TestSizeAnnotationMap method getTestSize.
@Nullable
private static TestSize getTestSize(PsiAnnotation[] annotations) {
for (PsiAnnotation annotation : annotations) {
String qualifiedName = annotation.getQualifiedName();
TestSize testSize = ANNOTATION_TO_TEST_SIZE.get(qualifiedName);
if (testSize != null) {
return testSize;
}
}
return null;
}
use of com.intellij.psi.PsiAnnotation in project google-cloud-intellij by GoogleCloudPlatform.
the class ApiNamespaceInspectionTest method runQuickFixTest.
private void runQuickFixTest(String annotationString, String expectedString) {
final Project myProject = myFixture.getProject();
PsiAnnotation annotation = JavaPsiFacade.getInstance(myProject).getElementFactory().createAnnotationFromText(annotationString, null);
MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotation, "", ProblemHighlightType.ERROR);
ApiNamespaceInspection.MyQuickFix myQuickFix = new ApiNamespaceInspection().new MyQuickFix();
myQuickFix.applyFix(myProject, problemDescriptor);
assertEquals(expectedString, annotation.getText());
}
use of com.intellij.psi.PsiAnnotation in project google-cloud-intellij by GoogleCloudPlatform.
the class FullMethodNameInspectionTest method testQuickFix_ApiMethodAnnotation.
/**
* Tests that the FullMethodNameInspection's quick fix updates the name attribute of {@link
* GctConstants.APP_ENGINE_ANNOTATION_API_METHOD} by adding "_1" as a suffix.
*/
public void testQuickFix_ApiMethodAnnotation() {
Project myProject = myFixture.getProject();
String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_METHOD + "(name = \"someName\")";
PsiAnnotation annotation = JavaPsiFacade.getInstance(myProject).getElementFactory().createAnnotationFromText(annotationString, null);
FullMethodNameInspection.MyQuickFix myQuickFix = new FullMethodNameInspection().new MyQuickFix();
MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotation, "", ProblemHighlightType.ERROR);
myQuickFix.applyFix(myProject, problemDescriptor);
Assert.assertEquals("@" + GctConstants.APP_ENGINE_ANNOTATION_API_METHOD + "(name = \"someName_1\")", annotation.getText());
}
use of com.intellij.psi.PsiAnnotation in project google-cloud-intellij by GoogleCloudPlatform.
the class RestSignatureInspection method getHttpMethod.
/**
* Returns the http method of the specified psiMethod. The httpMethod can be set by the user by
* setting the httpMethod attribute in @ApiMethod. If the httpMethod attribute of the @ApiMethod
* is not set, the default value of the method is used.
*
* @param psiMethod the method hose HTTP method is to be determined
* @return the http Method pf psiMethod
*/
public String getHttpMethod(PsiMethod psiMethod) {
PsiModifierList modifierList = psiMethod.getModifierList();
String httpMethod = null;
// Check if the httpMethod was specified by uses in @ApiMethod's httpMethod attribute
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
try {
httpMethod = getAttributeFromAnnotation(annotation, GctConstants.APP_ENGINE_ANNOTATION_API_METHOD, "httpMethod");
} catch (InvalidAnnotationException ex) {
// do nothing
} catch (MissingAttributeException ex) {
break;
}
if (httpMethod != null && !httpMethod.isEmpty()) {
return httpMethod;
}
}
// Create httpMethod from method name
return getDefaultRestMethod(psiMethod).getHttpMethod();
}
Aggregations