Example usage for org.eclipse.jdt.core.dom EnumConstantDeclaration resolveConstructorBinding

List of usage examples for org.eclipse.jdt.core.dom EnumConstantDeclaration resolveConstructorBinding

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom EnumConstantDeclaration resolveConstructorBinding.

Prototype

public IMethodBinding resolveConstructorBinding() 

Source Link

Document

Resolves and returns the binding for the constructor invoked by this enum constant.

Usage

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.EnumConstantDeclaration node) {
    String fieldName = node.getName().getIdentifier();
    IMethodBinding constructorBinding = node.resolveConstructorBinding();
    // prepare enum name
    org.eclipse.jdt.core.dom.EnumDeclaration parentEnum = (org.eclipse.jdt.core.dom.EnumDeclaration) node
            .getParent();//from  www.j  a v  a 2 s .com
    String enumTypeName = parentEnum.getName().getIdentifier();
    // may be create Dart top-level class for Java inner class
    String innerClassName = null;
    {
        AnonymousClassDeclaration anoClassDeclaration = node.getAnonymousClassDeclaration();
        if (anoClassDeclaration != null) {
            innerClassName = enumTypeName + "_" + fieldName;
            declareInnerClass(constructorBinding, anoClassDeclaration, innerClassName,
                    new String[] { "String", ENUM_NAME_FIELD_NAME, "int", ENUM_ORDINAL_FIELD_NAME });
        }
    }
    // prepare field type
    TypeName type = typeName(enumTypeName);
    // prepare field variables
    List<VariableDeclaration> variables = Lists.newArrayList();
    {
        List<Expression> argList = translateArguments(null, node.arguments());
        {
            int ordinal = parentEnum.enumConstants().indexOf(node);
            argList.add(0, integer(ordinal));
            argList.add(0, string(fieldName));
        }
        InstanceCreationExpression init;
        if (innerClassName == null) {
            init = instanceCreationExpression(Keyword.NEW, typeName(enumTypeName), argList);
            context.getConstructorDescription(constructorBinding).instanceCreations.add(init);
        } else {
            init = instanceCreationExpression(Keyword.NEW, typeName(innerClassName), argList);
        }
        variables.add(variableDeclaration(fieldName, init));
    }
    return done(fieldDeclaration(translateJavadoc(node), true, Keyword.FINAL, type, variables));
}

From source file:com.google.devtools.j2cpp.types.BindingMapBuilder.java

License:Open Source License

@Override
public boolean visit(EnumConstantDeclaration node) {
    put(node, node.resolveConstructorBinding());
    return true;
}

From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java

License:Open Source License

/**
 * Called only from visitFieldInitNode(node,context)
 *//* w w  w .  j  a  v a2  s  .  com*/
private CAstNode createEnumConstantDeclarationInit(EnumConstantDeclaration node, WalkContext context) {
    String hiddenVariableName = (String) node
            .getProperty("com.ibm.wala.cast.java.translator.jdt.fakeValuesDeclName");
    if (hiddenVariableName == null) {
        FieldReference fieldRef = fIdentityMapper.getFieldRef(node.resolveVariable());
        // We use null to indicate an OBJECT_REF to a static field
        CAstNode lhsNode = makeNode(context, fFactory, node, CAstNode.OBJECT_REF,
                makeNode(context, fFactory, null, CAstNode.VOID), fFactory.makeConstant(fieldRef));

        // CONSTRUCT ARGUMENTS & "new MyEnum(...)" statement
        ArrayList<Object> arguments = new ArrayList<Object>();
        arguments.add(fFactory.makeConstant(node.getName().getIdentifier())); // name of constant
        arguments.add(fFactory.makeConstant(node.resolveVariable().getVariableId())); // id
        arguments.addAll(node.arguments());
        CAstNode rhsNode = createClassInstanceCreation(node, arguments, node.resolveConstructorBinding(), null,
                node.getAnonymousClassDeclaration(), context);

        CAstNode assNode = makeNode(context, fFactory, node, CAstNode.ASSIGN, lhsNode, rhsNode);

        return assNode; // their naming, not mine
    } else {

        // String[] x = (new Direction[] {
        // NORTH, EAST, SOUTH, WEST, $VALUES, $VALUES$
        // });

        return null;
    }
}

From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes:/*from   w  ww .  j av  a  2  s .  c o  m*/
 * <ul>
 *   <li>Enum constant entity to <code>IEntityWriter</code>
 *   <ul>
 *     <li>Inside relation to <code>IRelationWriter</code></li>
 *     <li>Holds relation to <code>IRelationWriter</code></li>
 *     <li>Instantiated relation to<code>IRelationWriter</code></li>
 *   </ul></li>
 * </ul>
 * 
 * Enum constant fully qualified names (FQNs) adhere to the following format:<br> 
 * parent fqn + . + simple name
 */
@SuppressWarnings("unchecked")
@Override
public boolean visit(EnumConstantDeclaration node) {
    // Get the fqn
    String fqn = fqnStack.getTypeFqn(node.getName().getIdentifier());

    // Write the entity
    entityWriter.writeEnumConstant(fqn, 0, MetricsCalculator.computeLinesOfCode(getSource(node)),
            getLocation(node));

    // Write the inside relation
    relationWriter.writeInside(fqn, fqnStack.getFqn(), getUnknownLocation());

    // Write the holds relation
    relationWriter.writeHolds(fqn, fqnStack.getFqn(), getUnknownLocation());

    // Write the instantiates relation
    IMethodBinding methodBinding = node.resolveConstructorBinding();
    if (methodBinding == null) {
        String methodFqn = fqnStack.getFqn() + ".<init>" + getFuzzyMethodArgs(node.arguments());
        relationWriter.writeInstantiates(fqn, methodFqn, getLocation(node.getName()));
    } else {
        // Write the calls relation
        relationWriter.writeInstantiates(fqn, getMethodFqn(methodBinding, false), getLocation(node.getName()));
    }

    // Push the enum constant onto the stack
    fqnStack.push(fqn, Entity.ENUM_CONSTANT);
    accept(node.arguments());
    accept(node.getAnonymousClassDeclaration());
    return false;
}

From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes://w w  w  .  ja  v  a2 s.  c  o m
 * <ul>
 *   <li>Enum constant entity to <code>IEntityWriter</code>
 *   <ul>
 *     <li>Inside relation to <code>IRelationWriter</code></li>
 *     <li>Holds relation to <code>IRelationWriter</code></li>
 *     <li>Instantiated relation to<code>IRelationWriter</code></li>
 *   </ul></li>
 * </ul>
 * 
 * Enum constant fully qualified names (FQNs) adhere to the following format:<br> 
 * parent fqn + . + simple name
 */
@Override
public boolean visit(EnumConstantDeclaration node) {
    // Get the fqn
    String fqn = fqnStack.peek(EnclosingDeclaredType.class).getFieldFqn(node.getName().getIdentifier());

    // Write the inside relation
    relationWriter.writeRelation(Relation.CONTAINS, fqnStack.getFqn(), fqn, createUnknownLocation());

    // Write the holds relation
    relationWriter.writeRelation(Relation.HOLDS, fqn, fqnStack.getFqn(), createUnknownLocation());

    // Write the calls relation
    IMethodBinding methodBinding = node.resolveConstructorBinding();
    if (methodBinding == null) {
        String methodFqn = fqnStack.getFqn() + ".<init>" + getFuzzyMethodArgs(node.arguments());
        relationWriter.writeRelation(Relation.CALLS, fqn, methodFqn, createLocation(node.getName()));
    } else {
        relationWriter.writeRelation(Relation.CALLS, fqn,
                getMethodName(methodBinding, false) + getMethodArgs(methodBinding),
                createLocation(node.getName()));
    }

    // Write the instantiates relation
    relationWriter.writeRelation(Relation.INSTANTIATES, fqn, fqnStack.getFqn(), createLocation(node.getName()));

    // Visit the children
    fqnStack.push(fqn, Entity.ENUM_CONSTANT);
    accept(node.arguments());
    accept(node.getAnonymousClassDeclaration());

    // Write the entity
    entityWriter.writeEntity(Entity.ENUM_CONSTANT, fqn, 0, createMetrics(node), createLocation(node));

    fqnStack.pop();
    return false;
}

From source file:lang.java.jdt.internal.BindingsResolver.java

License:Open Source License

public void resolveBindings(EnumConstantDeclaration node) {
    importBinding(node.resolveConstructorBinding());
    importBinding(node.resolveVariable());
}

From source file:net.sf.j2s.core.astvisitors.MethodReferenceASTVisitor.java

License:Open Source License

public boolean visit(EnumConstantDeclaration node) {
    IMethodBinding constructorBinding = node.resolveConstructorBinding();
    String key = constructorBinding.getKey();
    if (key != null) {
        key = key.replaceAll("%?<[^>]+>", "");
    }//from  w w w  .j a v  a 2s . c o m
    if (methodSignature.equals(key)) {
        isReferenced = true;
        return false;
    }
    return super.visit(node);
}

From source file:sharpen.core.CSharpBuilder.java

License:Open Source License

private CSMethodInvocationExpression mapEnumInitializer(EnumConstantDeclaration node,
        CSTypeReferenceExpression typeName) {
    Configuration.MemberMapping mappedConstructor = effectiveMappingFor(node.resolveConstructorBinding());
    if (null == mappedConstructor) {
        return new CSConstructorInvocationExpression(typeName);
    }/*from w w  w .j  a  v a  2  s. c om*/
    final String mappedName = mappedConstructor.name;
    if (mappedName.length() == 0) {
        pushExpression(mapExpression((Expression) node.arguments().get(0)));
        return null;
    }
    if (mappedName.startsWith("System.Convert.To")) {
        if (optimizeSystemConvert(mappedName, node)) {
            return null;
        }
    }
    return new CSMethodInvocationExpression(new CSReferenceExpression(methodName(mappedName)));
}