use of org.eclipse.jdt.core.dom.TypeDeclaration in project flux by eclipse.
the class ASTNodeFactory method newType.
public static Type newType(AST ast, String content) {
StringBuffer buffer = new StringBuffer(TYPE_HEADER);
buffer.append(content);
buffer.append(TYPE_FOOTER);
ASTParser p = ASTParser.newParser(ast.apiLevel());
p.setSource(buffer.toString().toCharArray());
CompilationUnit root = (CompilationUnit) p.createAST(null);
List<AbstractTypeDeclaration> list = root.types();
TypeDeclaration typeDecl = (TypeDeclaration) list.get(0);
MethodDeclaration methodDecl = typeDecl.getMethods()[0];
ASTNode type = methodDecl.getReturnType2();
ASTNode result = ASTNode.copySubtree(ast, type);
result.accept(new PositionClearer());
return (Type) result;
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project eclipse-pmd by acanda.
the class SuppressWarningsQuickFix method findBodyDeclaration.
private BodyDeclaration findBodyDeclaration(final ASTNode node) {
final BodyDeclaration[] bodyDeclaration = new BodyDeclaration[1];
node.accept(new ASTVisitor() {
@Override
public boolean visit(final EnumDeclaration node) {
bodyDeclaration[0] = node;
return false;
}
@Override
public boolean visit(final TypeDeclaration node) {
bodyDeclaration[0] = node;
return false;
}
@Override
public boolean visit(final AnnotationTypeDeclaration node) {
bodyDeclaration[0] = node;
return false;
}
});
return bodyDeclaration[0];
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project AutoRefactor by JnRouvignac.
the class AndroidViewHolderCleanUp method createViewHolderItemClass.
private TypeDeclaration createViewHolderItemClass(final FindViewByIdVisitor findViewByIdVisitor, final SimpleName typeName, final TypeNameDecider typeNameDecider) {
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TypeDeclaration result = ast.getAST().newTypeDeclaration();
Collections.addAll(result.modifiers(), ast.private0(), ast.static0());
result.setName(typeName);
List<BodyDeclaration> viewItemsFieldDecls = result.bodyDeclarations();
for (FindViewByIdVisitor.FindViewByIdItem item : findViewByIdVisitor.items) {
viewItemsFieldDecls.add(item.toFieldDecl(ast, typeNameDecider));
}
return result;
}
use of org.eclipse.jdt.core.dom.TypeDeclaration 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.TypeDeclaration 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;
}
Aggregations