Java Code Examples for org.eclipse.xtext.common.types.JvmType
The following examples show how to use
org.eclipse.xtext.common.types.JvmType.
These examples are extracted from open source projects.
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 Project: xtext-eclipse Author: eclipse File: FindReferencesTest.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void testFindReferencesTypeLiteralTwice() throws Exception { createFile("find.references.test/src/Test." + fileExtension, "com.acme.OtherwiseUnused != com.acme.OtherwiseUnused"); waitForBuild(); XtextResourceSet set = get(XtextResourceSet.class); set.setClasspathURIContext(JavaCore.create(project)); Resource resource = set.getResource(URI.createPlatformResourceURI("find.references.test/src/Test." + fileExtension, true), true); // obtain reference to type XBinaryOperation expression = (XBinaryOperation) resource.getContents().get(0); JvmType lookup = (JvmType) ((XAbstractFeatureCall) expression.getLeftOperand()).getFeature(); final MockAcceptor mockAcceptor = new MockAcceptor(); mockAcceptor.expect(expression.getLeftOperand(), lookup, XABSTRACT_FEATURE_CALL__FEATURE); mockAcceptor.expect(expression.getRightOperand(), lookup, XABSTRACT_FEATURE_CALL__FEATURE); findReferencesTester.checkFindReferences(lookup, "Java References to com.acme.OtherwiseUnused", mockAcceptor); }
Example #2
Source Project: xtext-extras Author: eclipse File: AbstractTypeProviderTest.java License: Eclipse Public License 2.0 | 6 votes |
@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); }
Example #3
Source Project: xtext-extras Author: eclipse File: JvmParameterizedTypeReferenceImpl.java License: Eclipse Public License 2.0 | 6 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case TypesPackage.JVM_PARAMETERIZED_TYPE_REFERENCE__ARGUMENTS: getArguments().clear(); getArguments().addAll((Collection<? extends JvmTypeReference>)newValue); return; case TypesPackage.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE: setType((JvmType)newValue); return; } super.eSet(featureID, newValue); }
Example #4
Source Project: xtext-eclipse Author: eclipse File: AbstractTypeProviderTest.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_06() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodMap = getMethodFromType(type, ParameterizedTypes.class, "methodMap(java.util.Map)"); assertEquals(1, methodMap.getParameters().size()); assertEquals(1, methodMap.getTypeParameters().size()); assertEquals("Z", methodMap.getTypeParameters().get(0).getIdentifier()); JvmType z = methodMap.getReturnType().getType(); assertSame(methodMap.getTypeParameters().get(0), z); JvmTypeReference mapType = methodMap.getParameters().get(0).getParameterType(); assertEquals("java.util.Map<? extends java.lang.Object & super Z, ? extends S>", mapType.getIdentifier()); JvmParameterizedTypeReference parameterizedMapType = (JvmParameterizedTypeReference) mapType; assertEquals(2, parameterizedMapType.getArguments().size()); JvmWildcardTypeReference extendsS = (JvmWildcardTypeReference) parameterizedMapType.getArguments().get(1); assertEquals(1, extendsS.getConstraints().size()); JvmType s = type.getTypeParameters().get(0); assertSame(s, extendsS.getConstraints().get(0).getTypeReference().getType()); }
Example #5
Source Project: xtext-eclipse Author: eclipse File: AbstractTypeProviderTest.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void testMethods_publicAbstractMethod_01() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicAbstractMethod()"); assertSame(type, method.getDeclaringType()); assertTrue(method.isAbstract()); assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); assertFalse(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
Example #6
Source Project: xtext-extras Author: eclipse File: ArrayTypes.java License: Eclipse Public License 2.0 | 6 votes |
/** * This handles bogus constraint definitions, e.g. * <ul> * <li>{@code T extends String[]},</li> * <li>{@code T extends V[]}, or</li> * <li>{@code T extends V, V extends String[]}</li> * </ul> */ /* @Nullable */ private ArrayTypeReference doTryConvertToArray(ParameterizedTypeReference typeReference, RecursionGuard<JvmTypeParameter> recursionGuard) { JvmType type = typeReference.getType(); if (recursionGuard.tryNext((JvmTypeParameter) type)) { List<LightweightTypeReference> superTypes = typeReference.getSuperTypes(); for(int i = 0, size = superTypes.size(); i < size; i++) { LightweightTypeReference superType = superTypes.get(i); if (superType.isArray()) { return (ArrayTypeReference) superType; } ArrayTypeReference result = doTryConvertToArray(typeReference); if (result != null) { return result; } else { JvmType rawSuperType = superType.getType(); if (rawSuperType != null && rawSuperType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) { result = doTryConvertToArray((ParameterizedTypeReference) superType, recursionGuard); if (result != null) return result; } } } } return null; }
Example #7
Source Project: xtext-extras Author: eclipse File: XFunctionTypeRefImplCustom.java License: Eclipse Public License 2.0 | 6 votes |
@Override public JvmTypeReference getEquivalent() { if (equivalent == null) { JvmType rawType = getType(); if (rawType != null && rawType instanceof JvmDeclaredType) { JvmParameterizedTypeReference result = !isInstanceContext() ? createEquivalentWithWildcards(rawType, isProcedure()) : createEquivalentWithoutWildcards(rawType, isProcedure()); boolean wasDeliver = eDeliver(); try { eSetDeliver(false); setEquivalent(result); } finally { eSetDeliver(wasDeliver); } } else { equivalent = null; } } return equivalent; }
Example #8
Source Project: xtext-extras Author: eclipse File: AbstractTypeProviderTest.java License: Eclipse Public License 2.0 | 6 votes |
@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); }
Example #9
Source Project: xtext-extras Author: eclipse File: ClosureTypeComputerUnitTest.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void testHintsAfterPrepareComputation_01() throws Exception { JvmType iterableType = getTypeForName(Iterable.class, state); JvmTypeParameter typeParameter = createTypeParameter("ELEMENT", state); ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType); UnboundTypeReference elementReference = (UnboundTypeReference) createTypeReference(typeParameter, state); iterableTypeReference.addTypeArgument(elementReference); assertTrue(state.getResolvedTypes().getHints(elementReference.getHandle()).isEmpty()); TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false); ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state); computer.selectStrategy(); FunctionTypeReference closureType = computer.getExpectedClosureType(); assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier()); assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType)); assertEquals("()=>Iterator<Unbound[T]>", closureType.getSimpleName()); assertEquals(1, state.getResolvedTypes().getHints(elementReference.getHandle()).size()); UnboundTypeReference closureTypeArgument = (UnboundTypeReference) closureType.getTypeArguments().get(0); assertEquals(1, state.getResolvedTypes().getHints(closureTypeArgument.getHandle()).size()); }
Example #10
Source Project: xtext-extras Author: eclipse File: TypeLiteralLinkingCandidate.java License: Eclipse Public License 2.0 | 6 votes |
@Override protected void preApply() { XAbstractFeatureCall expression = getExpression(); JvmType type = getType(); if (expression instanceof XMemberFeatureCall) { if (type instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) type; if (declaredType.getDeclaringType() == null) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } else { String queriedName = description.getName().toString(); // may be Map$Entry String qualifiedName = declaredType.getIdentifier(); String packageName = Strings.emptyIfNull(declaredType.getPackageName()); if (packageName.length() + 1 + queriedName.length() == qualifiedName.length()) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } } } } }
Example #11
Source Project: xtext-xtend Author: eclipse File: AbstractBuilderTest.java License: Eclipse Public License 2.0 | 6 votes |
protected JvmDeclaredType getJavaClass() { try { JvmDeclaredType _xblockexpression = null; { if ((AbstractBuilderTest.javaClass == null)) { StringConcatenation _builder = new StringConcatenation(); _builder.append("public class Bar {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this._workbenchTestHelper.createFile("Bar.java", _builder.toString()); IResourcesSetupUtil.waitForBuild(); JvmType _type = this._typeReferences.getTypeForName("Bar", this.getXtendClass()).getType(); AbstractBuilderTest.javaClass = ((JvmDeclaredType) _type); } _xblockexpression = AbstractBuilderTest.javaClass; } return _xblockexpression; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #12
Source Project: xtext-extras Author: eclipse File: TypeLiteralScope.java License: Eclipse Public License 2.0 | 6 votes |
@Override protected List<IEObjectDescription> getLocalElementsByName(QualifiedName name) { XAbstractFeatureCall featureCall = getFeatureCall(); if (featureCall.isExplicitOperationCallOrBuilderSyntax()) return Collections.emptyList(); QualifiedName fqn = parentSegments.append(name); IScope typeScope = getSession().getScope(getFeatureCall(), TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes); IEObjectDescription typeDescription = typeScope.getSingleElement(fqn); if (typeDescription != null) { EObject type = typeDescription.getEObjectOrProxy(); if (type instanceof JvmType) return Collections.<IEObjectDescription>singletonList(new TypeLiteralDescription( new AliasedEObjectDescription(name, typeDescription), isVisible((JvmType) type))); } return Collections.emptyList(); }
Example #13
Source Project: xtext-extras Author: eclipse File: AbstractTypeProviderTest.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void testMethods_defaultStaticMethod_01() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "defaultStaticMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertFalse(method.isFinal()); assertTrue(method.isStatic()); assertFalse(method.isSynchronized()); assertFalse(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.DEFAULT, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
Example #14
Source Project: xtext-extras Author: eclipse File: JvmCompoundTypeReferenceImpl.java License: Eclipse Public License 2.0 | 6 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case TypesPackage.JVM_COMPOUND_TYPE_REFERENCE__TYPE: setType((JvmType)newValue); return; case TypesPackage.JVM_COMPOUND_TYPE_REFERENCE__REFERENCES: getReferences().clear(); getReferences().addAll((Collection<? extends JvmTypeReference>)newValue); return; } super.eSet(featureID, newValue); }
Example #15
Source Project: dsl-devkit Author: dsldevkit File: CheckCompiler.java License: Eclipse Public License 1.0 | 6 votes |
@Override protected void appendImmutableCollectionExpression(final XCollectionLiteral literal, final ITreeAppendable b, final String collectionsMethod, final Class<?> guavaHelper, final String guavaHelperMethod) { // This is a work-around for a bug in the xbase compiler, which always constructs empty list literals #[] as List<Object>, // which then cannot be assigned (without cast) to any typed list. Note that this is not a problem in check; it also occurs // in plain xtend. if (literal.getElements().isEmpty()) { JvmType collectionsClass = findKnownTopLevelType(Collections.class, literal); if (collectionsClass != null) { if (literal instanceof XListLiteral) { b.append(collectionsClass).append(".emptyList()"); return; } else if (literal instanceof XSetLiteral) { b.append(collectionsClass).append(".emptySet()"); return; } } } super.appendImmutableCollectionExpression(literal, b, collectionsMethod, guavaHelper, guavaHelperMethod); }
Example #16
Source Project: xtext-eclipse Author: eclipse File: AbstractTypeProviderTest.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListWildcardsListResult_03() { JvmOperation twoListWildcardsListResult = getMethodFromParameterizedMethods( "twoListWildcardsListResult(java.util.List,java.util.List)"); JvmTypeReference returnType = twoListWildcardsListResult.getReturnType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); assertTrue(typeParameter instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) typeParameter; assertEquals(1, wildcard.getConstraints().size()); assertTrue(wildcard.getConstraints().get(0) instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) wildcard.getConstraints().get(0); assertNotNull(upperBound.getTypeReference()); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertFalse(upperBoundType.eIsProxy()); assertEquals("java.lang.Object", upperBoundType.getIdentifier()); }
Example #17
Source Project: xtext-xtend Author: eclipse File: JdtBasedProcessorProvider.java License: Eclipse Public License 2.0 | 6 votes |
@Override public Object getProcessorInstance(final JvmType type) { try { final ClassLoader classLoader = this.getClassLoader(type); final Class<?> result = classLoader.loadClass(type.getIdentifier()); return result.getDeclaredConstructor().newInstance(); } catch (final Throwable _t) { if (_t instanceof Exception) { final Exception e = (Exception)_t; String _identifier = type.getIdentifier(); String _plus = ("Problem during instantiation of " + _identifier); String _plus_1 = (_plus + " : "); String _message = e.getMessage(); String _plus_2 = (_plus_1 + _message); throw new IllegalStateException(_plus_2, e); } else { throw Exceptions.sneakyThrow(_t); } } }
Example #18
Source Project: xtext-extras Author: eclipse File: Primitives.java License: Eclipse Public License 2.0 | 6 votes |
public JvmType getWrapperType(JvmPrimitiveType primitive) { switch (primitiveKind(primitive)) { case Byte : return getType(Byte.class, primitive); case Short : return getType(Short.class, primitive); case Char : return getType(Character.class, primitive); case Int : return getType(Integer.class, primitive); case Long : return getType(Long.class, primitive); case Float : return getType(Float.class, primitive); case Double : return getType(Double.class, primitive); case Boolean : return getType(Boolean.class, primitive); case Void : return getType(Void.class, primitive); default : throw new IllegalArgumentException("Not a primitive : "+primitive); } }
Example #19
Source Project: xtext-extras Author: eclipse File: NameConcatHelper.java License: Eclipse Public License 2.0 | 6 votes |
private static void computeFor(JvmParameterizedTypeReference typeReference, char innerClassDelimiter, NameType nameType, StringBuilder result) { if (typeReference.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) { JvmParameterizedTypeReference outer = ((JvmInnerTypeReference) typeReference).getOuter(); if (outer != null) { computeFor(outer, innerClassDelimiter, nameType, result); if (result.length() != 0) { JvmType type = typeReference.getType(); result.append(innerClassDelimiter); result.append(type.getSimpleName()); } else { appendType(typeReference, innerClassDelimiter, nameType, result); } } else { appendType(typeReference, innerClassDelimiter, nameType, result); } } else { appendType(typeReference, innerClassDelimiter, nameType, result); } if (typeReference.eIsSet(TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__ARGUMENTS)) { result.append("<"); appendArguments(result, typeReference.getArguments(), innerClassDelimiter, nameType); result.append(">"); } }
Example #20
Source Project: xtext-extras Author: eclipse File: FeatureCallCompiler.java License: Eclipse Public License 2.0 | 6 votes |
protected void _toJavaExpression(XAbstractFeatureCall call, ITreeAppendable b) { if (call.isTypeLiteral()) { b.append((JvmType) call.getFeature()).append(".class"); } else if (isPrimitiveVoid(call)) { throw new IllegalArgumentException("feature yields 'void'"); } else { final String referenceName = getReferenceName(call, b); if (referenceName != null) { if (call instanceof XFeatureCall || call instanceof XMemberFeatureCall) { b.trace(call, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, 0).append(referenceName); } else { b.trace(call, false).append(referenceName); } } else { featureCalltoJavaExpression(call, b, true); } } }
Example #21
Source Project: xtext-extras Author: eclipse File: Primitives.java License: Eclipse Public License 2.0 | 6 votes |
public JvmType getPrimitiveTypeIfWrapper(JvmDeclaredType type) { if (typeReferences.is(type, Byte.class)) { return typeReferences.findDeclaredType(Byte.TYPE, type); } else if (typeReferences.is(type, Short.class)) { return typeReferences.findDeclaredType(Short.TYPE, type); } else if (typeReferences.is(type, Character.class)) { return typeReferences.findDeclaredType(Character.TYPE, type); } else if (typeReferences.is(type, Integer.class)) { return typeReferences.findDeclaredType(Integer.TYPE, type); } else if (typeReferences.is(type, Long.class)) { return typeReferences.findDeclaredType(Long.TYPE, type); } else if (typeReferences.is(type, Float.class)) { return typeReferences.findDeclaredType(Float.TYPE, type); } else if (typeReferences.is(type, Double.class)) { return typeReferences.findDeclaredType(Double.TYPE, type); } else if (typeReferences.is(type, Boolean.class)) { return typeReferences.findDeclaredType(Boolean.TYPE, type); } else if (typeReferences.is(type, Void.class)) { return typeReferences.findDeclaredType(Void.TYPE, type); } return null; }
Example #22
Source Project: xtext-extras Author: eclipse File: ClasspathTypeProvider.java License: Eclipse Public License 2.0 | 6 votes |
private JvmType findTypeByClass(BinaryClass clazz) { try { IndexedJvmTypeAccess indexedJvmTypeAccess = getIndexedJvmTypeAccess(); URI resourceURI = clazz.getResourceURI(); if (indexedJvmTypeAccess != null) { URI proxyURI = resourceURI.appendFragment(clazz.getURIFragment()); EObject candidate = indexedJvmTypeAccess.getIndexedJvmType(proxyURI, getResourceSet()); if (candidate instanceof JvmType) return (JvmType) candidate; } TypeResource result = (TypeResource) getResourceSet().getResource(resourceURI, true); return findTypeByClass(clazz, result); } catch(UnknownNestedTypeException e) { return null; } }
Example #23
Source Project: sarl Author: sarl File: SARLJvmTypeReferencesValidator.java License: Apache License 2.0 | 5 votes |
@Override protected void warnRawType(JvmType type, JvmParameterizedTypeReference typeRef) { if (isIgnored(IssueCodes.RAW_TYPE)) { return; } super.warnRawType(type, typeRef); }
Example #24
Source Project: xtext-xtend Author: eclipse File: PrimitiveAwareScope.java License: Eclipse Public License 2.0 | 5 votes |
@Override protected void doGetElements(JvmType type, List<IEObjectDescription> result) { if (type instanceof JvmVoid) { result.add(EObjectDescription.create("void", type)); return; } if (type instanceof JvmPrimitiveType) { result.add(EObjectDescription.create(((JvmPrimitiveType) type).getSimpleName(), type)); return; } parent.doGetElements(type, result); }
Example #25
Source Project: xtext-extras Author: eclipse File: TypeImporter.java License: Eclipse Public License 2.0 | 5 votes |
protected IFeatureScopeSession process(AbstractFeatureScopeSession parent, ITypeImporter.Client client) { client.doAddImports(this); AbstractFeatureScopeSession result = parent; if (!bogusStaticImports.isEmpty()) { // import all static extensions also as static plain imports result = new FeatureScopeSessionWithStaticTypes( result, bogusStaticImports, Collections.<JvmType>emptyList(), result.getResolvedFeaturesProvider()); } if (!bogusNamedStaticExtensionImports.isEmpty()) { result = new FeatureScopeSessionWithNamedStaticTypes( result, bogusNamedStaticExtensionImports, Collections.<JvmType, Set<String>>emptyMap(), result.getResolvedFeaturesProvider()); } if (!staticImports.isEmpty() || !staticExtensionImports.isEmpty()) { result = new FeatureScopeSessionWithStaticTypes( result, staticImports, staticExtensionImports, result.getResolvedFeaturesProvider()); } if (!namedStaticImports.isEmpty() || !namedStaticExtensionImports.isEmpty()) { result = new FeatureScopeSessionWithNamedStaticTypes( result, namedStaticImports, namedStaticExtensionImports, result.getResolvedFeaturesProvider()); } return result; }
Example #26
Source Project: xtext-extras Author: eclipse File: AbstractTypeProviderTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void testFindTypeByName_int_array_02() { String typeName = int[].class.getName(); JvmType type = getTypeProvider().findTypeByName(typeName); assertNotNull(type); assertTrue(type instanceof JvmArrayType); assertEquals("int[]", type.getIdentifier()); }
Example #27
Source Project: xtext-eclipse Author: eclipse File: XbaseReferenceUpdater.java License: Eclipse Public License 2.0 | 5 votes |
protected boolean canLinkJvmType(EObject referringElement, JvmType type) { if (type == null) { return false; } QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(type); if (qualifiedName == null) { return false; } IScope scope = getLinkingScopeProvider().getScope(referringElement, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE); return scope.getSingleElement(qualifiedName) != null; }
Example #28
Source Project: xtext-extras Author: eclipse File: ParameterizedTypeReference.java License: Eclipse Public License 2.0 | 5 votes |
private Primitive getPrimitiveKind(JvmTypeParameter type, /* @Nullable */ RecursionGuard<JvmTypeParameter> guard) { if (type.eIsProxy()) return null; for(JvmTypeConstraint constraint: type.getConstraints()) { if (constraint.eClass() == TypesPackage.Literals.JVM_UPPER_BOUND) { JvmTypeReference upperBound = constraint.getTypeReference(); if (upperBound != null) { JvmType upperBoundType = upperBound.getType(); if (upperBoundType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { return getPrimitiveKind((JvmGenericType) upperBoundType); } if (type == upperBoundType) { return null; } // guard against recursive deps if (upperBoundType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) { JvmTypeParameter upperBoundTypeParameter = (JvmTypeParameter) upperBoundType; if (guard == null) { guard = new RecursionGuard<JvmTypeParameter>(); guard.tryNext(type); } if (guard.tryNext(upperBoundTypeParameter)) { return getPrimitiveKind(upperBoundTypeParameter, guard); } return null; } } } } return null; }
Example #29
Source Project: xtext-extras Author: eclipse File: ParameterizedTypeReference.java License: Eclipse Public License 2.0 | 5 votes |
private LightweightTypeReference findPrimitive(String primitive) { JvmType result = (JvmType) getOwner().getContextResourceSet().getEObject(URIHelperConstants.PRIMITIVES_URI.appendFragment(primitive), true); if (result != null) { return getOwner().newParameterizedTypeReference(result); } throw new IllegalStateException("Cannot find primitive type: " + primitive); }
Example #30
Source Project: xtext-xtend Author: eclipse File: KnownTypesScope.java License: Eclipse Public License 2.0 | 5 votes |
@Override protected IEObjectDescription toDescription(QualifiedName name, JvmType result, int dollarIndex, int index) { if (result != null) { JvmType actualResult = dollarIndex > 0 || name.getSegmentCount() > 0 ? findNestedType(result, index, name) : result; if (actualResult != null) { return EObjectDescription.create(name, actualResult); } } return null; }