org.eclipse.xtend.lib.macro.declaration.TypeDeclaration Java Examples

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.TypeDeclaration. 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: XtendAnnotationReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public AnnotationTypeDeclaration getAnnotationTypeDeclaration() {
  AnnotationTypeDeclaration _switchResult = null;
  JvmType _annotationType = this.getAnnotationType();
  final JvmType type = _annotationType;
  boolean _matched = false;
  if (type instanceof JvmAnnotationType) {
    _matched=true;
    TypeDeclaration _typeDeclaration = this.getCompilationUnit().toTypeDeclaration(((JvmDeclaredType)type));
    _switchResult = ((AnnotationTypeDeclaration) _typeDeclaration);
  }
  if (!_matched) {
    _switchResult = null;
  }
  return _switchResult;
}
 
Example #2
Source File: AddNestedTypesProcessor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doRegisterGlobals(final List<? extends TypeDeclaration> annotatedSourceElements, final RegisterGlobalsContext context) {
  for (final TypeDeclaration type : annotatedSourceElements) {
    {
      String _qualifiedName = type.getQualifiedName();
      String _plus = (_qualifiedName + ".NestedClass");
      context.registerClass(_plus);
      String _qualifiedName_1 = type.getQualifiedName();
      String _plus_1 = (_qualifiedName_1 + ".NestedInterface");
      context.registerInterface(_plus_1);
      String _qualifiedName_2 = type.getQualifiedName();
      String _plus_2 = (_qualifiedName_2 + ".NestedAnnotationType");
      context.registerAnnotationType(_plus_2);
      String _qualifiedName_3 = type.getQualifiedName();
      String _plus_3 = (_qualifiedName_3 + ".NestedEnumerationType");
      context.registerEnumerationType(_plus_3);
    }
  }
}
 
Example #3
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAnnotation2() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("class MyClass {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@com.google.inject.Inject() MyClass foo");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
    final ClassDeclaration sourceClazz = ((ClassDeclaration) _head);
    final MutableClassDeclaration javaClass = it.getTypeLookup().findClass("MyClass");
    Assert.assertEquals(javaClass.getQualifiedName(), sourceClazz.getQualifiedName());
    final FieldDeclaration field = IterableExtensions.head(sourceClazz.getDeclaredFields());
    Assert.assertEquals(Boolean.FALSE, IterableExtensions.head(field.getAnnotations()).getValue("optional"));
    final MutableFieldDeclaration javaField = IterableExtensions.head(javaClass.getDeclaredFields());
    Object _value = IterableExtensions.head(javaField.getAnnotations()).getValue("optional");
    Assert.assertFalse((((Boolean) _value)).booleanValue());
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #4
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNestedClass() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package p");
  _builder.newLine();
  _builder.newLine();
  _builder.append("class Outer {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("static class Inner {}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    Assert.assertEquals("p", it.getPackageName());
    TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
    final ClassDeclaration outer = ((ClassDeclaration) _head);
    Assert.assertEquals("p.Outer", outer.getQualifiedName());
    final ClassDeclaration inner = IterableExtensions.head(outer.getDeclaredClasses());
    Assert.assertEquals("Inner", inner.getSimpleName());
    Assert.assertEquals("p.Outer.Inner", inner.getQualifiedName());
    Assert.assertNotNull(it.getTypeLookup().findClass("p.Outer.Inner"));
    Assert.assertNotNull(it.getTypeLookup().findTypeGlobally("p.Outer.Inner"));
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #5
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testRemove() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("class C {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def void m() {}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
    final ClassDeclaration c = ((ClassDeclaration) _head);
    final MutableClassDeclaration mutable = it.getTypeLookup().findClass(c.getQualifiedName());
    final Consumer<MutableMemberDeclaration> _function_1 = (MutableMemberDeclaration it_1) -> {
      it_1.remove();
    };
    mutable.getDeclaredMembers().forEach(_function_1);
    Assert.assertTrue(IterableExtensions.isEmpty(mutable.getDeclaredMembers()));
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #6
Source File: DelegateProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public Iterable<? extends MemberDeclaration> getDelegates(final TypeDeclaration it) {
  final Function1<MemberDeclaration, Boolean> _function = (MemberDeclaration it_1) -> {
    AnnotationReference _findAnnotation = it_1.findAnnotation(this.context.findTypeGlobally(Delegate.class));
    return Boolean.valueOf((_findAnnotation != null));
  };
  return IterableExtensions.filter(it.getDeclaredMembers(), _function);
}
 
Example #7
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public TypeDeclaration findDeclaredType(final String name) {
  final Function1<TypeDeclaration, Boolean> _function = (TypeDeclaration type) -> {
    String _simpleName = type.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  return IterableExtensions.findFirst(this.getDeclaredTypes(), _function);
}
 
Example #8
Source File: XtendTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TypeDeclaration findDeclaredType(final String name) {
  final Function1<TypeDeclaration, Boolean> _function = (TypeDeclaration type) -> {
    String _simpleName = type.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  return IterableExtensions.findFirst(this.getDeclaredTypes(), _function);
}
 
Example #9
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends TypeDeclaration> getSourceTypeDeclarations() {
  final Function1<XtendTypeDeclaration, XtendTypeDeclarationImpl<? extends XtendTypeDeclaration>> _function = (XtendTypeDeclaration it) -> {
    return this.toXtendTypeDeclaration(it);
  };
  return ListExtensions.<XtendTypeDeclaration, XtendTypeDeclarationImpl<? extends XtendTypeDeclaration>>map(this.xtendFile.getXtendTypes(), _function);
}
 
Example #10
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testOverriddenMethodFromSource() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package p");
  _builder.newLine();
  _builder.newLine();
  _builder.append("abstract class C extends java.util.AbstractList<String> implements I {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("override add(String s);");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  _builder.append("interface I {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def boolean add(String s)");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    Assert.assertEquals("p", it.getPackageName());
    TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
    final ClassDeclaration clazz = ((ClassDeclaration) _head);
    Assert.assertEquals("p.C", clazz.getQualifiedName());
    final MethodDeclaration add = IterableExtensions.head(clazz.getDeclaredMethods());
    final Iterable<? extends MethodDeclaration> allOverridden = add.getOverriddenOrImplementedMethods();
    Assert.assertEquals(2, IterableExtensions.size(allOverridden));
    final MethodDeclaration listAdd = IterableExtensions.head(allOverridden);
    Assert.assertEquals("add", listAdd.getSimpleName());
    Assert.assertEquals("E", IterableExtensions.head(listAdd.getParameters()).getType().getSimpleName());
    final MethodDeclaration intfAdd = IterableExtensions.last(allOverridden);
    Assert.assertEquals("add", intfAdd.getSimpleName());
    Assert.assertEquals("String", IterableExtensions.head(intfAdd.getParameters()).getType().getSimpleName());
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #11
Source File: XtendMemberDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TypeDeclaration getDeclaringType() {
  XtendTypeDeclarationImpl<? extends XtendTypeDeclaration> _switchResult = null;
  EObject _eContainer = this.getDelegate().eContainer();
  final EObject container = _eContainer;
  boolean _matched = false;
  if (container instanceof XtendTypeDeclaration) {
    _matched=true;
    _switchResult = this.getCompilationUnit().toXtendTypeDeclaration(((XtendTypeDeclaration)container));
  }
  if (!_matched) {
    _switchResult = null;
  }
  return _switchResult;
}
 
Example #12
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSimpleClassWithField() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package foo");
  _builder.newLine();
  _builder.newLine();
  _builder.append("class MyClass extends Object implements java.io.Serializable {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("MyClass foo");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    Assert.assertEquals("foo", it.getPackageName());
    TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
    final ClassDeclaration clazz = ((ClassDeclaration) _head);
    Assert.assertEquals("foo.MyClass", clazz.getQualifiedName());
    Assert.assertEquals("Object", clazz.getExtendedClass().toString());
    Assert.assertEquals("Serializable", IterableExtensions.head(clazz.getImplementedInterfaces()).toString());
    MemberDeclaration _head_1 = IterableExtensions.head(clazz.getDeclaredMembers());
    final FieldDeclaration field = ((FieldDeclaration) _head_1);
    Assert.assertEquals("foo", field.getSimpleName());
    Assert.assertSame(it.getTypeLookup().findClass("foo.MyClass"), field.getType().getType());
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #13
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAnnotation() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@SuppressWarnings(\"unused\")");
  _builder.newLine();
  _builder.append("class MyClass {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@com.google.inject.Inject(optional=true) MyClass foo");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    Assert.assertNull(it.getPackageName());
    TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
    final ClassDeclaration clazz = ((ClassDeclaration) _head);
    Assert.assertEquals("MyClass", clazz.getQualifiedName());
    final AnnotationReference suppressWarning = IterableExtensions.head(clazz.getAnnotations());
    final AnnotationTypeDeclaration supressWarningsDeclaration = suppressWarning.getAnnotationTypeDeclaration();
    Assert.assertEquals("java.lang.SuppressWarnings", supressWarningsDeclaration.getQualifiedName());
    Assert.assertEquals("unused", suppressWarning.getStringArrayValue("value")[0]);
    Assert.assertEquals(2, IterableExtensions.size(supressWarningsDeclaration.getAnnotations()));
    final AnnotationTypeElementDeclaration valueProperty = IterableExtensions.<AnnotationTypeElementDeclaration>head(Iterables.<AnnotationTypeElementDeclaration>filter(supressWarningsDeclaration.getDeclaredMembers(), AnnotationTypeElementDeclaration.class));
    Assert.assertEquals("String[]", valueProperty.getType().toString());
    Assert.assertEquals("value", valueProperty.getSimpleName());
    MemberDeclaration _head_1 = IterableExtensions.head(clazz.getDeclaredMembers());
    final FieldDeclaration field = ((FieldDeclaration) _head_1);
    final AnnotationReference inject = IterableExtensions.head(field.getAnnotations());
    Object _value = inject.getValue("optional");
    Assert.assertTrue((((Boolean) _value)).booleanValue());
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #14
Source File: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public ResolvedConstructor getSuperConstructor(final TypeDeclaration it) {
  if ((it instanceof ClassDeclaration)) {
    if ((Objects.equal(((ClassDeclaration)it).getExtendedClass(), this.context.getObject()) || (((ClassDeclaration)it).getExtendedClass() == null))) {
      return null;
    }
    return IterableExtensions.head(((ClassDeclaration)it).getExtendedClass().getDeclaredResolvedConstructors());
  } else {
    return null;
  }
}
 
Example #15
Source File: MutableJvmAnnotationTypeElementDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableTypeDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((MutableTypeDeclaration) _declaringType);
}
 
Example #16
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableTypeDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((MutableTypeDeclaration) _declaringType);
}
 
Example #17
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableTypeDeclaration> getDeclaredTypes() {
  Iterable<? extends TypeDeclaration> _declaredTypes = super.getDeclaredTypes();
  return ((Iterable<? extends MutableTypeDeclaration>) _declaredTypes);
}
 
Example #18
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableTypeDeclaration findDeclaredType(final String name) {
  TypeDeclaration _findDeclaredType = super.findDeclaredType(name);
  return ((MutableTypeDeclaration) _findDeclaredType);
}
 
Example #19
Source File: XtendTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends TypeDeclaration> getDeclaredTypes() {
  return Iterables.<TypeDeclaration>filter(this.getDeclaredMembers(), TypeDeclaration.class);
}
 
Example #20
Source File: MutableJvmMethodDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableTypeDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((MutableTypeDeclaration) _declaringType);
}
 
Example #21
Source File: MutableJvmEnumerationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableTypeDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((MutableTypeDeclaration) _declaringType);
}
 
Example #22
Source File: MutableJvmEnumerationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableTypeDeclaration> getDeclaredTypes() {
  Iterable<? extends TypeDeclaration> _declaredTypes = super.getDeclaredTypes();
  return ((Iterable<? extends MutableTypeDeclaration>) _declaredTypes);
}
 
Example #23
Source File: MutableJvmEnumerationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableTypeDeclaration findDeclaredType(final String name) {
  TypeDeclaration _findDeclaredType = super.findDeclaredType(name);
  return ((MutableTypeDeclaration) _findDeclaredType);
}
 
Example #24
Source File: JsonRpcDataProcessor.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
protected MutableMethodDeclaration generateToString(final MutableClassDeclaration impl, @Extension final TransformationContext context) {
  MutableMethodDeclaration _xblockexpression = null;
  {
    final ArrayList<FieldDeclaration> toStringFields = CollectionLiterals.<FieldDeclaration>newArrayList();
    ClassDeclaration c = impl;
    do {
      {
        Iterable<? extends FieldDeclaration> _declaredFields = c.getDeclaredFields();
        Iterables.<FieldDeclaration>addAll(toStringFields, _declaredFields);
        TypeReference _extendedClass = c.getExtendedClass();
        Type _type = null;
        if (_extendedClass!=null) {
          _type=_extendedClass.getType();
        }
        c = ((ClassDeclaration) _type);
      }
    } while(((c != null) && (!Objects.equal(c, context.getObject()))));
    final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
      it.setReturnType(context.getString());
      it.addAnnotation(context.newAnnotationReference(Override.class));
      it.addAnnotation(context.newAnnotationReference(Pure.class));
      final AccessorsProcessor.Util accessorsUtil = new AccessorsProcessor.Util(context);
      StringConcatenationClient _client = new StringConcatenationClient() {
        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
          _builder.append(ToStringBuilder.class);
          _builder.append(" b = new ");
          _builder.append(ToStringBuilder.class);
          _builder.append("(this);");
          _builder.newLineIfNotEmpty();
          {
            for(final FieldDeclaration field : toStringFields) {
              _builder.append("b.add(\"");
              String _simpleName = field.getSimpleName();
              _builder.append(_simpleName);
              _builder.append("\", ");
              {
                TypeDeclaration _declaringType = field.getDeclaringType();
                boolean _equals = Objects.equal(_declaringType, impl);
                if (_equals) {
                  _builder.append("this.");
                  String _simpleName_1 = field.getSimpleName();
                  _builder.append(_simpleName_1);
                } else {
                  String _getterName = accessorsUtil.getGetterName(field);
                  _builder.append(_getterName);
                  _builder.append("()");
                }
              }
              _builder.append(");");
              _builder.newLineIfNotEmpty();
            }
          }
          _builder.append("return b.toString();");
          _builder.newLine();
        }
      };
      it.setBody(_client);
    };
    _xblockexpression = impl.addMethod("toString", _function);
  }
  return _xblockexpression;
}
 
Example #25
Source File: MutableJvmFieldDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableTypeDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((MutableTypeDeclaration) _declaringType);
}
 
Example #26
Source File: XtendEnumerationValueDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public EnumerationTypeDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((EnumerationTypeDeclaration) _declaringType);
}
 
Example #27
Source File: XtendFieldDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ClassDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((ClassDeclaration) _declaringType);
}
 
Example #28
Source File: JvmEnumerationValueDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public EnumerationTypeDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((EnumerationTypeDeclaration) _declaringType);
}
 
Example #29
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Iterable<? extends TypeDeclaration> getDeclaredTypes() {
  return Iterables.<TypeDeclaration>filter(this.getDeclaredMembers(), TypeDeclaration.class);
}
 
Example #30
Source File: MutableJvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableTypeDeclaration getDeclaringType() {
  TypeDeclaration _declaringType = super.getDeclaringType();
  return ((MutableTypeDeclaration) _declaringType);
}