How to set the background color of elements according to their visibility modifier in Eclipse?

I would like to set the background color of the fields and methods (at the first level) according to their visibility modifier in Eclipse.

For example, private fields should have a red background, while public fields and methods get green . > background:

enter image description here

Is there a way to configure this in Eclipse?

+5
source share
1 answer

To get this kind of color background, you need to use Markers and MarkerAnnotationSpecification . You will find how to use them here: http://cubussapiens.hu/2011/05/custom-markers-and-annotations-the-bright-side-of-eclipse/

As for how to find private , public fields, you need to use the JDT plugin and AST parser to parse the Java file and find all the information you want. I am adding a small piece of code to get you started with this.

ASTParser parser = ASTParser.newParser(AST_LEVEL); parser.setSource(cmpUnit); parser.setResolveBindings(true); CompilationUnit astRoot = (CompilationUnit) parser.createAST(null); AST ast = astRoot.getAST(); TypeDeclaration javaType = null; Object type = astRoot.types().get(0); if (type instanceof TypeDeclaration) { javaType = ((TypeDeclaration) type); } List<FieldDeclarationInfo> fieldDeclarations = new ArrayList<FieldDeclarationInfo>(); // Get the field info for (FieldDeclaration fieldDeclaration : javaType.getFields()) { // From this object you can recover all the information that you want about the fields. } 

Here cmpUnit is an ICompilationUnit Java file.

+1
source

Source: https://habr.com/ru/post/1234014/


All Articles