Search in sources :

Example 91 with VariableDeclarationFragment

use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project xtext-xtend by eclipse.

the class JavaASTFlattener method visit.

@Override
public boolean visit(final Initializer it) {
    Javadoc _javadoc = it.getJavadoc();
    boolean _tripleNotEquals = (_javadoc != null);
    if (_tripleNotEquals) {
        it.getJavadoc().accept(this);
    }
    this.appendModifiers(it, it.modifiers());
    boolean _isStatic = this._aSTFlattenerUtils.isStatic(it.modifiers());
    if (_isStatic) {
        if (((it.getParent() instanceof TypeDeclaration) && IterableExtensions.<FieldDeclaration>forall(IterableExtensions.<FieldDeclaration>filter(((Iterable<FieldDeclaration>) Conversions.doWrapArray(((TypeDeclaration) it.getParent()).getFields())), ((Function1<FieldDeclaration, Boolean>) (FieldDeclaration it_1) -> {
            return Boolean.valueOf((this._aSTFlattenerUtils.isStatic(it_1.modifiers()) && this._aSTFlattenerUtils.isFinal(it_1.modifiers())));
        })), ((Function1<FieldDeclaration, Boolean>) (FieldDeclaration f) -> {
            final Function1<VariableDeclarationFragment, Boolean> _function = (VariableDeclarationFragment fragment) -> {
                Boolean _isAssignedInBody = this._aSTFlattenerUtils.isAssignedInBody(it.getBody(), fragment);
                return Boolean.valueOf((!(_isAssignedInBody).booleanValue()));
            };
            return Boolean.valueOf(IterableExtensions.<VariableDeclarationFragment>forall(f.fragments(), _function));
        })))) {
            this.appendToBuffer(" final Void static_initializer = {");
            this.appendLineWrapToBuffer();
            it.getBody().accept(this);
            this.appendToBuffer("null }");
            this.appendLineWrapToBuffer();
        } else {
            this.addProblem(it, "Static initializer is not fully supported");
            this.appendToBuffer("{/*FIXME ");
            it.getBody().accept(this);
            this.appendToBuffer("*/}");
        }
    } else {
        ASTNode _parent = it.getParent();
        if ((_parent instanceof AnonymousClassDeclaration)) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("Initializer is not supported in ");
            String _simpleName = ASTNode.nodeClassForType(it.getParent().getNodeType()).getSimpleName();
            _builder.append(_simpleName);
            this.addProblem(it, _builder.toString());
        }
        it.getBody().accept(this);
    }
    return false;
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Javadoc(org.eclipse.jdt.core.dom.Javadoc) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) AnnotationTypeDeclaration(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 92 with VariableDeclarationFragment

use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project xtext-xtend by eclipse.

the class JavaASTFlattener method visit.

@Override
public boolean visit(final FieldDeclaration it) {
    Javadoc _javadoc = it.getJavadoc();
    boolean _tripleNotEquals = (_javadoc != null);
    if (_tripleNotEquals) {
        it.getJavadoc().accept(this);
    }
    final Consumer<VariableDeclarationFragment> _function = (VariableDeclarationFragment frag) -> {
        this.appendModifiers(it, it.modifiers());
        boolean _isPackageVisibility = this._aSTFlattenerUtils.isPackageVisibility(Iterables.<Modifier>filter(it.modifiers(), Modifier.class));
        if (_isPackageVisibility) {
            ASTNode _parent = it.getParent();
            if ((_parent instanceof TypeDeclaration)) {
                ASTNode _parent_1 = it.getParent();
                boolean _isInterface = ((TypeDeclaration) _parent_1).isInterface();
                boolean _not = (!_isInterface);
                if (_not) {
                    this.appendToBuffer("package ");
                }
            }
        }
        it.getType().accept(this);
        this.appendExtraDimensions(frag.getExtraDimensions());
        this.appendSpaceToBuffer();
        frag.accept(this);
    };
    it.fragments().forEach(_function);
    return false;
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Javadoc(org.eclipse.jdt.core.dom.Javadoc) Modifier(org.eclipse.jdt.core.dom.Modifier) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) AnnotationTypeDeclaration(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration)

Example 93 with VariableDeclarationFragment

use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project AutoRefactor by JnRouvignac.

the class AbstractPrimitiveRatherThanWrapperRefactoring method visit.

@Override
public boolean visit(VariableDeclarationStatement node) {
    if (node.fragments().size() == 1) {
        final VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.fragments().get(0);
        if (hasType(fragment.resolveBinding().getType(), getWrapperFullyQualifiedName()) && fragment.getInitializer() != null) {
            if (isNotNull(fragment.getInitializer())) {
                final VarOccurrenceVisitor varOccurrenceVisitor = new VarOccurrenceVisitor(fragment);
                final Block parentBlock = getAncestorOrNull(fragment, Block.class);
                if (parentBlock != null) {
                    varOccurrenceVisitor.visitNode(parentBlock);
                    if (varOccurrenceVisitor.isPrimitiveAllowed() && varOccurrenceVisitor.getAutoBoxingCount() < 2) {
                        refactorWrapper(node);
                        return DO_NOT_VISIT_SUBTREE;
                    }
                }
            }
        }
    }
    return VISIT_SUBTREE;
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) Block(org.eclipse.jdt.core.dom.Block)

Example 94 with VariableDeclarationFragment

use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project AutoRefactor by JnRouvignac.

the class ASTBuilder method declareStmt.

/**
 * Builds a new {@link VariableDeclarationStatement} instance.
 *
 * @param type
 *            the type of the variable being declared
 * @param varName
 *            the name of the variable being declared
 * @param initializer
 *            the variable initializer, can be null
 * @return a new variable declaration statement
 */
public VariableDeclarationStatement declareStmt(Type type, SimpleName varName, Expression initializer) {
    final VariableDeclarationFragment fragment = declareFragment(varName, initializer);
    final VariableDeclarationStatement vds = ast.newVariableDeclarationStatement(fragment);
    vds.setType(type);
    return vds;
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) VariableDeclarationStatement(org.eclipse.jdt.core.dom.VariableDeclarationStatement)

Example 95 with VariableDeclarationFragment

use of org.eclipse.jdt.core.dom.VariableDeclarationFragment in project AutoRefactor by JnRouvignac.

the class ASTBuilder method declareFragment.

/**
 * Builds a new {@link VariableDeclarationFragment} instance.
 *
 * @param varName
 *            the declared variable name
 * @return a new variable declaration fragment
 */
public VariableDeclarationFragment declareFragment(SimpleName varName) {
    final VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
    vdf.setName(varName);
    return vdf;
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment)

Aggregations

VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)101 ASTNode (org.eclipse.jdt.core.dom.ASTNode)44 AST (org.eclipse.jdt.core.dom.AST)38 Expression (org.eclipse.jdt.core.dom.Expression)33 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)33 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)30 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)28 Assignment (org.eclipse.jdt.core.dom.Assignment)25 SimpleName (org.eclipse.jdt.core.dom.SimpleName)25 Type (org.eclipse.jdt.core.dom.Type)25 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)22 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)21 Block (org.eclipse.jdt.core.dom.Block)17 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)16 ArrayList (java.util.ArrayList)15 CastExpression (org.eclipse.jdt.core.dom.CastExpression)15 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)15 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)15 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)15 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)14