本文整理汇总了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);
}
}
}
示例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);
}
}
}
}
}
示例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();
}
}
}
示例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);
}
}
}
}
}
示例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++;
}
}
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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);
}
示例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)));
}
}
示例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;
}
示例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);
}
}
}
示例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));
}
}