本文整理匯總了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;
}