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


Java CompilationUnit.accept方法代码示例

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


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

示例1: getField

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的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.CompilationUnit; //导入方法依赖的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: analyzeCompilationUnit

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的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

示例4: getGeneratedClassAnnotation

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的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

示例5: findPathGeneratorInGraphWalkerAnnotation

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的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

示例6: toGroovyTypeModel

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public TypeModel toGroovyTypeModel(String source) {
    source = source.replaceAll("//(?i)\\s*" + quote("given") + SEPARATOR, "givenBlockStart();");
    source = source.replaceAll("//(?i)\\s*" + quote("when") + SEPARATOR, "whenBlockStart();");
    source = source.replaceAll("//(?i)\\s*" + quote("then") + SEPARATOR, "thenBlockStart();");

    ASTParser parser = ASTParser.newParser(JLS8);
    parser.setSource(source.toCharArray());
    parser.setKind(K_COMPILATION_UNIT);
    parser.setCompilerOptions(compilerOptions());

    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    astProxy.setTarget(cu.getAST());

    TypeVisitor visitor = testClassVisitorSupplier.get();
    cu.accept(visitor);
    return visitor.typeModel();
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:18,代码来源:Spocker.java

示例7: getFullName

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * Evaluates fully qualified name of the Name object.
 */
private static String getFullName(Name name) {
    // check if the root node is a CompilationUnit
    if (name.getRoot().getClass() != CompilationUnit.class) {
        // cannot resolve a full name, CompilationUnit root node is missing
        return name.getFullyQualifiedName();
    }
    // get the root node
    CompilationUnit root = (CompilationUnit) name.getRoot();
    // check if the name is declared in the same file
    TypeDeclVisitor tdVisitor = new TypeDeclVisitor(name.getFullyQualifiedName());
    root.accept(tdVisitor);
    if (tdVisitor.getFound()) {
        // the name is the use of the TypeDeclaration in the same file
        return getFullName(tdVisitor.getTypeDecl());
    }
    // check if the name is declared in the same package or imported
    PckgImprtVisitor piVisitor = new PckgImprtVisitor(name.getFullyQualifiedName());
    root.accept(piVisitor);
    if (piVisitor.getFound()) {
        // the name is declared in the same package or imported
        return piVisitor.getFullName();
    }
    // could be a class from the java.lang (String) or a param name (T, E,...)
    return name.getFullyQualifiedName();
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:29,代码来源:NameResolver.java

示例8: measure

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * @see Measure#measure
 */
@Override
public <T> void measure(T unit) {
	
	IMethod[] iMethods = null;
	try {
		IType[] iTypes = ((ICompilationUnit)unit).getTypes();
		
		for (IType iType : iTypes){
			iMethods = iType.getMethods();
		}
		
	} catch (JavaModelException exception) {
		logger.error(exception);
	}
	
	CompilationUnit parse = parse(unit);
	ResponseForClassVisitor visitor = ResponseForClassVisitor.getInstance();
	visitor.cleanVariables();
	visitor.addListOfMethodsDeclaration(iMethods);
	parse.accept(visitor);

	setCalculatedValue(getResponseForClassValue(visitor));
	setMeanValue(getCalculatedValue());
	setMaxValue(getCalculatedValue(), parse.getJavaElement().getElementName());
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:29,代码来源:ResponseForClass.java

示例9: measure

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * @see Measure#measure
 */
@Override
public <T> void measure(T unit) {
	
	IType[] iTypes = null;
	
	try {
		iTypes = ((ICompilationUnit)unit).getTypes();
	} catch (JavaModelException exception) {
		logger.error(exception);
	}
	
	CompilationUnit parse = parse(unit);
	CouplingBetweenObjectsVisitor visitor = CouplingBetweenObjectsVisitor.getInstance();
	visitor.cleanArrayAndVariable();
	visitor.addListOfTypes(iTypes);
	parse.accept(visitor);

	setCalculatedValue(getCouplingBetweenObjectsValue(visitor));
	setMeanValue(getCalculatedValue());
	setMaxValue(getCalculatedValue(), parse.getJavaElement().getElementName());
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:25,代码来源:CouplingBetweenObjects.java

示例10: getBodyMethod

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

示例11: findPathInStaticField

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * @param project
 * @param itype
 * @return
 * @throws JavaModelException
 */
private static IPath findPathInStaticField(IProject project, IType itype) throws JavaModelException {
	List<IPath> wrapper = new ArrayList<IPath>();
	ICompilationUnit cu = itype.getCompilationUnit();
	CompilationUnit ast = parse(cu);
	ast.accept(new ASTVisitor() {
		public boolean visit(VariableDeclarationFragment node) {
			SimpleName simpleName = node.getName();
			IBinding bding = simpleName.resolveBinding();
			if (bding instanceof IVariableBinding) {
				IVariableBinding binding = (IVariableBinding) bding;
				String type = binding.getType().getBinaryName(); //
				String name = simpleName.getFullyQualifiedName();
				if ("MODEL_PATH".equals(name) && "java.nio.file.Path".equals(type)) {
					Expression expression = node.getInitializer();
					if (expression instanceof MethodInvocation) {
						MethodInvocation mi = (MethodInvocation) expression;
						if ("get".equals(mi.resolveMethodBinding().getName())
								&& "java.nio.file.Path".equals(mi.resolveTypeBinding().getBinaryName())) {
							StringLiteral sl = (StringLiteral) mi.arguments().get(0);
							String argument = sl.getLiteralValue();
							try {
								IPath p = ResourceManager.find(project, argument);
								wrapper.add(p);
							} catch (CoreException e) {
								ResourceManager.logException(e);
							}
						}
					}
				}
			}
			return true;
		}
	});
	if (wrapper.size() > 0)
		return wrapper.get(0);
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:44,代码来源:JDTManager.java

示例12: execute

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public List<String> execute(Parser parser, String astJson) {
    List<String> synthesizedPrograms = new LinkedList<>();
    List<DSubTree> asts = getASTsFromNN(astJson);

    classLoader = URLClassLoader.newInstance(parser.classpathURLs);

    CompilationUnit cu = parser.cu;
    List<String> programs = new ArrayList<>();
    for (DSubTree ast : asts) {
        Visitor visitor = new Visitor(ast, new Document(parser.source), cu, mode);
        try {
            cu.accept(visitor);
            if (visitor.synthesizedProgram == null)
                continue;
            String program = visitor.synthesizedProgram.replaceAll("\\s", "");
            if (! programs.contains(program)) {
                String formattedProgram = new Formatter().formatSource(visitor.synthesizedProgram);
                programs.add(program);
                synthesizedPrograms.add(formattedProgram);
            }
        } catch (SynthesisException|FormatterException e) {
            // do nothing and try next ast
        }
    }

    return synthesizedPrograms;
}
 
开发者ID:capergroup,项目名称:bayou,代码行数:28,代码来源:Synthesizer.java

示例13: processCompilationUnit

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
protected void processCompilationUnit(String sourceFilePath, char[] fileContent, CompilationUnit compilationUnit, SDModel model) {
	PackageDeclaration packageDeclaration = compilationUnit.getPackage();
	String packageName = "";
	if (packageDeclaration != null) {
		packageName = packageDeclaration.getName().getFullyQualifiedName();
	}
	String packagePath = packageName.replace('.', '/');
	String sourceFolder = "/";
	if (sourceFilePath.contains(packagePath)) {
		sourceFolder = sourceFilePath.substring(0, sourceFilePath.indexOf(packagePath));
	}
	// RastNode nCompUnit = model.createCompilationUnit(packageName, sourceFolder, sourceFilePath, compilationUnit);
	BindingsRecoveryAstVisitor visitor = new BindingsRecoveryAstVisitor(model, compilationUnit, sourceFilePath, fileContent, packageName, postProcessReferences, postProcessSupertypes);
	compilationUnit.accept(visitor);
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:16,代码来源:SDModelBuilder.java

示例14: processCompilationUnit

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
protected void processCompilationUnit(String sourceFilePath, char[] fileContent, CompilationUnit compilationUnit, SDModel.Snapshot model) {
	PackageDeclaration packageDeclaration = compilationUnit.getPackage();
	String packageName = "";
	if (packageDeclaration != null) {
		packageName = packageDeclaration.getName().getFullyQualifiedName();
	}
	String packagePath = packageName.replace('.', '/');
	String sourceFolder = "/";
	if (sourceFilePath.contains(packagePath)) {
	  sourceFolder = sourceFilePath.substring(0, sourceFilePath.indexOf(packagePath));
	}
	SDPackage sdPackage = model.getOrCreatePackage(packageName, sourceFolder);
	BindingsRecoveryAstVisitor visitor = new BindingsRecoveryAstVisitor(model, sourceFilePath, fileContent, sdPackage, postProcessReferences, postProcessSupertypes, postProcessClientCode, srbForTypes, srbForMethods, srbForAttributes);
	compilationUnit.accept(visitor);
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:16,代码来源:SDModelBuilder.java

示例15: parse

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public void parse(ASTVisitor visitor) {
		parser.setSource(this.source);
		CompilationUnit unit = (CompilationUnit) parser.createAST(null);
		
//		if(unit.getProblems().length > 0)
//			throw new RuntimeException("code has compilation errors");
		
		unit.accept(visitor);
		hasErrors = unit.getProblems().length > 0;
	}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:11,代码来源:JavaSourceParser.java


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