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

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

Introduction

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

Prototype

public SimpleName getName() 

Source Link

Document

Returns the name of the constant declared in this enum declaration.

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  a va 2s . 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:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final EnumConstantDeclaration pNode) {
    // JLS3(8.9): It is impossible to define a local (14.3) enum, or to
    // define an enum in an inner class (8.1.3).
    // assert (aCurrMethodReminder.empty());

    final String lSimpleName = pNode.getName().getIdentifier();
    if (lSimpleName == null)
        return false;

    IElement lField;//from  www. jav a2s .  co m
    lField = FlyweightElementFactory.getElement(Category.FIELD, this.aCurrType.getId() + "." + lSimpleName);
    this.aDB.addElement(lField, pNode.getModifiers());
    this.aDB.addRelation(this.aCurrType, Relation.DECLARES_FIELD, lField);

    // Register CALLS relationship to constructor
    // IMethodBinding lCBinding = pNode.resolveConstructorBinding();
    // if( checkForNull( lCBinding )) return false;
    // saveMethodRelation( lCBinding );
    // return true;
    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);
    }/*from   w w w . j a va2  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  a va2 s.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;// w  w w  . ja v  a 2  s.  c  o  m
    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.codenvy.ide.ext.java.server.internal.core.util.DOMFinder.java

License:Open Source License

public boolean visit(EnumConstantDeclaration node) {
    if (found(node, node.getName()) && this.resolveBinding)
        this.foundBinding = node.resolveVariable();
    return true;/*w ww .j av  a 2s.co m*/
}

From source file:com.google.currysrc.api.process.ast.BodyDeclarationLocators.java

License:Apache License

/**
 * Creates {@link BodyDeclarationLocator} objects that can find the supplied
 * {@link BodyDeclaration}. Usually returns a single element, except for fields declarations.
 */// w  ww.  j  a  v a2  s  .  co  m
public static List<BodyDeclarationLocator> createLocators(BodyDeclaration bodyDeclaration) {
    AbstractTypeDeclaration typeDeclaration = TypeLocator.findTypeDeclarationNode(bodyDeclaration);
    if (typeDeclaration == null) {
        throw new AssertionError("Unable to find type declaration for " + typeDeclaration);
    }
    TypeLocator typeLocator = new TypeLocator(typeDeclaration);

    int nodeType = bodyDeclaration.getNodeType();
    switch (nodeType) {
    case ASTNode.FIELD_DECLARATION:
        List<String> fieldNames = FieldLocator.getFieldNames((FieldDeclaration) bodyDeclaration);
        List<BodyDeclarationLocator> fieldLocators = new ArrayList<>(fieldNames.size());
        for (String fieldName : fieldNames) {
            fieldLocators.add(new FieldLocator(typeLocator, fieldName));
        }
        return fieldLocators;
    case ASTNode.METHOD_DECLARATION:
        MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
        List<String> parameterTypeNames = ParameterMatcher.getParameterTypeNames(methodDeclaration);
        return ImmutableList.<BodyDeclarationLocator>of(new MethodLocator(typeLocator,
                methodDeclaration.getName().getIdentifier(), parameterTypeNames));
    case ASTNode.TYPE_DECLARATION:
    case ASTNode.ENUM_DECLARATION:
        return ImmutableList.<BodyDeclarationLocator>of(typeLocator);
    case ASTNode.ENUM_CONSTANT_DECLARATION:
        EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) bodyDeclaration;
        String constantName = enumConstantDeclaration.getName().getIdentifier();
        return ImmutableList.<BodyDeclarationLocator>of(new EnumConstantLocator(typeLocator, constantName));
    default:
        throw new IllegalArgumentException("Unsupported node type: " + nodeType);
    }
}

From source file:com.google.currysrc.api.process.ast.EnumConstantLocator.java

License:Apache License

@Override
public boolean matches(BodyDeclaration node) {
    if (!(node instanceof EnumConstantDeclaration)) {
        return false;
    }// w  w w  . j a v  a 2  s.c o m

    if (typeLocator.matches((BodyDeclaration) node.getParent())) {
        EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) node;
        if (enumConstantDeclaration.getName().getFullyQualifiedName().equals(constantName)) {
            return true;
        }
    }
    return false;
}

From source file:com.google.currysrc.api.process.ast.EnumConstantLocator.java

License:Apache License

@Override
public BodyDeclaration find(CompilationUnit cu) {
    AbstractTypeDeclaration typeDeclaration = typeLocator.find(cu);
    if (typeDeclaration == null || !(typeDeclaration instanceof EnumDeclaration)) {
        return null;
    }//  www  . ja  va2 s .c  o m
    for (EnumConstantDeclaration enumConstantDeclaration : (List<EnumConstantDeclaration>) ((EnumDeclaration) typeDeclaration)
            .enumConstants()) {
        if (enumConstantDeclaration.getName().getFullyQualifiedName().equals(constantName)) {
            return enumConstantDeclaration;
        }
    }
    return null;
}

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  w  w  w  .  j  a  v  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));
}