Bug 81105 [quick fix] Change field to method: does not appear when non-accessible field exists
I20041214-2000 import java.util.HashMap; public class A { { int s= new HashMap().size; // No suggestion int s2= new HashMap().siz; // OK } }
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessor.java
private static ASTRewriteCorrectionProposal getMissingAnnotationsProposal(IInvocationContext context, IProblemLocation problem, String annotationName) {
		ICompilationUnit cu= context.getCompilationUnit();
		ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
		ASTNode declaringNode= null;		
		if (selectedNode instanceof MethodDeclaration) {
			declaringNode= selectedNode;
		} else if (selectedNode instanceof SimpleName) {
			StructuralPropertyDescriptor locationInParent= selectedNode.getLocationInParent();
			if (locationInParent == MethodDeclaration.NAME_PROPERTY || locationInParent == TypeDeclaration.NAME_PROPERTY) {
				declaringNode= selectedNode.getParent();
			} else if (locationInParent == VariableDeclarationFragment.NAME_PROPERTY) {
				declaringNode= selectedNode.getParent().getParent();
			}
		}
		if (declaringNode instanceof BodyDeclaration) {
			BodyDeclaration declaration= (BodyDeclaration) declaringNode;
			AST ast= declaration.getAST();
			ASTRewrite rewrite= ASTRewrite.create(ast);
			ListRewrite listRewrite= rewrite.getListRewrite(declaration, declaration.getModifiersProperty());
			Annotation newAnnotation= ast.newMarkerAnnotation();
			newAnnotation.setTypeName(ast.newSimpleName(annotationName));
			listRewrite.insertFirst(newAnnotation, null);
			
			return new ASTRewriteCorrectionProposal("", cu, rewrite, 5, null); 
		}
		return null;
		
	}
}