Java Code Examples for org.eclipse.xtend.lib.macro.declaration.TypeReference#getType()

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.TypeReference#getType() . 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: TypeAdapterImplProcessor.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
private ArrayList<FieldDeclaration> getTargetFields(final TypeReference targetType, @Extension final TransformationContext context) {
  final Type objectType = context.newTypeReference(Object.class).getType();
  final ArrayList<FieldDeclaration> targetFields = CollectionLiterals.<FieldDeclaration>newArrayList();
  TypeReference typeRef = targetType;
  while ((!Objects.equal(typeRef.getType(), objectType))) {
    {
      Type _type = typeRef.getType();
      final ClassDeclaration clazz = ((ClassDeclaration) _type);
      final Function1<FieldDeclaration, Boolean> _function = (FieldDeclaration it) -> {
        boolean _isStatic = it.isStatic();
        return Boolean.valueOf((!_isStatic));
      };
      Iterable<? extends FieldDeclaration> _filter = IterableExtensions.filter(clazz.getDeclaredFields(), _function);
      Iterables.<FieldDeclaration>addAll(targetFields, _filter);
      typeRef = clazz.getExtendedClass();
    }
  }
  return targetFields;
}
 
Example 2
Source File: DelegateProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public Set<TypeReference> getImplementedInterfaces(final TypeReference it) {
  Set<TypeReference> _xblockexpression = null;
  {
    final LinkedHashSet<TypeReference> seen = CollectionLiterals.<TypeReference>newLinkedHashSet();
    this.collectAllSuperTypes(it, seen);
    final Function1<TypeReference, Boolean> _function = (TypeReference it_1) -> {
      Type _type = it_1.getType();
      return Boolean.valueOf((_type instanceof InterfaceDeclaration));
    };
    _xblockexpression = IterableExtensions.<TypeReference>toSet(IterableExtensions.<TypeReference>filter(seen, _function));
  }
  return _xblockexpression;
}
 
Example 3
Source File: JsonRpcDataTransformationContext.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
public TypeReference getLeftType(final TypeReference typeReference) {
  final Type type = typeReference.getType();
  Type _type = this.eitherType.getType();
  boolean _tripleEquals = (type == _type);
  if (_tripleEquals) {
    return IterableExtensions.<TypeReference>head(typeReference.getActualTypeArguments());
  }
  if ((type instanceof InterfaceDeclaration)) {
    final Function1<TypeReference, TypeReference> _function = (TypeReference it) -> {
      return this.getLeftType(it);
    };
    return IterableExtensions.<TypeReference>head(IterableExtensions.<TypeReference>filterNull(IterableExtensions.map(((InterfaceDeclaration)type).getExtendedInterfaces(), _function)));
  }
  return null;
}
 
Example 4
Source File: JsonRpcDataTransformationContext.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
public TypeReference getRightType(final TypeReference typeReference) {
  final Type type = typeReference.getType();
  Type _type = this.eitherType.getType();
  boolean _tripleEquals = (type == _type);
  if (_tripleEquals) {
    return IterableExtensions.<TypeReference>last(typeReference.getActualTypeArguments());
  }
  if ((type instanceof InterfaceDeclaration)) {
    final Function1<TypeReference, TypeReference> _function = (TypeReference it) -> {
      return this.getRightType(it);
    };
    return IterableExtensions.<TypeReference>head(IterableExtensions.<TypeReference>filterNull(IterableExtensions.map(((InterfaceDeclaration)type).getExtendedInterfaces(), _function)));
  }
  return null;
}
 
Example 5
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;
}