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

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.TypeReference. 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: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public ConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
  ConstructorDeclaration _xblockexpression = null;
  {
    ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(parameterTypes)), "parameterTypes");
    final Function1<ConstructorDeclaration, Boolean> _function = (ConstructorDeclaration constructor) -> {
      final Function1<ParameterDeclaration, TypeReference> _function_1 = (ParameterDeclaration it) -> {
        return it.getType();
      };
      List<TypeReference> _list = IterableExtensions.<TypeReference>toList(IterableExtensions.map(constructor.getParameters(), _function_1));
      List<TypeReference> _list_1 = IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>)Conversions.doWrapArray(parameterTypes)));
      return Boolean.valueOf(Objects.equal(_list, _list_1));
    };
    _xblockexpression = IterableExtensions.findFirst(this.getDeclaredConstructors(), _function);
  }
  return _xblockexpression;
}
 
Example #2
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public JvmTypeReference toJvmTypeReference(final TypeReference typeRef) {
  this.checkCanceled();
  JvmTypeReference _switchResult = null;
  boolean _matched = false;
  if (typeRef instanceof TypeReferenceImpl) {
    _matched=true;
    _switchResult = ((TypeReferenceImpl)typeRef).getLightweightTypeReference().toJavaCompliantTypeReference();
  }
  if (!_matched) {
    if (typeRef instanceof InferredTypeReferenceImpl) {
      _matched=true;
      _switchResult = EcoreUtil.<XComputedTypeReferenceImplCustom>copy(((InferredTypeReferenceImpl)typeRef).getDelegate());
    }
  }
  return _switchResult;
}
 
Example #3
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 #4
Source File: MutableJvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void setExtendedClass(final TypeReference superclass) {
  this.checkMutable();
  ConditionUtils.checkInferredTypeReferences("extended class", superclass);
  JvmTypeReference _xifexpression = null;
  if ((superclass != null)) {
    _xifexpression = this.getCompilationUnit().toJvmTypeReference(superclass);
  } else {
    _xifexpression = this.getCompilationUnit().getTypeReferences().getTypeForName(Object.class, this.getCompilationUnit().getXtendFile());
  }
  final JvmTypeReference newTypeRef = _xifexpression;
  final Function1<JvmTypeReference, Boolean> _function = (JvmTypeReference it) -> {
    return Boolean.valueOf(((it.getType() instanceof JvmGenericType) && (!((JvmGenericType) it.getType()).isInterface())));
  };
  final JvmTypeReference oldType = IterableExtensions.<JvmTypeReference>findFirst(this.getDelegate().getSuperTypes(), _function);
  if ((oldType != null)) {
    this.getDelegate().getSuperTypes().remove(oldType);
  }
  this.getDelegate().getSuperTypes().add(newTypeRef);
}
 
Example #5
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public TypeReference toTypeReference(final LightweightTypeReference delegate, final JvmTypeReference source) {
  TypeReferenceImpl _xblockexpression = null;
  {
    this.checkCanceled();
    if ((delegate == null)) {
      return null;
    }
    TypeReferenceImpl _typeReferenceImpl = new TypeReferenceImpl();
    final Procedure1<TypeReferenceImpl> _function = (TypeReferenceImpl it) -> {
      it.setDelegate(delegate);
      it.setCompilationUnit(this);
      it.setSource(source);
    };
    _xblockexpression = ObjectExtensions.<TypeReferenceImpl>operator_doubleArrow(_typeReferenceImpl, _function);
  }
  return _xblockexpression;
}
 
Example #6
Source File: DelegateProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public boolean hasDelegationConflicts(final MemberDeclaration delegate) {
  boolean _xblockexpression = false;
  {
    boolean conflict = false;
    Iterable<? extends MemberDeclaration> _otherDelegates = this.otherDelegates(delegate);
    for (final MemberDeclaration other : _otherDelegates) {
      {
        final Set<TypeReference> otherInterfaces = this.getDelegatedInterfaces(other);
        Set<TypeReference> _delegatedInterfaces = this.getDelegatedInterfaces(delegate);
        for (final TypeReference iface : _delegatedInterfaces) {
          boolean _contains = otherInterfaces.contains(iface);
          if (_contains) {
            conflict = true;
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("The interface ");
            String _simpleName = iface.getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" is also implemented by the delegate ");
            String _simpleName_1 = other.getSimpleName();
            _builder.append(_simpleName_1);
            this.context.addError(delegate, _builder.toString());
          }
        }
      }
    }
    _xblockexpression = conflict;
  }
  return _xblockexpression;
}
 
Example #7
Source File: XtendTypeParameterDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isAssignableFrom(final Type otherType) {
  if ((otherType == null)) {
    return false;
  }
  final TypeReference thisTypeRef = this.getCompilationUnit().getTypeReferenceProvider().newTypeReference(this);
  final TypeReference thatTypeRef = this.getCompilationUnit().getTypeReferenceProvider().newTypeReference(otherType);
  return thisTypeRef.isAssignableFrom(thatTypeRef);
}
 
Example #8
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 #9
Source File: PrimitiveTypeImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isAssignableFrom(final Type otherType) {
  if ((otherType == null)) {
    return false;
  }
  final TypeReference thisTypeRef = this.getCompilationUnit().getTypeReferenceProvider().newTypeReference(this);
  final TypeReference thatTypeRef = this.getCompilationUnit().getTypeReferenceProvider().newTypeReference(otherType);
  return thisTypeRef.isAssignableFrom(thatTypeRef);
}
 
Example #10
Source File: XtendTypeParameterDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends TypeReference> getUpperBounds() {
  final Function1<JvmUpperBound, TypeReference> _function = (JvmUpperBound it) -> {
    return this.getCompilationUnit().toTypeReference(it.getTypeReference());
  };
  return IterableExtensions.<TypeReference>toList(IterableExtensions.<JvmUpperBound, TypeReference>map(Iterables.<JvmUpperBound>filter(this.getDelegate().getConstraints(), JvmUpperBound.class), _function));
}
 
Example #11
Source File: DotAttributeProcessor.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private TypeReference paramType(Context c, TransformationContext context) {
	switch (c) {
	case GRAPH:
		return context.newTypeReference("org.eclipse.gef.graph.Graph");
	case NODE:
		return context.newTypeReference("org.eclipse.gef.graph.Node");
	case EDGE:
		return context.newTypeReference("org.eclipse.gef.graph.Edge");
	default:
		throw new IllegalArgumentException(
				"Cluster and Subgraph not yet supported.");
	}
}
 
Example #12
Source File: DotAttributeProcessor.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private String parsed(String attributeValue,
		TypeReference attributeParsedType) {
	if (String.class.getName().equals(attributeParsedType.getName())) {
		// no further parsing needed or string
		return attributeValue;
	}
	return "parseAttributeValue(" + parser(attributeParsedType) + ", "
			+ attributeValue + ")";
}
 
Example #13
Source File: DotAttributeProcessor.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private String serialized(String attributeValue,
		TypeReference attributeParsedType) {
	if (String.class.getName().equals(attributeParsedType.getName())) {
		// no further serialization needed for String
		return attributeValue;
	}
	return "serializeAttributeValue(" + serializer(attributeParsedType)
			+ ", " + attributeValue + ")";
}
 
Example #14
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isAssignableFrom(final Type otherType) {
  if ((otherType == null)) {
    return false;
  }
  final TypeReference thisTypeRef = this.getCompilationUnit().getTypeReferenceProvider().newTypeReference(((Type) this));
  final TypeReference thatTypeRef = this.getCompilationUnit().getTypeReferenceProvider().newTypeReference(otherType);
  return thisTypeRef.isAssignableFrom(thatTypeRef);
}
 
Example #15
Source File: DelegateProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public TypeReference getType(final MemberDeclaration it) {
  if (it instanceof MethodDeclaration) {
    return _getType((MethodDeclaration)it);
  } else if (it instanceof FieldDeclaration) {
    return _getType((FieldDeclaration)it);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it).toString());
  }
}
 
Example #16
Source File: ResolvedExecutableImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends TypeReference> getResolvedExceptionTypes() {
  final Function1<LightweightTypeReference, TypeReference> _function = (LightweightTypeReference it) -> {
    return this.getCompilationUnit().toTypeReference(it);
  };
  return ListExtensions.<LightweightTypeReference, TypeReference>map(this.getDelegate().getResolvedExceptions(), _function);
}
 
Example #17
Source File: TypeReferenceProviderImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TypeReference newSelfTypeReference(final Type typeDeclaration) {
  TypeReference _xifexpression = null;
  if ((typeDeclaration instanceof TypeParameterDeclarator)) {
    final Function1<TypeParameterDeclaration, TypeReference> _function = (TypeParameterDeclaration it) -> {
      return this.newTypeReference(it);
    };
    _xifexpression = this.newTypeReference(typeDeclaration, ((TypeReference[])Conversions.unwrapArray(IterableExtensions.map(((TypeParameterDeclarator)typeDeclaration).getTypeParameters(), _function), TypeReference.class)));
  } else {
    _xifexpression = this.newTypeReference(typeDeclaration);
  }
  return _xifexpression;
}
 
Example #18
Source File: DelegateProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public TypeReference replace(final TypeReference target, final TypeReference oldType, final TypeReference newType) {
  boolean _equals = Objects.equal(target, oldType);
  if (_equals) {
    return newType;
  }
  boolean _isEmpty = target.getActualTypeArguments().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    final Function1<TypeReference, TypeReference> _function = (TypeReference it) -> {
      return this.replace(it, oldType, newType);
    };
    return this.context.newTypeReference(target.getType(), ((TypeReference[])Conversions.unwrapArray(ListExtensions.<TypeReference, TypeReference>map(target.getActualTypeArguments(), _function), TypeReference.class)));
  }
  boolean _isWildCard = target.isWildCard();
  if (_isWildCard) {
    TypeReference _upperBound = target.getUpperBound();
    TypeReference _object = this.context.getObject();
    boolean _notEquals = (!Objects.equal(_upperBound, _object));
    if (_notEquals) {
      return this.context.newWildcardTypeReference(this.replace(target.getUpperBound(), oldType, newType));
    } else {
      boolean _isAnyType = target.getLowerBound().isAnyType();
      boolean _not_1 = (!_isAnyType);
      if (_not_1) {
        return this.context.newWildcardTypeReferenceWithLowerBound(this.replace(target.getLowerBound(), oldType, newType));
      }
    }
  }
  boolean _isArray = target.isArray();
  if (_isArray) {
    return this.context.newArrayTypeReference(this.replace(target.getArrayComponentType(), oldType, newType));
  }
  return target;
}
 
Example #19
Source File: JsonRpcDataProcessor.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
private TypeReference getPreconditionsUtil(final Type type, @Extension final TransformationContext context) {
  TypeReference _xifexpression = null;
  boolean _startsWith = type.getQualifiedName().startsWith("org.eclipse.lsp4j.debug");
  if (_startsWith) {
    _xifexpression = context.newTypeReference("org.eclipse.lsp4j.debug.util.Preconditions");
  } else {
    _xifexpression = context.newTypeReference("org.eclipse.lsp4j.util.Preconditions");
  }
  return _xifexpression;
}
 
Example #20
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected String getAnnotationValueTypeName(final JvmType type) {
  String _switchResult = null;
  String _identifier = null;
  if (type!=null) {
    _identifier=type.getIdentifier();
  }
  String _replace = null;
  if (_identifier!=null) {
    _replace=_identifier.replace("$", ".");
  }
  final String result = _replace;
  if (result != null) {
    switch (result) {
      case "java.lang.Class":
        _switchResult = TypeReference.class.getName();
        break;
      case "java.lang.Class[]":
        String _name = TypeReference.class.getName();
        _switchResult = (_name + "[]");
        break;
      default:
        _switchResult = result;
        break;
    }
  } else {
    _switchResult = result;
  }
  return _switchResult;
}
 
Example #21
Source File: JvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public MethodDeclaration findDeclaredMethod(final String name, final TypeReference... parameterTypes) {
  MethodDeclaration _xblockexpression = null;
  {
    ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(parameterTypes)), "parameterTypes");
    final Function1<MethodDeclaration, Boolean> _function = (MethodDeclaration it) -> {
      return Boolean.valueOf((Objects.equal(it.getSimpleName(), name) && Objects.equal(IterableExtensions.<TypeReference>toList(IterableExtensions.map(it.getParameters(), ((Function1<ParameterDeclaration, TypeReference>) (ParameterDeclaration it_1) -> {
        return it_1.getType();
      }))), IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>)Conversions.doWrapArray(parameterTypes))))));
    };
    _xblockexpression = IterableExtensions.<MethodDeclaration>findFirst(Iterables.<MethodDeclaration>filter(this.getDeclaredMembers(), MethodDeclaration.class), _function);
  }
  return _xblockexpression;
}
 
Example #22
Source File: AccessorsProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
private TypeReference orObject(final TypeReference ref) {
  TypeReference _xifexpression = null;
  if ((ref == null)) {
    _xifexpression = this.context.getObject();
  } else {
    _xifexpression = ref;
  }
  return _xifexpression;
}
 
Example #23
Source File: JsonRpcDataTransformationContext.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
public Collection<EitherTypeArgument> getChildTypes(final TypeReference typeReference) {
  final ArrayList<EitherTypeArgument> types = CollectionLiterals.<EitherTypeArgument>newArrayList();
  boolean _isEither = this.isEither(typeReference);
  if (_isEither) {
    this.collectChildTypes(this.getLeftType(typeReference), null, false, types);
    this.collectChildTypes(this.getRightType(typeReference), null, true, types);
  }
  return types;
}
 
Example #24
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmTypeAnnotationValue it, final TypeReference[] value, final String componentType, final boolean mustBeArray) {
  EList<JvmTypeReference> _values = it.getValues();
  final Function1<TypeReferenceImpl, JvmTypeReference> _function = (TypeReferenceImpl it_1) -> {
    return this.compilationUnit.toJvmTypeReference(it_1);
  };
  Iterable<JvmTypeReference> _map = IterableExtensions.<TypeReferenceImpl, JvmTypeReference>map(Iterables.<TypeReferenceImpl>filter(((Iterable<?>)Conversions.doWrapArray(value)), TypeReferenceImpl.class), _function);
  Iterables.<JvmTypeReference>addAll(_values, _map);
}
 
Example #25
Source File: TypeReferenceAssignabilityTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void isAssignableFrom(final Pair<String, String> lhsAndParams, final String rhs, final boolean expectation) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def ");
    {
      boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(lhsAndParams.getValue());
      boolean _not = (!_isNullOrEmpty);
      if (_not) {
        _builder.append("<");
        String _value = lhsAndParams.getValue();
        _builder.append(_value);
        _builder.append("> ");
      }
    }
    _builder.append("void method(");
    String _fixup = this.fixup(lhsAndParams.getKey());
    _builder.append(_fixup);
    _builder.append(" lhs, ");
    String _fixup_1 = this.fixup(rhs);
    _builder.append(_fixup_1);
    _builder.append(" rhs) {}");
    final String signature = _builder.toString();
    final XtendFunction function = this.function(signature.toString());
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    EObject _rootContainer = EcoreUtil.getRootContainer(function);
    final XtendFile xtendFile = ((XtendFile) _rootContainer);
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
      TypeReference _xifexpression = null;
      String _key = lhsAndParams.getKey();
      boolean _tripleNotEquals = (_key != null);
      if (_tripleNotEquals) {
        _xifexpression = it.toTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
      } else {
        _xifexpression = it.toTypeReference(this.getOwner().newAnyTypeReference());
      }
      final TypeReference lhsType = _xifexpression;
      TypeReference _xifexpression_1 = null;
      if ((rhs != null)) {
        _xifexpression_1 = it.toTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType());
      } else {
        _xifexpression_1 = it.toTypeReference(this.getOwner().newAnyTypeReference());
      }
      final TypeReference rhsType = _xifexpression_1;
      String _simpleName = lhsType.getSimpleName();
      String _plus = (_simpleName + " := ");
      String _simpleName_1 = rhsType.getSimpleName();
      String _plus_1 = (_plus + _simpleName_1);
      Assert.assertEquals(_plus_1, Boolean.valueOf(expectation), 
        Boolean.valueOf(this.testIsAssignable(it, lhsType, rhsType)));
      if (expectation) {
        Iterable<? extends TypeReference> _declaredSuperTypes = lhsType.getDeclaredSuperTypes();
        for (final TypeReference superType : _declaredSuperTypes) {
          if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) {
            Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(it, superType, rhsType)));
          }
        }
      }
    };
    this.asCompilationUnit(xtendFile, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #26
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setClassValue(final String name, final TypeReference... value) {
  int _length = value.length;
  boolean _notEquals = (_length != 1);
  this._internalSet(name, value, _notEquals);
}
 
Example #27
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void checkPrimitive(final TypeReference primitiveType, final String wrapperTypeName) {
  Assert.assertTrue(primitiveType.toString(), primitiveType.isPrimitive());
  Assert.assertEquals(wrapperTypeName, primitiveType.getWrapperIfPrimitive().getType().getQualifiedName());
}
 
Example #28
Source File: DeclarationsTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testAnnotationReferenceValues() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package foo");
  _builder.newLine();
  _builder.append("@test.Annotation(");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("intValue = 2 / 2 + 2 * 3 - 4 % 1,");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("longValue = 42 + 4 + 6 * 42 - 4 / 45,");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("stringValue = \'foo\' + \'baz\',");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("booleanArrayValue = #[true, false],");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("intArrayValue = #[ -1, 34 + 45, 2 - 6 ],");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("longArrayValue = #[42, 5 * -3],");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("stringArrayValue = #[\'foo\', \'bla\' + \'buzz\'],");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("typeValue = String,");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("typeArrayValue = #[String, Integer],");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("annotation2Value = @test.Annotation2(\'foo\' + \'wuppa\'),");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("annotation2ArrayValue = #[@test.Annotation2, @test.Annotation2(\'foo\'+\'wuppa\')]");
  _builder.newLine();
  _builder.append("\t");
  _builder.append(") class Bar {");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
    final MutableClassDeclaration baseClass = it.getTypeLookup().findClass("foo.Bar");
    final AnnotationReference annoRef = IterableExtensions.head(baseClass.getAnnotations());
    Assert.assertEquals(Integer.valueOf((((2 / 2) + (2 * 3)) - (4 % 1))), annoRef.getValue("intValue"));
    Assert.assertEquals(Integer.valueOf((((42 + 4) + (6 * 42)) - (4 / 45))), annoRef.getValue("longValue"));
    Assert.assertEquals("foobaz", annoRef.getValue("stringValue"));
    Object _value = annoRef.getValue("booleanArrayValue");
    final boolean[] bools = ((boolean[]) _value);
    Assert.assertTrue(bools[0]);
    Assert.assertFalse(bools[1]);
    Object _value_1 = annoRef.getValue("intArrayValue");
    Assert.assertArrayEquals(new int[] { (-1), (34 + 45), (2 - 6) }, ((int[]) _value_1));
    Object _value_2 = annoRef.getValue("typeArrayValue");
    final TypeReference[] type = ((TypeReference[]) _value_2);
    Assert.assertEquals(it.getTypeReferenceProvider().newTypeReference(Integer.class), type[1]);
    Object _value_3 = annoRef.getValue("annotation2Value");
    final AnnotationReference anno = ((AnnotationReference) _value_3);
    Assert.assertEquals("foowuppa", anno.getValue("value"));
    Object _value_4 = annoRef.getValue("annotation2ArrayValue");
    final AnnotationReference[] annoArray = ((AnnotationReference[]) _value_4);
    Assert.assertEquals("HUBBA BUBBA!", (annoArray[0]).getValue("value"));
  };
  this.asCompilationUnit(this.validFile(_builder), _function);
}
 
Example #29
Source File: TransformationContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public TypeReference newWildcardTypeReference() {
  return this.getTypeReferenceProvider().newWildcardTypeReference();
}
 
Example #30
Source File: TransformationContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public TypeReference getPrimitiveByte() {
  return this.getTypeReferenceProvider().getPrimitiveByte();
}