當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeDeclaration.accept方法代碼示例

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

}
 
開發者ID:fpalomba,項目名稱:aDoctor,代碼行數:79,代碼來源:ClassParser.java


注:本文中的org.eclipse.jdt.core.dom.TypeDeclaration.accept方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。