#author("2023-06-25T18:40:49+09:00","","") #author("2023-06-25T18:43:55+09:00","","") [[ソフトウェア開発>SoftwareEngineering]] / [[Java>../../]] / [[JDT>../]] / [[example>./]] * Example [#l9b80ff8] #contents ** AppEntry [#fa0e7351] #highlightjs([java]) package org.codereign; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import org.codereign.jdt.ExampleVisitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.CompilationUnit; public class AppEntry { public static void main(String[] args) throws IOException { File targetDirectory = new File("C:\\pleiades\\4.18.0\\workspace\\JavaAnalyser\\src"); List<File> files = getJavaFiles(targetDirectory); for (File file : files) { Path path = Paths.get(file.getAbsolutePath()); char[] source = getSource(path); ASTParser parser = ASTParser.newParser(AST.JLS_Latest); parser.setSource(source); CompilationUnit unit = (CompilationUnit) parser.createAST(new NullProgressMonitor()); ASTVisitor visitor = new ExampleVisitor(); unit.accept(visitor); } } public static char[] getSource(final Path path) throws IOException { return Files.lines(path).collect(Collectors.joining(System.lineSeparator())).toCharArray(); } public static List<File> getJavaFiles(File directory) { List<File> files = new ArrayList<File>(); for (File file : directory.listFiles()) { if (file.isDirectory()) { files.addAll(getJavaFiles(file)); } else if (file.getName().endsWith(".java")) { files.add(file); } } return files; } } ** ExampleVisitor [#sa1334ea] #highlightjs([java]) package org.codereign; import java.nio.file.Path; import org.codereign.jdt.Status; import org.codereign.jdt.StatusBuilder; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.MarkerAnnotation; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.TypeDeclaration; public class ExampleVisitor extends ASTVisitor { private Path path; private CompilationUnit unit; public ExampleVisitor(final Path path) { this.path = path; } @SuppressWarnings("unchecked") private <T> T findByParentNode(ASTNode node, Class<T> clazz) { T instance = null; ASTNode parentNode = node.getParent(); while (parentNode != null) { if (clazz.isAssignableFrom(parentNode.getClass())) { instance = (T) parentNode; break; } parentNode = parentNode.getParent(); } return instance; } @Override public void preVisit(ASTNode node) { if (node instanceof CompilationUnit) { this.unit = (CompilationUnit) node; } } @Override public boolean visit(TypeDeclaration node) { StatusBuilder builder = new StatusBuilder(path, unit, node).withTypeDeclaration(node); for (Object element : node.modifiers()) { if (element instanceof MarkerAnnotation) { MarkerAnnotation annotation = (MarkerAnnotation) element; Status status = builder.build(); status.setTitle("クラスのアノテーション"); status.setDescription(annotation + " は使用禁止アノテーションです。"); System.out.println(status); status = builder.build(); status.setCurrentNode(annotation); status.setTitle("クラスのアノテーション"); status.setDescription(annotation + " は使用禁止アノテーションです。"); System.out.println(status); status = builder.build(); status.setTitle("クラスのアノテーション"); status.setDescription(annotation + " は使用禁止アノテーションです。"); System.out.println(status); } } return super.visit(node); } @Override public boolean visit(MethodDeclaration node) { final TypeDeclaration typeDeclaration = findByParentNode(node, TypeDeclaration.class); StatusBuilder builder = new StatusBuilder(path, unit, node).withTypeDeclaration(typeDeclaration) .withMethodDeclaration(node); Status status = null; status = builder.build(); status.setLineNumber(1); status.setTitle("title"); status.setDescription("description"); System.out.println(status); status = builder.build(); status.setTitle("title"); status.setDescription("description"); System.out.println(status); status = builder.build(); status.setCurrentNode(node); status.setTitle("title"); status.setDescription("description"); System.out.println(status); return super.visit(node); } } ** ExampleVisitor(解析用) [#ncbe2191] #highlightjs([java]) package org.codereign.jdt; import javax.lang.model.type.UnionType; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; import org.eclipse.jdt.core.dom.ArrayAccess; import org.eclipse.jdt.core.dom.ArrayCreation; import org.eclipse.jdt.core.dom.ArrayInitializer; import org.eclipse.jdt.core.dom.ArrayType; import org.eclipse.jdt.core.dom.AssertStatement; import org.eclipse.jdt.core.dom.Assignment; import org.eclipse.jdt.core.dom.Block; import org.eclipse.jdt.core.dom.BlockComment; import org.eclipse.jdt.core.dom.BooleanLiteral; import org.eclipse.jdt.core.dom.BreakStatement; import org.eclipse.jdt.core.dom.CastExpression; import org.eclipse.jdt.core.dom.CatchClause; import org.eclipse.jdt.core.dom.CharacterLiteral; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.ConditionalExpression; import org.eclipse.jdt.core.dom.ConstructorInvocation; import org.eclipse.jdt.core.dom.ContinueStatement; import org.eclipse.jdt.core.dom.CreationReference; import org.eclipse.jdt.core.dom.Dimension; import org.eclipse.jdt.core.dom.DoStatement; import org.eclipse.jdt.core.dom.EmptyStatement; import org.eclipse.jdt.core.dom.EnhancedForStatement; import org.eclipse.jdt.core.dom.EnumConstantDeclaration; import org.eclipse.jdt.core.dom.EnumDeclaration; import org.eclipse.jdt.core.dom.ExpressionMethodReference; import org.eclipse.jdt.core.dom.ExpressionStatement; import org.eclipse.jdt.core.dom.FieldAccess; import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.ForStatement; import org.eclipse.jdt.core.dom.IfStatement; import org.eclipse.jdt.core.dom.ImportDeclaration; import org.eclipse.jdt.core.dom.InfixExpression; import org.eclipse.jdt.core.dom.Initializer; import org.eclipse.jdt.core.dom.InstanceofExpression; import org.eclipse.jdt.core.dom.IntersectionType; import org.eclipse.jdt.core.dom.Javadoc; import org.eclipse.jdt.core.dom.LabeledStatement; import org.eclipse.jdt.core.dom.LambdaExpression; import org.eclipse.jdt.core.dom.LineComment; import org.eclipse.jdt.core.dom.MarkerAnnotation; import org.eclipse.jdt.core.dom.MemberRef; import org.eclipse.jdt.core.dom.MemberValuePair; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.MethodRef; import org.eclipse.jdt.core.dom.MethodRefParameter; import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.NameQualifiedType; import org.eclipse.jdt.core.dom.NormalAnnotation; import org.eclipse.jdt.core.dom.NullLiteral; import org.eclipse.jdt.core.dom.NumberLiteral; import org.eclipse.jdt.core.dom.PackageDeclaration; import org.eclipse.jdt.core.dom.ParameterizedType; import org.eclipse.jdt.core.dom.ParenthesizedExpression; import org.eclipse.jdt.core.dom.PostfixExpression; import org.eclipse.jdt.core.dom.PrefixExpression; import org.eclipse.jdt.core.dom.PrimitiveType; import org.eclipse.jdt.core.dom.QualifiedName; import org.eclipse.jdt.core.dom.QualifiedType; import org.eclipse.jdt.core.dom.ReturnStatement; import org.eclipse.jdt.core.dom.SimpleName; import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleMemberAnnotation; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.SuperConstructorInvocation; import org.eclipse.jdt.core.dom.SuperFieldAccess; import org.eclipse.jdt.core.dom.SuperMethodInvocation; import org.eclipse.jdt.core.dom.SuperMethodReference; import org.eclipse.jdt.core.dom.SwitchCase; import org.eclipse.jdt.core.dom.SwitchStatement; import org.eclipse.jdt.core.dom.SynchronizedStatement; import org.eclipse.jdt.core.dom.TagElement; import org.eclipse.jdt.core.dom.TextElement; import org.eclipse.jdt.core.dom.ThisExpression; import org.eclipse.jdt.core.dom.ThrowStatement; import org.eclipse.jdt.core.dom.TryStatement; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.TypeDeclarationStatement; import org.eclipse.jdt.core.dom.TypeLiteral; import org.eclipse.jdt.core.dom.TypeMethodReference; import org.eclipse.jdt.core.dom.TypeParameter; import org.eclipse.jdt.core.dom.VariableDeclarationExpression; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; import org.eclipse.jdt.core.dom.WhileStatement; import org.eclipse.jdt.core.dom.WildcardType; public class ExampleVisitor extends ASTVisitor { private void print(final String name, final String source) { System.out.println("// -----------------------------------------------------------------------------"); System.out.println("// [START]" + name); System.out.println("// -----------------------------------------------------------------------------"); System.out.println(source); System.out.println("// -----------------------------------------------------------------------------"); System.out.println("// [END]" + name); System.out.println("// -----------------------------------------------------------------------------"); } public boolean preVisit2(ASTNode node) { print(node.getClass().getName(), node.toString()); return true; } public void preVisit(ASTNode node) { print(node.getClass().getName(), node.toString()); } public void postVisit(ASTNode node) { print(node.getClass().getName(), node.toString()); } public boolean visit(AnnotationTypeDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(AnnotationTypeDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(AnnotationTypeMemberDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(AnnotationTypeMemberDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(AnonymousClassDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(AnonymousClassDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ArrayAccess node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ArrayAccess node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ArrayCreation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ArrayCreation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ArrayInitializer node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ArrayInitializer node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ArrayType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ArrayType node) { print(node.getClass().getName(), node.toString()); } public boolean visit(AssertStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(AssertStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(Assignment node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(Assignment node) { print(node.getClass().getName(), node.toString()); } public boolean visit(Block node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(Block node) { print(node.getClass().getName(), node.toString()); } public boolean visit(BlockComment node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(BlockComment node) { print(node.getClass().getName(), node.toString()); } public boolean visit(BooleanLiteral node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(BooleanLiteral node) { print(node.getClass().getName(), node.toString()); } public boolean visit(BreakStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(BreakStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(CastExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(CastExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(CatchClause node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(CatchClause node) { print(node.getClass().getName(), node.toString()); } public boolean visit(CharacterLiteral node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(CharacterLiteral node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ClassInstanceCreation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ClassInstanceCreation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(CompilationUnit node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(CompilationUnit node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ConditionalExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ConditionalExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ConstructorInvocation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ConstructorInvocation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ContinueStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ContinueStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(CreationReference node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(CreationReference node) { print(node.getClass().getName(), node.toString()); } public boolean visit(Dimension node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(Dimension node) { print(node.getClass().getName(), node.toString()); } public boolean visit(DoStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(DoStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(EmptyStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(EmptyStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(EnhancedForStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(EnhancedForStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(EnumConstantDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(EnumConstantDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(EnumDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(EnumDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ExpressionMethodReference node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ExpressionMethodReference node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ExpressionStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ExpressionStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(FieldAccess node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(FieldAccess node) { print(node.getClass().getName(), node.toString()); } public boolean visit(FieldDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(FieldDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ForStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ForStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(IfStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(IfStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ImportDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ImportDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(InfixExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(InfixExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(Initializer node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(Initializer node) { print(node.getClass().getName(), node.toString()); } public boolean visit(InstanceofExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(InstanceofExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(IntersectionType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(IntersectionType node) { print(node.getClass().getName(), node.toString()); } public boolean visit(Javadoc node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(Javadoc node) { print(node.getClass().getName(), node.toString()); } public boolean visit(LabeledStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(LabeledStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(LambdaExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(LambdaExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(LineComment node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(LineComment node) { print(node.getClass().getName(), node.toString()); } public boolean visit(MarkerAnnotation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(MarkerAnnotation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(MemberRef node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(MemberRef node) { print(node.getClass().getName(), node.toString()); } public boolean visit(MemberValuePair node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(MemberValuePair node) { print(node.getClass().getName(), node.toString()); } public boolean visit(MethodDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(MethodDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(MethodInvocation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(MethodInvocation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(MethodRef node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(MethodRef node) { print(node.getClass().getName(), node.toString()); } public boolean visit(MethodRefParameter node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(MethodRefParameter node) { print(node.getClass().getName(), node.toString()); } public boolean visit(Modifier node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(Modifier node) { print(node.getClass().getName(), node.toString()); } public boolean visit(NameQualifiedType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(NameQualifiedType node) { print(node.getClass().getName(), node.toString()); } public boolean visit(NormalAnnotation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(NormalAnnotation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(NullLiteral node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(NullLiteral node) { print(node.getClass().getName(), node.toString()); } public boolean visit(NumberLiteral node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(NumberLiteral node) { print(node.getClass().getName(), node.toString()); } public boolean visit(PackageDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(PackageDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ParameterizedType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ParameterizedType node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ParenthesizedExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ParenthesizedExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(PostfixExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(PostfixExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(PrefixExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(PrefixExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(PrimitiveType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(PrimitiveType node) { print(node.getClass().getName(), node.toString()); } public boolean visit(QualifiedName node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(QualifiedName node) { print(node.getClass().getName(), node.toString()); } public boolean visit(QualifiedType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(QualifiedType node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ReturnStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ReturnStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SimpleName node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SimpleName node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SimpleType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SimpleType node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SingleMemberAnnotation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SingleMemberAnnotation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SingleVariableDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SingleVariableDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(StringLiteral node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(StringLiteral node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SuperConstructorInvocation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SuperConstructorInvocation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SuperFieldAccess node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SuperFieldAccess node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SuperMethodInvocation node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SuperMethodInvocation node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SuperMethodReference node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SuperMethodReference node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SwitchCase node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SwitchCase node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SwitchStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SwitchStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(SynchronizedStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(SynchronizedStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(TagElement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(TagElement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(TextElement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(TextElement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ThisExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ThisExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(ThrowStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(ThrowStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(TryStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(TryStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(TypeDeclaration node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(TypeDeclaration node) { print(node.getClass().getName(), node.toString()); } public boolean visit(TypeDeclarationStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(TypeDeclarationStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(TypeLiteral node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(TypeLiteral node) { print(node.getClass().getName(), node.toString()); } public boolean visit(TypeMethodReference node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(TypeMethodReference node) { print(node.getClass().getName(), node.toString()); } public boolean visit(TypeParameter node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(TypeParameter node) { print(node.getClass().getName(), node.toString()); } public boolean visit(UnionType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(UnionType node) { print(node.getClass().getName(), node.toString()); } public boolean visit(VariableDeclarationExpression node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(VariableDeclarationExpression node) { print(node.getClass().getName(), node.toString()); } public boolean visit(VariableDeclarationFragment node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(VariableDeclarationFragment node) { print(node.getClass().getName(), node.toString()); } public boolean visit(VariableDeclarationStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(VariableDeclarationStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(WhileStatement node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(WhileStatement node) { print(node.getClass().getName(), node.toString()); } public boolean visit(WildcardType node) { print(node.getClass().getName(), node.toString()); return true; } public void endVisit(WildcardType node) { print(node.getClass().getName(), node.toString()); } } ** Status [#ea2e214e] #highlightjs([java]) package org.codereign.jdt; import java.nio.file.Path; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.TypeDeclaration; public class Status { private Path path; private CompilationUnit unit; private TypeDeclaration typeDeclaration; private MethodDeclaration methodDeclaration; private ASTNode currentNode; private int lineNumber = 1; private String title; private String description; public Status(StatusBuilder builder) { this.path = builder.getPath(); this.unit = builder.getUnit(); this.typeDeclaration = builder.getTypeDeclaration(); this.methodDeclaration = builder.getMethodDeclaration(); this.currentNode = builder.getCurrentNode(); this.lineNumber = this.unit.getLineNumber(this.currentNode.getStartPosition()); } public void setCurrentNode(ASTNode currentNode) { this.currentNode = currentNode; this.lineNumber = this.unit.getLineNumber(this.currentNode.getStartPosition()); } public void setLineNumber(int lineNumber) { if (0 < lineNumber) { this.lineNumber = lineNumber; } } public void setTitle(String title) { this.title = title; } public void setDescription(String description) { this.description = description; } @Override public String toString() { final String fileName = path.getFileName().toString(); final String packageName = unit.getPackage().getName().toString(); final String className = (typeDeclaration != null) ? typeDeclaration.getName().toString() : ""; final String methodName = (methodDeclaration != null) ? methodDeclaration.getName().toString() : ""; return packageName + "." + className + "." + methodName + "(" + fileName + ":" + lineNumber + ") : " + title + ":" + description; } } ** StatusBuilder [#m13e2ef3] #highlightjs([java]) package org.codereign.jdt; import java.nio.file.Path; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.TypeDeclaration; public class StatusBuilder { private Path path; private CompilationUnit unit; private TypeDeclaration typeDeclaration; private MethodDeclaration methodDeclaration; private ASTNode currentNode; public StatusBuilder(Path path, CompilationUnit unit, ASTNode currentNode) { this.setPath(path); this.setUnit(unit); this.setCurrentNode(currentNode); } public Path getPath() { return path; } public void setPath(Path path) { this.path = path; } public CompilationUnit getUnit() { return unit; } public void setUnit(CompilationUnit unit) { this.unit = unit; } public ASTNode getCurrentNode() { return currentNode; } public void setCurrentNode(ASTNode currentNode) { this.currentNode = currentNode; } public TypeDeclaration getTypeDeclaration() { return typeDeclaration; } public void setTypeDeclaration(TypeDeclaration typeDeclaration) { this.typeDeclaration = typeDeclaration; } public MethodDeclaration getMethodDeclaration() { return methodDeclaration; } public void setMethodDeclaration(MethodDeclaration methodDeclaration) { this.methodDeclaration = methodDeclaration; } public StatusBuilder withTypeDeclaration(TypeDeclaration typeDeclaration) { this.typeDeclaration = typeDeclaration; return this; } public StatusBuilder withMethodDeclaration(MethodDeclaration methodDeclaration) { this.methodDeclaration = methodDeclaration; return this; } public Status build() { return new Status(this); } }