org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration Java Examples
The following examples show how to use
org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddInterfaceWithDefaultProcessor.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) { super.doTransform(annotatedClass, context); Type _findTypeGlobally = context.findTypeGlobally("de.test.Test"); final MutableInterfaceDeclaration ifType = ((MutableInterfaceDeclaration) _findTypeGlobally); final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("System.out.println(\"Hello World\");"); } }; it.setBody(_client); it.setDefault(true); }; ifType.addMethod("sayHello", _function); }
Example #2
Source File: AnnotationWithNestedEnumProcessor.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) { final MutableInterfaceDeclaration interfaceType = context.findInterface(this.getInterfaceName(annotatedClass)); context.setPrimarySourceElement(interfaceType, annotatedClass); try { final EnumerationValueDeclaration value = annotatedClass.findAnnotation(context.findTypeGlobally(AnnotationWithNestedEnum.class)).getEnumValue("value"); final Procedure1<AnnotationReferenceBuildContext> _function = (AnnotationReferenceBuildContext it) -> { it.setEnumValue("value", value); }; final AnnotationReference ref = context.newAnnotationReference(AnnotationWithNestedEnum.class, _function); interfaceType.addAnnotation(ref); } catch (final Throwable _t) { if (_t instanceof Exception) { final Exception exc = (Exception)_t; String _message = exc.getMessage(); String _plus = ("failed: " + _message); context.addError(annotatedClass, _plus); } else { throw Exceptions.sneakyThrow(_t); } } }
Example #3
Source File: DeclarationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testMutableInterfaceDeclaration() { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("interface MyInterface {"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> { final MutableInterfaceDeclaration genInterface = it.getTypeLookup().findInterface("foo.MyInterface"); final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it_1) -> { }; final MutableMethodDeclaration m = genInterface.addMethod("newMethod", _function_1); Assert.assertTrue(m.isAbstract()); }; this.asCompilationUnit(this.validFile(_builder), _function); }
Example #4
Source File: ExtractTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testExtractAnnotation() { StringConcatenation _builder = new StringConcatenation(); _builder.append("@extract.Extract"); _builder.newLine(); _builder.append("class MyClass {"); _builder.newLine(); _builder.append("\t"); _builder.append("override doStuff(String myParam) throws IllegalArgumentException {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("return myParam"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> { @Extension final TransformationContext ctx = it.getTransformationContext(); final MutableInterfaceDeclaration interf = ctx.findInterface("MyClassInterface"); final MutableClassDeclaration clazz = ctx.findClass("MyClass"); Assert.assertEquals(IterableExtensions.head(clazz.getImplementedInterfaces()).getType(), interf); MutableMethodDeclaration _head = IterableExtensions.head(interf.getDeclaredMethods()); final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it_1) -> { Assert.assertEquals("doStuff", it_1.getSimpleName()); Assert.assertEquals(ctx.getString(), it_1.getReturnType()); Assert.assertEquals(ctx.newTypeReference(IllegalArgumentException.class), IterableExtensions.head(it_1.getExceptions())); }; ObjectExtensions.<MutableMethodDeclaration>operator_doubleArrow(_head, _function_1); }; this.compilerTester.compile(_builder, _function); }
Example #5
Source File: ExtractProcessor.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) { final MutableInterfaceDeclaration interfaceType = context.findInterface(this.getInterfaceName(annotatedClass)); context.setPrimarySourceElement(interfaceType, annotatedClass); Iterable<? extends TypeReference> _implementedInterfaces = annotatedClass.getImplementedInterfaces(); TypeReference _newTypeReference = context.newTypeReference(interfaceType); Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_implementedInterfaces, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(_newTypeReference))); annotatedClass.setImplementedInterfaces(_plus); Iterable<? extends MutableMethodDeclaration> _declaredMethods = annotatedClass.getDeclaredMethods(); for (final MutableMethodDeclaration method : _declaredMethods) { Visibility _visibility = method.getVisibility(); boolean _equals = Objects.equal(_visibility, Visibility.PUBLIC); if (_equals) { final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> { it.setDocComment(method.getDocComment()); it.setReturnType(method.getReturnType()); Iterable<? extends MutableParameterDeclaration> _parameters = method.getParameters(); for (final MutableParameterDeclaration p : _parameters) { it.addParameter(p.getSimpleName(), p.getType()); } it.setExceptions(((TypeReference[])Conversions.unwrapArray(method.getExceptions(), TypeReference.class))); context.setPrimarySourceElement(it, method); }; interfaceType.addMethod(method.getSimpleName(), _function); } } }
Example #6
Source File: DeclarationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testSetImplementedInterfaces() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class BaseClass {}"); _builder.newLine(); _builder.append("interface Interface {}"); _builder.newLine(); final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> { final MutableClassDeclaration baseClass = it.getTypeLookup().findClass("BaseClass"); final MutableInterfaceDeclaration interf = it.getTypeLookup().findInterface("Interface"); final TypeReference objectType = baseClass.getExtendedClass(); Assert.assertEquals("Object", objectType.getSimpleName()); Assert.assertTrue(IterableExtensions.isEmpty(baseClass.getImplementedInterfaces())); final TypeReference superType = it.getTypeReferenceProvider().newTypeReference(AccessibleObject.class); baseClass.setExtendedClass(superType); Assert.assertEquals("AccessibleObject", baseClass.getExtendedClass().getSimpleName()); Assert.assertTrue(IterableExtensions.isEmpty(baseClass.getImplementedInterfaces())); baseClass.setExtendedClass(null); Assert.assertEquals("Object", baseClass.getExtendedClass().getSimpleName()); Assert.assertTrue(IterableExtensions.isEmpty(baseClass.getImplementedInterfaces())); TypeReference _newTypeReference = it.getTypeReferenceProvider().newTypeReference(interf); baseClass.setImplementedInterfaces(Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(_newTypeReference))); Assert.assertEquals("Interface", IterableExtensions.head(baseClass.getImplementedInterfaces()).getSimpleName()); baseClass.setImplementedInterfaces(Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList())); Assert.assertTrue(IterableExtensions.isEmpty(baseClass.getImplementedInterfaces())); }; this.asCompilationUnit(this.validFile(_builder), _function); }
Example #7
Source File: TypeLookupImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public MutableInterfaceDeclaration findInterface(final String qualifiedName) { final Type type = this.findType(qualifiedName); MutableInterfaceDeclaration _switchResult = null; boolean _matched = false; if (type instanceof MutableInterfaceDeclaration) { _matched=true; _switchResult = ((MutableInterfaceDeclaration)type); } return _switchResult; }
Example #8
Source File: JsonRpcDataTransformationContext.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public MutableInterfaceDeclaration findInterface(final String arg0) { return this.delegate.findInterface(arg0); }
Example #9
Source File: MutableJvmInterfaceDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Iterable<? extends MutableInterfaceDeclaration> getDeclaredInterfaces() { Iterable<? extends InterfaceDeclaration> _declaredInterfaces = super.getDeclaredInterfaces(); return ((Iterable<? extends MutableInterfaceDeclaration>) _declaredInterfaces); }
Example #10
Source File: MutableJvmEnumerationTypeDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Iterable<? extends MutableInterfaceDeclaration> getDeclaredInterfaces() { Iterable<? extends InterfaceDeclaration> _declaredInterfaces = super.getDeclaredInterfaces(); return ((Iterable<? extends MutableInterfaceDeclaration>) _declaredInterfaces); }
Example #11
Source File: MutableJvmClassDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Iterable<? extends MutableInterfaceDeclaration> getDeclaredInterfaces() { Iterable<? extends InterfaceDeclaration> _declaredInterfaces = super.getDeclaredInterfaces(); return ((Iterable<? extends MutableInterfaceDeclaration>) _declaredInterfaces); }
Example #12
Source File: MutableJvmAnnotationTypeDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Iterable<? extends MutableInterfaceDeclaration> getDeclaredInterfaces() { Iterable<? extends InterfaceDeclaration> _declaredInterfaces = super.getDeclaredInterfaces(); return ((Iterable<? extends MutableInterfaceDeclaration>) _declaredInterfaces); }
Example #13
Source File: TransformationContextImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public MutableInterfaceDeclaration findInterface(final String qualifiedName) { return this.getTypeLookup().findInterface(qualifiedName); }
Example #14
Source File: ValidationContextImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public MutableInterfaceDeclaration findInterface(final String qualifiedName) { return this.getTypeLookup().findInterface(qualifiedName); }
Example #15
Source File: CheckMutableInterfaceDeclarationProcessor.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public void doGenerateCode(final List<? extends MutableInterfaceDeclaration> annotatedSourceElements, @Extension final CodeGenerationContext context) { }
Example #16
Source File: AbstractInterfaceProcessor.java From xtext-lib with Eclipse Public License 2.0 | 4 votes |
public void doTransform(List<? extends MutableInterfaceDeclaration> annotatedInterfaces, @Extension TransformationContext context) { for (MutableInterfaceDeclaration annotatedInterface : annotatedInterfaces) { doTransform(annotatedInterface, context); } }
Example #17
Source File: AbstractInterfaceProcessor.java From xtext-lib with Eclipse Public License 2.0 | 2 votes |
/** * @param annotatedInterface a mutable interface representation annotated with the annotation this processor is responsible for. * @param context */ public void doTransform(MutableInterfaceDeclaration annotatedInterface, @Extension TransformationContext context) {}
Example #18
Source File: TypeLookup.java From xtext-lib with Eclipse Public License 2.0 | 2 votes |
/** * @param qualifiedName * the qualified name of the type to look up. Nested class delimiter is expected to be the '.' (dot). * @return the <code>MutableInterfaceDeclaration</code> with given qualified * name, or <code>null</code> if no such interface declaration is * contained in the currently processed <code>CompilationUnit</code> */ MutableInterfaceDeclaration findInterface(String qualifiedName);