use of com.intellij.psi.PsiAnnotation in project google-cloud-intellij by GoogleCloudPlatform.
the class NamedResourceInspectionTest method testQuickFix_noQueryNameSpecifiedWithoutParameter.
/**
* Tests that the NamedResourceInspection's quick fix flagged with {@link
* NamedResourceError#MISSING_NAME} for an @Named annotation with no parent updates the query name
* to "myName".
*/
public void testQuickFix_noQueryNameSpecifiedWithoutParameter() {
Project myProject = myFixture.getProject();
String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "()";
PsiAnnotation annotation = JavaPsiFacade.getInstance(myProject).getElementFactory().createAnnotationFromText(annotationString, null);
NamedResourceInspection.MissingNameQuickFix myQuickFix = new NamedResourceInspection().new MissingNameQuickFix();
MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotation, "", ProblemHighlightType.ERROR);
myQuickFix.applyFix(myProject, problemDescriptor);
assertEquals("@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "(\"myName\")", annotation.getText());
}
use of com.intellij.psi.PsiAnnotation in project google-cloud-intellij by GoogleCloudPlatform.
the class NamedResourceInspectionTest method testQuickFix_noQueryNameSpecifiedWithParameter.
/**
* Tests that the NamedResourceInspection's quick fix flagged with {@link
* NamedResourceError#MISSING_NAME} for an @Named annotation with a {@link PsiParameter} parent
* updates the query name to to the name of the {@link PsiParameter}.
*/
public void testQuickFix_noQueryNameSpecifiedWithParameter() {
Project myProject = myFixture.getProject();
PsiParameter parameter = JavaPsiFacade.getInstance(myProject).getElementFactory().createParameterFromText("@javax.inject.Named() String foobar", null);
PsiAnnotation[] annotationsList = parameter.getModifierList().getAnnotations();
assert (annotationsList.length == 1);
NamedResourceInspection.MissingNameQuickFix myQuickFix = new NamedResourceInspection().new MissingNameQuickFix();
MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotationsList[0], "", ProblemHighlightType.ERROR);
myQuickFix.applyFix(myProject, problemDescriptor);
assertEquals("@javax.inject.Named(\"foobar\")", annotationsList[0].getText());
}
use of com.intellij.psi.PsiAnnotation in project google-cloud-intellij by GoogleCloudPlatform.
the class RestSignatureInspectionTest method initializePsiMethod.
private void initializePsiMethod(String methodName, String httpMethodValue, String pathValue) {
PsiAnnotationMemberValue mockAnnotationMemberValue1 = mock(PsiAnnotationMemberValue.class);
when(mockAnnotationMemberValue1.getText()).thenReturn(httpMethodValue);
PsiAnnotationMemberValue mockAnnotationMemberValue2 = mock(PsiAnnotationMemberValue.class);
when(mockAnnotationMemberValue2.getText()).thenReturn(pathValue);
PsiAnnotation mockAnnotation = mock(PsiAnnotation.class);
when(mockAnnotation.getQualifiedName()).thenReturn(GctConstants.APP_ENGINE_ANNOTATION_API_METHOD);
when(mockAnnotation.findAttributeValue("httpMethod")).thenReturn(mockAnnotationMemberValue1);
when(mockAnnotation.findAttributeValue("path")).thenReturn(mockAnnotationMemberValue2);
PsiAnnotation[] mockAnnotationsArray = { mockAnnotation };
PsiModifierList mockModifierList = mock(PsiModifierList.class);
when(mockModifierList.getAnnotations()).thenReturn(mockAnnotationsArray);
mockPsiMethod = mock(PsiMethod.class);
when(mockPsiMethod.getModifierList()).thenReturn(mockModifierList);
when(mockPsiMethod.getName()).thenReturn(methodName);
when(mockPsiMethod.getContainingClass()).thenReturn(mockPsiClass);
PsiParameterList mockParameterList = mock(PsiParameterList.class);
when(mockParameterList.getParameters()).thenReturn(new PsiParameter[0]);
when(mockPsiMethod.getParameterList()).thenReturn(mockParameterList);
}
use of com.intellij.psi.PsiAnnotation in project google-cloud-intellij by GoogleCloudPlatform.
the class FullMethodNameInspectionTest method testQuickFix_NonApiMethodAnnotation.
/**
* Tests that the FullMethodNameInspection's quick fix does not update an annotation that is not
* {@link GctConstants.APP_ENGINE_ANNOTATION_API_METHOD}
*/
public void testQuickFix_NonApiMethodAnnotation() {
Project myProject = myFixture.getProject();
String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "(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(annotationString, annotation.getText());
}
use of com.intellij.psi.PsiAnnotation in project azure-tools-for-java by Microsoft.
the class FunctionUtils method patchStorageBinding.
private static void patchStorageBinding(final PsiMethod method, final List<Binding> bindings) {
final PsiAnnotation storageAccount = AnnotationUtil.findAnnotation(method, StorageAccount.class.getCanonicalName());
if (storageAccount != null) {
// todo: Remove System.out.println
System.out.println(message("function.binding.storage.found"));
final String connectionString = AnnotationUtil.getDeclaredStringAttributeValue(storageAccount, "value");
// Replace empty connection string
bindings.stream().filter(binding -> binding.getBindingEnum().isStorage()).filter(binding -> StringUtils.isEmpty((String) binding.getAttribute("connection"))).forEach(binding -> binding.setAttribute("connection", connectionString));
} else {
// todo: Remove System.out.println
System.out.println(message("function.binding.storage.notFound"));
}
}
Aggregations