org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference. 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: AbstractResolvedExecutable.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getResolvedErasureSignature() {
	JvmExecutable declaration = getDeclaration();
	List<LightweightTypeReference> parameterTypes = getResolvedParameterTypes();
	StringBuilder result = new StringBuilder(declaration.getSimpleName().length() + 2 + 20 * parameterTypes.size());
	result.append(declaration.getSimpleName());
	result.append('(');
	for(int i = 0; i < parameterTypes.size(); i++) {
		if (i != 0) {
			result.append(',');
		}
		result.append(parameterTypes.get(i).getRawTypeReference().getJavaIdentifier());
	}
	result.append(')');
	return result.toString();
}
 
Example #2
Source File: MemberFromSuperImplementor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void initializeExecutableBuilder(final AbstractExecutableBuilder builder, final JvmDeclaredType overrider, final IResolvedExecutable overridden) {
  final JvmExecutable executable = overridden.getDeclaration();
  builder.setContext(overrider);
  builder.setVisibility(overridden.getDeclaration().getVisibility());
  final Procedure2<LightweightTypeReference, Integer> _function = (LightweightTypeReference it, Integer index) -> {
    final JvmFormalParameter declaredParameter = executable.getParameters().get((index).intValue());
    final AbstractParameterBuilder parameterBuilder = builder.newParameterBuilder();
    parameterBuilder.setName(declaredParameter.getSimpleName());
    parameterBuilder.setType(it);
    JvmAnnotationReference _findAnnotation = this.annotationLookup.findAnnotation(declaredParameter, Extension.class);
    boolean _tripleNotEquals = (_findAnnotation != null);
    parameterBuilder.setExtensionFlag(_tripleNotEquals);
  };
  IterableExtensions.<LightweightTypeReference>forEach(overridden.getResolvedParameterTypes(), _function);
  builder.setVarArgsFlag(executable.isVarArgs());
  builder.setExceptions(overridden.getResolvedExceptions());
}
 
Example #3
Source File: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected int doIsConformantOuter(LightweightTypeReference left, LightweightTypeReference right, int nestedResult, int flags) {
	if ((nestedResult & SUCCESS) != 0) {
		JvmType leftType = left.getType();
		EObject leftDeclarator = leftType.eContainer();
		if (leftDeclarator instanceof JvmDeclaredType) {
			JvmDeclaredType castedLeftDeclarator = (JvmDeclaredType) leftDeclarator;
			LightweightTypeReference leftOuter = left.getOuter().getSuperType(castedLeftDeclarator);
			if (leftOuter != null) {
				LightweightTypeReference rightOuter = right.getOuter().getSuperType(castedLeftDeclarator);
				if (rightOuter != null) {
					int outerResult = doIsConformant(leftOuter, rightOuter, flags);
					if ((outerResult & SUCCESS) == 0) {
						return outerResult;
					}
				}
			}
		}
	}
	return nestedResult;
}
 
Example #4
Source File: ResolvedMethodImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<? extends ResolvedTypeParameter> getResolvedTypeParameters() {
  ArrayList<ResolvedTypeParameterImpl> _xblockexpression = null;
  {
    final ArrayList<ResolvedTypeParameterImpl> resolvedTypeParameters = CollectionLiterals.<ResolvedTypeParameterImpl>newArrayList();
    for (int i = 0; (i < this.getDelegate().getResolvedTypeParameters().size()); i++) {
      TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(this.getDelegate().getResolvedTypeParameters().get(i));
      final Function1<LightweightTypeReference, TypeReference> _function = (LightweightTypeReference it) -> {
        return this.getCompilationUnit().toTypeReference(it);
      };
      List<TypeReference> _list = IterableExtensions.<TypeReference>toList(ListExtensions.<LightweightTypeReference, TypeReference>map(this.getDelegate().getResolvedTypeParameterConstraints(i), _function));
      ResolvedTypeParameterImpl _resolvedTypeParameterImpl = new ResolvedTypeParameterImpl(_typeParameterDeclaration, _list);
      resolvedTypeParameters.add(_resolvedTypeParameterImpl);
    }
    _xblockexpression = resolvedTypeParameters;
  }
  return _xblockexpression;
}
 
Example #5
Source File: Bug409780Test.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testConstraintsInfluenceType() throws Exception {
	XtendFile file = file(
			"class C {\n" + 
			"	def private a(Iterable<CharSequence> it) {\n" + 
			"		map[ b ]\n" + 
			"	}\n" + 
			"	def private <T extends Appendable> T b(CharSequence c) {}\n" + 
			"}"); 
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction m = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) m.getExpression();
	XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement method = featureCall.getFeature();
	assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
	assertTrue(featureCall.isStatic());
	assertTrue(featureCall.isExtension());
	assertFalse(featureCall.isTypeLiteral());
	LightweightTypeReference type = getType(featureCall);
	assertEquals("java.lang.Iterable<java.lang.Appendable>", type.getIdentifier());
}
 
Example #6
Source File: AbstractResolvedFeature.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isResolvedTypeParameter(LightweightTypeReference typeReference, JvmTypeParameter typeParameter) {
	List<LightweightTypeReference> typeArguments = typeReference.getTypeArguments();
	for(int i = 0, size = typeArguments.size(); i < size; i++) {
		LightweightTypeReference typeArgument = typeArguments.get(i);
		if (typeParameter.equals(typeArgument.getType()) || isResolvedTypeParameter(typeArgument, typeParameter)) {
			return true;
		}
	}
	LightweightTypeReference outer = typeReference.getOuter();
	if (outer != null) {
		if (isResolvedTypeParameter(outer, typeParameter)) {
			return true;
		}
	}
	return false;
}
 
Example #7
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Append the type parameters of the given operation.
 *
 * @param appendable the receiver of the Java code.
 * @param operation the source operation.
 * @param instantiatedType the type of the operation container.
 */
protected void appendTypeParameters(ITreeAppendable appendable, JvmOperation operation, LightweightTypeReference instantiatedType) {
	Preconditions.checkArgument(!operation.getTypeParameters().isEmpty(), "the operation is not generic");
	BottomResolvedOperation resolvedOperation = new BottomResolvedOperation(operation, instantiatedType, overrideTester);
	List<JvmTypeParameter> typeParameters = resolvedOperation.getResolvedTypeParameters();
	appendable.append("<");
	for(int i = 0; i < typeParameters.size(); i++) {
		if (i != 0) {
			appendable.append(", ");
		}
		JvmTypeParameter typeParameter = typeParameters.get(i);
		appendable.append(typeParameter.getName());
		List<LightweightTypeReference> constraints = resolvedOperation.getResolvedTypeParameterConstraints(i);
		if (!constraints.isEmpty()) {
			appendable.append(" extends ");
			for(int j = 0; j < constraints.size(); j++) {
				if (j != 0) {
					appendable.append(" & ");
				}
				appendable.append(constraints.get(j));
			}
		}
	}
	appendable.append("> ");
}
 
Example #8
Source File: ElementOrComponentTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference) {
	DeclaratorTypeArgumentCollector typeArgumentCollector = new ConstraintAwareTypeArgumentCollector(owner);
	Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping = typeArgumentCollector.getTypeParameterMapping(reference);
	TypeParameterSubstitutor<?> substitutor = new UnboundTypeParameterPreservingSubstitutor(typeParameterMapping, owner);
	JvmGenericType iterable = (JvmGenericType) owner.getServices().getTypeReferences().findDeclaredType(Iterable.class, owner.getContextResourceSet());
	if (iterable == null) {
		return owner.newReferenceToObject();
	}
	LightweightTypeReference substituteMe = owner.newParameterizedTypeReference(iterable.getTypeParameters().get(0));
	LightweightTypeReference substitutedArgument = substitutor.substitute(substituteMe).getUpperBoundSubstitute();
	if (substitutedArgument.getType() instanceof JvmTypeParameter && 
			!(owner.getDeclaredTypeParameters().contains(substitutedArgument.getType()))) {
		return substitutedArgument.getRawTypeReference();
	}
	return substitutedArgument;
}
 
Example #9
Source File: AbstractPendingLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the unresolved string representation of the given type parameter. The simple names of
 * the type bounds are used. The string representation includes the bounds, except for
 * the upper bound {@link Object}. 
 */
protected String getTypeParameterAsString(JvmTypeParameter typeParameter) {
	StringBuilder b = new StringBuilder();
	b.append(typeParameter.getName());
	ITypeReferenceOwner referenceOwner = getState().getReferenceOwner();
	if(!typeParameter.getConstraints().isEmpty()) {
		boolean firstUpperBound = true;
		for(int j=0; j<typeParameter.getConstraints().size(); ++j) {
			JvmTypeConstraint constraint = typeParameter.getConstraints().get(j);
			LightweightTypeReference typeRef = referenceOwner.toLightweightTypeReference(constraint.getTypeReference());
			if(constraint instanceof JvmUpperBound) {
				if(typeRef.isType(Object.class))
					continue;
				if (firstUpperBound) {
					b.append(" extends ");
					firstUpperBound = false;
				} else {
					b.append(" & ");
				}
			} else 
				b.append(" super ");
			b.append(typeRef.getHumanReadableName());
		}
	}
	return b.toString();
}
 
Example #10
Source File: AbstractBatchReturnTypeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getEquivalent(final ParameterizedTypeReference type) {
  StringConcatenation _builder = new StringConcatenation();
  String _simpleName = type.getType().getSimpleName();
  _builder.append(_simpleName);
  final Function1<LightweightTypeReference, CharSequence> _function = (LightweightTypeReference it) -> {
    return it.getSimpleName();
  };
  String _join = IterableExtensions.<LightweightTypeReference>join(type.getTypeArguments(), "<", ", ", ">", _function);
  _builder.append(_join);
  return _builder.toString();
}
 
Example #11
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void appendNullValueUntyped(LightweightTypeReference type, @SuppressWarnings("unused") EObject context, ITreeAppendable b) {
	if (!type.isPrimitive()) {
		b.append("null");
	} else {
		b.append(getDefaultLiteral((JvmPrimitiveType) type.getType()));
	}
}
 
Example #12
Source File: Bug661Test.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Test
public void isSubtypeOf_00() throws Exception {
	SarlScript mas0 = file(getParseHelper(), SNIPSET1);
	SarlScript mas1 = file(getParseHelper(), SNIPSET1);

	assertNotSame(mas0.eResource().getResourceSet(), mas1.eResource().getResourceSet());
	
	JvmTypeReference reference0 = this.typeReferences.getTypeForName("boolean", mas0);
	
	StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, mas1);
	LightweightTypeReference reference1 = owner.newParameterizedTypeReference(this.typeReferences.findDeclaredType("boolean", mas1));
	
	assertFalse(reference1.isSubtypeOf(reference0.getType()));
}
 
Example #13
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeXMemberFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if (model instanceof XMemberFeatureCall) {
		XExpression memberCallTarget = ((XMemberFeatureCall) model).getMemberCallTarget();
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(memberCallTarget);
		LightweightTypeReference memberCallTargetType = resolvedTypes.getActualType(memberCallTarget);
		Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(model, input -> {
			if(input instanceof JvmOperation && input.isStatic()) {
				List<JvmFormalParameter> parameters = ((JvmOperation) input).getParameters();
				if(parameters.size() > 0) {
					JvmFormalParameter firstParam = parameters.get(0);
					JvmTypeReference parameterType = firstParam.getParameterType();
					if(parameterType != null) {
						LightweightTypeReference lightweightTypeReference = memberCallTargetType.getOwner().toLightweightTypeReference(parameterType);
						if(lightweightTypeReference != null) {
							return memberCallTargetType.isAssignableFrom(lightweightTypeReference);
						}
					}
				}
			}
			return false;
		});
		// Create StaticExtensionFeatureDescriptionWithImplicitFirstArgument instead of SimpleIdentifiableElementDescription since we want the Proposal to show parameters
		Iterable<IEObjectDescription> scopedFeatures = Iterables.transform(featuresToImport, feature -> {
			QualifiedName qualifiedName = QualifiedName.create(feature.getSimpleName());
			return new StaticExtensionFeatureDescriptionWithImplicitFirstArgument(qualifiedName, feature, memberCallTarget, memberCallTargetType, 0, true);
		});
		// Scope for all static features
		IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures);
		proposeFavoriteStaticFeatures(model, context, acceptor, staticMemberScope);
		// Regular proposals
		createReceiverProposals(((XMemberFeatureCall) model).getMemberCallTarget(), (CrossReference) assignment.getTerminal(),
				context, acceptor);
	} else if (model instanceof XAssignment) {
		createReceiverProposals(((XAssignment) model).getAssignable(), (CrossReference) assignment.getTerminal(),
				context, acceptor);
	}
}
 
Example #14
Source File: TypeComputationStateWithExpectation.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractTypeExpectation createTypeExpectation(/* @Nullable */ LightweightTypeReference expectedType, AbstractTypeComputationState actualState, boolean returnType) {
	AbstractTypeExpectation result = null;
	if (expectedType != null) {
		LightweightTypeReference copied = expectedType.copyInto(actualState.getReferenceOwner());
		result = new TypeExpectation(copied, actualState, returnType);
	} else {
		result = new NoExpectation(actualState, returnType);
	}
	return result;
}
 
Example #15
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void addNonRecursiveHints(List<LightweightBoundTypeArgument> hints, Set<Object> seenHandles,
		List<LightweightBoundTypeArgument> result) {
	for(LightweightBoundTypeArgument hint: hints) {
		LightweightTypeReference reference = hint.getTypeReference();
		if (reference instanceof UnboundTypeReference) {
			addNonRecursiveHints(hint, (UnboundTypeReference)reference, seenHandles, result);
		} else {
			if (!result.contains(hint))
				result.add(hint);
		}
	}
}
 
Example #16
Source File: DispatchOperationBodyComputationState.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public DispatchOperationBodyComputationState(
		ResolvedTypes resolvedTypes, 
		IFeatureScopeSession featureScopeSession,
		JvmOperation operation,
		JvmOperation dispatcher,
		/* @Nullable */ LightweightTypeReference inheritedExpectedType) {
	super(resolvedTypes, featureScopeSession, operation);
	this.dispatcher = dispatcher;
	this.inheritedExpectedType = inheritedExpectedType;
}
 
Example #17
Source File: AbstractTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected LightweightTypeReference getTypeForName(Class<?> clazz, ITypeComputationState state) {
	JvmType type = findDeclaredType(clazz, state);
	ITypeReferenceOwner owner = state.getReferenceOwner();
	if (type == null) {
		return owner.newUnknownTypeReference(clazz.getName());
	}
	return owner.toLightweightTypeReference(type);
}
 
Example #18
Source File: UtilsTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static LightweightTypeReference mockLightweightTypeReference(Class<?> type) {
	final JvmGenericType jvmtype = mock(JvmGenericType.class);
	when(jvmtype.isInterface()).thenReturn(type.isInterface());
	when(jvmtype.isAbstract()).thenReturn(Modifier.isAbstract(type.getModifiers()));
	when(jvmtype.isFinal()).thenReturn(Modifier.isFinal(type.getModifiers()));
	final LightweightTypeReference reference = mock(LightweightTypeReference.class);
	when(reference.getType()).thenReturn(jvmtype);
	return reference;
}
 
Example #19
Source File: ContextualVisibilityHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public ContextualVisibilityHelper(IVisibilityHelper parent, LightweightTypeReference contextType) {
	this.parent = parent;
	this.rawContextType = contextType.getRawTypeReference().getType();
	if (rawContextType instanceof JvmDeclaredType) {
		this.packageName = ((JvmDeclaredType) rawContextType).getPackageName();
	}
}
 
Example #20
Source File: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected int addHintAndAnnounceSuccess(UnboundTypeReference left, LightweightTypeReference hint,
		int flags) {
	if (hint instanceof WildcardTypeReference) {
		List<LightweightTypeReference> bounds = ((WildcardTypeReference) hint).getUpperBounds();
		for(LightweightTypeReference upperBound: bounds)
			left.acceptHint(upperBound, BoundTypeArgumentSource.INFERRED, this, VarianceInfo.OUT, VarianceInfo.OUT);
	} else {
		left.acceptHint(hint, BoundTypeArgumentSource.INFERRED, this, VarianceInfo.OUT, VarianceInfo.OUT);
	}
	return flags | SUCCESS;
}
 
Example #21
Source File: AssignmentFeatureCallArgumentsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected AssignmentFeatureCallArguments toArguments(final String type, final String expression) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def void m(");
    _builder.append(type);
    _builder.append(") {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append(expression, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    final String functionString = _builder.toString();
    final XtendFunction function = this.function(functionString);
    XExpression _expression = function.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    final XExpression value = IterableExtensions.<XExpression>head(body.getExpressions());
    JvmFormalParameter _head = IterableExtensions.<JvmFormalParameter>head(this._iXtendJvmAssociations.getDirectlyInferredOperation(function).getParameters());
    JvmTypeReference _parameterType = null;
    if (_head!=null) {
      _parameterType=_head.getParameterType();
    }
    final JvmTypeReference declaredType = _parameterType;
    if ((declaredType != null)) {
      LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(declaredType);
      return new AssignmentFeatureCallArguments(value, _lightweightTypeReference);
    } else {
      return new AssignmentFeatureCallArguments(value, null);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #22
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Map<JvmIdentifiableElement, LightweightTypeReference> getFlattenedReassignedTypes() {
	if (reassignedTypes == null || reassignedTypes.isEmpty()) {
		return null;
	}
	if (reassignedTypes.size() == 1) {
		Map.Entry<JvmIdentifiableElement, LightweightTypeReference> singleEntry = reassignedTypes.entrySet().iterator().next();
		return Collections.singletonMap(singleEntry.getKey(), singleEntry.getValue());
	}
	return new HashMap<JvmIdentifiableElement, LightweightTypeReference>(reassignedTypes);
}
 
Example #23
Source File: ValidatingReassigningResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public LightweightTypeReference getMergedType(List<LightweightTypeReference> types) {
	for (LightweightTypeReference it : types) {
		if (!it.isOwnedBy(it.getOwner())) {
			throw new IllegalArgumentException("result is not owned by this resolved types");
		}
	}
	LightweightTypeReference result = super.getMergedType(types);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #24
Source File: ValidatingReassigningResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public LightweightTypeReference getExpectedType(XExpression expression) {
	LightweightTypeReference result = super.getExpectedType(expression);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #25
Source File: ValidatingRootResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void reassignType(JvmIdentifiableElement identifiable, LightweightTypeReference reference) {
	if (reference != null && !reference.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("reference is not owned by this resolved types");
	}
	super.reassignType(identifiable, reference);
}
 
Example #26
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void createExceptionMismatchError(IResolvedOperation operation, EObject sourceElement,
		List<IResolvedOperation> exceptionMismatch) {
	List<LightweightTypeReference> exceptions = operation.getIllegallyDeclaredExceptions();
	StringBuilder message = new StringBuilder(100);
	message.append("The declared exception");
	if (exceptions.size() > 1) {
		message.append('s');
	}
	message.append(' ');
	for(int i = 0; i < exceptions.size(); i++) {
		if (i != 0) {
			if (i != exceptions.size() - 1)
				message.append(", ");
			else
				message.append(" and ");
		}
		message.append(exceptions.get(i).getHumanReadableName());
	}
	if (exceptions.size() > 1) {
		message.append(" are");
	} else {
		message.append(" is");
	}
	message.append(" not compatible with throws clause in ");
	for(int i = 0; i < exceptionMismatch.size(); i++) {
		if (i != 0) {
			if (i != exceptionMismatch.size() - 1)
				message.append(", ");
			else
				message.append(" and ");
		}
		IResolvedOperation resolvedOperation = exceptionMismatch.get(i);
		message.append(getDeclaratorName(resolvedOperation));
		message.append('.');
		message.append(exceptionMismatch.get(i).getSimpleSignature());
	}
	error(message.toString(), sourceElement, exceptionsFeature(sourceElement), INCOMPATIBLE_THROWS_CLAUSE);
}
 
Example #27
Source File: CreateMemberQuickfixes.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void newFieldQuickfix(String name, XAbstractFeatureCall call, 
		final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
	JvmDeclaredType callersType = getCallersType(call);
	LightweightTypeReference receiverType = getReceiverType(call);
	LightweightTypeReference fieldType = getNewMemberType(call);
	if(callersType != null && receiverType != null && callersType == receiverType.getType()) 
		newFieldQuickfix(callersType, name, fieldType, isStaticAccess(call), call, issue, issueResolutionAcceptor);
}
 
Example #28
Source File: CommonSuperTypeTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isPrimitiveOrVoid(final LightweightTypeReference computedSuperType) {
  boolean _xblockexpression = false;
  {
    if ((computedSuperType == null)) {
      return false;
    }
    _xblockexpression = (computedSuperType.isPrimitiveVoid() || computedSuperType.isPrimitive());
  }
  return _xblockexpression;
}
 
Example #29
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testTypeParameterReference_12() throws Exception {
	XtendFunction func = (XtendFunction) ((XtendClass)file("class X<Z> implements Iterable<Z> { def Iterable<String> foo() { val result = new X return result }}")
			.getXtendTypes().get(0)).getMembers().get(0);
	JvmOperation operation = associator.getDirectlyInferredOperation(func);
	JvmTypeReference returnType = operation.getReturnType();
	assertEquals("java.lang.Iterable<java.lang.String>", returnType.getIdentifier());
	LightweightTypeReference bodyType = getType(func.getExpression());
	assertEquals("void", bodyType.getIdentifier());
	LightweightTypeReference bodyReturnType = getReturnType(func.getExpression());
	assertEquals("X<java.lang.String>", bodyReturnType.getIdentifier());
}
 
Example #30
Source File: DeferredTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitTypeReference(LightweightTypeReference reference, UnboundTypeReference declaration) {
	if (declaration.internalIsResolved() || getOwner().isResolved(declaration.getHandle())) {
		declaration.tryResolve();
		outerVisit(declaration, reference, declaration, getExpectedVariance(), getActualVariance());
	} else if (reference.isValidHint()) {
		addHint(declaration, reference);
	}
}