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


Java CompilationUnit.types方法代码示例

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


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

示例1: 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

示例2: getClassAttributes

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * Method to get class attributes and add them in a list.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param node
 */
@SuppressWarnings("unchecked")
private void getClassAttributes(CompilationUnit node){
	
	for (Object type : node.types()){
		if (type instanceof TypeDeclaration){
			
			FieldDeclaration [] attributes = ((TypeDeclaration) type).getFields();
			
			for (FieldDeclaration attribute: attributes){
				List<FieldDeclaration> fragments = attribute.fragments();
				Object obj = fragments.get(0);
				if (obj instanceof VariableDeclarationFragment){
					String str = ((VariableDeclarationFragment) obj).getName().toString();
					this.listOfAttributes.add(str);
				}
			}
		}
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:26,代码来源:TightClassCohesionVisitor.java

示例3: calculateWeightMethods

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * Method to calculate the sum of the complexities of all class methods.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param node
 */
@SuppressWarnings("unchecked")
private void calculateWeightMethods(CompilationUnit node){
	
	for (Object type : node.types()){
	
		if ((type instanceof TypeDeclaration) && !((TypeDeclaration) type).isInterface()){
				
			List<TypeDeclaration> bodyDeclarationsList = ((TypeDeclaration) type).
					bodyDeclarations();
			Iterator<TypeDeclaration> itBodyDeclaration = bodyDeclarationsList.iterator();
			
			while (itBodyDeclaration.hasNext()){
				Object itItem = itBodyDeclaration.next();
				if (itItem instanceof MethodDeclaration){
					checkStatementsInMethodsDeclaration(itItem);
				}
			}
			this.wmcIndex += this.visitor.getCyclomaticComplexityIndex();
		}
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:28,代码来源:WeightMethodsPerClassVisitor.java

示例4: getClassAttributes

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * Method to get all attributes or fields of a class.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param node
 */
@SuppressWarnings("unchecked")
private void getClassAttributes(CompilationUnit node){
	
	for (Object type : node.types()){
		if (type instanceof TypeDeclaration){
			
			FieldDeclaration [] attributes = ((TypeDeclaration) type).getFields();
			
			for (FieldDeclaration attribute: attributes){
				List<FieldDeclaration> fragments = attribute.fragments();
				Object obj = fragments.get(0);
				if (obj instanceof VariableDeclarationFragment){
					String s = ((VariableDeclarationFragment) obj).getName().toString();
					this.listOfAttributes.add(s);
				}
			}
		}
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:26,代码来源:LooseClassCohesionVisitor.java

示例5: calculateNumberOfClasses

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * Method that calculates the number of classes of
 * a specific project.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param unit
 */
@SuppressWarnings("unchecked")
private void calculateNumberOfClasses(CompilationUnit unit) {

	numOfClassClasses++;
	
	for (Object type :unit.types()){
		if ((type instanceof TypeDeclaration) && !((TypeDeclaration) type).isInterface()){
			
			List<TypeDeclaration> bodyDeclarationsList = ((TypeDeclaration) type).bodyDeclarations();
			Iterator<TypeDeclaration> itBodyDeclaration = bodyDeclarationsList.iterator();
			
			while (itBodyDeclaration.hasNext()){
				Object itItem = itBodyDeclaration.next();
				if ((itItem instanceof TypeDeclaration)
						&& !((TypeDeclaration) itItem).isInterface()){
					numOfClassClasses++;
				}
			}
		}
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:29,代码来源:ClassVisitor.java

示例6: getMethodDeclaration

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public static MethodDeclaration getMethodDeclaration(String methodName) {
	IJavaElement javaElem = EditorUtility.getActiveEditorJavaInput();
	if (javaElem.getElementType() == IJavaElement.COMPILATION_UNIT) {
		ICompilationUnit iCompUnit = (ICompilationUnit) javaElem;
		ASTNode astNode = Crystal.getInstance()
				.getASTNodeFromCompilationUnit(iCompUnit);
		if (astNode != null
				&& astNode.getNodeType() == ASTNode.COMPILATION_UNIT) {
			CompilationUnit compUnit = (CompilationUnit) astNode;
			for (Object declaration : compUnit.types()) {
				if (declaration instanceof TypeDeclaration) {
					for (MethodDeclaration method : ((TypeDeclaration) declaration)
							.getMethods()) {
						if (methodName.contentEquals(method.getName()
								.getFullyQualifiedName())) {
							return method;
						}
					}
				}
			}
		}
	}
	return null;
}
 
开发者ID:aroog,项目名称:code,代码行数:25,代码来源:ASTUtils.java

示例7: visit

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public boolean visit(CompilationUnit node) {
	IJavaElement thisFile = node.getJavaElement();

	for (Object abstractTypeDeclaration : node.types()) {
		if (abstractTypeDeclaration instanceof TypeDeclaration) {
			TypeDeclaration td = (TypeDeclaration) abstractTypeDeclaration;
			typeToFileMap_.put(getQualifiedName(td.resolveBinding()),
					thisFile);
		}
	}

	return true;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:14,代码来源:ASTVisitorAtomicChange.java

示例8: calculateNumberOfMethods

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * Method to calculate the number of methods in a class and verify if 
 * two methods share attributes.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param unit
 */
private void calculateNumberOfMethods(CompilationUnit unit){
	
	for (Object type : unit.types()){
		if (type instanceof TypeDeclaration){
			
			MethodDeclaration [] methods = ((TypeDeclaration) type).getMethods();
			
			for (MethodDeclaration method: methods){
				this.listOfMethods.add(method);
			}
		}
	}
	
	Iterator<MethodDeclaration> itMethods = this.listOfMethods.iterator();
	
	while (itMethods.hasNext()){
		
		MethodDeclaration firstMethod = itMethods.next();
		MethodDeclaration secondMethod = null;
		
		if (itMethods.hasNext())
			secondMethod = itMethods.next();
		
		checkMethodsBody(firstMethod, secondMethod);
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:34,代码来源:TightClassCohesionVisitor.java

示例9: calculateNumberOfMethods

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * Method to calculate the number of methods in a class.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param unit
 */
private void calculateNumberOfMethods(CompilationUnit unit){
	for (Object type :unit.types()){
		if (type instanceof TypeDeclaration){
			
			MethodDeclaration [] methods = ((TypeDeclaration) type).getMethods();
			
			for (MethodDeclaration method: methods){
				this.methodsList.add(method);
			}
		}
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:19,代码来源:NumberOfMethodsVisitor.java

示例10: calculateFanOut

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
 * Method to calculate FOUT checking the number of types 
 * the class references.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param unit
 */
private void calculateFanOut(CompilationUnit unit){
	for (Object type :unit.types()){
		if (type instanceof TypeDeclaration){
			typesList.add((TypeDeclaration)type);
		}
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:15,代码来源:FanOutVisitor.java

示例11: getFirstType

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
private TypeDeclaration getFirstType(CompilationUnit compilationUnit) {
    List<TypeDeclaration> types = compilationUnit.types();
    if (types == null || types.size() == 0) {
        throw new PluginException("No types are present in the current java file");
    }
    return types.get(0);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:8,代码来源:BuilderOwnerClassFinder.java

示例12: removeBuilder

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public void removeBuilder(ASTRewrite rewriter, CompilationUnit compilationUnit) {
    List<TypeDeclaration> types = compilationUnit.types();
    if (types.size() == 1) {
        builderRemovers.stream()
                .forEach(remover -> remover.remove(rewriter, types.get(0)));
    }
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:8,代码来源:BuilderAstRemover.java

示例13: newTypeParameter

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public static TypeParameter newTypeParameter(AST ast, String content) {
	StringBuffer buffer= new StringBuffer(TYPEPARAM_HEADER);
	buffer.append(content);
	buffer.append(TYPEPARAM_FOOTER);
	ASTParser p= ASTParser.newParser(ast.apiLevel());
	p.setSource(buffer.toString().toCharArray());
	CompilationUnit root= (CompilationUnit) p.createAST(null);
	List<AbstractTypeDeclaration> list= root.types();
	TypeDeclaration typeDecl= (TypeDeclaration) list.get(0);
	MethodDeclaration methodDecl= typeDecl.getMethods()[0];
	TypeParameter tp= (TypeParameter) methodDecl.typeParameters().get(0);
	ASTNode result= ASTNode.copySubtree(ast, tp);
	result.accept(new PositionClearer());
	return (TypeParameter) result;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:16,代码来源:ASTNodeFactory.java

示例14: analyzeCompilationUnit

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
private void analyzeCompilationUnit(CompilationUnit unit, ICompilationUnit compilationUnit) {
	List types = unit.types();
	for (Iterator iter = types.iterator(); iter.hasNext();) {

		Object next = iter.next();
		if (next instanceof TypeDeclaration) {
			TypeDeclaration declaration = (TypeDeclaration) next;
			traverseType(declaration);
		}
	}

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

示例15: getWrongTypeNameProposals

import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public static void getWrongTypeNameProposals(IInvocationContext context, IProblemLocation problem,
		Collection<CUCorrectionProposal> proposals) {
	ICompilationUnit cu= context.getCompilationUnit();

	IJavaProject javaProject= cu.getJavaProject();
	String sourceLevel= javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
	String compliance= javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);

	CompilationUnit root= context.getASTRoot();

	ASTNode coveredNode= problem.getCoveredNode(root);
	if (!(coveredNode instanceof SimpleName)) {
		return;
	}

	ASTNode parentType= coveredNode.getParent();
	if (!(parentType instanceof AbstractTypeDeclaration)) {
		return;
	}

	String currTypeName= ((SimpleName) coveredNode).getIdentifier();
	String newTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName());


	List<AbstractTypeDeclaration> types= root.types();
	for (int i= 0; i < types.size(); i++) {
		AbstractTypeDeclaration curr= types.get(i);
		if (parentType != curr) {
			if (newTypeName.equals(curr.getName().getIdentifier())) {
				return;
			}
		}
	}
	if (!JavaConventions.validateJavaTypeName(newTypeName, sourceLevel, compliance).matches(IStatus.ERROR)) {
		proposals.add(new CorrectMainTypeNameProposal(cu, context, currTypeName, newTypeName, IProposalRelevance.RENAME_TYPE));
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:38,代码来源:ReorgCorrectionsSubProcessor.java


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