Java 类org.eclipse.xtext.common.types.JvmGenericType 实例源码

项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testMethods_publicStrictFpMethod_01() {
    String typeName = Methods.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()");
    assertSame(type, method.getDeclaringType());
    assertFalse(method.isAbstract());
    assertFalse(method.isFinal());
    assertFalse(method.isStatic());
    assertFalse(method.isSynchronized());
    assertTrue(method.isStrictFloatingPoint());
    assertFalse(method.isNative());
    assertEquals(JvmVisibility.PUBLIC, method.getVisibility());
    JvmType methodType = method.getReturnType().getType();
    assertEquals("void", methodType.getIdentifier());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testFindTypeByName_javaLangNumber_01() {
    String typeName = Number.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    assertFalse("toplevel type is not static", type.isStatic());
    assertEquals(type.getSuperTypes().toString(), 2, type.getSuperTypes().size());
    JvmType objectType = type.getSuperTypes().get(0).getType();
    assertFalse("isProxy: " + objectType, objectType.eIsProxy());
    assertEquals(Object.class.getName(), objectType.getIdentifier());
    JvmType serializableType = type.getSuperTypes().get(1).getType();
    assertFalse("isProxy: " + serializableType, serializableType.eIsProxy());
    assertEquals(Serializable.class.getName(), serializableType.getIdentifier());
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
项目:xtext-extras    文件:JvmTypesBuilderTest.java   
@Test
public void testInterfaceCreation() {
  try {
    final XExpression e = this.expression("\'foo\'");
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      EList<JvmTypeReference> _superTypes = it.getSuperTypes();
      JvmTypeReference _typeRef = this._jvmTypeReferenceBuilder.typeRef(Iterable.class);
      this._jvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _typeRef);
    };
    final JvmGenericType anno = this._jvmTypesBuilder.toInterface(e, "foo.bar.MyAnnotation", _function);
    Assert.assertTrue(anno.isInterface());
    Assert.assertEquals("foo.bar", anno.getPackageName());
    Assert.assertEquals("MyAnnotation", anno.getSimpleName());
    Assert.assertEquals(1, anno.getSuperTypes().size());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testFindTypeByName_javaUtilList_07() {
    String typeName = List.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    assertEquals(1, type.getSuperTypes().size());
    JvmParameterizedTypeReference superType = (JvmParameterizedTypeReference) type.getSuperTypes().get(0);
    assertFalse(superType.getType().eIsProxy());
    assertEquals("java.util.Collection<E>", superType.getIdentifier());
    assertEquals(1, type.getTypeParameters().size());
    JvmType rawType = superType.getType();
    assertFalse(rawType.eIsProxy());
    assertEquals(1, superType.getArguments().size());
    JvmTypeReference superTypeParameter = superType.getArguments().get(0);
    JvmType parameterType = superTypeParameter.getType();
    assertFalse(parameterType.eIsProxy());
    assertSame(parameterType, type.getTypeParameters().get(0));
}
项目:xtext-extras    文件:ClosureWithExpectationHelper.java   
protected ITypeComputationState getClosureBodyTypeComputationState(ITypeAssigner typeAssigner) {
    ITypeComputationState result = assignParameters(typeAssigner);
    LightweightTypeReference expectedType = getExpectation().getExpectedType();
    if (expectedType == null) {
        throw new IllegalStateException();
    }
    JvmType knownType = expectedType.getType();
    if (knownType != null && knownType instanceof JvmGenericType) {
        result.assignType(IFeatureNames.SELF, knownType, expectedType);
    }
    List<JvmTypeReference> exceptions = operation.getExceptions();
    if (exceptions.isEmpty()) {
        result.withinScope(getClosure());
        return result;
    }
    List<LightweightTypeReference> expectedExceptions = Lists.newArrayListWithCapacity(exceptions.size());
    for (JvmTypeReference exception : exceptions) {
        expectedExceptions.add(typeAssigner.toLightweightTypeReference(exception));
    }
    result.withinScope(getClosure());
    return result.withExpectedExceptions(expectedExceptions);
}
项目:xtext-extras    文件:ReusedTypeProviderTest.java   
@Test
@Override
public void testFindTypeByName_AbstractMultimap_02() {
  String typeName = "com.google.common.collect.AbstractMultimap";
  JvmType _findTypeByName = this.getTypeProvider().findTypeByName(typeName);
  JvmGenericType type = ((JvmGenericType) _findTypeByName);
  JvmFeature _onlyElement = Iterables.<JvmFeature>getOnlyElement(type.findAllFeaturesByName("containsValue"));
  JvmOperation containsValue = ((JvmOperation) _onlyElement);
  Assert.assertNotNull(containsValue);
  JvmFormalParameter firstParam = containsValue.getParameters().get(0);
  Assert.assertEquals(1, firstParam.getAnnotations().size());
  JvmAnnotationReference annotationReference = firstParam.getAnnotations().get(0);
  JvmAnnotationType annotationType = annotationReference.getAnnotation();
  Assert.assertTrue(annotationType.eIsProxy());
  Assert.assertEquals("java:/Objects/javax.annotation.Nullable", EcoreUtil.getURI(annotationType).trimFragment().toString());
}
项目:xtext-extras    文件:StaticFeatureOnTypeLiteralScope.java   
@Override
protected List<IEObjectDescription> getAllLocalElements() {
    List<IEObjectDescription> result = super.getAllLocalElements();
    if (getSession().isInstanceContext() && !isExplicitStaticFeatureCall()) {
        ITypeReferenceOwner owner = getReceiverType().getOwner();
        QualifiedThisOrSuperDescription thisDescription = new QualifiedThisOrSuperDescription(THIS,
                owner.newParameterizedTypeReference(getTypeLiteral()), getBucket().getId(), true, getReceiver());
        addToList(thisDescription, result);
        JvmType receiverRawType = getTypeLiteral();
        if (receiverRawType instanceof JvmDeclaredType) {
            JvmType referencedType = receiverRawType;
            // If the receiver type is an interface, 'super' always refers to that interface
            if (!(receiverRawType instanceof JvmGenericType && ((JvmGenericType) receiverRawType).isInterface())) {
                JvmTypeReference superType = ((JvmDeclaredType) receiverRawType).getExtendedClass();
                if (superType != null) {
                    referencedType = superType.getType();
                }
            }
            QualifiedThisOrSuperDescription superDescription = new QualifiedThisOrSuperDescription(SUPER,
                    owner.newParameterizedTypeReference(referencedType), getBucket().getId(), true, getReceiver());
            addToList(superDescription, result);
        }
    }
    return result;
}
项目:xtext-extras    文件:JvmModelGeneratorTest.java   
@Test
public void testImplements() {
  try {
    final XExpression expression = this.expression("null", false);
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      it.setAbstract(true);
      EList<JvmTypeReference> _superTypes = it.getSuperTypes();
      JvmTypeReference _typeRef = this.typeRef(expression, Iterable.class, String.class);
      this.builder.<JvmTypeReference>operator_add(_superTypes, _typeRef);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    final Class<?> compiled = this.compile(expression.eResource(), clazz);
    Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:JvmModelBasedLinkingTest.java   
@Test
public void testLinkToParameter() {
  try {
    final XExpression expr = this.expression("x", false);
    final Resource resource = expr.eResource();
    resource.eSetDeliver(false);
    EList<EObject> _contents = resource.getContents();
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      EList<JvmMember> _members = it.getMembers();
      final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
        EList<JvmFormalParameter> _parameters = it_1.getParameters();
        JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(expr, "x", this.stringType(expr));
        this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter);
        this._jvmTypesBuilder.setBody(it_1, expr);
      };
      JvmOperation _method = this._jvmTypesBuilder.toMethod(expr, "doStuff", this.stringType(expr), _function_1);
      this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method);
    };
    JvmGenericType _class = this._jvmTypesBuilder.toClass(expr, "Foo", _function);
    this._jvmTypesBuilder.<JvmGenericType>operator_add(_contents, _class);
    this._validationTestHelper.assertNoErrors(expr);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:XFunctionTypeRefImplCustom.java   
protected JvmTypeReference getJavaLangObjectTypeRef(JvmType rawType, TypesFactory typesFactory) {
    ResourceSet rs = EcoreUtil2.getResourceSet(rawType);
    JvmParameterizedTypeReference refToObject = typesFactory.createJvmParameterizedTypeReference();
    if (rs != null) {
        EObject javaLangObject = rs.getEObject(javaLangObjectURI, true);
        if (javaLangObject instanceof JvmType) {
            JvmType objectDeclaration = (JvmType) javaLangObject;
            refToObject.setType(objectDeclaration);
            return refToObject;
        }
    }
    JvmGenericType proxy = typesFactory.createJvmGenericType();
    ((InternalEObject)proxy).eSetProxyURI(javaLangObjectURI);
    refToObject.setType(proxy);
    return refToObject;
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public ITreeAppendable generateModifier(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (it instanceof JvmConstructor) {
    return _generateModifier((JvmConstructor)it, appendable, config);
  } else if (it instanceof JvmOperation) {
    return _generateModifier((JvmOperation)it, appendable, config);
  } else if (it instanceof JvmField) {
    return _generateModifier((JvmField)it, appendable, config);
  } else if (it instanceof JvmGenericType) {
    return _generateModifier((JvmGenericType)it, appendable, config);
  } else if (it instanceof JvmDeclaredType) {
    return _generateModifier((JvmDeclaredType)it, appendable, config);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, appendable, config).toString());
  }
}
项目:xtext-extras    文件:JvmModelGeneratorTest.java   
@Test
public void testBug377925No_Nullpointer() {
  try {
    final XExpression expression = this.expression("[Object o| null]");
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      EList<JvmMember> _members = it.getMembers();
      final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
        this.builder.setBody(it_1, expression);
      };
      JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName("java.lang.Object", expression), _function_1);
      this.builder.<JvmOperation>operator_add(_members, _method);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    this.compile(expression.eResource(), clazz);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:AbstractLogicalContainerAwareRootComputationState.java   
@Override
protected XExpression getRootExpression() {
    XExpression result = ((LogicalContainerAwareReentrantTypeResolver) getResolver()).getLogicalContainerProvider().getAssociatedExpression(getMember());
    if (result == null && member instanceof JvmFeature) {
        // make sure we process dangling local classes if the expression has been removed by an
        // active annotation
        // 
        // To some extend this is a workaround for a bug with #setBody which should
        // take care of local classes, too
        List<JvmGenericType> localClasses = ((JvmFeature) member).getLocalClasses();
        for(JvmGenericType localClass: localClasses) {
            LocalVariableCapturer.captureLocalVariables(localClass, this);
        }
    }
    return result;
}
项目:xtext-extras    文件:ResourceDescriptionProviderTest.java   
@Test
public void testStubGeneration_02() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public interface MyTest {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("public String helloWorld();");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
    Assert.assertEquals("MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString());
    EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getEObjectOrProxy();
    Assert.assertTrue(((JvmGenericType) _eObjectOrProxy).isInterface());
    Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects()));
  };
  this.resultsIn(_builder, _function);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_ParameterizedTypes_Inner_08() {
    String typeName = ParameterizedTypes.Inner.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodZArray_02()");
    JvmTypeReference listZ = methodV.getReturnType();
    assertEquals("java.util.List<Z[]>[]", listZ.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) ((JvmGenericArrayTypeReference) listZ)
            .getComponentType();
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    JvmType argumentType = typeArgument.getType();
    assertTrue(argumentType instanceof JvmArrayType);
    JvmComponentType componentType = ((JvmArrayType) argumentType).getComponentType();
    JvmTypeParameter z = type.getTypeParameters().get(2);
    assertSame(z, componentType);
}
项目:xtext-extras    文件:JvmDeclaredTypeImplCustom.java   
@Override
public Iterable<JvmTypeReference> getExtendedInterfaces() {
    if (extendedInterfaces == null) {
        extendedInterfaces = Iterables.filter(getSuperTypes(), new Predicate<JvmTypeReference>() {
            @Override
            public boolean apply(JvmTypeReference typeReference) {
                JvmType type = typeReference.getType();
                if (type != null && type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
                    return ((JvmGenericType) type).isInterface();
                }
                return false;
            }
        });
    }
    return extendedInterfaces;
}
项目:xtext-extras    文件:FunctionTypes.java   
protected JvmOperation findImplementingOperation(List<JvmType> rawTypes) {
    if (rawTypes.size() == 1) {
        JvmType rawType = rawTypes.get(0);
        if (rawType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
            JvmGenericType castedRawType = (JvmGenericType) rawType;
            if (!castedRawType.isFinal()) {
                Iterable<JvmFeature> features = castedRawType.getAllFeatures();
                JvmOperation result = null;
                for (JvmFeature feature : features) {
                    if (feature.eClass() == TypesPackage.Literals.JVM_OPERATION) {
                        JvmOperation op = (JvmOperation) feature;
                        if (isValidFunction(op)) {
                            if (result == null)
                                result = op;
                            else {
                                return null;
                            }
                        }
                    }
                }
                return result;
            }
        }
    }
    return null;
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_ParameterizedTypes_W_01() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmTypeParameter typeParameterW = type.getTypeParameters().get(4);
    assertEquals("W", typeParameterW.getIdentifier());
    assertSame(type, typeParameterW.getDeclarator());
    assertEquals(2, typeParameterW.getConstraints().size());
    JvmTypeConstraint firstTypeConstraint = typeParameterW.getConstraints().get(0);
    assertTrue(firstTypeConstraint instanceof JvmUpperBound);
    JvmUpperBound firstUpperBound = (JvmUpperBound) firstTypeConstraint;
    assertNotNull(firstUpperBound.getTypeReference());
    assertFalse(firstUpperBound.getTypeReference().toString(), firstUpperBound.getTypeReference().eIsProxy());
    assertEquals("java.lang.Comparable<S>", firstUpperBound.getTypeReference().getIdentifier());
    JvmParameterizedTypeReference comparableType = (JvmParameterizedTypeReference) firstUpperBound
            .getTypeReference();
    assertEquals(1, comparableType.getArguments().size());
    JvmTypeReference typeArgument = comparableType.getArguments().get(0);
    assertEquals("S", typeArgument.getIdentifier());
    JvmTypeParameter s = type.getTypeParameters().get(0);
    assertSame(s, typeArgument.getType());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_ParameterizedTypes_Inner_05() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_01()");
    JvmTypeReference listT = methodV.getReturnType();
    assertEquals("java.util.List<? extends V>[]", listT.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) ((JvmGenericArrayTypeReference) listT)
            .getComponentType();
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    assertTrue(typeArgument instanceof JvmWildcardTypeReference);
    JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument;
    assertEquals("? extends V", wildcardTypeArgument.getIdentifier());
    assertEquals(1, wildcardTypeArgument.getConstraints().size());
    JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0);
    JvmTypeParameter v = type.getTypeParameters().get(3);
    assertSame(v, upperBound.getTypeReference().getType());
}
项目:xtext-extras    文件:JvmModelCompleter.java   
protected void completeJvmGenericType(JvmGenericType element) {
    // if no super type add Object
    ensureSuperTypeObject(element);
    addAnnotations(element);
    if (!element.isInterface()) {
        // if no constructors have been added, add a default constructor
        if (isEmpty(element.getDeclaredConstructors())) {
            JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor();
            constructor.setSimpleName(element.getSimpleName());
            constructor.setVisibility(JvmVisibility.PUBLIC);
            typeExtensions.setSynthetic(constructor, true);
            EObject primarySourceElement = associations.getPrimarySourceElement(element);
            if (primarySourceElement != null) {
                associator.associate(primarySourceElement, constructor);
            }
            element.getMembers().add(constructor);
        }
    }
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_ParameterizedTypes_Inner_06() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_02()");
    JvmTypeReference listV = methodV.getReturnType();
    assertEquals("java.util.List<? extends V[]>", listV.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listV;
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    assertTrue(typeArgument instanceof JvmWildcardTypeReference);
    JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument;
    assertEquals("? extends V[]", wildcardTypeArgument.getIdentifier());
    assertEquals(1, wildcardTypeArgument.getConstraints().size());
    JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0);
    JvmType upperBoundType = upperBound.getTypeReference().getType();
    assertTrue(upperBoundType instanceof JvmArrayType);
    assertTrue(((JvmArrayType) upperBoundType).getComponentType() instanceof JvmTypeParameter);
    JvmTypeParameter v = type.getTypeParameters().get(3);
    assertSame(v, ((JvmArrayType) upperBoundType).getComponentType());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testFindTypeByName_javaUtilList_01() {
    String typeName = List.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    assertEquals(typeName, type.getIdentifier());
    assertEquals(1, type.getTypeParameters().size());
    JvmTypeParameter typeVariable = type.getTypeParameters().get(0);
    assertEquals("E", typeVariable.getName());
    assertEquals(1, typeVariable.getConstraints().size());
    JvmTypeConstraint typeConstraint = typeVariable.getConstraints().get(0);
    assertTrue(typeConstraint instanceof JvmUpperBound);
    JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
    assertSame(typeVariable, upperBound.getOwner());
    assertNotNull(upperBound.getTypeReference());
    assertFalse(upperBound.getTypeReference().getType().eIsProxy());
    assertEquals(Object.class.getName(), upperBound.getTypeReference().getIdentifier());
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_ParameterizedTypes_Inner_Y_01() {
    String typeName = ParameterizedTypes.Inner.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmTypeParameter typeParameterY = type.getTypeParameters().get(1);
    assertEquals("Y", typeParameterY.getIdentifier());
    assertSame(type, typeParameterY.getDeclarator());
    assertEquals(1, typeParameterY.getConstraints().size());
    JvmTypeConstraint typeConstraint = typeParameterY.getConstraints().get(0);
    assertTrue(typeConstraint instanceof JvmUpperBound);
    JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
    assertNotNull(upperBound.getTypeReference());
    assertEquals("java.util.List<X>", upperBound.getTypeReference().getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference();
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    assertEquals("X", typeArgument.getIdentifier());
    JvmTypeParameter x = type.getTypeParameters().get(0);
    assertSame(x, typeArgument.getType());
}
项目:xtext-extras    文件:CollectionLiteralsTypeComputer.java   
/**
 * Creates a list of collection type references from the element types of a collection literal.
 */
protected List<LightweightTypeReference> computeCollectionTypeCandidates(XCollectionLiteral literal, JvmGenericType collectionType, LightweightTypeReference elementTypeExpectation, ITypeComputationState state) {
    List<XExpression> elements = literal.getElements();
    if(!elements.isEmpty()) {
        List<LightweightTypeReference> elementTypes = Lists.newArrayListWithCapacity(elements.size());
        for(XExpression element: elements) {
            ITypeComputationResult elementType = computeTypes(element, elementTypeExpectation, state);
            LightweightTypeReference actualType = elementType.getActualExpressionType();
            if(actualType != null && !actualType.isAny()) {
                ParameterizedTypeReference collectionTypeCandidate = state.getReferenceOwner().newParameterizedTypeReference(collectionType);
                collectionTypeCandidate.addTypeArgument(actualType.getWrapperTypeIfPrimitive());
                elementTypes.add(collectionTypeCandidate);
            }
        }
        return elementTypes;
    }
    return Collections.emptyList();
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testMethods_privateSynchronizedMethod_01() {
    String typeName = Methods.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation method = getMethodFromType(type, Methods.class, "privateSynchronizedMethod()");
    assertSame(type, method.getDeclaringType());
    assertFalse(method.isAbstract());
    assertFalse(method.isFinal());
    assertFalse(method.isStatic());
    assertTrue(method.isSynchronized());
    assertFalse(method.isStrictFloatingPoint());
    assertFalse(method.isNative());
    assertEquals(JvmVisibility.PRIVATE, method.getVisibility());
    JvmType methodType = method.getReturnType().getType();
    assertEquals("void", methodType.getIdentifier());
}
项目:xtext-extras    文件:JvmModelGeneratorTest.java   
@Test
public void testBug426073() {
  try {
    final XExpression expression = this.expression("org.eclipse.emf.common.util.URI.createURI(\"dummy\")");
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      EList<JvmMember> _members = it.getMembers();
      final Procedure1<JvmField> _function_1 = (JvmField it_1) -> {
        this.builder.setInitializer(it_1, expression);
      };
      JvmField _field = this.builder.toField(expression, "URI", this.typeRef(expression, URI.class), _function_1);
      this.builder.<JvmField>operator_add(_members, _field);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    this.compile(expression.eResource(), clazz);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testMethods_protectedFinalMethod_01() {
    String typeName = Methods.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation method = getMethodFromType(type, Methods.class, "protectedFinalMethod()");
    assertSame(type, method.getDeclaringType());
    assertFalse(method.isAbstract());
    assertTrue(method.isFinal());
    assertFalse(method.isStatic());
    assertFalse(method.isSynchronized());
    assertFalse(method.isStrictFloatingPoint());
    assertFalse(method.isNative());
    assertEquals(JvmVisibility.PROTECTED, method.getVisibility());
    JvmType methodType = method.getReturnType().getType();
    assertEquals("void", methodType.getIdentifier());
}
项目:xtext-extras    文件:PureXbaseJvmModelInferrer.java   
protected void _infer(final Model m, final IJvmDeclaredTypeAcceptor acceptor, final boolean prelinkingPhase) {
  final XBlockExpression e = m.getBlock();
  final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
    EList<JvmMember> _members = it.getMembers();
    final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
      EList<JvmTypeReference> _exceptions = it_1.getExceptions();
      JvmTypeReference _typeRef = this._typeReferenceBuilder.typeRef(Throwable.class);
      this._jvmTypesBuilder.<JvmTypeReference>operator_add(_exceptions, _typeRef);
      this._jvmTypesBuilder.setBody(it_1, e);
    };
    JvmOperation _method = this._jvmTypesBuilder.toMethod(e, "myMethod", this._jvmTypesBuilder.inferredType(), _function_1);
    this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method);
  };
  acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(e, this.name(e.eResource())), _function);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testRawIterable_01() {
    String typeName = RawIterable.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmTypeReference> superTypes = type.getSuperTypes();
    JvmParameterizedTypeReference iterableSuperType = (JvmParameterizedTypeReference) superTypes.get(1);
    assertEquals("java.lang.Iterable", iterableSuperType.getIdentifier());
    assertTrue(iterableSuperType.getArguments().isEmpty());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testFindTypeByName_javaLangCharSequence_03() {
    String typeName = CharSequence.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation length = (JvmOperation) type.eResource().getEObject("java.lang.CharSequence.length()");
    assertNotNull(length);
    JvmType returnType = length.getReturnType().getType();
    assertNotNull(returnType);
    assertFalse(returnType.eIsProxy());
    assertEquals("int", returnType.getIdentifier());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testFindTypeByName_javaLangCharSequence_04() {
    String typeName = CharSequence.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation charAt = (JvmOperation) type.eResource().getEObject("java.lang.CharSequence.charAt(int)");
    assertNotNull(charAt);
    JvmType returnType = charAt.getReturnType().getType();
    assertNotNull(returnType);
    assertFalse(returnType.eIsProxy());
    assertEquals("char", returnType.getIdentifier());
    assertEquals(1, charAt.getParameters().size());
    JvmType intType = getTypeProvider().findTypeByName("int");
    assertSame(intType, charAt.getParameters().get(0).getParameterType().getType());
}
项目:xtext-extras    文件:ParameterizedTypeReference.java   
protected boolean isInner(JvmType type) {
    if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
        if (type.eContainer() instanceof JvmDeclaredType) {
            return !((JvmGenericType) type).isStatic();
        }
    }
    return false;
}
项目:xtext-extras    文件:FunctionTypes.java   
public FunctionTypeKind getFunctionTypeKind(ParameterizedTypeReference typeReference) {
    JvmType type = typeReference.getType();
    if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
        JvmDeclaredType outerType = ((JvmGenericType) type).getDeclaringType();
        if (outerType != null) {
            if (Procedures.class.getName().equals(outerType.getIdentifier())) {
                return FunctionTypeKind.PROCEDURE;
            }
            if (Functions.class.getName().equals(outerType.getIdentifier())) {
                return FunctionTypeKind.FUNCTION;
            }
        }
    }
    return FunctionTypeKind.NONE;
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testFindTypeByName_javaUtilList_05() {
    String typeName = List.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation addAll = (JvmOperation) type.eResource().getEObject("java.util.List.addAll(java.util.Collection)");
    assertEquals(1, addAll.getParameters().size());
    assertEquals(getCollectionParamName(), addAll.getParameters().get(0).getName());
    JvmType parameterType = addAll.getParameters().get(0).getParameterType().getType();
    assertFalse(parameterType.toString(), parameterType.eIsProxy());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testFields_publicInt_01() {
    String typeName = Fields.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmField field = getFieldFromType(type, Fields.class, "publicInt");
    assertSame(type, field.getDeclaringType());
    assertEquals(JvmVisibility.PUBLIC, field.getVisibility());
    JvmType fieldType = field.getType().getType();
    assertEquals("int", fieldType.getIdentifier());
    assertTrue(field.getType().getType() instanceof JvmPrimitiveType);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotatedConstructor_01() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated()");
    assertNotNull(constructor);
    JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor);
    assertEquals(1, value.getValues().size());
    String s = value.getValues().get(0);
    assertEquals("constructor", s);
}
项目:xtext-extras    文件:CollectionLiteralsTypeComputer.java   
protected void setUnboundCollectionType(XCollectionLiteral literal, JvmGenericType collectionType, ITypeExpectation expectation,
        LightweightTypeReference elementTypeExpectation, ITypeComputationState state) {
    ParameterizedTypeReference unboundCollectionType = state.getReferenceOwner().newParameterizedTypeReference(collectionType);
    if (elementTypeExpectation != null) {
        unboundCollectionType.addTypeArgument(elementTypeExpectation);
    } else {
        UnboundTypeReference unboundTypeArgument = expectation.createUnboundTypeReference(literal, collectionType.getTypeParameters().get(0));
        unboundCollectionType.addTypeArgument(unboundTypeArgument);
    }
    expectation.acceptActualType(unboundCollectionType, ConformanceFlags.UNCHECKED);
}
项目:xtext-extras    文件:JvmFeatureImpl.java   
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
    switch (featureID)
    {
        case TypesPackage.JVM_FEATURE__LOCAL_CLASSES:
            getLocalClasses().clear();
            getLocalClasses().addAll((Collection<? extends JvmGenericType>)newValue);
            return;
    }
    super.eSet(featureID, newValue);
}
项目:xtext-extras    文件:Bug462047ElementImpl.java   
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue)
{
  switch (featureID)
  {
    case Bug462047Package.BUG462047_ELEMENT__NAME:
      setName((String)newValue);
      return;
    case Bug462047Package.BUG462047_ELEMENT__REF:
      setRef((JvmGenericType)newValue);
      return;
  }
  super.eSet(featureID, newValue);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testInnerType_WrappedIterator_02b() throws Exception {
    JvmGenericType wrappedIterator = (JvmGenericType) getTypeProvider().findTypeByName(
            "org.eclipse.xtext.common.types.testSetups.NestedParameterizedTypes.WrappedCollection.WrappedIterator",
            false);
    doTestInnerType_WrappedIterator_02(wrappedIterator);
}