Examples of ConstructorDeclaration


Examples of com.sun.mirror.declaration.ConstructorDeclaration

  @NotNull
  protected JInvocation createDomainObjectCreationExpression( @NotNull DomainObjectDescriptor domainObjectDescriptor ) {
    JInvocation invocation = JExpr._new( codeGenerator.ref( domainObjectDescriptor.getQualifiedName() ) );

    ConstructorDeclaration constructor = domainObjectDescriptor.findBestConstructor();
    for ( ParameterDeclaration parameterDeclaration : constructor.getParameters() ) {
      invocation.arg( codeGenerator.getNewInstanceFactory().create( parameterDeclaration.getType(), parameterDeclaration.getSimpleName() ) );
    }

    return invocation;
  }
View Full Code Here

Examples of com.sun.mirror.declaration.ConstructorDeclaration

    return findConstructorCallInfoForField( fieldDeclaration.getSimpleName(), fieldDeclaration.getType() );
  }

  @NotNull
  public ConstructorCallInfo findConstructorCallInfoForField( @NotNull @NonNls String simpleName, @NotNull TypeMirror type ) throws IllegalArgumentException {
    ConstructorDeclaration constructorDeclaration = TypeUtils.findBestConstructor( classDeclaration );

    int index = 0;

    for ( ParameterDeclaration parameterDeclaration : constructorDeclaration.getParameters() ) {
      if ( parameterDeclaration.getSimpleName().equals( simpleName ) ) {
        //Found a fitting type
        if ( TypeUtils.mightBeConstructorCallFor( parameterDeclaration.getType(), type ) ) {
          return new ConstructorCallInfo( constructorDeclaration, index, parameterDeclaration );
        } else {
View Full Code Here

Examples of com.sun.mirror.declaration.ConstructorDeclaration

    return returnBinaryName ? classWithWildcard.binaryName() : classWithWildcard.fullName();
  }

  @NotNull
  public static ConstructorDeclaration findBestConstructor( @NotNull ClassDeclaration classDeclaration ) {
    ConstructorDeclaration currentlyBest = null;
    for ( ConstructorDeclaration constructorDeclaration : classDeclaration.getConstructors() ) {
      if ( currentlyBest == null || constructorDeclaration.getParameters().size() > currentlyBest.getParameters().size() ) {
        currentlyBest = constructorDeclaration;
      }
    }

    if ( currentlyBest == null ) {
View Full Code Here

Examples of japa.parser.ast.body.ConstructorDeclaration

                                    compilationUnitServices, typeParameterNames)
                            .build();
                    cidBuilder.addMethod(method);
                }
                if (member instanceof ConstructorDeclaration) {
                    final ConstructorDeclaration castMember = (ConstructorDeclaration) member;
                    final ConstructorMetadata constructor = JavaParserConstructorMetadataBuilder
                            .getInstance(declaredByMetadataId, castMember,
                                    compilationUnitServices, typeParameterNames)
                            .build();
                    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 japa.parser.ast.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 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 lombok.ast.ConstructorDeclaration

                    return true;
                }
            } else if (type == ConstructorDeclaration.class) {
                // Constructor
                // Look for annotations on the method
                ConstructorDeclaration declaration = (ConstructorDeclaration) scope;
                if (isSuppressed(issue, declaration.astModifiers())) {
                    return true;
                }
            } else if (type == ClassDeclaration.class) {
                // Class
                ClassDeclaration declaration = (ClassDeclaration) scope;
                if (isSuppressed(issue, declaration.astModifiers())) {
                    return true;
                }
            }

            scope = scope.getParent();
View Full Code Here

Examples of lombok.ast.ConstructorDeclaration

                    return true;
                }
            } else if (type == ConstructorDeclaration.class) {
                // Constructor
                // Look for annotations on the method
                ConstructorDeclaration declaration = (ConstructorDeclaration) scope;
                if (isSuppressed(issue, declaration.astModifiers())) {
                    return true;
                }
            } else if (type == ClassDeclaration.class) {
                // Class
                ClassDeclaration declaration = (ClassDeclaration) scope;
                if (isSuppressed(issue, declaration.astModifiers())) {
                    return true;
                }
            }

            scope = scope.getParent();
View Full Code Here

Examples of org.apache.beehive.netui.compiler.typesystem.declaration.ConstructorDeclaration

            }
           
            if ( array.length == 0 )
            {
                XConstructor ctor = new DefaultConstructor( getDelegateXClass() );
                ConstructorDeclaration decl = WrapperFactory.get().getConstructorDeclaration( ctor );
                _constructors = new ConstructorDeclaration[]{ decl };
            }
            else
            {
                _constructors = array;
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration

    // if selecting a type for an anonymous type creation, we have to
    // find its target super constructor (if extending a class) or its target
    // super interface (if extending an interface)
    if (anonymousType.binding.superInterfaces == Binding.NO_SUPERINTERFACES) {
      // find the constructor binding inside the super constructor call
      ConstructorDeclaration constructor = (ConstructorDeclaration) anonymousType.declarationOf(binding.original());
      throw new SelectionNodeFound(constructor.constructorCall.binding);
    } else {
      // open on the only superinterface
      throw new SelectionNodeFound(anonymousType.binding.superInterfaces[0]);
    }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration

    }
    return internalFormatExpression(source, indentationLevel, lineSeparator, expression, offset, length);
  }

  private TextEdit formatStatements(String source, int indentationLevel, String lineSeparator, int offset, int length) {
    ConstructorDeclaration constructorDeclaration = this.codeSnippetParsingUtil.parseStatements(source.toCharArray(), getDefaultCompilerOptions(), true, false);
   
    if (constructorDeclaration.statements == null) {
      // a problem occured while parsing the source
      return null;
    }
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.