Examples of ConstructorDeclaration


Examples of com.asakusafw.utils.java.model.syntax.ConstructorDeclaration

            SimpleName name = factory.newSimpleName(
                    Naming.getReduceFragmentClass(fragment.getSerialNumber()));
            importer.resolvePackageMember(name);
            List<TypeBodyDeclaration> members = Lists.create();
            members.addAll(connection.createFields());
            ConstructorDeclaration ctor = connection.createConstructor(name);
            List<MethodDeclaration> methods = Lists.create();
            SimpleName value = names.create("value");
            methods.add(createProcess(value));
            methods.addAll(emit(value));
            members.addAll(extraFields);
View Full Code Here

Examples of com.asakusafw.utils.java.model.syntax.ConstructorDeclaration

            SimpleName name = getClassSimpleName();
            importer.resolvePackageMember(name);

            List<TypeBodyDeclaration> members = Lists.create();
            members.addAll(createFields());
            ConstructorDeclaration ctor = createConstructor();
            MethodDeclaration method = createBody();
            members.addAll(extraFields);
            members.add(ctor);
            members.add(method);
            return factory.newClassDeclaration(
View Full Code Here

Examples of com.asakusafw.utils.java.model.syntax.ConstructorDeclaration

            SimpleName name = factory.newSimpleName(
                    Naming.getMapFragmentClass(fragment.getSerialNumber()));
            importer.resolvePackageMember(name);
            List<TypeBodyDeclaration> members = Lists.create();
            members.addAll(connection.createFields());
            ConstructorDeclaration ctor = connection.createConstructor(name);
            MethodDeclaration method = createBody();
            members.addAll(extraFields);
            members.add(ctor);
            members.add(method);
            Type inputType = createInputType();
View Full Code Here

Examples of com.asakusafw.utils.java.model.syntax.ConstructorDeclaration

        assert className != null;
        assert importer != null;
        assert arguments != null;
        ModelFactory f = environment.getModelFactory();
        Statement ctorChain = f.newSuperConstructorInvocation(arguments);
        ConstructorDeclaration ctorDecl = f.newConstructorDeclaration(
                new JavadocBuilder(f)
                    .text("Creates a new instance.")
                    .toJavadoc(),
                new AttributeBuilder(f)
                    .Public()
View Full Code Here

Examples of com.bacoder.parser.java.api.ConstructorDeclaration

  @Override
  public ConstructorDeclaration adapt(GenericConstructorDeclarationContext context) {
    ConstructorDeclarationContext constructorDeclarationContext =
        getChild(context, ConstructorDeclarationContext.class);
    if (constructorDeclarationContext == null) {
      ConstructorDeclaration constructorDeclaration =
          getAdapter(ConstructorDeclarationAdapter.class).adapt(constructorDeclarationContext);
      TypeParametersContext typeParametersContext = getChild(context, TypeParametersContext.class);
      if (typeParametersContext != null) {
        constructorDeclaration.setTypeParameters(
            getAdapter(TypeParametersAdapter.class).adapt(typeParametersContext));
      }
      return constructorDeclaration;
    }
View Full Code Here

Examples of com.bacoder.parser.java.api.ConstructorDeclaration

    super(adapters);
  }

  @Override
  public ConstructorDeclaration adapt(ConstructorDeclarationContext context) {
    ConstructorDeclaration constructorDeclaration = createNode(context);

    TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
    if (identifierNode != null) {
      constructorDeclaration.setName(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
    }

    FormalParametersContext formalParametersContext =
        getChild(context, FormalParametersContext.class);
    if (formalParametersContext != null) {
      constructorDeclaration.setFormalParameters(
          getAdapter(FormalParametersAdapter.class).adapt(formalParametersContext));
    }

    QualifiedNameListContext qualifiedNameListContext =
        getChild(context, QualifiedNameListContext.class);
    if (qualifiedNameListContext != null) {
      constructorDeclaration.setThrowsExceptions(
          getAdapter(QualifiedNamesAdapter.class).adapt(qualifiedNameListContext));
    }

    ConstructorBodyContext constructorBodyContext = getChild(context, ConstructorBodyContext.class);
    if (constructorBodyContext != null) {
      BlockContext blockContext = getChild(constructorBodyContext, BlockContext.class);
      if (blockContext != null) {
        constructorDeclaration.setBody(getAdapter(BlockAdapter.class).adapt(blockContext));
      }
    }

    return constructorDeclaration;
  }
View Full Code Here

Examples of com.github.antlrjavaparser.api.body.ConstructorDeclaration

                    method.setCommentStructure(commentStructure);

                    cidBuilder.addMethod(method);
                }
                if (member instanceof ConstructorDeclaration) {
                    final ConstructorDeclaration castMember = (ConstructorDeclaration) member;
                    final ConstructorMetadata constructor = JavaParserConstructorMetadataBuilder
                            .getInstance(declaredByMetadataId, castMember,
                                    compilationUnitServices, typeParameterNames)
                            .build();

                    final CommentStructure commentStructure = new CommentStructure();
                    JavaParserCommentMetadataBuilder.updateCommentsToRoo(
                            commentStructure, member);
                    constructor.setCommentStructure(commentStructure);

                    cidBuilder.addConstructor(constructor);
                }
                if (member instanceof TypeDeclaration) {
                    final TypeDeclaration castMember = (TypeDeclaration) member;
                    final JavaType innerType = new JavaType(
                            castMember.getName(), name);
                    final String innerTypeMetadataId = PhysicalTypeIdentifier
                            .createIdentifier(innerType, PhysicalTypeIdentifier
                                    .getPath(declaredByMetadataId));
                    final ClassOrInterfaceTypeDetails cid = new JavaParserClassOrInterfaceTypeDetailsBuilder(
                            compilationUnit, compilationUnitServices,
View Full Code Here

Examples of com.github.antlrjavaparser.api.body.ConstructorDeclaration

                "Compilation unit services required");
        Validate.notNull(members, "Members required");
        Validate.notNull(constructor, "Method required");

        // Start with the basic constructor
        final ConstructorDeclaration d = new ConstructorDeclaration();
        d.setModifiers(JavaParserUtils.getJavaParserModifier(constructor
                .getModifier()));
        d.setName(PhysicalTypeIdentifier.getJavaType(
                constructor.getDeclaredByMetadataId()).getSimpleTypeName());

        // Add any constructor-level annotations (not parameter annotations)
        final List<AnnotationExpr> annotations = new ArrayList<AnnotationExpr>();
        d.setAnnotations(annotations);
        for (final AnnotationMetadata annotation : constructor.getAnnotations()) {
            JavaParserAnnotationMetadataBuilder.addAnnotationToList(
                    compilationUnitServices, annotations, annotation);
        }

        // Add any constructor parameters, including their individual
        // annotations and type parameters
        final List<Parameter> parameters = new ArrayList<Parameter>();
        d.setParameters(parameters);
        int index = -1;
        for (final AnnotatedJavaType constructorParameter : constructor
                .getParameterTypes()) {
            index++;

            // Add the parameter annotations applicable for this parameter type
            final List<AnnotationExpr> parameterAnnotations = new ArrayList<AnnotationExpr>();

            for (final AnnotationMetadata parameterAnnotation : constructorParameter
                    .getAnnotations()) {
                JavaParserAnnotationMetadataBuilder.addAnnotationToList(
                        compilationUnitServices, parameterAnnotations,
                        parameterAnnotation);
            }

            // Compute the parameter name
            final String parameterName = constructor.getParameterNames()
                    .get(index).getSymbolName();

            // Compute the parameter type
            Type parameterType = null;
            if (constructorParameter.getJavaType().isPrimitive()) {
                parameterType = JavaParserUtils.getType(constructorParameter
                        .getJavaType());
            }
            else {
                final Type finalType = JavaParserUtils.getResolvedName(
                        constructorParameter.getJavaType(),
                        constructorParameter.getJavaType(),
                        compilationUnitServices);
                final ClassOrInterfaceType cit = JavaParserUtils
                        .getClassOrInterfaceType(finalType);

                // Add any type arguments presented for the return type
                if (constructorParameter.getJavaType().getParameters().size() > 0) {
                    final List<Type> typeArgs = new ArrayList<Type>();
                    cit.setTypeArgs(typeArgs);
                    for (final JavaType parameter : constructorParameter
                            .getJavaType().getParameters()) {
                        // NameExpr importedParameterType =
                        // JavaParserUtils.importTypeIfRequired(compilationUnitServices.getEnclosingTypeName(),
                        // compilationUnitServices.getImports(), parameter);
                        // typeArgs.add(JavaParserUtils.getReferenceType(importedParameterType));
                        typeArgs.add(JavaParserUtils.importParametersForType(
                                compilationUnitServices.getEnclosingTypeName(),
                                compilationUnitServices.getImports(), parameter));
                    }

                }
                parameterType = finalType;
            }

            // Create a Java Parser constructor parameter and add it to the list
            // of parameters
            final Parameter p = new Parameter(parameterType,
                    new VariableDeclaratorId(parameterName));
            p.setAnnotations(parameterAnnotations);
            parameters.add(p);
        }

        // Set the body
        if (constructor.getBody() == null
                || constructor.getBody().length() == 0) {
            d.setBlock(new BlockStmt());
        }
        else {
            // There is a body.
            // We need to make a fake constructor that we can have JavaParser
            // parse.
            // Easiest way to do that is to build a simple source class
            // containing the required method and re-parse it.
            final StringBuilder sb = new StringBuilder();
            sb.append("class TemporaryClass {\n");
            sb.append("  TemporaryClass() {\n");
            sb.append(constructor.getBody());
            sb.append("\n");
            sb.append("  }\n");
            sb.append("}\n");
            final ByteArrayInputStream bais = new ByteArrayInputStream(sb
                    .toString().getBytes());
            CompilationUnit ci;
            try {
                ci = JavaParser.parse(bais);
            }
            catch (final IOException e) {
                throw new IllegalStateException(
                        "Illegal state: Unable to parse input stream", e);
            }
            catch (final ParseException pe) {
                throw new IllegalStateException(
                        "Illegal state: JavaParser did not parse correctly", pe);
            }
            final List<TypeDeclaration> types = ci.getTypes();
            if (types == null || types.size() != 1) {
                throw new IllegalArgumentException("Method body invalid");
            }
            final TypeDeclaration td = types.get(0);
            final List<BodyDeclaration> bodyDeclarations = td.getMembers();
            if (bodyDeclarations == null || bodyDeclarations.size() != 1) {
                throw new IllegalStateException(
                        "Illegal state: JavaParser did not return body declarations correctly");
            }
            final BodyDeclaration bd = bodyDeclarations.get(0);
            if (!(bd instanceof ConstructorDeclaration)) {
                throw new IllegalStateException(
                        "Illegal state: JavaParser did not return a method declaration correctly");
            }
            final ConstructorDeclaration cd = (ConstructorDeclaration) bd;
            d.setBlock(cd.getBlock());
        }

        // Locate where to add this constructor; also verify if this method
        // already exists
        for (final BodyDeclaration bd : members) {
            if (bd instanceof ConstructorDeclaration) {
                // Next constructor should appear after this current constructor
                final ConstructorDeclaration cd = (ConstructorDeclaration) bd;
                if (cd.getParameters().size() == d.getParameters().size()) {
                    // Possible match, we need to consider parameter types as
                    // well now
                    final ConstructorMetadata constructorMetadata = new JavaParserConstructorMetadataBuilder(
                            constructor.getDeclaredByMetadataId(), cd,
                            compilationUnitServices, typeParameters).build();
View Full Code Here

Examples of com.github.antlrjavaparser.api.body.ConstructorDeclaration

                    cidConstructor.add((ConstructorDeclaration) element);
                }
            }
        }

        ConstructorDeclaration originalConstructor, newConstructor;
        boolean notFound;
        // Iterate over every method definition
        if (originalType.getMembers() != null) {
            for (final Iterator<BodyDeclaration> originalMemberstIter = originalType
                    .getMembers().iterator(); originalMemberstIter.hasNext();) {
                final BodyDeclaration originalMember = originalMemberstIter
                        .next();
                if (!(originalMember instanceof ConstructorDeclaration)) {
                    // this is not a method definition
                    continue;
                }
                originalConstructor = (ConstructorDeclaration) originalMember;

                notFound = true;

                // look at cidConstructor for originalConstructor
                for (final Iterator<ConstructorDeclaration> newConstructorIter = cidConstructor
                        .iterator(); newConstructorIter.hasNext();) {
                    newConstructor = newConstructorIter.next();
                    // Check if is the same constructor (comparing its
                    // parameters)
                    if (equalsDeclaration(originalConstructor, newConstructor)) {
                        notFound = false;

                        // Remove from cid methods to check
                        newConstructorIter.remove();

                        // Update modifier if is changed
                        if (originalConstructor.getModifiers() != newConstructor
                                .getModifiers()) {
                            originalConstructor.setModifiers(newConstructor
                                    .getModifiers());
                        }

                        // Update annotations if are changed
                        if (!equalsAnnotations(
                                originalConstructor.getAnnotations(),
                                newConstructor.getAnnotations())) {
                            originalConstructor.setAnnotations(newConstructor
                                    .getAnnotations());
                        }

                        // Update body if is changed
                        if (!equals(originalConstructor.getBlock(),
                                newConstructor.getBlock())) {
                            originalConstructor.setBlock(newConstructor
                                    .getBlock());
                        }
                        break;

                    }
View Full Code Here

Examples of com.google.dart.engine.ast.ConstructorDeclaration

          return annotation.getElement();
        }
      }
      // Extra work to map Constructor Declarations to their associated Constructor Elements
      if (parent instanceof ConstructorDeclaration) {
        ConstructorDeclaration decl = (ConstructorDeclaration) parent;
        Identifier returnType = decl.getReturnType();
        if (returnType == node) {
          SimpleIdentifier name = decl.getName();
          if (name != null) {
            return name.getBestElement();
          }
          Element element = node.getBestElement();
          if (element instanceof ClassElement) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.