Example usage for org.eclipse.jdt.internal.compiler.ast ExplicitConstructorCall ExplicitConstructorCall

List of usage examples for org.eclipse.jdt.internal.compiler.ast ExplicitConstructorCall ExplicitConstructorCall

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast ExplicitConstructorCall ExplicitConstructorCall.

Prototype

public ExplicitConstructorCall(int accessMode) 

Source Link

Usage

From source file:lombok.eclipse.handlers.ast.EclipseASTMaker.java

License:Open Source License

@Override
public ASTNode visitConstructorDecl(final lombok.ast.ConstructorDecl node, final Void p) {
    final ConstructorDeclaration constructorDeclaration = new ConstructorDeclaration(
            ((CompilationUnitDeclaration) sourceNode.top().get()).compilationResult);
    setGeneratedByAndCopyPos(constructorDeclaration, source, posHintOf(node));
    constructorDeclaration.modifiers = modifiersFor(node.getModifiers());
    constructorDeclaration.annotations = toArray(build(node.getAnnotations()), new Annotation[0]);
    if (node.implicitSuper()) {
        constructorDeclaration.constructorCall = new ExplicitConstructorCall(
                ExplicitConstructorCall.ImplicitSuper);
    }//w  ww . jav  a2  s.  c o  m
    constructorDeclaration.selector = node.getName().toCharArray();
    constructorDeclaration.thrownExceptions = toArray(build(node.getThrownExceptions()), new TypeReference[0]);
    constructorDeclaration.typeParameters = toArray(build(node.getTypeParameters()), new TypeParameter[0]);
    constructorDeclaration.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructorDeclaration.arguments = toArray(build(node.getArguments()), new Argument[0]);
    if (!node.getStatements().isEmpty()) {
        constructorDeclaration.statements = toArray(build(node.getStatements()), new Statement[0]);
    }
    constructorDeclaration.javadoc = build(node.getJavaDoc());
    return constructorDeclaration;
}

From source file:lombok.eclipse.handlers.HandleConstructor.java

License:Open Source License

public static ConstructorDeclaration createConstructor(AccessLevel level, EclipseNode type,
        Collection<EclipseNode> fields, boolean allToDefault, Boolean suppressConstructorProperties,
        EclipseNode sourceNode, List<Annotation> onConstructor) {

    ASTNode source = sourceNode.get();/*from w  w  w  .  j  ava 2s .c  o m*/
    TypeDeclaration typeDeclaration = ((TypeDeclaration) type.get());
    long p = (long) source.sourceStart << 32 | source.sourceEnd;

    boolean isEnum = (((TypeDeclaration) type.get()).modifiers & ClassFileConstants.AccEnum) != 0;

    if (isEnum)
        level = AccessLevel.PRIVATE;

    if (suppressConstructorProperties == null) {
        if (fields.isEmpty()) {
            suppressConstructorProperties = false;
        } else {
            suppressConstructorProperties = Boolean.TRUE.equals(type.getAst()
                    .readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES));
        }
    }

    ConstructorDeclaration constructor = new ConstructorDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);

    constructor.modifiers = toEclipseModifier(level);
    constructor.selector = typeDeclaration.name;
    constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper);
    constructor.constructorCall.sourceStart = source.sourceStart;
    constructor.constructorCall.sourceEnd = source.sourceEnd;
    constructor.thrownExceptions = null;
    constructor.typeParameters = null;
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
    constructor.arguments = null;

    List<Argument> params = new ArrayList<Argument>();
    List<Statement> assigns = new ArrayList<Statement>();
    List<Statement> nullChecks = new ArrayList<Statement>();

    for (EclipseNode fieldNode : fields) {
        FieldDeclaration field = (FieldDeclaration) fieldNode.get();
        char[] rawName = field.name;
        char[] fieldName = removePrefixFromField(fieldNode);
        FieldReference thisX = new FieldReference(rawName, p);
        int s = (int) (p >> 32);
        int e = (int) p;
        thisX.receiver = new ThisReference(s, e);

        Expression assignmentExpr = allToDefault ? getDefaultExpr(field.type, s, e)
                : new SingleNameReference(fieldName, p);

        Assignment assignment = new Assignment(thisX, assignmentExpr, (int) p);
        assignment.sourceStart = (int) (p >> 32);
        assignment.sourceEnd = assignment.statementEnd = (int) (p >> 32);
        assigns.add(assignment);
        if (!allToDefault) {
            long fieldPos = (((long) field.sourceStart) << 32) | field.sourceEnd;
            Argument parameter = new Argument(fieldName, fieldPos, copyType(field.type, source),
                    Modifier.FINAL);
            Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
            Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
            if (nonNulls.length != 0) {
                Statement nullCheck = generateNullCheck(field, sourceNode);
                if (nullCheck != null)
                    nullChecks.add(nullCheck);
            }
            parameter.annotations = copyAnnotations(source, nonNulls, nullables);
            params.add(parameter);
        }
    }

    nullChecks.addAll(assigns);
    constructor.statements = nullChecks.isEmpty() ? null : nullChecks.toArray(new Statement[nullChecks.size()]);
    constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]);

    /* Generate annotations that must  be put on the generated method, and attach them. */ {
        Annotation[] constructorProperties = null;
        if (!allToDefault && !suppressConstructorProperties && level != AccessLevel.PRIVATE
                && level != AccessLevel.PACKAGE && !isLocalType(type)) {
            constructorProperties = createConstructorProperties(source, fields);
        }

        constructor.annotations = copyAnnotations(source, onConstructor.toArray(new Annotation[0]),
                constructorProperties);
    }

    constructor.traverse(new SetGeneratedByVisitor(source), typeDeclaration.scope);
    return constructor;
}

From source file:lombok.eclipse.handlers.HandleFieldNameConstants.java

License:Open Source License

private void createInnerTypeFieldNameConstants(EclipseNode typeNode, EclipseNode errorNode, ASTNode source,
        AccessLevel level, List<EclipseNode> fields, boolean asEnum, String innerTypeName) {
    if (fields.isEmpty())
        return;//from   www. j  av  a 2s.c o  m

    ASTVisitor generatedByVisitor = new SetGeneratedByVisitor(source);
    TypeDeclaration parent = (TypeDeclaration) typeNode.get();
    EclipseNode fieldsType = findInnerClass(typeNode, innerTypeName);
    boolean genConstr = false, genClinit = false;
    char[] name = innerTypeName.toCharArray();
    TypeDeclaration generatedInnerType = null;
    if (fieldsType == null) {
        generatedInnerType = new TypeDeclaration(parent.compilationResult);
        generatedInnerType.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
        generatedInnerType.modifiers = toEclipseModifier(level) | (asEnum ? ClassFileConstants.AccEnum
                : (ClassFileConstants.AccStatic | ClassFileConstants.AccFinal));
        generatedInnerType.name = name;
        fieldsType = injectType(typeNode, generatedInnerType);
        genConstr = true;
        genClinit = asEnum;
        generatedInnerType.traverse(generatedByVisitor, ((TypeDeclaration) typeNode.get()).scope);
    } else {
        TypeDeclaration builderTypeDeclaration = (TypeDeclaration) fieldsType.get();
        if (asEnum && (builderTypeDeclaration.modifiers & ClassFileConstants.AccEnum) == 0) {
            errorNode.addError("Existing " + innerTypeName + " must be declared as an 'enum'.");
            return;
        }
        if (!asEnum && (builderTypeDeclaration.modifiers & ClassFileConstants.AccStatic) == 0) {
            errorNode.addError("Existing " + innerTypeName + " must be declared as a 'static class'.");
            return;
        }
        genConstr = constructorExists(fieldsType) == MemberExistsResult.NOT_EXISTS;
    }

    if (genConstr) {
        ConstructorDeclaration constructor = new ConstructorDeclaration(parent.compilationResult);
        constructor.selector = name;
        constructor.modifiers = ClassFileConstants.AccPrivate;
        ExplicitConstructorCall superCall = new ExplicitConstructorCall(0);
        superCall.sourceStart = source.sourceStart;
        superCall.sourceEnd = source.sourceEnd;
        superCall.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
        constructor.constructorCall = superCall;
        if (!asEnum)
            constructor.statements = new Statement[0];
        injectMethod(fieldsType, constructor);
    }

    if (genClinit) {
        Clinit cli = new Clinit(parent.compilationResult);
        injectMethod(fieldsType, cli);
        cli.traverse(generatedByVisitor, ((TypeDeclaration) fieldsType.get()).scope);
    }

    for (EclipseNode fieldNode : fields) {
        FieldDeclaration field = (FieldDeclaration) fieldNode.get();
        char[] fName = field.name;
        if (fieldExists(new String(fName), fieldsType) != MemberExistsResult.NOT_EXISTS)
            continue;
        int pS = source.sourceStart, pE = source.sourceEnd;
        long p = (long) pS << 32 | pE;
        FieldDeclaration constantField = new FieldDeclaration(fName, pS, pE);
        constantField.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
        if (asEnum) {
            AllocationExpression ac = new AllocationExpression();
            ac.enumConstant = constantField;
            ac.sourceStart = source.sourceStart;
            ac.sourceEnd = source.sourceEnd;
            constantField.initialization = ac;
            constantField.modifiers = 0;
        } else {
            constantField.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_STRING,
                    new long[] { p, p, p });
            constantField.initialization = new StringLiteral(field.name, pS, pE, 0);
            constantField.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic
                    | ClassFileConstants.AccFinal;
        }
        injectField(fieldsType, constantField);
        constantField.traverse(generatedByVisitor, ((TypeDeclaration) fieldsType.get()).initializerScope);
    }
}

From source file:lombok.eclipse.handlers.HandleSuperBuilder.java

License:Open Source License

/**
 * Generates a constructor that has a builder as the only parameter.
 * The values from the builder are used to initialize the fields of new instances.
 *
 * @param typeNode//from www  .  j  a v a  2 s.  c o  m
 *            the type (with the {@code @Builder} annotation) for which a
 *            constructor should be generated.
 * @param typeParams
 * @param builderFields a list of fields in the builder which should be assigned to new instances.
 * @param source the annotation (used for setting source code locations for the generated code).
 * @param callBuilderBasedSuperConstructor
 *            If {@code true}, the constructor will explicitly call a super
 *            constructor with the builder as argument. Requires
 *            {@code builderClassAsParameter != null}.
 */
private void generateBuilderBasedConstructor(EclipseNode typeNode, TypeParameter[] typeParams,
        List<BuilderFieldData> builderFields, EclipseNode sourceNode, String builderClassName,
        boolean callBuilderBasedSuperConstructor) {

    ASTNode source = sourceNode.get();

    TypeDeclaration typeDeclaration = ((TypeDeclaration) typeNode.get());
    long p = (long) source.sourceStart << 32 | source.sourceEnd;

    ConstructorDeclaration constructor = new ConstructorDeclaration(
            ((CompilationUnitDeclaration) typeNode.top().get()).compilationResult);

    constructor.modifiers = toEclipseModifier(AccessLevel.PROTECTED);
    constructor.selector = typeDeclaration.name;
    if (callBuilderBasedSuperConstructor) {
        constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.Super);
        constructor.constructorCall.arguments = new Expression[] {
                new SingleNameReference(BUILDER_VARIABLE_NAME, p) };
    } else {
        constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper);
    }
    constructor.constructorCall.sourceStart = source.sourceStart;
    constructor.constructorCall.sourceEnd = source.sourceEnd;
    constructor.thrownExceptions = null;
    constructor.typeParameters = null;
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;

    TypeReference[] wildcards = new TypeReference[] { new Wildcard(Wildcard.UNBOUND),
            new Wildcard(Wildcard.UNBOUND) };
    TypeReference builderType = new ParameterizedSingleTypeReference(builderClassName.toCharArray(),
            mergeToTypeReferences(typeParams, wildcards), 0, p);
    constructor.arguments = new Argument[] {
            new Argument(BUILDER_VARIABLE_NAME, p, builderType, Modifier.FINAL) };

    List<Statement> statements = new ArrayList<Statement>();

    for (BuilderFieldData fieldNode : builderFields) {
        char[] fieldName = removePrefixFromField(fieldNode.originalFieldNode);
        FieldReference fieldInThis = new FieldReference(fieldNode.rawName, p);
        int s = (int) (p >> 32);
        int e = (int) p;
        fieldInThis.receiver = new ThisReference(s, e);

        Expression assignmentExpr;
        if (fieldNode.singularData != null && fieldNode.singularData.getSingularizer() != null) {
            fieldNode.singularData.getSingularizer().appendBuildCode(fieldNode.singularData, typeNode,
                    statements, fieldNode.name, BUILDER_VARIABLE_NAME_STRING);
            assignmentExpr = new SingleNameReference(fieldNode.name, p);
        } else {
            char[][] variableInBuilder = new char[][] { BUILDER_VARIABLE_NAME, fieldName };
            long[] positions = new long[] { p, p };
            assignmentExpr = new QualifiedNameReference(variableInBuilder, positions, s, e);
        }
        Statement assignment = new Assignment(fieldInThis, assignmentExpr, (int) p);

        // In case of @Builder.Default, set the value to the default if it was NOT set in the builder.
        if (fieldNode.nameOfSetFlag != null) {
            char[][] setVariableInBuilder = new char[][] { BUILDER_VARIABLE_NAME, fieldNode.nameOfSetFlag };
            long[] positions = new long[] { p, p };
            QualifiedNameReference setVariableInBuilderRef = new QualifiedNameReference(setVariableInBuilder,
                    positions, s, e);

            MessageSend defaultMethodCall = new MessageSend();
            defaultMethodCall.sourceStart = source.sourceStart;
            defaultMethodCall.sourceEnd = source.sourceEnd;
            defaultMethodCall.receiver = new SingleNameReference(((TypeDeclaration) typeNode.get()).name, 0L);
            defaultMethodCall.selector = fieldNode.nameOfDefaultProvider;
            defaultMethodCall.typeArguments = typeParameterNames(
                    ((TypeDeclaration) typeNode.get()).typeParameters);

            Statement defaultAssignment = new Assignment(fieldInThis, defaultMethodCall, (int) p);
            IfStatement ifBlockForDefault = new IfStatement(setVariableInBuilderRef, assignment,
                    defaultAssignment, s, e);
            statements.add(ifBlockForDefault);
        } else {
            statements.add(assignment);
        }

        if (hasNonNullAnnotations(fieldNode.originalFieldNode)) {
            Statement nullCheck = generateNullCheck((FieldDeclaration) fieldNode.originalFieldNode.get(),
                    sourceNode);
            if (nullCheck != null)
                statements.add(nullCheck);
        }
    }

    constructor.statements = statements.isEmpty() ? null : statements.toArray(new Statement[0]);

    constructor.traverse(new SetGeneratedByVisitor(source), typeDeclaration.scope);

    injectMethod(typeNode, constructor);
}

From source file:lombok.eclipse.handlers.HandleUtilityClass.java

License:Open Source License

private void createPrivateDefaultConstructor(EclipseNode typeNode, EclipseNode sourceNode) {
    ASTNode source = sourceNode.get();//  ww  w . ja va  2 s  . c  om

    TypeDeclaration typeDeclaration = ((TypeDeclaration) typeNode.get());
    long p = (long) source.sourceStart << 32 | source.sourceEnd;

    ConstructorDeclaration constructor = new ConstructorDeclaration(
            ((CompilationUnitDeclaration) typeNode.top().get()).compilationResult);

    constructor.modifiers = ClassFileConstants.AccPrivate;
    constructor.selector = typeDeclaration.name;
    constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper);
    constructor.constructorCall.sourceStart = source.sourceStart;
    constructor.constructorCall.sourceEnd = source.sourceEnd;
    constructor.thrownExceptions = null;
    constructor.typeParameters = null;
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
    constructor.arguments = null;

    AllocationExpression exception = new AllocationExpression();
    setGeneratedBy(exception, source);
    long[] ps = new long[JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION.length];
    Arrays.fill(ps, p);
    exception.type = new QualifiedTypeReference(JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION, ps);
    setGeneratedBy(exception.type, source);
    exception.arguments = new Expression[] {
            new StringLiteral(UNSUPPORTED_MESSAGE, source.sourceStart, source.sourceEnd, 0) };
    setGeneratedBy(exception.arguments[0], source);
    ThrowStatement throwStatement = new ThrowStatement(exception, source.sourceStart, source.sourceEnd);
    setGeneratedBy(throwStatement, source);

    constructor.statements = new Statement[] { throwStatement };

    injectMethod(typeNode, constructor);
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeExplicitConstructorInvocation(int flag, int recFlag) {

    /* flag allows to distinguish 3 cases :
    (0) :// w  w  w .  jav  a  2s.c  o  m
    ExplicitConstructorInvocation ::= 'this' '(' ArgumentListopt ')' ';'
    ExplicitConstructorInvocation ::= 'super' '(' ArgumentListopt ')' ';'
    (1) :
    ExplicitConstructorInvocation ::= Primary '.' 'super' '(' ArgumentListopt ')' ';'
    ExplicitConstructorInvocation ::= Primary '.' 'this' '(' ArgumentListopt ')' ';'
    (2) :
    ExplicitConstructorInvocation ::= Name '.' 'super' '(' ArgumentListopt ')' ';'
    ExplicitConstructorInvocation ::= Name '.' 'this' '(' ArgumentListopt ')' ';'
    */
    int startPosition = this.intStack[this.intPtr--];
    ExplicitConstructorCall ecc = new ExplicitConstructorCall(recFlag);
    int length;
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        this.expressionPtr -= length;
        System.arraycopy(this.expressionStack, this.expressionPtr + 1, ecc.arguments = new Expression[length],
                0, length);
    }
    switch (flag) {
    case 0:
        ecc.sourceStart = startPosition;
        break;
    case 1:
        this.expressionLengthPtr--;
        ecc.sourceStart = (ecc.qualification = this.expressionStack[this.expressionPtr--]).sourceStart;
        break;
    case 2:
        ecc.sourceStart = (ecc.qualification = getUnspecifiedReferenceOptimized()).sourceStart;
        break;
    }
    pushOnAstStack(ecc);
    ecc.sourceEnd = this.endStatementPosition;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeExplicitConstructorInvocationWithTypeArguments(int flag, int recFlag) {

    /* flag allows to distinguish 3 cases :
    (0) ://  w ww .  j  a  va2  s .  c o  m
    ExplicitConstructorInvocation ::= TypeArguments 'this' '(' ArgumentListopt ')' ';'
    ExplicitConstructorInvocation ::= TypeArguments 'super' '(' ArgumentListopt ')' ';'
    (1) :
    ExplicitConstructorInvocation ::= Primary '.' TypeArguments 'super' '(' ArgumentListopt ')' ';'
    ExplicitConstructorInvocation ::= Primary '.' TypeArguments 'this' '(' ArgumentListopt ')' ';'
    (2) :
    ExplicitConstructorInvocation ::= Name '.' TypeArguments 'super' '(' ArgumentListopt ')' ';'
    ExplicitConstructorInvocation ::= Name '.' TypeArguments 'this' '(' ArgumentListopt ')' ';'
    */
    int startPosition = this.intStack[this.intPtr--];
    ExplicitConstructorCall ecc = new ExplicitConstructorCall(recFlag);
    int length;
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        this.expressionPtr -= length;
        System.arraycopy(this.expressionStack, this.expressionPtr + 1, ecc.arguments = new Expression[length],
                0, length);
    }
    length = this.genericsLengthStack[this.genericsLengthPtr--];
    this.genericsPtr -= length;
    System.arraycopy(this.genericsStack, this.genericsPtr + 1, ecc.typeArguments = new TypeReference[length], 0,
            length);
    ecc.typeArgumentsSourceStart = this.intStack[this.intPtr--];

    switch (flag) {
    case 0:
        ecc.sourceStart = startPosition;
        break;
    case 1:
        this.expressionLengthPtr--;
        ecc.sourceStart = (ecc.qualification = this.expressionStack[this.expressionPtr--]).sourceStart;
        break;
    case 2:
        ecc.sourceStart = (ecc.qualification = getUnspecifiedReferenceOptimized()).sourceStart;
        break;
    }

    pushOnAstStack(ecc);
    ecc.sourceEnd = this.endStatementPosition;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseAllocationExpression.java

License:Open Source License

/**
* @param baseExpr//w  w  w .java 2s  .  c o  m
*/
private ExplicitConstructorCall genLiftCtorCall(Expression baseExpr) {
    ExplicitConstructorCall constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.Super);
    constructorCall.arguments = new Expression[] { baseExpr };
    constructorCall.sourceStart = this.sourceStart;
    constructorCall.sourceEnd = this.sourceEnd;
    return constructorCall;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.DeclaredLifting.java

License:Open Source License

/**
 * At a specific point the constructor chain turns from this calls (w/ marker args)
 * to real super calls. Create a constructor which does nothing but this turning.
 * @param teamDecl/*from   www. j  a  v a 2s  . c o m*/
 * @param superTeamCtor
 * @param gen
 *
 * @return a binding if a new method has been generated, else null.
 */
public static MethodBinding maybeCreateTurningCtor(TypeDeclaration teamDecl, MethodBinding superTeamCtor,
        AstGenerator gen) {
    // constructor chains are created during resolve, so super team must be resolved.
    Dependencies.ensureTeamState(teamDecl.binding.superclass().getTeamModel(),
            ITranslationStates.STATE_RESOLVED);

    boolean hasMarkerArg = (superTeamCtor.parameters.length > 0
            && TSuperHelper.isMarkerInterface(superTeamCtor.parameters[superTeamCtor.parameters.length - 1]));

    TypeBinding[] newParams = superTeamCtor.parameters;
    if (!hasMarkerArg) {
        TypeBinding markerType = TSuperHelper.getMarkerInterface(teamDecl.scope, superTeamCtor.declaringClass);
        newParams = AstEdit.extendTypeArray(superTeamCtor.parameters, markerType);
    }

    // do we need to work at all?
    MethodBinding existingCtor = teamDecl.binding.getExactConstructor(newParams);
    if (existingCtor != null)
        return existingCtor;

    // start creating:
    Argument[] arguments = AstConverter.createArgumentsFromParameters(superTeamCtor.parameters, gen);
    ConstructorDeclaration newCtor = gen.constructor(teamDecl.compilationResult, ClassFileConstants.AccPublic,
            teamDecl.name, arguments);
    // arguments
    if (!hasMarkerArg) {
        TSuperHelper.addMarkerArg(newCtor, superTeamCtor.declaringClass);
        arguments = newCtor.arguments;
    }
    // constructor call
    newCtor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.Super);
    int length = superTeamCtor.parameters.length;// as many as the target (super) expects.
    Expression[] selfcallArgs = new Expression[length];
    for (int i = 0; i < length; i++) {
        selfcallArgs[i] = gen.singleNameReference(arguments[i].name);
    }
    newCtor.constructorCall.arguments = selfcallArgs;
    // empty body
    newCtor.setStatements(new Statement[0]);

    newCtor.isTSuper = true; // no matter if new or old marker arg
    AstEdit.addMethod(teamDecl, newCtor);

    return newCtor.binding;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java

License:Open Source License

public ExplicitConstructorCall explicitConstructorCall(int accessMode) {
    ExplicitConstructorCall call = new ExplicitConstructorCall(accessMode);
    call.sourceStart = this.sourceStart;
    call.sourceEnd = this.sourceEnd;
    return call;/*w  w w .j a va  2  s  .  c o  m*/
}