Java Code Examples for org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation#getDeclaration()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation#getDeclaration() . 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: ResolvedOperationTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testVarArgsMismatch_01() {
  final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).withVarArgs(null)");
  JvmOperation _declaration = operation.getDeclaration();
  _declaration.setVisibility(JvmVisibility.PROTECTED);
  final Consumer<JvmOperation> _function = (JvmOperation it) -> {
    it.setVisibility(JvmVisibility.PUBLIC);
  };
  operation.getOverriddenAndImplementedMethodCandidates().forEach(_function);
  this.withDetails(this.candidatesAndOverrides(this.has(operation, 1), 1), IOverrideCheckResult.OverrideCheckDetails.REDUCED_VISIBILITY, IOverrideCheckResult.OverrideCheckDetails.VAR_ARG_MISMATCH);
}
 
Example 2
Source File: ResolvedOperationTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testVarArgsMismatch_02() {
  final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).withArray(null)");
  JvmOperation _declaration = operation.getDeclaration();
  _declaration.setVisibility(JvmVisibility.PROTECTED);
  final Consumer<JvmOperation> _function = (JvmOperation it) -> {
    it.setVisibility(JvmVisibility.DEFAULT);
  };
  operation.getOverriddenAndImplementedMethodCandidates().forEach(_function);
  this.withDetails(this.candidatesAndOverrides(this.has(operation, 1), 1), IOverrideCheckResult.OverrideCheckDetails.VAR_ARG_MISMATCH);
}
 
Example 3
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;
}