Search in sources :

Example 31 with Extension

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

the class AbstractHierarchyBuilderTest method testBuildHierarchy.

protected void testBuildHierarchy(final Procedure1<? super AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration> configurator) {
    @Extension final AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration configuration = new AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration();
    configurator.apply(configuration);
    final ResourceSet resourceSet = this.createResourceSet(configuration);
    final IHierarchyBuilder hierarchyBuilder = configuration.hierarchyBuilderProvider.apply(resourceSet);
    String _xifexpression = null;
    if ((configuration.resourceURI == null)) {
        _xifexpression = IterableExtensions.<Pair<String, String>>last(configuration.models).getKey();
    } else {
        _xifexpression = configuration.resourceURI;
    }
    final String resourceURI = _xifexpression;
    Resource _resource = resourceSet.getResource(URI.createURI(resourceURI), false);
    final XtextResource resource = ((XtextResource) _resource);
    final URI rootURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(this._eObjectAtOffsetHelper.resolveElementAt(resource, configuration.index));
    final String actualHierarchy = this.toExpectation(rootURI, hierarchyBuilder);
    Assert.assertEquals(configuration.expectedHierarchy, actualHierarchy);
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IHierarchyBuilder(org.eclipse.xtext.ide.editor.hierarchy.IHierarchyBuilder) URI(org.eclipse.emf.common.util.URI) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 32 with Extension

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

the class AccessorsProcessor method _transform.

protected void _transform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
    AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
    boolean _tripleNotEquals = (_findAnnotation != null);
    if (_tripleNotEquals) {
        return;
    }
    @Extension final FinalFieldsConstructorProcessor.Util requiredArgsUtil = new FinalFieldsConstructorProcessor.Util(context);
    if ((requiredArgsUtil.needsFinalFieldConstructor(it) || (it.findAnnotation(context.findTypeGlobally(FinalFieldsConstructor.class)) != null))) {
        requiredArgsUtil.addFinalFieldsConstructor(it);
    }
    final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
        return Boolean.valueOf(((!it_1.isStatic()) && context.isThePrimaryGeneratedJavaElement(it_1)));
    };
    final Consumer<MutableFieldDeclaration> _function_1 = (MutableFieldDeclaration it_1) -> {
        this._transform(it_1, context);
    };
    IterableExtensions.filter(it.getDeclaredFields(), _function).forEach(_function_1);
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) FinalFieldsConstructor(org.eclipse.xtend.lib.annotations.FinalFieldsConstructor) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) Data(org.eclipse.xtend.lib.annotations.Data) FinalFieldsConstructorProcessor(org.eclipse.xtend.lib.annotations.FinalFieldsConstructorProcessor)

Example 33 with Extension

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

the class ToStringProcessor 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 ToStringProcessor.Util util = new ToStringProcessor.Util(context);
    final AnnotationReference annotation = it.findAnnotation(context.findTypeGlobally(ToString.class));
    final ToStringConfiguration configuration = new ToStringConfiguration(annotation);
    boolean _hasToString = util.hasToString(it);
    if (_hasToString) {
        context.addWarning(annotation, "toString is already defined, this annotation has no effect.");
    } else {
        TypeReference _extendedClass = it.getExtendedClass();
        TypeReference _object = context.getObject();
        boolean _notEquals = (!Objects.equal(_extendedClass, _object));
        if (_notEquals) {
            util.addReflectiveToString(it, configuration);
        } else {
            final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
                return Boolean.valueOf(((context.isThePrimaryGeneratedJavaElement(it_1) && (!it_1.isStatic())) && (!it_1.isTransient())));
            };
            util.addToString(it, IterableExtensions.filter(it.getDeclaredFields(), _function), configuration);
        }
    }
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) ToStringConfiguration(org.eclipse.xtend.lib.annotations.ToStringConfiguration) Data(org.eclipse.xtend.lib.annotations.Data) Extension(org.eclipse.xtext.xbase.lib.Extension) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) ToString(org.eclipse.xtend.lib.annotations.ToString)

Example 34 with Extension

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

the class FinalFieldsConstructorProcessor method _transform.

protected void _transform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
    AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
    boolean _tripleNotEquals = (_findAnnotation != null);
    if (_tripleNotEquals) {
        return;
    }
    AnnotationReference _findAnnotation_1 = it.findAnnotation(context.findTypeGlobally(Accessors.class));
    boolean _tripleNotEquals_1 = (_findAnnotation_1 != null);
    if (_tripleNotEquals_1) {
        return;
    }
    @Extension final FinalFieldsConstructorProcessor.Util util = new FinalFieldsConstructorProcessor.Util(context);
    util.addFinalFieldsConstructor(it);
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) Data(org.eclipse.xtend.lib.annotations.Data) Accessors(org.eclipse.xtend.lib.annotations.Accessors)

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