use of org.eclipse.jdt.core.dom.EnumConstantDeclaration in project eclipse.jdt.ls by eclipse.
the class AddUnimplementedMethodsOperation method rewriteAST.
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
IMethodBinding[] unimplementedMethods = getUnimplementedMethods(fTypeNode);
if (unimplementedMethods.length == 0) {
return;
}
ImportRewriteContext context = new ContextSensitiveImportRewriteContext((CompilationUnit) fTypeNode.getRoot(), fTypeNode.getStartPosition(), cuRewrite.getImportRewrite());
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ICompilationUnit unit = cuRewrite.getCu();
CodeGenerationSettings settings = PreferenceManager.getCodeGenerationSettings(unit.getJavaProject().getProject());
ListRewrite listRewrite;
ITypeBinding currentType = null;
if (fTypeNode instanceof AnonymousClassDeclaration) {
AnonymousClassDeclaration decl = (AnonymousClassDeclaration) fTypeNode;
listRewrite = rewrite.getListRewrite(decl, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY);
settings.createComments = false;
currentType = decl.resolveBinding();
} else if (fTypeNode instanceof AbstractTypeDeclaration) {
AbstractTypeDeclaration decl = (AbstractTypeDeclaration) fTypeNode;
listRewrite = rewrite.getListRewrite(decl, decl.getBodyDeclarationsProperty());
currentType = decl.resolveBinding();
} else if (fTypeNode instanceof EnumConstantDeclaration) {
EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) fTypeNode;
AnonymousClassDeclaration anonymousClassDeclaration = enumConstantDeclaration.getAnonymousClassDeclaration();
if (anonymousClassDeclaration == null) {
anonymousClassDeclaration = rewrite.getAST().newAnonymousClassDeclaration();
rewrite.set(enumConstantDeclaration, EnumConstantDeclaration.ANONYMOUS_CLASS_DECLARATION_PROPERTY, anonymousClassDeclaration, createTextEditGroup(CorrectionMessages.AddUnimplementedMethodsOperation_AddMissingMethod_group, cuRewrite));
}
listRewrite = rewrite.getListRewrite(anonymousClassDeclaration, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY);
settings.createComments = false;
} else {
// $NON-NLS-1$
Assert.isTrue(false, "Unknown type node");
return;
}
ImportRewrite imports = cuRewrite.getImportRewrite();
for (int i = 0; i < unimplementedMethods.length; i++) {
IMethodBinding curr = unimplementedMethods[i];
MethodDeclaration newMethodDecl = StubUtility2.createImplementationStub(unit, rewrite, imports, context, curr, curr.getDeclaringClass(), settings, false, currentType, false);
listRewrite.insertLast(newMethodDecl, createTextEditGroup(CorrectionMessages.AddUnimplementedMethodsOperation_AddMissingMethod_group, cuRewrite));
}
}
use of org.eclipse.jdt.core.dom.EnumConstantDeclaration 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