org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation. 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: 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 #2
Source File: AbstractOverloadedInstanceMethodTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void linksTo(final String invocation, final String method) {
  try {
    final XtendFile file = this.file(this.inMethodBody(invocation), false);
    XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    final XtendClass c = ((XtendClass) _head);
    XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
    final XtendFunction m = ((XtendFunction) _head_1);
    XExpression _expression = m.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
    final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
    JvmIdentifiableElement _feature = featureCall.getFeature();
    final JvmOperation operation = ((JvmOperation) _feature);
    final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
    final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
    final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
    Assert.assertEquals(method, resolved.getSimpleSignature());
    Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
    Assert.assertNotNull(featureCall.getImplicitReceiver());
    Assert.assertNull(featureCall.getImplicitFirstArgument());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #3
Source File: AbstractOverloadedStaticMethodTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void linksTo(final String invocation, final String method) {
  try {
    final XtendFile file = this.file(this.inMethodBody(invocation), false);
    XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    final XtendClass c = ((XtendClass) _head);
    XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
    final XtendFunction m = ((XtendFunction) _head_1);
    XExpression _expression = m.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
    final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
    JvmIdentifiableElement _feature = featureCall.getFeature();
    final JvmOperation operation = ((JvmOperation) _feature);
    final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
    final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
    final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
    Assert.assertEquals(method, resolved.getSimpleSignature());
    Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
    Assert.assertNull(featureCall.getImplicitReceiver());
    Assert.assertNull(featureCall.getImplicitFirstArgument());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #4
Source File: Bug621ResolvedFeatures.java    From sarl with Apache License 2.0 6 votes vote down vote up
protected void computeAllOperations(boolean isSuperClassBranch, Multimap<String, AbstractResolvedOperation> superClassBranchOperations,
		JvmDeclaredType type, Multimap<String, AbstractResolvedOperation> processedOperations) {
	for (JvmOperation operation: type.getDeclaredOperations()) {
		boolean addToResult = true;
		if (targetVersion.isAtLeast(JavaVersion.JAVA8)) {
			addToResult = handleOverridesAndConflicts(isSuperClassBranch, operation, processedOperations, superClassBranchOperations);
		} else {
			String simpleName = operation.getSimpleName();
			if (processedOperations.containsKey(simpleName)) {
				addToResult = !isOverridden(operation, processedOperations.get(simpleName));
			}
		}
		if (addToResult) {
			BottomResolvedOperation resolvedOperation = createResolvedOperation(operation);
			processedOperations.put(operation.getSimpleName(), resolvedOperation);
			if (isSuperClassBranch) {
				superClassBranchOperations.put(operation.getSimpleName(), resolvedOperation);
			}
		}
	}
}
 
Example #5
Source File: ExtendedEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IResolvedExecutable getResolvedFeature(JvmExecutable executable, LightweightTypeReference contextType) {
	if (executable instanceof JvmOperation) {
		return new BottomResolvedOperation((JvmOperation) executable, contextType, overrideTester);
	}
	if (executable instanceof JvmConstructor) {
		return new ResolvedConstructor((JvmConstructor) executable, contextType);
	}
	throw new IllegalArgumentException(String.valueOf(executable));
}
 
Example #6
Source File: ResolvedOperationTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public IResolvedOperation toOperation(final String expression) {
  try {
    XExpression _expression = this.expression(expression);
    final XMemberFeatureCall featureCall = ((XMemberFeatureCall) _expression);
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(featureCall);
    final LightweightTypeReference receiverType = resolvedTypes.getActualType(featureCall.getMemberCallTarget());
    JvmIdentifiableElement _feature = featureCall.getFeature();
    final JvmOperation operation = ((JvmOperation) _feature);
    Assert.assertFalse(operation.eIsProxy());
    return new BottomResolvedOperation(operation, receiverType, this.overrideTester);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #7
Source File: SuperMemberImplementorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void checkOverrideMethodCode(String operationName, String overrideCode) {
	StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
	LightweightTypeReference contextType = getContextType();
	IResolvedOperation resolvedOperation = new BottomResolvedOperation((JvmOperation) findExecutable(implementedInterface, operationName), contextType, new OverrideTester());
	implementor.appendOverrideFunction(xtendClass, resolvedOperation, appendable);
	String code = appendable.toString();
	if (!equalsIgnoreWhitespace(overrideCode, code))
		assertEquals(overrideCode, code);
}
 
Example #8
Source File: XtendReentrantTypeResolver.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected LightweightTypeReference getReturnTypeOfOverriddenOperation(JvmOperation operation,
		ResolvedTypes resolvedTypes, IFeatureScopeSession session) {
	if (operation.getVisibility() == JvmVisibility.PRIVATE)
		return null;
	if (InferredTypeIndicator.isInferred(operation.getReturnType())) {
		LightweightTypeReference declaringType = resolvedTypes.getActualType(operation.getDeclaringType());
		if (declaringType == null) {
			throw new IllegalStateException("Cannot determine declaring type of operation: " + operation);
		}
		BottomResolvedOperation resolvedOperation = new BottomResolvedOperation(operation, declaringType, overrideTester);
		List<IResolvedOperation> overriddenMethods = resolvedOperation.getOverriddenAndImplementedMethods();
		if (overriddenMethods.isEmpty())
			return null;
		IResolvedOperation overriddenMethod = overriddenMethods.get(0);
		JvmOperation declaration = overriddenMethod.getDeclaration();
		XExpression inferredFrom = getInferredFrom(declaration.getReturnType());
		// guard against active annotations that put an expression into a second method
		// namely in a synthesized super type - in that case, the expression should not be
		// inferred in the context of the super type but the subtype thus the return type
		// of a super method has to be ignored
		
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=439535
		if (inferredFrom != null && (inferredFrom == getInferredFrom(operation.getReturnType()) || isHandled(inferredFrom))) {
			return null;
		}
		LightweightTypeReference result = overriddenMethod.getResolvedReturnType();
		return result;
	}
	return null;
}