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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations