本文整理汇总了Java中org.eclipse.jdt.core.dom.TypeDeclaration.accept方法的典型用法代码示例。如果您正苦于以下问题:Java TypeDeclaration.accept方法的具体用法?Java TypeDeclaration.accept怎么用?Java TypeDeclaration.accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.TypeDeclaration
的用法示例。
在下文中一共展示了TypeDeclaration.accept方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.eclipse.jdt.core.dom.TypeDeclaration; //导入方法依赖的package包/类
public static ClassBean parse(TypeDeclaration pClassNode) {
int numberOfGetterOrSetter = 0;
// Instantiate the bean
ClassBean classBean = new ClassBean();
if (pClassNode.getSuperclassType() != null) {
classBean.setSuperclass(pClassNode.getSuperclassType().toString());
} else {
classBean.setSuperclass(null);
}
// Set the name
classBean.setName(pClassNode.getName().toString());
// Get the instance variable nodes
Collection<FieldDeclaration> instanceVariableNodes = new ArrayList<>();
pClassNode.accept(new InstanceVariableVisitor(instanceVariableNodes));
classBean.setTextContent(pClassNode.toString());
Pattern newLine = Pattern.compile("\n");
String[] lines = newLine.split(pClassNode.toString());
classBean.setLOC(lines.length);
// Get the instance variable beans from the instance variable nodes
Collection<InstanceVariableBean> instanceVariableBeans = new ArrayList<>();
for (FieldDeclaration instanceVariableNode : instanceVariableNodes) {
instanceVariableBeans.add(InstanceVariableParser.parse(instanceVariableNode));
}
// Set the collection of instance variables
classBean.setInstanceVariables(instanceVariableBeans);
// Get the method nodes
Collection<MethodDeclaration> methodNodes = new ArrayList<>();
pClassNode.accept(new MethodVisitor(methodNodes));
// Get the method beans from the method nodes
Collection<MethodBean> methodBeans = new ArrayList<>();
for (MethodDeclaration methodNode : methodNodes) {
if ((methodNode.getName().toString().contains("get") || (methodNode.getName().toString().contains("set")))) {
if (methodNode.parameters().isEmpty()) {
numberOfGetterOrSetter++;
}
}
methodBeans.add(MethodParser.parse(methodNode, instanceVariableBeans));
}
classBean.setNumberOfGetterAndSetter(numberOfGetterOrSetter);
// Iterate over the collection of methods
for (MethodBean classMethod : methodBeans) {
// Instantiate a collection of class-defined invocations
Collection<MethodBean> definedInvocations = new ArrayList<>();
// Get the method invocations
Collection<MethodBean> classMethodInvocations = classMethod.getMethodCalls();
// Iterate over the collection of method invocations
for (MethodBean classMethodInvocation : classMethodInvocations) {
definedInvocations.add(classMethodInvocation);
}
// Set the class-defined invocations
classMethod.setMethodCalls(definedInvocations);
}
// Set the collection of methods
classBean.setMethods(methodBeans);
return classBean;
}