Java Code Examples for org.eclipse.xtext.common.types.JvmOperation#getIdentifier()

The following examples show how to use org.eclipse.xtext.common.types.JvmOperation#getIdentifier() . 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: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
protected void _computeTypes(Map<JvmIdentifiableElement, ResolvedTypes> preparedResolvedTypes, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmOperation operation) {
	ResolvedTypes childResolvedTypes = preparedResolvedTypes.get(operation);
	if (childResolvedTypes == null) {
		if (preparedResolvedTypes.containsKey(operation))
			return;
		throw new IllegalStateException("No resolved type found. Operation was: " + operation.getIdentifier());
	} else {
		preparedResolvedTypes.put(operation, null);
	}
	OperationBodyComputationState state = new OperationBodyComputationState(childResolvedTypes, operation.isStatic() ? featureScopeSession : featureScopeSession.toInstanceContext(), operation);
	addExtensionProviders(state, operation.getParameters());
	markComputing(operation.getReturnType());
	try {
		state.computeTypes();
	} finally {
		unmarkComputing(operation.getReturnType());
	}
	computeAnnotationTypes(childResolvedTypes, featureScopeSession, operation);
	computeLocalTypes(preparedResolvedTypes, childResolvedTypes, featureScopeSession, operation);
	mergeChildTypes(childResolvedTypes);
}
 
Example 2
Source File: ResolvedOperationTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testListToArrayHasTwoOrThreeCandidates() {
  final IResolvedOperation operation = this.toOperation("(null as java.util.List<String>).toArray(null)");
  final List<JvmOperation> candidates = operation.getOverriddenAndImplementedMethodCandidates();
  final Function1<JvmOperation, String> _function = (JvmOperation it) -> {
    return it.getIdentifier();
  };
  final String message = IterableExtensions.join(ListExtensions.<JvmOperation, String>map(candidates, _function), ", ");
  try {
    Assert.assertEquals(message, 2, candidates.size());
  } catch (final Throwable _t) {
    if (_t instanceof AssertionError) {
      Assert.assertEquals(message, 3, candidates.size());
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example 3
Source File: DispatchHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected int compare(JvmOperation o1, JvmOperation o2) {
	int params = o1.getParameters().size();
	for (int i = 0; i < params; i++) {
		final JvmTypeReference p1 = o1.getParameters().get(i).getParameterType();
		final JvmTypeReference p2 = o2.getParameters().get(i).getParameterType();
		int distance1 = p1 == null ? Integer.MAX_VALUE : getMaxDistanceToObject(p1);
		int distance2 = p2 == null ? Integer.MAX_VALUE : getMaxDistanceToObject(p2);
		if (distance1 != distance2) {
			return distance2 - distance1;
		}
	}
	String identifier1 = o1.getIdentifier();
	String parameterTypes1 = identifier1.substring(identifier1.indexOf('('));
	String identifier2 = o2.getIdentifier();
	String parameterTypes2 = identifier2.substring(identifier2.indexOf('('));
	return parameterTypes1.compareTo(parameterTypes2);
}
 
Example 4
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static boolean isCalledOperation(JvmOperation operation, List<InferredPrototype> prototypes) {
	final String container = operation.getDeclaringType().getQualifiedName();
	for (final InferredPrototype prototype : prototypes) {
		if (Strings.equal(container, prototype.getActionName().getDeclaringType().getIdentifier())
				&& Strings.equal(operation.getSimpleName(), prototype.getActionName().getActionName())) {
			final String prefix = container + "."; //$NON-NLS-1$
			final String operationId = operation.getIdentifier();
			for (final ActionParameterTypes types : prototype.getParameterTypeAlternatives()) {
				String name = prefix + types.toActionPrototype(operation.getSimpleName()).toString();
				if (Strings.equal(operationId, name)) {
					return true;
				}
				name = prefix + types.toRawActionPrototype(operation.getSimpleName()).toString();
				if (Strings.equal(operationId, name)) {
					return true;
				}
			}
		}
	}
	return false;
}