ModuleDeclaration.traverse(new ASTVisitor() { });
ASTVisitor visitor = new ASTVisitor() { public boolean visit(MethodDeclaration node) { String caller = node.getName().toString(); System.out.println("CALLER: " + caller); return true; } public boolean visit(MethodInvocation node) { String methodName = node.getName().toString(); System.out.println("INVOKE: " + methodName);
private void fixEnumConstantIndents(ASTNode astRoot) { if (this.options.use_tabs_only_for_leading_indentations) { // enum constants should be indented like other declarations, not like wrapped elements astRoot.accept(new ASTVisitor() { @Override public boolean visit(EnumConstantDeclaration node) { WrapPreparator.this.tm.firstTokenIn(node, -1).setWrapPolicy(null); return true; } }); } } }
private void fixEnumConstantIndents(ASTNode astRoot) { if (this.options.use_tabs_only_for_leading_indentations) { // enum constants should be indented like other declarations, not like wrapped elements astRoot.accept(new ASTVisitor() { @Override public boolean visit(EnumConstantDeclaration node) { WrapPreparator.this.tm.firstTokenIn(node, -1).setWrapPolicy(null); return true; } }); } } }
private void fixEnumConstantIndents(ASTNode astRoot) { if (this.options.use_tabs_only_for_leading_indentations) { // enum constants should be indented like other declarations, not like wrapped elements astRoot.accept(new ASTVisitor() { @Override public boolean visit(EnumConstantDeclaration node) { WrapPreparator.this.tm.firstTokenIn(node, -1).setWrapPolicy(null); return true; } }); } } }
private void fixEnumConstantIndents(ASTNode astRoot) { if (this.options.use_tabs_only_for_leading_indentations) { // enum constants should be indented like other declarations, not like wrapped elements astRoot.accept(new ASTVisitor() { @Override public boolean visit(EnumConstantDeclaration node) { WrapPreparator.this.tm.firstTokenIn(node, -1).setWrapPolicy(null); return true; } }); } } }
public static IType[] findDependencies(ASTNode node) { final Set<IType> result = new HashSet<IType>(); node.accept(new ASTVisitor() { @Override public boolean visit(SimpleName node) { ITypeBinding typeBinding = node.resolveTypeBinding(); if (typeBinding == null) return false; IJavaElement element = typeBinding.getJavaElement(); if (element != null && element instanceof IType) { result.add((IType)element); } return false; } }); return result.toArray(new IType[result.size()]); }
private boolean processEnumType(TypeDeclaration node) { if (!isEnum(node)) { return false; } final CSEnum theEnum = new CSEnum(typeName(node)); mapVisibility(node, theEnum); mapJavadoc(node, theEnum); addType(theEnum); node.accept(new ASTVisitor() { public boolean visit(VariableDeclarationFragment node) { theEnum.addValue(identifier(node.getName())); return false; } @Override public boolean visit(MethodDeclaration node) { if (node.isConstructor() && isPrivate(node)) { return false; } unsupportedConstruct(node, "Enum can contain only fields and a private constructor."); return false; } }); return true; }
try { if(ruleName.equalsIgnoreCase("RuleName")) { cu.accept(new ASTVisitor() { try { public boolean visit(MethodInvocation e) { if(rule.getConditions().verify(e, env, parentKeys, astParser, file, cu)) // throws ParseException matches.add(getLinesPosition(cu, e)); return true; } catch(Exception e){ throw new CustomException(); } }); } // ... } catch(CustomException e) { throw AnotherException(); }
private ASTNode getOptionalBlock(ASTNode targetNode) { final ASTNode[] maybeBlock= new ASTNode[1]; targetNode.accept(new ASTVisitor(){ public boolean visit(ForStatement node) { if (node.getBody() instanceof Block) maybeBlock[0]= node.getBody(); return false; } public boolean visit(EnhancedForStatement node) { if (node.getBody() instanceof Block) maybeBlock[0]= node.getBody(); return false; } public boolean visit(WhileStatement node) { if (node.getBody() instanceof Block) maybeBlock[0]= node.getBody(); return false; } public boolean visit(DoStatement node) { if (node.getBody() instanceof Block) maybeBlock[0]= node.getBody(); return false; } public boolean visit(SwitchStatement node) { maybeBlock[0]= node; return false; } }); return maybeBlock[0]; }
class MyData<T> { T data; } public boolean containsBlock(String nodeName, ASTNode node) { final MyData<Boolean> found = new MyData<Boolean>(); found.data = Boolean.FALSE; if(nodeName.equals("if")) { node.accept(new ASTVisitor() { public boolean visit(IfStatement s) { found.data = Boolean.TRUE; return false; } }); } return found.data; }
//use ASTParse to parse string public static void parse(String str) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(str.toCharArray()); parser.setKind(ASTParser.K_COMPILATION_UNIT); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.accept(new ASTVisitor() { String packageName=""; public boolean visit(TypeDeclaration node) { String className=node.getName().getFullyQualifiedName(); if (packageName!="") System.out.println(packageName+"."+className); else System.out.println(className); return false; } public boolean visit(PackageDeclaration node) { packageName=node.getName().getFullyQualifiedName(); return false; } }); }
ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setSource(charArray); parser.setKind(ASTParser.K_COMPILATION_UNIT); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.accept(new ASTVisitor(){..methods..});
public static void parse(String fileContent) { //advise the parser to parse the code following to the Java Language Specification, Third Edition. ASTParser parser = ASTParser.newParser(AST.JLS3); Map options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options); parser.setCompilerOptions(options); // tell the parser, that it has to expect an ICompilationUnit (a pointer to a Java file) as input. parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource(fileContent.toCharArray()); parser.setResolveBindings(true); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.accept(new ASTVisitor() { public boolean visit(AnnotationTypeDeclaration node) { System.out.println("Annotaion: " + node.getName()); return true; } public boolean visit(TypeDeclaration node) { System.out.println("Type: " + node.getName()); return true; } }); }
private void handleSimpleLoop(Statement body, int wrappingOption) { if (!(body instanceof Block)) { this.wrapIndexes.add(this.tm.firstIndexIn(body, -1)); this.wrapParentIndex = this.tm.firstIndexBefore(body, TokenNameRPAREN); this.wrapGroupEnd = this.tm.lastIndexIn(body, -1); handleWrap(wrappingOption, body.getParent()); body.accept(new ASTVisitor() { @Override public boolean visit(Block node) { forceContinuousWrapping(node, WrapPreparator.this.tm.firstIndexIn(node, -1)); return false; } }); } }
cu.accept(new ASTVisitor() {
public void setPositionFinder(String methodName) throws JavaModelException { //findMethod(methodName); IType type = this.javaProject.findType(this.className); ICompilationUnit unit = type.getCompilationUnit(); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(unit); parser.setResolveBindings(true); CompilationUnit cunit = (CompilationUnit) parser.createAST(null); //ASTNode root = parser.createAST(null); final String name = this.newMethodName; cunit.accept(new ASTVisitor() { public boolean visit(MethodInvocation methodInvocation) { String methodName = methodInvocation.getName().toString(); System.out.println(methodName); if (methodName.equals(name)) { startPosition = methodInvocation.getStartPosition(); length = methodInvocation.getLength(); System.out.printf("startPosition %d - Length %d", startPosition, length); } return false; } }); }
IJavaElementDelta delta= event.getDelta(); if (delta != null) { delta.getCompilationUnitAST().accept(new ASTVisitor() {
root.accept(new ASTVisitor() { public boolean visit(SimpleName node) { System.out.println(node.toString());
final TextEditGroup textEdits = new TextEditGroup("test"); expr.accept(new ASTVisitor() { @Override public boolean visit(MethodInvocation node) {