Search in sources :

Example 11 with PsiAnnotation

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";
        }
    } };
}
Also used : Project(com.intellij.openapi.project.Project) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) PsiAnnotation(com.intellij.psi.PsiAnnotation) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) AddAnnotationFix(com.intellij.codeInsight.intention.AddAnnotationFix) PsiModifierList(com.intellij.psi.PsiModifierList) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PsiAnnotation

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;
}
Also used : PsiAnnotation(com.intellij.psi.PsiAnnotation) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 13 with PsiAnnotation

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());
}
Also used : Project(com.intellij.openapi.project.Project) MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 14 with PsiAnnotation

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());
}
Also used : Project(com.intellij.openapi.project.Project) MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 15 with PsiAnnotation

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();
}
Also used : PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiModifierList(com.intellij.psi.PsiModifierList)

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