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

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration. 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: MutableJvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
  this.checkMutable();
  ConditionUtils.checkJavaIdentifier(name, "name");
  ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds");
  ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
  final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
  param.setName(name);
  this.getDelegate().getTypeParameters().add(param);
  for (final TypeReference upper : upperBounds) {
    {
      final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
      final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
      jvmUpperBound.setTypeReference(typeRef);
      param.getConstraints().add(jvmUpperBound);
    }
  }
  TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
  return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
 
Example #2
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
  this.checkMutable();
  ConditionUtils.checkJavaIdentifier(name, "name");
  ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds");
  ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
  final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
  param.setName(name);
  this.getDelegate().getTypeParameters().add(param);
  for (final TypeReference upper : upperBounds) {
    {
      final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
      final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
      jvmUpperBound.setTypeReference(typeRef);
      param.getConstraints().add(jvmUpperBound);
    }
  }
  TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
  return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
 
Example #3
Source File: JvmExecutableDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
  this.checkMutable();
  ConditionUtils.checkJavaIdentifier(name, "name");
  ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds");
  ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
  final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
  param.setName(name);
  this.getDelegate().getTypeParameters().add(param);
  for (final TypeReference upper : upperBounds) {
    {
      final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
      final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
      jvmUpperBound.setTypeReference(typeRef);
      param.getConstraints().add(jvmUpperBound);
    }
  }
  TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
  return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
 
Example #4
Source File: TypeAdapterImplProcessor.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
protected MutableMethodDeclaration generateFactory(final MutableClassDeclaration factory, final MutableClassDeclaration impl, final TypeReference targetType, @Extension final TransformationContext context) {
  MutableMethodDeclaration _xblockexpression = null;
  {
    TypeReference _newTypeReference = context.newTypeReference("com.google.gson.TypeAdapterFactory");
    factory.setImplementedInterfaces(Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(_newTypeReference)));
    final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
      final MutableTypeParameterDeclaration t = it.addTypeParameter("T");
      it.addParameter("gson", context.newTypeReference("com.google.gson.Gson"));
      it.addParameter("typeToken", context.newTypeReference("com.google.gson.reflect.TypeToken", context.newTypeReference(t)));
      it.setReturnType(context.newTypeReference("com.google.gson.TypeAdapter", context.newTypeReference(t)));
      StringConcatenationClient _client = new StringConcatenationClient() {
        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
          _builder.append("if (!");
          _builder.append(targetType);
          _builder.append(".class.isAssignableFrom(typeToken.getRawType())) {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("return null;");
          _builder.newLine();
          _builder.append("}");
          _builder.newLine();
          _builder.append("return (TypeAdapter<T>) new ");
          _builder.append(impl);
          _builder.append("(gson);");
          _builder.newLineIfNotEmpty();
        }
      };
      it.setBody(_client);
    };
    _xblockexpression = factory.addMethod("create", _function);
  }
  return _xblockexpression;
}
 
Example #5
Source File: MutableJvmConstructorDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableTypeParameterDeclaration> getTypeParameters() {
  Iterable<? extends TypeParameterDeclaration> _typeParameters = super.getTypeParameters();
  return ((Iterable<? extends MutableTypeParameterDeclaration>) _typeParameters);
}
 
Example #6
Source File: MutableJvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableTypeParameterDeclaration> getTypeParameters() {
  Iterable<? extends TypeParameterDeclaration> _typeParameters = super.getTypeParameters();
  return ((Iterable<? extends MutableTypeParameterDeclaration>) _typeParameters);
}
 
Example #7
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableTypeParameterDeclaration> getTypeParameters() {
  Iterable<? extends TypeParameterDeclaration> _typeParameters = super.getTypeParameters();
  return ((Iterable<? extends MutableTypeParameterDeclaration>) _typeParameters);
}
 
Example #8
Source File: MutableJvmMethodDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableTypeParameterDeclaration> getTypeParameters() {
  Iterable<? extends TypeParameterDeclaration> _typeParameters = super.getTypeParameters();
  return ((Iterable<? extends MutableTypeParameterDeclaration>) _typeParameters);
}