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

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.Type. 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: EqualsHashCodeProcessor.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
public boolean hasSuperEquals(final ClassDeclaration cls) {
  boolean _xblockexpression = false;
  {
    Type _type = cls.getExtendedClass().getType();
    final ClassDeclaration superClass = ((ClassDeclaration) _type);
    boolean _xifexpression = false;
    boolean _equals = this.context.newTypeReference(superClass).equals(this.context.getObject());
    if (_equals) {
      _xifexpression = false;
    } else {
      boolean _xifexpression_1 = false;
      boolean _hasEquals = this.hasEquals(superClass);
      if (_hasEquals) {
        _xifexpression_1 = true;
      } else {
        _xifexpression_1 = this.hasSuperEquals(superClass);
      }
      _xifexpression = _xifexpression_1;
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #3
Source File: EqualsHashCodeProcessor.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
public boolean hasSuperHashCode(final ClassDeclaration cls) {
  boolean _xblockexpression = false;
  {
    Type _type = cls.getExtendedClass().getType();
    final ClassDeclaration superClass = ((ClassDeclaration) _type);
    boolean _xifexpression = false;
    boolean _equals = this.context.newTypeReference(superClass).equals(this.context.getObject());
    if (_equals) {
      _xifexpression = false;
    } else {
      boolean _xifexpression_1 = false;
      boolean _hasHashCode = this.hasHashCode(superClass);
      if (_hasHashCode) {
        _xifexpression_1 = true;
      } else {
        _xifexpression_1 = this.hasSuperHashCode(superClass);
      }
      _xifexpression = _xifexpression_1;
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #4
Source File: AddInterfaceWithDefaultProcessor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  super.doTransform(annotatedClass, context);
  Type _findTypeGlobally = context.findTypeGlobally("de.test.Test");
  final MutableInterfaceDeclaration ifType = ((MutableInterfaceDeclaration) _findTypeGlobally);
  final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("System.out.println(\"Hello World\");");
      }
    };
    it.setBody(_client);
    it.setDefault(true);
  };
  ifType.addMethod("sayHello", _function);
}
 
Example #5
Source File: ToAnnoProcessor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  super.doTransform(annotatedClass, context);
  Type _findTypeGlobally = context.findTypeGlobally(this.generatedAnnotationName(annotatedClass));
  final MutableAnnotationTypeDeclaration annotationType = ((MutableAnnotationTypeDeclaration) _findTypeGlobally);
  final Procedure1<MutableAnnotationTypeElementDeclaration> _function = (MutableAnnotationTypeElementDeclaration it) -> {
    it.setDocComment("Best building strategy game ever");
    it.setType(context.newTypeReference(Integer.TYPE));
    boolean _booleanValue = annotatedClass.findAnnotation(context.findTypeGlobally(ToAnno.class)).getBooleanValue("defaultValue");
    if (_booleanValue) {
      StringConcatenationClient _client = new StringConcatenationClient() {
        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
          _builder.append("1602");
        }
      };
      it.setDefaultValueExpression(_client);
    }
  };
  annotationType.addAnnotationTypeElement("anno", _function);
}
 
Example #6
Source File: TypeReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Type getType() {
  Type _switchResult = null;
  LightweightTypeReference _delegate = this.getDelegate();
  final LightweightTypeReference it = _delegate;
  boolean _matched = false;
  boolean _isUnknown = it.isUnknown();
  if (_isUnknown) {
    _matched=true;
    CompilationUnitImpl _compilationUnit = this.getCompilationUnit();
    String _packageName = this.getCompilationUnit().getPackageName();
    String _plus = (_packageName + ".");
    String _simpleName = it.getSimpleName();
    String _plus_1 = (_plus + _simpleName);
    _switchResult = new UnknownType(_compilationUnit, _plus_1);
  }
  if (!_matched) {
    _switchResult = this.getCompilationUnit().toType(it.getType());
  }
  return _switchResult;
}
 
Example #7
Source File: JvmAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public AnnotationReference findAnnotation(final Type annotationType) {
  final Function1<AnnotationReference, Boolean> _function = (AnnotationReference it) -> {
    AnnotationTypeDeclaration _annotationTypeDeclaration = it.getAnnotationTypeDeclaration();
    return Boolean.valueOf(Objects.equal(_annotationTypeDeclaration, annotationType));
  };
  return IterableExtensions.findFirst(this.getAnnotations(), _function);
}
 
Example #8
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 #9
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 #10
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 #11
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Type findTypeGlobally(final String typeName) {
  Type _elvis = null;
  Type _findType = this.findType(typeName);
  if (_findType != null) {
    _elvis = _findType;
  } else {
    final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
      return Boolean.valueOf(true);
    };
    Type _findTypeOnScope = this.findTypeOnScope(typeName, _function);
    _elvis = _findTypeOnScope;
  }
  return _elvis;
}
 
Example #12
Source File: JvmTypeParameterDeclarationImpl.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 #13
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Type findUpstreamType(final String typeName) {
  final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
    Resource _eResource = it.getEObjectOrProxy().eResource();
    Resource _eResource_1 = this.compilationUnit.getXtendFile().eResource();
    return Boolean.valueOf((!Objects.equal(_eResource, _eResource_1)));
  };
  return this.findTypeOnScope(typeName, _function);
}
 
Example #14
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private Type findTypeOnScope(final String typeName, final Function1<? super IEObjectDescription, ? extends Boolean> filter) {
  final QualifiedName qualifiedName = this.compilationUnit.getQualifiedNameConverter().toQualifiedName(typeName);
  final IEObjectDescription result = this.compilationUnit.getScopeProvider().getScope(this.compilationUnit.getXtendFile(), XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE).getSingleElement(qualifiedName);
  if ((((result != null) && TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(result.getEClass())) && (filter.apply(result)).booleanValue())) {
    EObject _eObjectOrProxy = result.getEObjectOrProxy();
    return this.compilationUnit.toType(((JvmType) _eObjectOrProxy));
  }
  return null;
}
 
Example #15
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 #16
Source File: XtendAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AnnotationReference findAnnotation(final Type annotationType) {
  final Function1<AnnotationReference, Boolean> _function = (AnnotationReference it) -> {
    AnnotationTypeDeclaration _annotationTypeDeclaration = it.getAnnotationTypeDeclaration();
    return Boolean.valueOf(Objects.equal(_annotationTypeDeclaration, annotationType));
  };
  return IterableExtensions.findFirst(this.getAnnotations(), _function);
}
 
Example #17
Source File: VoidTypeImpl.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 #18
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public MutableInterfaceDeclaration findInterface(final String qualifiedName) {
  final Type type = this.findType(qualifiedName);
  MutableInterfaceDeclaration _switchResult = null;
  boolean _matched = false;
  if (type instanceof MutableInterfaceDeclaration) {
    _matched=true;
    _switchResult = ((MutableInterfaceDeclaration)type);
  }
  return _switchResult;
}
 
Example #19
Source File: XtendTypeDeclarationImpl.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 #20
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 #21
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public MutableEnumerationTypeDeclaration findEnumerationType(final String qualifiedName) {
  final Type type = this.findType(qualifiedName);
  MutableEnumerationTypeDeclaration _switchResult = null;
  boolean _matched = false;
  if (type instanceof MutableEnumerationTypeDeclaration) {
    _matched=true;
    _switchResult = ((MutableEnumerationTypeDeclaration)type);
  }
  return _switchResult;
}
 
Example #22
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 #23
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public MutableClassDeclaration findClass(final String qualifiedName) {
  final Type type = this.findType(qualifiedName);
  MutableClassDeclaration _switchResult = null;
  boolean _matched = false;
  if (type instanceof MutableClassDeclaration) {
    _matched=true;
    _switchResult = ((MutableClassDeclaration)type);
  }
  return _switchResult;
}
 
Example #24
Source File: TypeParameterDeclarationImpl.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 #25
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public MutableAnnotationTypeDeclaration findAnnotationType(final String qualifiedName) {
  final Type type = this.findType(qualifiedName);
  MutableAnnotationTypeDeclaration _switchResult = null;
  boolean _matched = false;
  if (type instanceof MutableAnnotationTypeDeclaration) {
    _matched=true;
    _switchResult = ((MutableAnnotationTypeDeclaration)type);
  }
  return _switchResult;
}
 
Example #26
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 #27
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 #28
Source File: InferredTypeReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Type getType() {
  return this.throwInferredTypeException("getType").getType();
}
 
Example #29
Source File: TypeLookupImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Type findTypeGlobally(final Class<?> clazz) {
  return this.findTypeGlobally(clazz.getCanonicalName());
}
 
Example #30
Source File: AnnotationReferenceProviderImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AnnotationReference newAnnotationReference(final Type annotationTypeDelcaration, final Procedure1<AnnotationReferenceBuildContext> initializer) {
  Object _xblockexpression = null;
  {
    this.compilationUnit.checkCanceled();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("annotationTypeDelcaration cannot be null");
    Preconditions.checkArgument((annotationTypeDelcaration != null), _builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("initializer cannot be null");
    Preconditions.checkArgument((initializer != null), _builder_1);
    JvmDeclaredType _switchResult = null;
    boolean _matched = false;
    if (annotationTypeDelcaration instanceof JvmAnnotationTypeDeclarationImpl) {
      _matched=true;
      _switchResult = ((JvmAnnotationTypeDeclarationImpl)annotationTypeDelcaration).getDelegate();
    }
    if (!_matched) {
      if (annotationTypeDelcaration instanceof XtendAnnotationTypeDeclarationImpl) {
        _matched=true;
        _switchResult = this.compilationUnit.getJvmModelAssociations().getInferredType(((XtendAnnotationTypeDeclarationImpl)annotationTypeDelcaration).getDelegate());
      }
    }
    if (!_matched) {
      throw new IllegalArgumentException(("couldn\'t construct type reference for type " + annotationTypeDelcaration));
    }
    final JvmDeclaredType type = _switchResult;
    if ((type instanceof JvmAnnotationType)) {
      final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(type);
      AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
      final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
        it.setDelegate(newJvmAnnotationReference);
        it.setCompilationUnit(this.compilationUnit);
      };
      final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
      initializer.apply(buildContext);
      return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
    }
    _xblockexpression = null;
  }
  return ((AnnotationReference)_xblockexpression);
}