Search in sources :

Example 16 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-lib by eclipse.

the class EqualsHashCodeProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
    AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
    boolean _tripleNotEquals = (_findAnnotation != null);
    if (_tripleNotEquals) {
        return;
    }
    @Extension final EqualsHashCodeProcessor.Util util = new EqualsHashCodeProcessor.Util(context);
    boolean _hasEquals = util.hasEquals(it);
    if (_hasEquals) {
        final AnnotationReference annotation = it.findAnnotation(context.findTypeGlobally(EqualsHashCode.class));
        context.addWarning(annotation, "equals is already defined, this annotation has no effect");
    } else {
        boolean _hasHashCode = util.hasHashCode(it);
        if (_hasHashCode) {
            context.addWarning(it, "hashCode is already defined, this annotation has no effect");
        } else {
            final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
                return Boolean.valueOf((((!it_1.isStatic()) && (!it_1.isTransient())) && context.isThePrimaryGeneratedJavaElement(it_1)));
            };
            final Iterable<? extends MutableFieldDeclaration> fields = IterableExtensions.filter(it.getDeclaredFields(), _function);
            util.addEquals(it, fields, util.hasSuperEquals(it));
            util.addHashCode(it, fields, util.hasSuperHashCode(it));
        }
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) Data(org.eclipse.xtend.lib.annotations.Data) EqualsHashCode(org.eclipse.xtend.lib.annotations.EqualsHashCode)

Example 17 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testExtensionToAnnotation_01.

@Test
public void testExtensionToAnnotation_01() throws Exception {
    XtendFile xtendFile = file("class C { extension String }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField jvmField = (JvmField) inferredType.getMembers().get(1);
    assertEquals("_string", jvmField.getSimpleName());
    List<JvmAnnotationReference> annotations = jvmField.getAnnotations();
    assertEquals(1, annotations.size());
    assertEquals(Extension.class.getCanonicalName(), annotations.get(0).getAnnotation().getQualifiedName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) Extension(org.eclipse.xtext.xbase.lib.Extension) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) Test(org.junit.Test)

Example 18 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testExtensionToAnnotation_02.

@Test
public void testExtensionToAnnotation_02() throws Exception {
    XtendFile xtendFile = file("class C { def void m(extension String s) {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    List<JvmFormalParameter> parameters = jvmOperation.getParameters();
    JvmFormalParameter singleParameter = parameters.get(0);
    List<JvmAnnotationReference> annotations = singleParameter.getAnnotations();
    assertEquals(1, annotations.size());
    assertEquals(Extension.class.getCanonicalName(), annotations.get(0).getAnnotation().getQualifiedName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Extension(org.eclipse.xtext.xbase.lib.Extension) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) Test(org.junit.Test)

Example 19 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.

the class AbstractLanguageServerTest method testDocumentSymbol.

protected void testDocumentSymbol(final Procedure1<? super DocumentSymbolConfiguraiton> configurator) {
    try {
        @Extension final DocumentSymbolConfiguraiton configuration = new DocumentSymbolConfiguraiton();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
        DocumentSymbolParams _documentSymbolParams = new DocumentSymbolParams(_textDocumentIdentifier);
        final CompletableFuture<List<? extends SymbolInformation>> symbolsFuture = this.languageServer.documentSymbol(_documentSymbolParams);
        final List<? extends SymbolInformation> symbols = symbolsFuture.get();
        Procedure1<? super List<? extends SymbolInformation>> _assertSymbols = configuration.getAssertSymbols();
        boolean _tripleNotEquals = (_assertSymbols != null);
        if (_tripleNotEquals) {
            configuration.getAssertSymbols().apply(symbols);
        } else {
            final String actualSymbols = this.toExpectation(symbols);
            this.assertEquals(configuration.getExpectedSymbols(), actualSymbols);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) DocumentSymbolConfiguraiton(org.eclipse.xtext.testing.DocumentSymbolConfiguraiton) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 20 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.

the class AbstractLanguageServerTest method testDocumentHighlight.

protected void testDocumentHighlight(final Procedure1<? super DocumentHighlightConfiguration> configurator) {
    try {
        DocumentHighlightConfiguration _documentHighlightConfiguration = new DocumentHighlightConfiguration();
        final Procedure1<DocumentHighlightConfiguration> _function = (DocumentHighlightConfiguration it) -> {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("MyModel.");
            _builder.append(this.fileExtension);
            it.setFilePath(_builder.toString());
        };
        @Extension final DocumentHighlightConfiguration configuration = ObjectExtensions.<DocumentHighlightConfiguration>operator_doubleArrow(_documentHighlightConfiguration, _function);
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
        final Procedure1<TextDocumentPositionParams> _function_1 = (TextDocumentPositionParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
            it.setTextDocument(_textDocumentIdentifier);
            int _line = configuration.getLine();
            int _column = configuration.getColumn();
            Position _position = new Position(_line, _column);
            it.setPosition(_position);
        };
        TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function_1);
        final CompletableFuture<List<? extends DocumentHighlight>> highlights = this.languageServer.documentHighlight(_doubleArrow);
        final Function1<DocumentHighlight, String> _function_2 = (DocumentHighlight it) -> {
            return this.toExpectation(it);
        };
        final String actualDocumentHighlight = IterableExtensions.join(ListExtensions.map(highlights.get(), _function_2), " | ");
        this.assertEquals(configuration.getExpectedDocumentHighlight(), actualDocumentHighlight);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Extension(org.eclipse.xtext.xbase.lib.Extension) DocumentHighlightConfiguration(org.eclipse.xtext.testing.DocumentHighlightConfiguration) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Aggregations

Extension (org.eclipse.xtext.xbase.lib.Extension)34 List (java.util.List)11 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)11 CompletionList (org.eclipse.lsp4j.CompletionList)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 Test (org.junit.Test)8 Position (org.eclipse.lsp4j.Position)6 ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)6 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)4 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)4 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)4 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)4 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)4 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)4 Set (java.util.Set)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 Data (org.eclipse.xtend.lib.annotations.Data)3 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)3 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)3 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)3