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

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

Introduction

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

Prototype

ASTNode.NodeList arguments

To view the source code for org.eclipse.jdt.core.dom EnumConstantDeclaration arguments.

Click Source Link

Document

The list of argument expressions (element type: Expression ).

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(EnumConstantDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }/*from   w  w w .  j av  a2  s  .c o  m*/
    printModifiers(node.modifiers());
    node.getName().accept(this);
    if (!node.arguments().isEmpty()) {
        this.fBuffer.append("(");//$NON-NLS-1$
        for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext();) {
            Expression e = it.next();
            e.accept(this);
            if (it.hasNext()) {
                this.fBuffer.append(",");//$NON-NLS-1$
            }
        }
        this.fBuffer.append(")");//$NON-NLS-1$
    }
    if (node.getAnonymousClassDeclaration() != null) {
        node.getAnonymousClassDeclaration().accept(this);
    }
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(EnumConstantDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }/*  w ww .j  a  v a 2 s  .  c  om*/
    printIndent();
    printModifiers(node.modifiers());
    node.getName().accept(this);
    if (!node.arguments().isEmpty()) {
        this.buffer.append("(");//$NON-NLS-1$
        for (Iterator it = node.arguments().iterator(); it.hasNext();) {
            Expression e = (Expression) it.next();
            e.accept(this);
            if (it.hasNext()) {
                this.buffer.append(",");//$NON-NLS-1$
            }
        }
        this.buffer.append(")");//$NON-NLS-1$
    }
    if (node.getAnonymousClassDeclaration() != null) {
        node.getAnonymousClassDeclaration().accept(this);
    }
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java

License:Open Source License

@Override
public boolean visit(EnumConstantDeclaration node) {
    handleArguments(node.arguments(), this.options.alignment_for_arguments_in_enum_constant);
    AnonymousClassDeclaration anonymousClass = node.getAnonymousClassDeclaration();
    if (anonymousClass != null) {
        forceContinuousWrapping(anonymousClass, this.tm.firstIndexIn(node.getName(), -1));
    }/*from   w  ww  .j  av  a 2s.  co  m*/
    return true;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(EnumConstantDeclaration node) {
    List<Expression> arguments = node.arguments();
    Token openingParen = null;//ww w . ja va2  s .  com
    if (!arguments.isEmpty()) {
        openingParen = this.tm.firstTokenIn(node, TokenNameLPAREN);
        if (this.options.insert_space_after_opening_paren_in_enum_constant)
            openingParen.spaceAfter();
        handleTokenAfter(arguments.get(arguments.size() - 1), TokenNameRPAREN,
                this.options.insert_space_before_closing_paren_in_enum_constant, false);
    } else {
        // look for empty parenthesis, may not be there
        int from = this.tm.firstIndexIn(node.getName(), TokenNameIdentifier) + 1;
        AnonymousClassDeclaration classDeclaration = node.getAnonymousClassDeclaration();
        int to = classDeclaration != null ? this.tm.firstIndexBefore(classDeclaration, -1)
                : this.tm.lastIndexIn(node, -1);
        for (int i = from; i <= to; i++) {
            if (this.tm.get(i).tokenType == TokenNameLPAREN) {
                openingParen = this.tm.get(i);
                if (this.options.insert_space_between_empty_parens_in_enum_constant)
                    openingParen.spaceAfter();
                break;
            }
        }
    }
    if (openingParen != null && this.options.insert_space_before_opening_paren_in_enum_constant)
        openingParen.spaceBefore();
    handleCommas(arguments, this.options.insert_space_before_comma_in_enum_constant_arguments,
            this.options.insert_space_after_comma_in_enum_constant_arguments);
    return true;
}

From source file:com.crispico.flower.mp.codesync.code.java.adapter.JavaEnumConstantDeclarationModelAdapter.java

License:Open Source License

@Override
public Object createChildOnContainmentFeature(Object element, Object feature, Object correspondingChild) {
    if (AstCacheCodePackage.eINSTANCE.getEnumConstant_Arguments().equals(feature)) {
        EnumConstantDeclaration parent = (EnumConstantDeclaration) element;
        AST ast = parent.getAST();//w  w  w .  ja va  2 s  . com
        Expression arg = getExpressionFromString(ast, (String) correspondingChild);
        parent.arguments().add(arg);
        return arg;
    }
    return super.createChildOnContainmentFeature(element, feature, correspondingChild);
}

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 ww w  .jav  a  2 s. c  o  m*/
    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.gen.CppImplementationGenerator.java

License:Open Source License

@Override
protected void generate(EnumDeclaration node) {
    @SuppressWarnings("unchecked")
    List<EnumConstantDeclaration> constants = node.enumConstants(); // safe by definition
    List<MethodDeclaration> methods = Lists.newArrayList();
    List<FieldDeclaration> fields = Lists.newArrayList();
    MethodDeclaration initializeMethod = null;
    @SuppressWarnings("unchecked")
    List<BodyDeclaration> declarations = node.bodyDeclarations(); // safe by definition
    for (BodyDeclaration decl : declarations) {
        if (decl instanceof FieldDeclaration) {
            fields.add((FieldDeclaration) decl);
        } else if (decl instanceof MethodDeclaration) {
            MethodDeclaration md = (MethodDeclaration) decl;
            if (md.getName().getIdentifier().equals("initialize")) {
                initializeMethod = md;//w w  w  . j  a va2  s  . com
            } else {
                methods.add(md);
            }
        }
    }
    syncLineNumbers(node.getName()); // avoid doc-comment

    String typeName = NameTable.getFullName(node);
    for (EnumConstantDeclaration constant : constants) {
        printf("static %s *%s_%s;\n", typeName, typeName, NameTable.getName(constant.getName()));
    }
    printf("IOSObjectArray *%s_values;\n", typeName);
    newline();

    printf("@implementation %s\n\n", typeName);
    printStaticVars(fields);

    for (EnumConstantDeclaration constant : constants) {
        String name = NameTable.getName(constant.getName());
        printf("+ (%s *)%s {\n", typeName, name);
        printf("  return %s_%s;\n", typeName, name);
        println("}");
    }
    newline();

    // Enum constants needs to implement NSCopying.  Being singletons, they
    // can just return self, as long the retain count is incremented.
    String selfString = Options.useReferenceCounting() ? "[self retain]" : "self";
    printf("- (id)copyWithZone:(NSZone *)zone {\n  return %s;\n}\n\n", selfString);

    printProperties(fields.toArray(new FieldDeclaration[0]));
    printMethods(methods);

    printf("+ (void)initialize {\n  if (self == [%s class]) {\n", typeName);
    for (int i = 0; i < constants.size(); i++) {
        EnumConstantDeclaration constant = constants.get(i);
        @SuppressWarnings("unchecked")
        List<Expression> args = constant.arguments(); // safe by definition
        String name = NameTable.getName(constant.getName());
        String constantTypeName = NameTable.getFullName(Types.getMethodBinding(constant).getDeclaringClass());
        printf("    %s_%s = [[%s alloc] init", typeName, name, constantTypeName);
        boolean isSimpleEnum = constantTypeName.equals(typeName);

        // Common-case: no extra fields and no constant anonymous classes.
        if (args.isEmpty() && isSimpleEnum) {
            printf("WithNSString:@\"%s_%s\" withInt:%d];\n", typeName.replace("Enum", ""), name, i);
        } else {
            String argString = CppStatementGenerator.generateArguments(Types.getMethodBinding(constant), args,
                    fieldHiders, getBuilder().getCurrentLine());
            print(argString);
            if (args.isEmpty()) {
                print("With");
            } else {
                print(" with");
            }
            printf("NSString:@\"%s_%s\" withInt:%d];\n", typeName.replace("Enum", ""), name, i);
        }
    }
    printf("    %s_values = [[IOSObjectArray alloc] initWithObjects:(id[]){ ", typeName);
    for (EnumConstantDeclaration constant : constants) {
        printf("%s_%s, ", typeName, NameTable.getName(constant.getName()));
    }
    printf("nil } count:%d type:[IOSClass classWithClass:[%s class]]];\n", constants.size(), typeName);
    if (initializeMethod != null) {
        @SuppressWarnings("unchecked")
        List<Statement> stmts = initializeMethod.getBody().statements(); // safe by definition
        for (Statement s : stmts) {
            printf("    %s",
                    CppStatementGenerator.generate(s, fieldHiders, false, getBuilder().getCurrentLine()));
        }
    }
    println("  }\n}\n");

    // Print generated values and valueOf methods.
    println("+ (IOSObjectArray *)values {");
    printf("  return [IOSObjectArray arrayWithArray:%s_values];\n", typeName);
    println("}\n");
    printf("+ (%s *)valueOfWithNSString:(NSString *)name {\n", typeName);
    printf("  for (int i = 0; i < [%s_values count]; i++) {\n", typeName);
    printf("    %s *e = [%s_values objectAtIndex:i];\n", typeName, typeName);
    printf("    if ([name isEqual:[e name]]) {\n");
    printf("      return e;\n");
    printf("    }\n");
    printf("  }\n");
    printf("  @throw [[JavaLangIllegalArgumentException alloc] initWithNSString:name];\n");
    printf("  return nil;\n");
    println("}\n");

    println("@end");
}

From source file:com.google.devtools.j2cpp.translate.AnonymousClassConverter.java

License:Open Source License

/**
 * Convert the anonymous class into an inner class.  Fields are added for
 * final variables that are referenced, and a constructor is added.
 *
 * Note: endVisit is used for a depth-first traversal, to make it easier
 * to scan their containing nodes for references.
 *//*from  w  ww  .j a  v a 2s.  c  om*/
@Override
@SuppressWarnings("unchecked")
public void endVisit(AnonymousClassDeclaration node) {
    ASTNode parent = node.getParent();
    ClassInstanceCreation newInvocation = null;
    EnumConstantDeclaration enumConstant = null;
    List<Expression> parentArguments;
    String newClassName;
    ITypeBinding innerType;
    boolean isStatic = staticParent(node);
    int modifiers = isStatic ? Modifier.STATIC : 0;
    if (parent instanceof ClassInstanceCreation) {
        newInvocation = (ClassInstanceCreation) parent;
        parentArguments = newInvocation.arguments();
        innerType = Types.getTypeBinding(newInvocation);
        newClassName = innerType.getName();
        innerType = RenamedTypeBinding.rename(newClassName, innerType.getDeclaringClass(), innerType,
                modifiers);
    } else if (parent instanceof EnumConstantDeclaration) {
        enumConstant = (EnumConstantDeclaration) parent;
        parentArguments = enumConstant.arguments();
        innerType = Types.getTypeBinding(node);
        newClassName = Types.getTypeBinding(node).getName();
        innerType = RenamedTypeBinding.rename(newClassName, innerType.getDeclaringClass(), innerType,
                modifiers);
    } else {
        throw new AssertionError("unknown anonymous class declaration parent: " + parent.getClass().getName());
    }

    // Create a type declaration for this anonymous class.
    AST ast = node.getAST();
    TypeDeclaration typeDecl = ast.newTypeDeclaration();
    if (isStatic) {
        typeDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
    }
    Types.addBinding(typeDecl, innerType);
    typeDecl.setName(ast.newSimpleName(newClassName));
    Types.addBinding(typeDecl.getName(), innerType);
    typeDecl.setSourceRange(node.getStartPosition(), node.getLength());

    Type superType = Types.makeType(Types.mapType(innerType.getSuperclass()));
    typeDecl.setSuperclassType(superType);
    for (ITypeBinding interfaceType : innerType.getInterfaces()) {
        typeDecl.superInterfaceTypes().add(Types.makeType(Types.mapType(interfaceType)));
    }

    for (Object bodyDecl : node.bodyDeclarations()) {
        BodyDeclaration decl = (BodyDeclaration) bodyDecl;
        typeDecl.bodyDeclarations().add(NodeCopier.copySubtree(ast, decl));
    }
    typeDecl.accept(new InitializationNormalizer());

    // Fix up references to external types, if necessary.
    Set<IVariableBinding> methodVars = getMethodVars(node);
    final List<ReferenceDescription> references = findReferences(node, methodVars);
    final List<Expression> invocationArgs = parentArguments;
    if (!references.isEmpty() || !invocationArgs.isEmpty()) { // is there anything to fix-up?
        List<IVariableBinding> innerVars = getInnerVars(references);
        if (!innerVars.isEmpty() || !invocationArgs.isEmpty()) {
            GeneratedMethodBinding defaultConstructor = addInnerVars(typeDecl, innerVars, references,
                    parentArguments);
            Types.addBinding(parent, defaultConstructor);
            for (IVariableBinding var : innerVars) {
                if (!isConstant(var)) {
                    parentArguments.add(makeFieldRef(var, ast));
                }
            }
            assert defaultConstructor.getParameterTypes().length == parentArguments.size();
            typeDecl.accept(new ASTVisitor() {
                @Override
                public void endVisit(SimpleName node) {
                    IVariableBinding var = Types.getVariableBinding(node);
                    if (var != null) {
                        for (ReferenceDescription ref : references) {
                            if (var.isEqualTo(ref.binding)) {
                                if (ref.innerField != null) {
                                    setProperty(node, makeFieldRef(ref.innerField, node.getAST()));
                                } else {
                                    // In-line constant.
                                    Object o = var.getConstantValue();
                                    assert o != null;
                                    Expression literal = makeLiteral(o, var.getType().getQualifiedName(),
                                            node.getAST());
                                    setProperty(node, literal);
                                }
                                return;
                            }
                        }
                    }
                }
            });
        }
    }

    // If invocation, replace anonymous class invocation with the new constructor.
    if (newInvocation != null) {
        newInvocation.setAnonymousClassDeclaration(null);
        newInvocation.setType(Types.makeType(innerType));
        IMethodBinding oldBinding = Types.getMethodBinding(newInvocation);
        if (oldBinding == null) {
            oldBinding = newInvocation.resolveConstructorBinding();
        }
        if (oldBinding != null) {
            GeneratedMethodBinding invocationBinding = new GeneratedMethodBinding(oldBinding);
            invocationBinding.setDeclaringClass(innerType);
            Types.addBinding(newInvocation, invocationBinding);
        }
    } else {
        enumConstant.setAnonymousClassDeclaration(null);
    }

    // Add type declaration to enclosing type.
    ITypeBinding outerType = innerType.getDeclaringClass();
    if (outerType.isAnonymous()) {
        // Get outerType node.
        ASTNode n = parent.getParent();
        while (!(n instanceof AnonymousClassDeclaration) && !(n instanceof TypeDeclaration)) {
            n = n.getParent();
        }
        if (n instanceof AnonymousClassDeclaration) {
            AnonymousClassDeclaration outerDecl = (AnonymousClassDeclaration) n;
            outerDecl.bodyDeclarations().add(typeDecl);
        }
    } else {
        AbstractTypeDeclaration outerDecl = (AbstractTypeDeclaration) unit.findDeclaringNode(outerType);
        outerDecl.bodyDeclarations().add(typeDecl);
    }
    Symbols.scanAST(typeDecl);
    super.endVisit(node);
}

From source file:com.google.devtools.j2cpp.translate.Autoboxer.java

License:Open Source License

@Override
public void endVisit(EnumConstantDeclaration node) {
    @SuppressWarnings("unchecked")
    List<Expression> args = node.arguments(); // safe by definition
    if (!args.isEmpty()) {
        IMethodBinding constructor = Types.getMethodBinding(node);
        int n = args.size();
        for (int i = 0; i < n; i++) {
            Expression arg = args.get(i);
            ITypeBinding parameterType = constructor.getParameterTypes()[i];
            boolean argumentIsPrimitive = getBoxType(arg).isPrimitive();
            boolean parameterIsPrimitive = parameterType.isPrimitive();
            if (argumentIsPrimitive && !parameterIsPrimitive) {
                args.set(i, box(arg));// w  w  w .j a  v a  2 s  .  c o m
            } else if (parameterIsPrimitive && !argumentIsPrimitive) {
                args.set(i, unbox(arg));
            }
        }
    }
}

From source file:com.google.devtools.j2objc.util.ASTUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<Expression> getArguments(EnumConstantDeclaration node) {
    return node.arguments();
}