use of org.eclipse.jdt.core.dom.Comment 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;
}
use of org.eclipse.jdt.core.dom.Comment in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final Block node) {
this.appendToBuffer("{");
this.increaseIndent();
boolean _isEmpty = node.statements().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final Procedure2<ASTNode, Integer> _function = (ASTNode child, Integer counter) -> {
this.appendLineWrapToBuffer();
child.accept(this);
};
IterableExtensions.<ASTNode>forEach(node.statements(), _function);
}
ASTNode _root = node.getRoot();
if ((_root instanceof CompilationUnit)) {
ASTNode _root_1 = node.getRoot();
final CompilationUnit cu = ((CompilationUnit) _root_1);
final Function1<Comment, Boolean> _function_1 = (Comment it) -> {
int _startPosition = it.getStartPosition();
int _startPosition_1 = node.getStartPosition();
int _length = node.getLength();
int _plus = (_startPosition_1 + _length);
return Boolean.valueOf((_startPosition < _plus));
};
final Consumer<Comment> _function_2 = (Comment it) -> {
if ((!(it instanceof LineComment))) {
this.appendLineWrapToBuffer();
}
it.accept(this);
this.assignedComments.add(it);
};
IterableExtensions.<Comment>filter(this.unAssignedComments(cu), _function_1).forEach(_function_2);
}
this.decreaseIndent();
this.appendLineWrapToBuffer();
this.appendToBuffer("}");
return false;
}
use of org.eclipse.jdt.core.dom.Comment in project AutoRefactor by JnRouvignac.
the class CommentsRefactoring method visit.
@Override
public boolean visit(CompilationUnit node) {
this.astRoot = node;
for (Comment comment : getCommentList(astRoot)) {
comments.add(Pair.of(new SourceLocation(comment), comment));
}
for (Comment comment : getCommentList(astRoot)) {
if (comment.isBlockComment()) {
final BlockComment bc = (BlockComment) comment;
bc.accept(this);
} else if (comment.isLineComment()) {
final LineComment lc = (LineComment) comment;
lc.accept(this);
} else if (comment.isDocComment()) {
final Javadoc jc = (Javadoc) comment;
jc.accept(this);
} else {
throw new NotImplementedException(comment);
}
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.Comment in project AutoRefactor by JnRouvignac.
the class CommentsRefactoring method betterCommentExist.
private boolean betterCommentExist(Comment comment, ASTNode nodeWhereToAddJavadoc) {
if (hasJavadoc(nodeWhereToAddJavadoc)) {
return true;
}
final SourceLocation nodeLoc = new SourceLocation(nodeWhereToAddJavadoc);
SourceLocation bestLoc = new SourceLocation(comment);
Comment bestComment = comment;
for (Iterator<Pair<SourceLocation, Comment>> iter = this.comments.iterator(); iter.hasNext(); ) {
final Pair<SourceLocation, Comment> pair = iter.next();
final SourceLocation newLoc = pair.getFirst();
final Comment newComment = pair.getSecond();
if (newLoc.compareTo(bestLoc) < 0) {
// since comments are visited in ascending order,
// we can forget this comment.
iter.remove();
continue;
}
if (nodeLoc.compareTo(newLoc) < 0) {
break;
}
if (bestLoc.compareTo(newLoc) < 0) {
if (!(newComment instanceof LineComment)) {
// new comment is a BlockComment or a Javadoc
bestLoc = newLoc;
bestComment = newComment;
continue;
} else if (!(bestComment instanceof LineComment)) {
// new comment is a line comment and best comment is not
bestLoc = newLoc;
bestComment = newComment;
continue;
}
}
}
return bestComment != null && bestComment != comment;
}
use of org.eclipse.jdt.core.dom.Comment in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method addReplacementEdits.
private void addReplacementEdits(List<TextEdit> commentEdits) {
if (this.replacements.isEmpty()) {
return;
}
for (Pair<Comment, String> pair : this.replacements) {
final Comment node = pair.getFirst();
final int start = node.getStartPosition();
final int length = node.getLength();
commentEdits.add(new ReplaceEdit(start, length, pair.getSecond()));
}
}
Aggregations