org.eclipse.xtext.common.types.JvmType Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmType. 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: TypeLiteralScope.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #2
Source File: Primitives.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 #3
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 #4
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #5
Source File: JvmParameterizedTypeReferenceImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- 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 #6
Source File: FindReferencesTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #7
Source File: NameConcatHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 #8
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #9
Source File: Primitives.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 #10
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #11
Source File: JdtBasedProcessorProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #12
Source File: XFunctionTypeRefImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #13
Source File: ClasspathTypeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 #14
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #15
Source File: AbstractBuilderTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
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 #16
Source File: TypeLiteralLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #17
Source File: ClosureTypeComputerUnitTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #18
Source File: JvmCompoundTypeReferenceImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- 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 #19
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #20
Source File: CheckCompiler.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@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 #21
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #22
Source File: ArrayTypes.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 #23
Source File: RawTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<JvmType> doVisitCompoundTypeReference(CompoundTypeReference reference, ResourceSet resourceSet) {
	List<LightweightTypeReference> components = reference.getMultiTypeComponents();
	if (components.isEmpty())
		throw new IllegalStateException("Components may not be empty");
	return collectRawTypes(components, resourceSet);
}
 
Example #24
Source File: AnnotationValidation.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isValidAnnotationValueType(final JvmTypeReference reference) {
  JvmTypeReference _switchResult = null;
  boolean _matched = false;
  if (reference instanceof JvmGenericArrayTypeReference) {
    _matched=true;
    _switchResult = ((JvmGenericArrayTypeReference)reference).getComponentType();
  }
  if (!_matched) {
    _switchResult = reference;
  }
  final JvmTypeReference toCheck = _switchResult;
  if ((toCheck == null)) {
    return true;
  }
  JvmType _type = toCheck.getType();
  if ((_type instanceof JvmPrimitiveType)) {
    return true;
  }
  JvmType _type_1 = toCheck.getType();
  if ((_type_1 instanceof JvmEnumerationType)) {
    return true;
  }
  JvmType _type_2 = toCheck.getType();
  if ((_type_2 instanceof JvmAnnotationType)) {
    return true;
  }
  if ((Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.String") || Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.Class"))) {
    return true;
  }
  return false;
}
 
Example #25
Source File: ClasspathTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testJvmTypeNoPackage() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("SimpleName");
	resource.getContents().add(expected);
	JvmType actual = getTypeProvider().findTypeByName("SimpleName");
	assertEquals(expected, actual);
}
 
Example #26
Source File: DispatchRenameSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean addDispatcher(
		JvmGenericType type, 
		DispatchHelper.DispatchSignature signature,
		final IAcceptor<JvmOperation> acceptor,
		final Set<JvmGenericType> processedTypes,
		ResourceSet tempResourceSet) {
	if (processedTypes.contains(type))
		return false;
	processedTypes.add(type);
	boolean needProcessSubclasses = false;
	JvmOperation dispatcher = dispatchHelper.getDispatcherOperation(type, signature);
	if (dispatcher != null) {
		needProcessSubclasses = true;
		acceptor.accept(dispatcher);
	}
		
	for (JvmOperation dispatchCase : dispatchHelper.getLocalDispatchCases(type, signature)) {
		needProcessSubclasses = true;
		acceptor.accept(dispatchCase);
	}
	for (JvmTypeReference superTypeRef : type.getSuperTypes()) {
		JvmType superType = superTypeRef.getType();
		if (superType instanceof JvmGenericType)
			needProcessSubclasses |= addDispatcher((JvmGenericType) superType, signature, acceptor, processedTypes, tempResourceSet);
	}
	if (needProcessSubclasses) {
		for (JvmGenericType subType : getSubTypes(type, tempResourceSet))
			needProcessSubclasses |= addDispatcher(subType, signature, acceptor, processedTypes, tempResourceSet);
	}
	return needProcessSubclasses;
}
 
Example #27
Source File: InnerFunctionTypeReference.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public InnerFunctionTypeReference(ITypeReferenceOwner owner, LightweightTypeReference outer, JvmType type) {
	super(owner, type);
	if (outer == null) {
		throw new NullPointerException("outer type may not be null");
	}
	if (outer.getKind() != KIND_PARAMETERIZED_TYPE_REFERENCE && outer.getKind() != KIND_INNER_TYPE_REFERENCE) {
		throw new NullPointerException("outer type must be a parameterized type reference");
	}
	this.outer = outer;
}
 
Example #28
Source File: RawResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ListMultimap<String, JvmFeature> computeAllFeatures() {
	JvmType rawType = getRawType();
	if (!(rawType instanceof JvmDeclaredType)) {
		return ArrayListMultimap.create();
	}
	ListMultimap<String, JvmFeature> result = ArrayListMultimap.create();
	Multimap<String, AbstractResolvedOperation> processed = HashMultimap.create();
	Set<String> processedFields = Sets.newHashSetWithExpectedSize(5);
	computeAllFeatures((JvmDeclaredType)rawType, processed, processedFields, result, featureIndex.keySet());
	return Multimaps.unmodifiableListMultimap(result);
}
 
Example #29
Source File: StandardTypeReferenceOwner.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public InnerFunctionTypeReference newFunctionTypeReference(LightweightTypeReference outer, JvmType type) {
	if (!factory.isInner(type)) {
		throw new IllegalArgumentException(String.valueOf(type));
	}
	return new InnerFunctionTypeReference(this, outer, type);
}
 
Example #30
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**  Generate a feature call.
 *
 * @param expr the call expression.
 */
public void generate(XAbstractFeatureCall expr) {
	if (expr.isTypeLiteral()) {
		final JvmType type = (JvmType) expr.getFeature();
		this.codeReceiver.append(type);
	//} else if (getExpressionHelper().isShortCircuitOperation(expr)) {
	//	generateShortCircuitInvocation(expr);
	} else {
		if (expr instanceof XMemberFeatureCall && ((XMemberFeatureCall) expr).isNullSafe()) {
			featureCalltoJavaExpression(expr, () -> expr);
		} else {
			featureCalltoJavaExpression(expr, null);
		}
	}
}