private boolean hasParameterName(PsiParameter psiParameter) { PsiModifierList modifierList = psiParameter.getModifierList(); if (modifierList == null) { return false; } PsiAnnotation annotation = modifierList.findAnnotation("javax.inject.Named"); if (annotation != null) { return true; } annotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED); if (annotation != null) { return true; } return false; }
public boolean accepts(@NotNull final T t, final ProcessingContext context) { final PsiModifierList modifierList = t.getModifierList(); return modifierList != null && modifierList.findAnnotation(qualifiedName) != null; } });
/** * Checks if the parameter is annotated with the provided {@code annotation}. * * @param psiParameter the parameter on which we need to check for the annotation * @param annotation the annotation that we need to find * * @return {@code true} if the {@code psiParameter} is annotated with the {@code annotation}, {@code false} * otherwise */ private static boolean hasAnnotation(PsiParameter psiParameter, String annotation) { PsiModifierList modifierList = psiParameter.getModifierList(); return modifierList != null && modifierList.findAnnotation( annotation ) != null; }
@NotNull public static Optional<PsiAnnotation> getPsiAnnotation(@NotNull PsiModifierListOwner target, @NotNull Annotation annotation) { PsiModifierList modifierList = target.getModifierList(); return null == modifierList ? Optional.<PsiAnnotation>absent() : Optional.fromNullable(modifierList.findAnnotation(annotation.getQualifiedName())); }
public static boolean isAnnotationPresent(@NotNull PsiModifierListOwner target, @NotNull Annotation annotation) { PsiModifierList modifierList = target.getModifierList(); return null != modifierList && null != modifierList.findAnnotation(annotation.getQualifiedName()); }
private static boolean isJavaScriptAnnotated(PsiClass clz) { while (clz != null) { PsiModifierList modifierList = clz.getModifierList(); if (modifierList != null && modifierList.findAnnotation(JAVASCRIPT_INTERFACE_CLS) != null) { return true; } for (PsiMethod method : clz.getMethods()) { if (method.getModifierList().findAnnotation(JAVASCRIPT_INTERFACE_CLS) != null) { return true; } } clz = clz.getSuperClass(); } return false; } }
/** Remove @Default and @Nullable from the method parameter if they exist. */ @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); if (element == null) { return; } if (!(element instanceof PsiParameter)) { return; } PsiModifierList modifierList = ((PsiParameter) element).getModifierList(); PsiAnnotation gaeNullableAnnotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NULLABLE); if (gaeNullableAnnotation != null) { gaeNullableAnnotation.delete(); } PsiAnnotation javaxNullableAnnotation = modifierList.findAnnotation("javax.annotation.Nullable"); if (javaxNullableAnnotation != null) { javaxNullableAnnotation.delete(); } PsiAnnotation defaultValueAnnotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_DEFAULT_VALUE); if (defaultValueAnnotation != null) { defaultValueAnnotation.delete(); } } }
/** * Returns the value for @Named if it exists for <code>psiParameter</code> or null if it does not * exist. * * @param psiParameter The parameter whose @Named value is to be returned. * @return The @Named value if it exists for <code>psiParameter</code> or null if it does not * exist. */ @Nullable public PsiAnnotationMemberValue getNamedAnnotationValue(PsiParameter psiParameter) { PsiModifierList modifierList = psiParameter.getModifierList(); if (modifierList == null) { return null; } PsiAnnotation annotation = modifierList.findAnnotation("javax.inject.Named"); if (annotation == null) { annotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED); if (annotation == null) { return null; } } PsiNameValuePair[] nameValuePairs = annotation.getParameterList().getAttributes(); if (nameValuePairs.length != 1) { return null; } if (nameValuePairs[0] == null) { return null; } return nameValuePairs[0].getValue(); }
modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_API_TRANSFORMER); if (apiTransformerAnnotation != null) { return true; modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_API); if (apiAnnotation != null) { PsiAnnotationMemberValue transformerMember =
private void checkAnnotationTarget(@NonNull PsiAnnotationMemberValue element, PsiModifierList modifierList) { if (element instanceof PsiReferenceExpression) { PsiReferenceExpression ref = (PsiReferenceExpression) element; if ("TYPE_PARAMETER".equals(ref.getReferenceName()) || "TYPE_USE".equals(ref.getReferenceName())) { PsiAnnotation retention = modifierList .findAnnotation("java.lang.annotation.Retention"); if (retention == null || retention.getText().contains("RUNTIME")) { Location location = mContext.getLocation(element); String message = String.format("Type annotations are not " + "supported in Android: %1$s", ref.getReferenceName()); mContext.report(UNSUPPORTED, element, location, message); } } } }
@Override public void visitClass(UClass uClass) { //only check interface if(!uClass.isInterface()){ return; } Set<PropInfo> infos = getPropInfoWithSupers(uClass); if(infos.isEmpty()){ return; } //check method is relative of any field for(UMethod method: uClass.getMethods()){ PsiModifierList list = method.getModifierList(); PsiAnnotation pa_keep = list.findAnnotation(NAME_KEEP); PsiAnnotation pa_impl = list.findAnnotation(NAME_IMPL_METHOD); if (pa_keep == null && pa_impl == null) { if(!hasPropInfo(infos, method.getName())){ report(method); } } } }
/** * The default generation uses @java.lang.Override for some reason; * Let's clean that up */ void cleanOverrideAnnotation(PsiMethodMember member) { final PsiMethod[] ms = targetClass.findMethodsBySignature( member.getElement(), false); for (PsiMethod m : ms) { PsiModifierList modifierList = m.getModifierList(); PsiAnnotation annotation = modifierList.findAnnotation(Override.class.getName()); if (null != annotation) { annotation.delete(); modifierList.addAnnotation("Override"); } } }
private void initializePsiClass(boolean hasApiTransformerApi, boolean hasTransformerAttribute) { PsiAnnotation mockTransformerAnnotation = null; PsiAnnotation mockApiAnnotation = null; if (hasApiTransformerApi) { // Mock @ApiTransformer(MyTransformer.class)) mockTransformerAnnotation = mock(PsiAnnotation.class); when(mockTransformerAnnotation.getQualifiedName()) .thenReturn(GctConstants.APP_ENGINE_ANNOTATION_API_TRANSFORMER); } if (hasTransformerAttribute) { PsiAnnotationMemberValue mockAnnotationMemberValue = mock(PsiAnnotationMemberValue.class); when(mockAnnotationMemberValue.getText()).thenReturn("MyTransformer.class"); // Mock @Api(transformer = MyTransformer.class) mockApiAnnotation = mock(PsiAnnotation.class); when(mockApiAnnotation.getQualifiedName()).thenReturn(GctConstants.APP_ENGINE_ANNOTATION_API); when(mockApiAnnotation.findAttributeValue(API_TRANSFORMER_ATTRIBUTE)) .thenReturn(mockAnnotationMemberValue); } PsiModifierList mockModifierList = mock(PsiModifierList.class); when(mockModifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_API_TRANSFORMER)) .thenReturn(mockTransformerAnnotation); when(mockModifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_API)) .thenReturn(mockApiAnnotation); mockPsiClass = mock(PsiClass.class); when(mockPsiClass.getModifierList()).thenReturn(mockModifierList); }
if (modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED) != null) { return; if (modifierList.findAnnotation("") != null) { return;
@NonNull private static PermissionHolder addLocalPermissions( @NonNull PermissionHolder permissions, @NonNull PsiElement node) { // Accumulate @RequirePermissions available in the local context PsiMethod method = PsiTreeUtil.getParentOfType(node, PsiMethod.class, true); if (method == null) { return permissions; } PsiAnnotation annotation = method.getModifierList().findAnnotation(PERMISSION_ANNOTATION); permissions = mergeAnnotationPermissions(permissions, annotation); PsiClass containingClass = method.getContainingClass(); if (containingClass != null) { PsiModifierList modifierList = containingClass.getModifierList(); if (modifierList != null) { annotation = modifierList.findAnnotation(PERMISSION_ANNOTATION); permissions = mergeAnnotationPermissions(permissions, annotation); } } return permissions; }
PsiAnnotation annotation = modifierList.findAnnotation("javax.inject.Named"); if (annotation == null) { annotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED); if (annotation == null) { return;
PsiAnnotation annotation = modifierList.findAnnotation("javax.inject.Named"); if (annotation == null) { annotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED); if (annotation == null) { return;
final PsiModifierList modifierList = listOwner.getModifierList(); if (modifierList == null) return false; PsiAnnotation annotation = modifierList.findAnnotation(annotationFQN); if (annotation != null) return true; if (!skipExternal) {
method.getModifierList().findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_API_METHOD); if (apiMethodAnnotation == null) { return; .findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NULLABLE) != null) || (psiParameter.getModifierList().findAnnotation("javax.annotation.Nullable") != null) || (psiParameter .getModifierList() .findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_DEFAULT_VALUE) != null)) { holder.registerProblem(
modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_API_METHOD); if (apiMethodAnnotation == null) { return;