当前位置: 首页>>代码示例>>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;未经允许,请勿转载。