当前位置: 首页>>代码示例>>Java>>正文


Java ASTVisitor类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.ASTVisitor的典型用法代码示例。如果您正苦于以下问题:Java ASTVisitor类的具体用法?Java ASTVisitor怎么用?Java ASTVisitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ASTVisitor类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ASTVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getField

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
/**
 * @param methodname
 * @return
 */
public FieldDeclaration getField(   ) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	String s = getStaticVariable ( );
	if (s==null) return null;
	parser.setSource(s.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final  CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(FieldDeclaration node) {
			field = node;
			return true;
		}
	});		 
	return field;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:20,代码来源:ClassExtension.java

示例2: getGraphWalkerClassAnnotation

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
/**
 * @return
 */
public NormalAnnotation getGraphWalkerClassAnnotation() {
	String source = getSource ();
	if(source==null) return null;
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setSource(source.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(NormalAnnotation node) {
			annotation = node;
			return true;
		}
	});
	if (this.generateAnnotation) return annotation;
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:20,代码来源:ClassExtension.java

示例3: getLeftMostSimpleName

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
public static SimpleName getLeftMostSimpleName(Name name) {
	if (name instanceof SimpleName) {
		return (SimpleName)name;
	} else {
		final SimpleName[] result= new SimpleName[1];
		ASTVisitor visitor= new ASTVisitor() {
			@Override
			public boolean visit(QualifiedName qualifiedName) {
				Name left= qualifiedName.getQualifier();
				if (left instanceof SimpleName) {
					result[0]= (SimpleName)left;
				} else {
					left.accept(this);
				}
				return false;
			}
		};
		name.accept(visitor);
		return result[0];
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:ASTNodes.java

示例4: analyzeCompilationUnit

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
private void analyzeCompilationUnit(CompilationUnit unit, ICompilationUnit compilationUnit) {
	Set<String> filters = loadFilters();
	ASTVisitor importsVisitor = new ImportsVisitor(filters);
	unit.accept(importsVisitor);

	List types = unit.types();
	for (Iterator iter = types.iterator(); iter.hasNext();) {
		Object next = iter.next();
		if (next instanceof TypeDeclaration) {
			// declaration: Contains one file content at a time.
			TypeDeclaration declaration = (TypeDeclaration) next;
			// traverseType(declaration,true);

		}
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:17,代码来源:GenerateDefaultMap.java

示例5: getEnhancedForStatements

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
private static Set<EnhancedForStatement> getEnhancedForStatements(IMethod method, IProgressMonitor pm)
		throws JavaModelException {
	ICompilationUnit iCompilationUnit = method.getCompilationUnit();

	// get the ASTParser of the method
	CompilationUnit compilationUnit = RefactoringASTParser.parseWithASTProvider(iCompilationUnit, true,
			new SubProgressMonitor(pm, 1));

	// get the method declaration ASTNode.
	MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(method, compilationUnit);

	final Set<EnhancedForStatement> statements = new LinkedHashSet<EnhancedForStatement>();
	// extract all enhanced for loop statements in the method.
	methodDeclarationNode.accept(new ASTVisitor() {

		@Override
		public boolean visit(EnhancedForStatement node) {
			statements.add(node);
			return super.visit(node);
		}
	});

	return statements;
}
 
开发者ID:mdarefin,项目名称:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin,代码行数:25,代码来源:ForeachLoopToLambdaRefactoring.java

示例6: getGeneratedClassAnnotation

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
public NormalAnnotation getGeneratedClassAnnotation() {
	String source = getGeneratedAnnotationSource ();
	if(source==null) return null;
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setSource(source.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(NormalAnnotation node) {
			annotation = node;
			return true;
		}
	});
    return annotation;
	 
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:17,代码来源:ClassExtension.java

示例7: findPathGeneratorInGraphWalkerAnnotation

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
/**
 * @param cu
 * @return
 */
public static String findPathGeneratorInGraphWalkerAnnotation(ICompilationUnit cu) {
	CompilationUnit ast = parse(cu);
	Map<String, String> ret = new HashMap<String, String>();
	ast.accept(new ASTVisitor() {
		public boolean visit(MemberValuePair node) {
			String name = node.getName().getFullyQualifiedName();
			if ("value".equals(name) && node.getParent() != null && node.getParent() instanceof NormalAnnotation) {
				IAnnotationBinding annoBinding = ((NormalAnnotation) node.getParent()).resolveAnnotationBinding();
				String qname = annoBinding.getAnnotationType().getQualifiedName();
				if (GraphWalker.class.getName().equals(qname)) {
					StringLiteral sl = (StringLiteral) node.getValue();
					ret.put("ret", sl.getLiteralValue());
				}
			}
			return true;
		}
	});
	return ret.get("ret");
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:24,代码来源:JDTManager.java

示例8: intercept

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
@Override
public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
    switch (method.getName()) {
        case "appendDebugString":
            return ((StringBuffer) args[0]).append(groovyClosure.toString());
        case "getNodeType0":
            return NODE_TYPE;
        case "accept0":
            ASTVisitor visitor = ((ASTVisitor) args[0]);
            if (visitor instanceof NaiveASTFlattener) {
                Field field = findField(NaiveASTFlattener.class, "buffer");
                makeAccessible(field);
                ((StringBuffer) field.get(visitor)).append(groovyClosure.toString());
            } else {
                throw new UnsupportedOperationException();
            }
            return null;
        default:
            makeAccessible(method);
            return methodProxy.invokeSuper(o, args);
    }
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:23,代码来源:GroovyClosure.java

示例9: find

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
/**
 * Finds the equivalent AST node, or null if one could not be found.
 */
public ASTNode find() {
  final ASTNode foundNode[] = new ASTNode[1];
  newAncestorNode.accept(new ASTVisitor(true) {
    @Override
    public void preVisit(ASTNode visitedNode) {
      if (foundNode[0] != null) {
        // Already found a result, do not search further
        return;
      }

      if (!treesMatch(originalNode, visitedNode, ancestorNode,
          newAncestorNode, matcher)) {
        // Keep searching
        return;
      }

      foundNode[0] = visitedNode;

      // We are done
    }
  });

  return foundNode[0];
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:28,代码来源:EquivalentNodeFinder.java

示例10: getCurrentlyUsedNames

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
/**
 * @param vars
 * @param entry
 * @return
 */
private Set<Integer> getCurrentlyUsedNames(
		final Multimap<ASTNode, Variable> vars,
		final Entry<ASTNode, Variable> entry) {
	// Create a list of all the names that are used in that scope
	final Set<Variable> scopeUsedNames = Sets.newHashSet();
	// Check all the parents & self
	ASTNode currentNode = entry.getKey();
	while (currentNode != null) {
		scopeUsedNames.addAll(vars.get(currentNode));
		currentNode = currentNode.getParent();
	}
	// and now add all children
	final ASTVisitor v = new ASTVisitor() {
		@Override
		public void preVisit(final ASTNode node) {
			scopeUsedNames.addAll(vars.get(node));
		}
	};
	entry.getKey().accept(v);
	// and we're done
	return getUsedIds(scopeUsedNames);
}
 
开发者ID:mast-group,项目名称:naturalize,代码行数:28,代码来源:JunkVariableRenamer.java

示例11: replaceMarker

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
private boolean replaceMarker(final ASTRewrite rewrite, final Expression qualifier, Expression assignedValue, final NullLiteral marker) {
	class MarkerReplacer extends ASTVisitor {

		private boolean fReplaced= false;

		@Override
		public boolean visit(NullLiteral node) {
			if (node == marker) {
				rewrite.replace(node, rewrite.createCopyTarget(qualifier), null);
				fReplaced= true;
				return false;
			}
			return true;
		}
	}
	if (assignedValue != null && qualifier != null) {
		MarkerReplacer visitor= new MarkerReplacer();
		assignedValue.accept(visitor);
		return visitor.fReplaced;
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:ExtractClassRefactoring.java

示例12: findField

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
private ASTNode findField(ASTNode astRoot, final String name) {

		class STOP_VISITING extends RuntimeException {
			private static final long serialVersionUID= 1L;
		}

		final ASTNode[] result= new ASTNode[1];

		try {
			astRoot.accept(new ASTVisitor() {

				@Override
				public boolean visit(VariableDeclarationFragment node) {
					if (name.equals(node.getName().getFullyQualifiedName())) {
						result[0]= node.getParent();
						throw new STOP_VISITING();
					}
					return true;
				}
			});
		} catch (STOP_VISITING ex) {
			// stop visiting AST
		}

		return result[0];
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:AccessorClassModifier.java

示例13: getLeftMostSimpleName

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
public static SimpleName getLeftMostSimpleName(Name name) {
	if (name instanceof SimpleName) {
		return (SimpleName)name;
	} else {
		final SimpleName[] result= new SimpleName[1];
		ASTVisitor visitor= new ASTVisitor() {
			@Override
			public boolean visit(QualifiedName qualifiedName) {
				Name left= qualifiedName.getQualifier();
				if (left instanceof SimpleName)
					result[0]= (SimpleName)left;
				else
					left.accept(this);
				return false;
			}
		};
		name.accept(visitor);
		return result[0];
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:ASTNodes.java

示例14: statements

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
/**
 * Returns all statements within a method.
 * 
 * @return Set of all statements
 */
private ArraySet<AbstractJavaStatement> statements() {
    final List<AbstractJavaStatement> list = new ArrayList<AbstractJavaStatement>();
    methodDeclaration.accept(new ASTVisitor() {
        @Override
        public boolean visit(ExpressionStatement node) {
            if (node.getExpression() instanceof MethodInvocation) {
                MethodInvocation methodInvocation = (MethodInvocation) node.getExpression();
                String methodName = methodInvocation.getName().toString();
                if (null != methodInvocation.getExpression()) {
                    ITypeBinding typeBinding = methodInvocation.getExpression().resolveTypeBinding();
                    if (null != typeBinding) {
                        JavaCall javaCall = new JavaCall(node, methodName, typeBinding, JavaMethod.this);
                        list.add(javaCall);
                    }
                }
            }
            return false;
        }
    });
    return new ArraySet<AbstractJavaStatement>(list.toArray(new JavaCall[list.size()]), JavaCall.class);
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:27,代码来源:JavaMethod.java

示例15: assignments

import org.eclipse.jdt.core.dom.ASTVisitor; //导入依赖的package包/类
/**
 * Returns all statements within a method.
 * 
 * @return Set of all statements
 */
private ArraySet<AbstractJavaStatement> assignments() {
    final List<AbstractJavaStatement> list = new ArrayList<AbstractJavaStatement>();
    methodDeclaration.accept(new ASTVisitor() {
        @Override
        public boolean visit(Assignment node) {
            Expression lhs = node.getLeftHandSide();
            ITypeBinding typeBinding = lhs.resolveTypeBinding();
            Expression rhs = node.getRightHandSide();
            if (rhs instanceof ClassInstanceCreation && node.getParent() instanceof ExpressionStatement) {
                ExpressionStatement parent = (ExpressionStatement) node.getParent();
                JavaAssignment assignment = new JavaAssignment(JavaMethod.this, parent, lhs.toString(), typeBinding,
                        (ClassInstanceCreation) rhs);
                list.add(assignment);
            }
            // TODO SE: (Static) method invocations, e.g. call of another
            // factory are not supported.

            return false;
        }
    });
    return new ArraySet<AbstractJavaStatement>(list.toArray(new JavaAssignment[list.size()]), JavaAssignment.class);
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:28,代码来源:JavaMethod.java


注:本文中的org.eclipse.jdt.core.dom.ASTVisitor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。