org.eclipse.xtend.lib.macro.declaration.Visibility Java Examples
The following examples show how to use
org.eclipse.xtend.lib.macro.declaration.Visibility.
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: PropertyProcessor.java From xtext-lib with Eclipse Public License 2.0 | 6 votes |
@Override public void doTransform(final MutableFieldDeclaration it, @Extension final TransformationContext context) { @Extension final AccessorsProcessor.Util util = new AccessorsProcessor.Util(context); boolean _hasGetter = util.hasGetter(it); boolean _not = (!_hasGetter); if (_not) { util.addGetter(it, Visibility.PUBLIC); } if (((!it.isFinal()) && (!util.hasSetter(it)))) { util.addSetter(it, Visibility.PUBLIC); } String _firstLower = StringExtensions.toFirstLower(it.getSimpleName()); String _plus = ("_" + _firstLower); it.setSimpleName(_plus); }
Example #2
Source File: AccessorsAnnotationTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testProperty() { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.core.tests.macro.Accessors"); _builder.newLine(); _builder.newLine(); _builder.append("class A {"); _builder.newLine(); _builder.append("\t"); _builder.append("@Accessors String field"); _builder.newLine(); _builder.append("\t"); _builder.append("@Accessors val String finalField = \'foo\'"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> { final TransformationContext ctx = it.getTransformationContext(); final MutableClassDeclaration classA = ctx.findClass("A"); Assert.assertEquals(Visibility.PUBLIC, classA.findDeclaredMethod("getField").getVisibility()); Assert.assertEquals(Visibility.PUBLIC, classA.findDeclaredMethod("setField", ctx.getString()).getVisibility()); Assert.assertEquals(Visibility.PUBLIC, classA.findDeclaredMethod("getFinalField").getVisibility()); Assert.assertNull(classA.findDeclaredMethod("setFinalField", ctx.getString())); }; this._xtendCompilerTester.compile(_builder, _function); }
Example #3
Source File: CompilationUnitImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public Visibility toVisibility(final JvmVisibility delegate) { Visibility _switchResult = null; if (delegate != null) { switch (delegate) { case DEFAULT: _switchResult = Visibility.DEFAULT; break; case PRIVATE: _switchResult = Visibility.PRIVATE; break; case PROTECTED: _switchResult = Visibility.PROTECTED; break; case PUBLIC: _switchResult = Visibility.PUBLIC; break; default: break; } } return _switchResult; }
Example #4
Source File: JvmMemberDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public void setVisibility(final Visibility visibility) { this.checkMutable(); T _delegate = this.getDelegate(); JvmVisibility _switchResult = null; if (visibility != null) { switch (visibility) { case DEFAULT: _switchResult = JvmVisibility.DEFAULT; break; case PUBLIC: _switchResult = JvmVisibility.PUBLIC; break; case PRIVATE: _switchResult = JvmVisibility.PRIVATE; break; case PROTECTED: _switchResult = JvmVisibility.PROTECTED; break; default: break; } } _delegate.setVisibility(_switchResult); }
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: AccessorsAnnotationTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testProperty2() { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.core.tests.macro.Accessors"); _builder.newLine(); _builder.newLine(); _builder.append("class A {"); _builder.newLine(); _builder.append("\t"); _builder.append("@Accessors String field"); _builder.newLine(); _builder.append("\t"); _builder.append("private def String getField() {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("return null"); _builder.newLine(); _builder.append("\t"); _builder.append("} "); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> { final TransformationContext ctx = it.getTransformationContext(); final MutableClassDeclaration classA = ctx.findClass("A"); Assert.assertEquals(Visibility.PRIVATE, classA.findDeclaredMethod("getField").getVisibility()); Assert.assertEquals(Visibility.PUBLIC, classA.findDeclaredMethod("setField", ctx.getString()).getVisibility()); Assert.assertEquals(2, IterableExtensions.size(classA.getDeclaredMethods())); }; this._xtendCompilerTester.compile(_builder, _function); }
Example #7
Source File: JsonRpcDataProcessor.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
protected void addEitherSetter(final MutableFieldDeclaration field, final String setterName, final EitherTypeArgument argument, @Extension final JsonRpcDataTransformationContext context) { final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration method) -> { context.setPrimarySourceElement(method, context.getPrimarySourceElement(field)); method.addParameter(field.getSimpleName(), argument.getType()); method.setStatic(field.isStatic()); method.setVisibility(Visibility.PUBLIC); method.setReturnType(context.getPrimitiveVoid()); final CompilationStrategy _function_1 = (CompilationStrategy.CompilationContext ctx) -> { return this.compileEitherSetterBody(field, argument, field.getSimpleName(), ctx, context); }; method.setBody(_function_1); }; field.getDeclaringType().addMethod(setterName, _function); }
Example #8
Source File: SarlAccessorsProcessor.java From sarl with Apache License 2.0 | 5 votes |
/** Apply the minimum and maximum visibilities to the given one. * * @param visibility the visibility. * @param it the field associated to the accessors to generate. * @param context the transformation context. * @return the given {@code visibility}, or the min/max visibility if the given one is too high. */ @SuppressWarnings("static-method") protected Visibility applyMinMaxVisibility(Visibility visibility, MutableFieldDeclaration it, TransformationContext context) { if (context.findTypeGlobally(Agent.class).isAssignableFrom(it.getDeclaringType())) { if (visibility.compareTo(Visibility.PROTECTED) > 0) { return Visibility.PROTECTED; } } return visibility; }
Example #9
Source File: DeclarationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Test public void testMutableClassDeclaration() { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("class MyClass<T extends CharSequence> {"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("String myField"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("new(String initial) {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("this.myField = initial"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("def <T2 extends CharSequence> MyClass myMethod(T2 a, T b) {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("myField = myField + a + b"); _builder.newLine(); _builder.append("\t\t"); _builder.append("return this"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> { final MutableClassDeclaration genClazz = it.getTypeLookup().findClass("foo.MyClass"); final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it_1) -> { CompilationUnit _compilationUnit = genClazz.getCompilationUnit(); it_1.setReturnType(((CompilationUnitImpl) _compilationUnit).getTypeReferenceProvider().getString()); it_1.setVisibility(Visibility.PRIVATE); final CompilationStrategy _function_2 = (CompilationStrategy.CompilationContext it_2) -> { StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("return \"foo\";"); _builder_1.newLine(); return _builder_1; }; it_1.setBody(_function_2); }; genClazz.addMethod("newMethod", _function_1); final MutableMethodDeclaration mutableMethod = genClazz.findDeclaredMethod("newMethod"); Assert.assertSame(mutableMethod, ((Object[])Conversions.unwrapArray(genClazz.getDeclaredMethods(), Object.class))[1]); Assert.assertEquals("String", mutableMethod.getReturnType().toString()); Assert.assertEquals(Visibility.PRIVATE, mutableMethod.getVisibility()); }; this.asCompilationUnit(this.validFile(_builder), _function); }
Example #10
Source File: JvmMemberDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Visibility getVisibility() { return this.getCompilationUnit().toVisibility(this.getDelegate().getVisibility()); }
Example #11
Source File: JvmEnumerationValueDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public void setVisibility(final Visibility visibility) { throw new UnsupportedOperationException("It is not possible to change visibility of enumeration value."); }
Example #12
Source File: XtendFieldDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Visibility getVisibility() { return this.getCompilationUnit().toVisibility(this.getDelegate().getVisibility()); }
Example #13
Source File: XtendMethodDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Visibility getVisibility() { return this.getCompilationUnit().toVisibility(this.getDelegate().getVisibility()); }
Example #14
Source File: XtendTypeDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Visibility getVisibility() { return this.getCompilationUnit().toVisibility(this.getDelegate().getVisibility()); }
Example #15
Source File: XtendConstructorDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Visibility getVisibility() { return this.getCompilationUnit().toVisibility(this.getDelegate().getVisibility()); }
Example #16
Source File: XtendMemberDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public Visibility getVisibility() { return this.getCompilationUnit().toVisibility(this.getDelegate().getVisibility()); }