use of org.eclipse.jdt.core.dom.BodyDeclaration in project AutoRefactor by JnRouvignac.
the class ObsoleteRemoveSemiColonCleanUp method visit.
private boolean visit(final BodyDeclaration visited) {
BodyDeclaration nextSibling = ASTNodes.getNextSibling(visited);
ASTNode parent = visited.getParent();
if (nextSibling != null) {
return maybeRemoveSuperfluousSemiColons(visited, SourceLocation.getEndPosition(visited), nextSibling.getStartPosition());
}
if (parent instanceof AbstractTypeDeclaration) {
AbstractTypeDeclaration typeDecl = (AbstractTypeDeclaration) parent;
return maybeRemoveSuperfluousSemiColons(visited, SourceLocation.getEndPosition(visited), SourceLocation.getEndPosition(typeDecl) - 1);
}
if (parent instanceof AnonymousClassDeclaration) {
AnonymousClassDeclaration classDecl = (AnonymousClassDeclaration) parent;
return maybeRemoveSuperfluousSemiColons(visited, SourceLocation.getEndPosition(visited), SourceLocation.getEndPosition(classDecl) - 1);
}
if (parent instanceof CompilationUnit) {
CompilationUnit cu = (CompilationUnit) parent;
return maybeRemoveSuperfluousSemiColons(visited, SourceLocation.getEndPosition(visited), SourceLocation.getEndPosition(cu) - 1);
}
if (parent instanceof TypeDeclarationStatement) {
return true;
}
throw new NotImplementedException(visited, // $NON-NLS-1$
"for a parent of type " + (parent != null ? parent.getClass().getSimpleName() : null));
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project xtext-xtend by eclipse.
the class JavaCodeAnalyzer method determinateJavaType.
public JavaCodeAnalyzer.JavaParseResult<? extends ASTNode> determinateJavaType(final String javaCode) {
ASTParser parser = this.parserFactory.createDefaultJavaParser(this.parserFactory.minParserApiLevel);
parser.setSource(javaCode.toCharArray());
parser.setStatementsRecovery(true);
ASTNode _createAST = parser.createAST(null);
CompilationUnit unit = ((CompilationUnit) _createAST);
int _size = unit.types().size();
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
List<CompilationUnit> _singletonList = Collections.<CompilationUnit>singletonList(unit);
return new JavaCodeAnalyzer.JavaParseResult<CompilationUnit>(javaCode, ASTParser.K_COMPILATION_UNIT, _singletonList);
}
parser.setSource(javaCode.toCharArray());
parser.setStatementsRecovery(false);
parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
ASTNode root = parser.createAST(null);
if ((root instanceof TypeDeclaration)) {
List<BodyDeclaration> bodyDeclarations = ((TypeDeclaration) root).bodyDeclarations();
int _size_1 = bodyDeclarations.size();
boolean _greaterThan_1 = (_size_1 > 0);
if (_greaterThan_1) {
return new JavaCodeAnalyzer.JavaParseResult<BodyDeclaration>(javaCode, ASTParser.K_CLASS_BODY_DECLARATIONS, bodyDeclarations);
}
}
parser.setSource(javaCode.toCharArray());
parser.setStatementsRecovery(false);
parser.setKind(ASTParser.K_STATEMENTS);
root = parser.createAST(null);
if ((root instanceof Block)) {
List<Statement> statements = ((Block) root).statements();
int _size_2 = statements.size();
boolean _greaterThan_2 = (_size_2 > 0);
if (_greaterThan_2) {
return new JavaCodeAnalyzer.JavaParseResult<Statement>(javaCode, ASTParser.K_STATEMENTS, statements);
}
}
parser.setSource(javaCode.toCharArray());
parser.setStatementsRecovery(false);
parser.setKind(ASTParser.K_EXPRESSION);
root = parser.createAST(null);
if ((root instanceof Expression)) {
List<Expression> _singletonList_1 = Collections.<Expression>singletonList(((Expression) root));
return new JavaCodeAnalyzer.JavaParseResult<Expression>(javaCode, ASTParser.K_EXPRESSION, _singletonList_1);
}
return null;
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final TypeDeclaration it) {
boolean _isDummyType = this._aSTFlattenerUtils.isDummyType(it);
if (_isDummyType) {
this.visitAll(it.bodyDeclarations(), this.nl());
return false;
}
boolean _isNotSupportedInnerType = this._aSTFlattenerUtils.isNotSupportedInnerType(it);
if (_isNotSupportedInnerType) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/* FIXME Non-static inner classes are not supported.*/");
this.appendToBuffer(_builder.toString());
this.addProblem(it, "Non-static inner classes are not supported.");
}
Javadoc _javadoc = it.getJavadoc();
boolean _tripleNotEquals = (_javadoc != null);
if (_tripleNotEquals) {
it.getJavadoc().accept(this);
}
this.appendModifiers(it, it.modifiers());
boolean _isInterface = it.isInterface();
if (_isInterface) {
this.appendToBuffer("interface ");
} else {
boolean _isPackageVisibility = this._aSTFlattenerUtils.isPackageVisibility(Iterables.<Modifier>filter(it.modifiers(), Modifier.class));
if (_isPackageVisibility) {
this.appendToBuffer("package ");
}
this.appendToBuffer("class ");
}
it.getName().accept(this);
boolean _isEmpty = it.typeParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
this.appendTypeParameters(it.typeParameters());
}
this.appendSpaceToBuffer();
Type _superclassType = it.getSuperclassType();
boolean _tripleNotEquals_1 = (_superclassType != null);
if (_tripleNotEquals_1) {
this.appendToBuffer("extends ");
it.getSuperclassType().accept(this);
this.appendSpaceToBuffer();
}
boolean _isEmpty_1 = it.superInterfaceTypes().isEmpty();
boolean _not_1 = (!_isEmpty_1);
if (_not_1) {
boolean _isInterface_1 = it.isInterface();
if (_isInterface_1) {
this.appendToBuffer("extends ");
} else {
this.appendToBuffer("implements ");
}
this.visitAllSeparatedByComma(it.superInterfaceTypes());
}
this.appendToBuffer("{");
this.increaseIndent();
BodyDeclaration prev = null;
List _bodyDeclarations = it.bodyDeclarations();
for (final BodyDeclaration body : ((Iterable<BodyDeclaration>) _bodyDeclarations)) {
{
if ((prev instanceof EnumConstantDeclaration)) {
if ((body instanceof EnumConstantDeclaration)) {
this.appendToBuffer(", ");
} else {
this.appendToBuffer("; ");
}
}
this.appendLineWrapToBuffer();
body.accept(this);
prev = body;
}
}
ASTNode _root = it.getRoot();
if ((_root instanceof CompilationUnit)) {
ASTNode _root_1 = it.getRoot();
final CompilationUnit cu = ((CompilationUnit) _root_1);
final Consumer<Comment> _function = (Comment it_1) -> {
it_1.accept(this);
this.assignedComments.add(it_1);
};
this.unAssignedComments(cu).forEach(_function);
}
this.decreaseIndent();
this.appendLineWrapToBuffer();
this.appendToBuffer("}");
return false;
}
Aggregations