Search in sources :

Example 91 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class CreateXtendTypeQuickfixes method newLocalXtendInterfaceQuickfix.

protected void newLocalXtendInterfaceQuickfix(String typeName, XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
    EObject eObject = resource.getEObject(issue.getUriToProblem().fragment());
    XtendTypeDeclaration xtendType = getAnnotationTarget(eObject);
    if (xtendType != null) {
        JvmDeclaredType inferredType = associations.getInferredType(xtendType);
        if (inferredType != null) {
            AbstractInterfaceBuilder interfaceBuilder = codeBuilderFactory.createInterfaceBuilder(inferredType);
            interfaceBuilder.setInterfaceName(typeName);
            interfaceBuilder.setVisibility(JvmVisibility.PUBLIC);
            interfaceBuilder.setContext(xtendType);
            interfaceBuilder.setImage("xtend_file.png");
            codeBuilderQuickfix.addQuickfix(interfaceBuilder, "Create local Xtend interface '" + typeName + "'", issue, issueResolutionAcceptor);
        }
    }
}
Also used : AbstractInterfaceBuilder(org.eclipse.xtend.ide.codebuilder.AbstractInterfaceBuilder) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 92 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class XtendQuickfixProvider method doOverrideMethods.

protected void doOverrideMethods(final Issue issue, IssueResolutionAcceptor acceptor, String label, final String[] operationUris) {
    acceptor.accept(issue, label, label, "fix_indent.gif", new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            XtendTypeDeclaration clazz = (XtendTypeDeclaration) element;
            JvmGenericType inferredType = (JvmGenericType) associations.getInferredType(clazz);
            ResolvedFeatures resolvedOperations = overrideHelper.getResolvedFeatures(inferredType);
            IXtextDocument document = context.getXtextDocument();
            final int offset = insertionOffsets.getNewMethodInsertOffset(null, clazz);
            int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, (XtextResource) clazz.eResource());
            final int indentationToUse = clazz.getMembers().isEmpty() ? currentIndentation + 1 : currentIndentation;
            ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(), offset, 0, new OptionalParameters() {

                {
                    ensureEmptyLinesAround = true;
                    baseIndentationLevel = indentationToUse;
                }
            });
            boolean isFirst = true;
            for (String operationUriAsString : operationUris) {
                URI operationURI = URI.createURI(operationUriAsString);
                EObject overridden = clazz.eResource().getResourceSet().getEObject(operationURI, true);
                if (overridden instanceof JvmOperation) {
                    if (!isFirst)
                        appendable.newLine().newLine();
                    isFirst = false;
                    superMemberImplementor.appendOverrideFunction(clazz, resolvedOperations.getResolvedOperation((JvmOperation) overridden), appendable);
                }
            }
            appendable.commitChanges();
        }
    });
}
Also used : ResolvedFeatures(org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) URI(org.eclipse.emf.common.util.URI) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) OptionalParameters(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters) EObject(org.eclipse.emf.ecore.EObject) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 93 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class InsertionOffsetTest method checkTypeInsertionOffset.

protected void checkTypeInsertionOffset(final CharSequence model) {
    try {
        final String modelAsString = model.toString();
        final int caretOffset = modelAsString.replace("$", "").indexOf("|");
        final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
        final XtendClass xtendClass = ((XtendClass) _head);
        Resource _eResource = xtendClass.eResource();
        final XtextResource xtextResource = ((XtextResource) _eResource);
        final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
        Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewTypeInsertOffset(caretElement, xtendClass));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 94 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class InsertionOffsetTest method checkConstructorInsertionOffset.

protected void checkConstructorInsertionOffset(final CharSequence model) {
    try {
        final String modelAsString = model.toString();
        final int caretOffset = modelAsString.replace("$", "").indexOf("|");
        final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
        final XtendClass xtendClass = ((XtendClass) _head);
        Resource _eResource = xtendClass.eResource();
        final XtextResource xtextResource = ((XtextResource) _eResource);
        final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
        Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewConstructorInsertOffset(caretElement, xtendClass));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 95 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class XtendHoverSignatureProviderTest method testInterfaceReference.

@Test
public void testInterfaceReference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Bar implements Foo {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("interface Foo { }");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        final JvmType in = IterableExtensions.<JvmTypeReference>head(((XtendClass) _head).getImplements()).getType();
        Assert.assertEquals("Foo", this.signatureProvider.getSignature(in));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Aggregations

XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)134 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)98 Test (org.junit.Test)91 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)77 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)57 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)39 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 XExpression (org.eclipse.xtext.xbase.XExpression)36 EObject (org.eclipse.emf.ecore.EObject)34 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)29 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendField (org.eclipse.xtend.core.xtend.XtendField)12 JvmType (org.eclipse.xtext.common.types.JvmType)11 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8