Package japa.parser.ast.body

Examples of japa.parser.ast.body.EnumDeclaration


            if (implementsList.size() > 0) {
                classOrInterfaceDeclaration.setImplements(implementsList);
            }
        }
        else {
            typeDeclaration = new EnumDeclaration(javaParserModifier, cid
                    .getName().getSimpleTypeName());
        }
        typeDeclaration.setMembers(new ArrayList<BodyDeclaration>());

        Validate.notNull(typeDeclaration.getName(),
                "Missing type declaration name for '" + cid.getName() + "'");

        // If adding a new top-level type, must add it to the compilation unit
        // types
        Validate.notNull(compilationUnit.getTypes(),
                "Compilation unit types must not be null when attempting to add '"
                        + cid.getName() + "'");

        if (parent == null) {
            // Top-level class
            compilationUnit.getTypes().add(typeDeclaration);
        }
        else {
            // Inner class
            parent.add(typeDeclaration);
        }

        // If the enclosing CompilationUnitServices was not provided a default
        // CompilationUnitServices needs to be created
        if (enclosingCompilationUnitServices == null) {
            // Create a compilation unit so that we can use JavaType*Metadata
            // static methods directly
            enclosingCompilationUnitServices = new CompilationUnitServices() {
                public JavaPackage getCompilationUnitPackage() {
                    return cid.getName().getPackage();
                }

                public JavaType getEnclosingTypeName() {
                    return cid.getName();
                }

                public List<ImportDeclaration> getImports() {
                    return compilationUnit.getImports();
                }

                public List<TypeDeclaration> getInnerTypes() {
                    return compilationUnit.getTypes();
                }

                public PhysicalTypeCategory getPhysicalTypeCategory() {
                    return cid.getPhysicalTypeCategory();
                }
            };
        }

        final CompilationUnitServices finalCompilationUnitServices = enclosingCompilationUnitServices;
        // A hybrid CompilationUnitServices must be provided that references the
        // enclosing types imports and package
        final CompilationUnitServices compilationUnitServices = new CompilationUnitServices() {
            public JavaPackage getCompilationUnitPackage() {
                return finalCompilationUnitServices.getCompilationUnitPackage();
            }

            public JavaType getEnclosingTypeName() {
                return cid.getName();
            }

            public List<ImportDeclaration> getImports() {
                return finalCompilationUnitServices.getImports();
            }

            public List<TypeDeclaration> getInnerTypes() {
                return compilationUnit.getTypes();
            }

            public PhysicalTypeCategory getPhysicalTypeCategory() {
                return cid.getPhysicalTypeCategory();
            }
        };

        // Add type annotations
        final List<AnnotationExpr> annotations = new ArrayList<AnnotationExpr>();
        typeDeclaration.setAnnotations(annotations);
        for (final AnnotationMetadata candidate : cid.getAnnotations()) {
            JavaParserAnnotationMetadataBuilder.addAnnotationToList(
                    compilationUnitServices, annotations, candidate);
        }

        // Add enum constants and interfaces
        if (typeDeclaration instanceof EnumDeclaration
                && cid.getEnumConstants().size() > 0) {
            final EnumDeclaration enumDeclaration = (EnumDeclaration) typeDeclaration;

            final List<EnumConstantDeclaration> constants = new ArrayList<EnumConstantDeclaration>();
            enumDeclaration.setEntries(constants);

            for (final JavaSymbolName constant : cid.getEnumConstants()) {
                addEnumConstant(constants, constant);
            }

            // Implements handling
            if (implementsList.size() > 0) {
                enumDeclaration.setImplements(implementsList);
            }
        }

        // Add fields
        for (final FieldMetadata candidate : cid.getDeclaredFields()) {
View Full Code Here


    public ClassOrInterfaceTypeDetails build() {
        Validate.notEmpty(compilationUnit.getTypes(),
                "No types in compilation unit, so unable to continue parsing");

        ClassOrInterfaceDeclaration clazz = null;
        EnumDeclaration enumClazz = null;

        final StringBuilder sb = new StringBuilder(compilationUnit.getPackage()
                .getName().toString());
        if (name.getEnclosingType() != null) {
            sb.append(".").append(name.getEnclosingType().getSimpleTypeName());
        }
        compilationUnitPackage = new JavaPackage(sb.toString());

        // Determine the type name, adding type parameters if possible
        final JavaType newName = JavaParserUtils.getJavaType(
                compilationUnitServices, typeDeclaration);

        // Revert back to the original type name (thus avoiding unnecessary
        // inferences about java.lang types; see ROO-244)
        name = new JavaType(newName.getFullyQualifiedTypeName(),
                newName.getEnclosingType(), newName.getArray(),
                newName.getDataType(), newName.getArgName(),
                newName.getParameters());

        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId);

        physicalTypeCategory = PhysicalTypeCategory.CLASS;
        if (typeDeclaration instanceof ClassOrInterfaceDeclaration) {
            clazz = (ClassOrInterfaceDeclaration) typeDeclaration;
            if (clazz.isInterface()) {
                physicalTypeCategory = PhysicalTypeCategory.INTERFACE;
            }

        }
        else if (typeDeclaration instanceof EnumDeclaration) {
            enumClazz = (EnumDeclaration) typeDeclaration;
            physicalTypeCategory = PhysicalTypeCategory.ENUMERATION;
        }

        Validate.notNull(physicalTypeCategory, UNSUPPORTED_MESSAGE_PREFIX
                + " (" + typeDeclaration.getClass().getSimpleName() + " for "
                + name + ")");

        cidBuilder.setName(name);
        cidBuilder.setPhysicalTypeCategory(physicalTypeCategory);

        imports = compilationUnit.getImports();
        if (imports == null) {
            imports = new ArrayList<ImportDeclaration>();
            compilationUnit.setImports(imports);
        }

        // Verify the package declaration appears to be correct
        Validate.isTrue(compilationUnitPackage.equals(name.getPackage()),
                "Compilation unit package '" + compilationUnitPackage
                        + "' unexpected for type '" + name.getPackage() + "'");

        for (final ImportDeclaration importDeclaration : imports) {
            if (importDeclaration.getName() instanceof QualifiedNameExpr) {
                final String qualifier = ((QualifiedNameExpr) importDeclaration
                        .getName()).getQualifier().toString();
                final String simpleName = importDeclaration.getName().getName();
                final String fullName = qualifier + "." + simpleName;
                // We want to calculate these...

                final JavaType type = new JavaType(fullName);
                final JavaPackage typePackage = importDeclaration.isAsterisk()
                    ? new JavaPackage(fullName) : type.getPackage();
                final ImportMetadataBuilder newImport = new ImportMetadataBuilder(
                        declaredByMetadataId, 0, typePackage, type,
                        importDeclaration.isStatic(),
                        importDeclaration.isAsterisk());
                cidBuilder.add(newImport.build());
            }
        }

        // Convert Java Parser modifier into JDK modifier
        cidBuilder.setModifier(JavaParserUtils.getJdkModifier(typeDeclaration
                .getModifiers()));

        // Type parameters
        final Set<JavaSymbolName> typeParameterNames = new HashSet<JavaSymbolName>();
        for (final JavaType param : name.getParameters()) {
            final JavaSymbolName arg = param.getArgName();
            // Fortunately type names can only appear at the top-level
            if (arg != null && !JavaType.WILDCARD_NEITHER.equals(arg)
                    && !JavaType.WILDCARD_EXTENDS.equals(arg)
                    && !JavaType.WILDCARD_SUPER.equals(arg)) {
                typeParameterNames.add(arg);
            }
        }

        List<ClassOrInterfaceType> implementsList;
        List<AnnotationExpr> annotationsList = null;
        List<BodyDeclaration> members = null;

        if (clazz != null) {
            final List<ClassOrInterfaceType> extendsList = clazz.getExtends();
            if (extendsList != null) {
                for (final ClassOrInterfaceType candidate : extendsList) {
                    final JavaType javaType = JavaParserUtils.getJavaTypeNow(
                            compilationUnitServices, candidate,
                            typeParameterNames);
                    cidBuilder.addExtendsTypes(javaType);
                }
            }

            final List<JavaType> extendsTypes = cidBuilder.getExtendsTypes();
            // Obtain the superclass, if this is a class and one is available
            if (physicalTypeCategory == PhysicalTypeCategory.CLASS
                    && extendsTypes.size() == 1) {
                final JavaType superclass = extendsTypes.get(0);
                final String superclassId = typeLocationService
                        .getPhysicalTypeIdentifier(superclass);
                PhysicalTypeMetadata superPtm = null;
                if (superclassId != null) {
                    superPtm = (PhysicalTypeMetadata) metadataService
                            .get(superclassId);
                }
                if (superPtm != null
                        && superPtm.getMemberHoldingTypeDetails() != null) {
                    cidBuilder.setSuperclass(superPtm
                            .getMemberHoldingTypeDetails());
                }
            }

            implementsList = clazz.getImplements();
            if (implementsList != null) {
                for (final ClassOrInterfaceType candidate : implementsList) {
                    final JavaType javaType = JavaParserUtils.getJavaTypeNow(
                            compilationUnitServices, candidate,
                            typeParameterNames);
                    cidBuilder.addImplementsType(javaType);
                }
            }

            annotationsList = typeDeclaration.getAnnotations();
            members = clazz.getMembers();
        }

        if (enumClazz != null) {
            final List<EnumConstantDeclaration> constants = enumClazz
                    .getEntries();
            if (constants != null) {
                for (final EnumConstantDeclaration enumConstants : constants) {
                    cidBuilder.addEnumConstant(new JavaSymbolName(enumConstants
                            .getName()));
                }
            }

            implementsList = enumClazz.getImplements();
            annotationsList = enumClazz.getAnnotations();
            members = enumClazz.getMembers();
        }

        if (annotationsList != null) {
            for (final AnnotationExpr candidate : annotationsList) {
                final AnnotationMetadata md = JavaParserAnnotationMetadataBuilder
View Full Code Here

        return Boolean.TRUE;
    }

    public Boolean visit(EnumDeclaration n1, Node arg) {
        EnumDeclaration n2 = (EnumDeclaration) arg;

        // javadoc are checked at CompilationUnit

        if (n1.getModifiers() != n2.getModifiers()) {
            return Boolean.FALSE;
        }

        if (!objEquals(n1.getName(), n2.getName())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getImplements(), n2.getImplements())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getEntries(), n2.getEntries())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getMembers(), n2.getMembers())) {
            return Boolean.FALSE;
        }

        return Boolean.TRUE;
    }
View Full Code Here

                ;
        }
        jj_consume_token(RBRACE);
        {
            if (true) {
                return new EnumDeclaration(line, column, token.endLine, token.endColumn, popJavadoc(), modifier.modifiers, modifier.annotations, name, impList, entries, members);
            }
        }
        throw new Error("Missing return statement in function");
    }
View Full Code Here

    List<ClassOrInterfaceType> implementsList = visit(_n.getImplements(), _arg);
    List<EnumConstantDeclaration> entries = visit(_n.getEntries(), _arg);
    List<BodyDeclaration> members = visit(_n.getMembers(), _arg);
    Comment comment = cloneNodes(_n.getComment(), _arg);

    EnumDeclaration r = new EnumDeclaration(
        _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
         _n.getModifiers(), annotations, _n.getName(), implementsList, entries, members
    );
    r.setComment(comment);
    return r;
  }
View Full Code Here

    return Boolean.TRUE;
  }

  @Override public Boolean visit(final EnumDeclaration n1, final Node arg) {
    final EnumDeclaration n2 = (EnumDeclaration) arg;

    // javadoc are checked at CompilationUnit

    if (n1.getModifiers() != n2.getModifiers()) {
      return Boolean.FALSE;
    }

    if (!objEquals(n1.getName(), n2.getName())) {
      return Boolean.FALSE;
    }

    if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
      return Boolean.FALSE;
    }

    if (!nodesEquals(n1.getImplements(), n2.getImplements())) {
      return Boolean.FALSE;
    }

    if (!nodesEquals(n1.getEntries(), n2.getEntries())) {
      return Boolean.FALSE;
    }

    if (!nodesEquals(n1.getMembers(), n2.getMembers())) {
      return Boolean.FALSE;
    }

    return Boolean.TRUE;
  }
View Full Code Here

TOP

Related Classes of japa.parser.ast.body.EnumDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.