public static SignatureAnnotationRewriteOperation createAddAnnotationOperation(CompilationUnit compilationUnit, IProblemLocation problem, String annotationToAdd, String annotationToRemove, Set<String> handledPositions, boolean thisUnitOnly, boolean allowRemove, boolean isArgumentProblem, ChangeKind changeKind) { // precondition: // thisUnitOnly => changeKind == LOCAL SignatureAnnotationRewriteOperation result; if (changeKind == ChangeKind.OVERRIDDEN) result= createAddAnnotationToOverriddenOperation(compilationUnit, problem, annotationToAdd, annotationToRemove, allowRemove); else result= createAddAnnotationOperation(compilationUnit, problem, annotationToAdd, annotationToRemove, changeKind == ChangeKind.TARGET, thisUnitOnly, allowRemove, isArgumentProblem); if (handledPositions != null && result != null) { if (handledPositions.contains(result.getKey())) return null; handledPositions.add(result.getKey()); } return result; }
operation.fNonNullByDefaultNames= RedundantNullnessTypeAnnotationsFilter.determineNonNullByDefaultNames(javaElement.getJavaProject()); return new NullAnnotationsFix(operation.getMessage(), operation.getCompilationUnit(), // note that this uses the findings from createAddAnnotationOperation(..) new NullAnnotationsRewriteOperations.SignatureAnnotationRewriteOperation[] { operation });
operation.fNonNullByDefaultName= getNonNullByDefaultAnnotationName(compilationUnit.getJavaElement(), false); return new NullAnnotationsFix(operation.getMessage(), operation.getCompilationUnit(), // note that this uses the findings from createAddAnnotationOperation(..) new NullAnnotationsRewriteOperations.SignatureAnnotationRewriteOperation[] { operation });
boolean hasNonNullDefault(IBinding enclosingElement) { if (!fRemoveIfNonNullByDefault) return false; IAnnotationBinding[] annotations = enclosingElement.getAnnotations(); for (int i= 0; i < annotations.length; i++) { IAnnotationBinding annot = annotations[i]; if (annot.getAnnotationType().getQualifiedName().equals(fNonNullByDefaultName)) { IMemberValuePairBinding[] pairs= annot.getDeclaredMemberValuePairs(); if (pairs.length > 0) { // is default cancelled by "false" or "value=false" ? for (int j= 0; j < pairs.length; j++) if (pairs[j].getKey() == null || pairs[j].getKey().equals("value")) //$NON-NLS-1$ return (pairs[j].getValue() != Boolean.FALSE); } return true; } } if (enclosingElement instanceof IMethodBinding) { return hasNonNullDefault(((IMethodBinding)enclosingElement).getDeclaringClass()); } else if (enclosingElement instanceof ITypeBinding) { ITypeBinding typeBinding= (ITypeBinding)enclosingElement; if (typeBinding.isLocal()) return hasNonNullDefault(typeBinding.getDeclaringMethod()); else if (typeBinding.isMember()) return hasNonNullDefault(typeBinding.getDeclaringClass()); else return hasNonNullDefault(typeBinding.getPackage()); } return false; }
public SignatureAnnotationRewriteOperation createAddAnnotationOperation(Set<String> handledPositions, boolean thisUnitOnly, ChangeKind changeKind) { // precondition: // thisUnitOnly => changeKind == LOCAL SignatureAnnotationRewriteOperation result; if (changeKind == ChangeKind.OVERRIDDEN) result= createAddAnnotationToOverriddenOperation(); else result= createAddAnnotationOperation(changeKind == ChangeKind.TARGET, thisUnitOnly); if (handledPositions != null && result != null) { if (handledPositions.contains(result.getKey())) return null; handledPositions.add(result.getKey()); } return result; }