Search in sources :

Example 11 with EnumConstantDeclaration

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));
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ImportRewrite(org.eclipse.jdt.core.dom.rewrite.ImportRewrite) CodeGenerationSettings(org.eclipse.jdt.ls.core.internal.corext.codemanipulation.CodeGenerationSettings) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) EnumConstantDeclaration(org.eclipse.jdt.core.dom.EnumConstantDeclaration) ContextSensitiveImportRewriteContext(org.eclipse.jdt.ls.core.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext) ImportRewriteContext(org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext) ContextSensitiveImportRewriteContext(org.eclipse.jdt.ls.core.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 12 with EnumConstantDeclaration

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;
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) EnumConstantDeclaration(org.eclipse.jdt.core.dom.EnumConstantDeclaration) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) LineComment(org.eclipse.jdt.core.dom.LineComment) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) WildcardType(org.eclipse.jdt.core.dom.WildcardType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Javadoc(org.eclipse.jdt.core.dom.Javadoc) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) ArrayList(java.util.ArrayList) List(java.util.List) Modifier(org.eclipse.jdt.core.dom.Modifier) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Aggregations

EnumConstantDeclaration (org.eclipse.jdt.core.dom.EnumConstantDeclaration)12 ASTNode (org.eclipse.jdt.core.dom.ASTNode)7 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)7 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)6 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)5 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 AnonymousClassDeclaration (org.eclipse.jdt.core.dom.AnonymousClassDeclaration)4 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)4 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)4 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)3 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)3 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)3 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)3 AST (org.eclipse.jdt.core.dom.AST)2 ClassInstanceCreation (org.eclipse.jdt.core.dom.ClassInstanceCreation)2 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)2 SimpleName (org.eclipse.jdt.core.dom.SimpleName)2