Java Code Examples for org.eclipse.xtext.common.types.JvmDeclaredType#getDeclaredOperations()

The following examples show how to use org.eclipse.xtext.common.types.JvmDeclaredType#getDeclaredOperations() . 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: ResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void computeAllOperations(JvmDeclaredType type, Multimap<String, AbstractResolvedOperation> processedOperations) {
	for (JvmOperation operation: type.getDeclaredOperations()) {
		boolean addToResult = true;
		if (targetVersion.isAtLeast(JavaVersion.JAVA8)) {
			addToResult = handleOverridesAndConflicts(operation, processedOperations);
		} 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);
		}
	}
}
 
Example 2
Source File: DispatchHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Computes all the dispatch methods that are declared in the given type or altered
 * by additional cases in this type. The associated operations are sorted by according their parameter types
 * from left to right where the most special types occur before more common types. Ambiguous
 * ordering is resolved alphabetically.
 * 
    * An exemplary order would look like this
 * <pre>
 *   method(String)
 *   method(Serializable)
 *   method(CharSequence)
 *   method(Object)
 * </pre>
 * 
 * @return a mapping from {@link DispatchSignature signature} to sorted operations.
 */
public ListMultimap<DispatchSignature, JvmOperation> getDeclaredOrEnhancedDispatchMethods(JvmDeclaredType type) {
	ListMultimap<DispatchSignature, JvmOperation> result = Multimaps2.newLinkedHashListMultimap(2,4);
	Iterable<JvmOperation> operations = type.getDeclaredOperations();
	ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type);
	ContextualVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper, owner.newParameterizedTypeReference(type));
	for(JvmOperation operation: operations) {
		if (isDispatchFunction(operation)) {
			DispatchSignature signature = new DispatchSignature(operation.getSimpleName().substring(1), operation.getParameters().size());
			if (!result.containsKey(signature)) {
				List<JvmOperation> allOperations = getAllDispatchMethods(signature, type,
						contextualVisibilityHelper);
				result.putAll(signature, allOperations);
			}
		}
	}
	return result;
}
 
Example 3
Source File: Jdt2Ecore.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create the JvmOperation for the given JDT method.
 *
 * @param method the JDT method.
 * @param context the context of the constructor.
 * @return the JvmOperation
 * @throws JavaModelException if the Java model is invalid.
 */
private JvmOperation getJvmOperation(IMethod method, JvmType context)
		throws JavaModelException {
	if (context instanceof JvmDeclaredType) {
		final JvmDeclaredType declaredType = (JvmDeclaredType) context;
		final ActionParameterTypes jdtSignature = this.actionPrototypeProvider.createParameterTypes(
				Flags.isVarargs(method.getFlags()),
				getFormalParameterProvider(method));
		for (final JvmOperation jvmOperation : declaredType.getDeclaredOperations()) {
			final ActionParameterTypes jvmSignature = this.actionPrototypeProvider.createParameterTypesFromJvmModel(
					jvmOperation.isVarArgs(),
					jvmOperation.getParameters());
			if (jvmSignature.equals(jdtSignature)) {
				return jvmOperation;
			}
		}
	}
	return null;
}
 
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: PyGenerator.java    From sarl with Apache License 2.0 6 votes vote down vote up
private void computeCapacityFunctionMarkers(JvmDeclaredType leafType) {
	final Map<JvmOperation, String> mapping = new HashMap<>();
	final LinkedList<JvmDeclaredType> buffer = new LinkedList<>();
	final Set<String> processed = new TreeSet<>();
	buffer.addLast(leafType);
	while (!buffer.isEmpty()) {
		final JvmDeclaredType type = buffer.removeFirst();
		boolean markOne = false;
		for (final JvmOperation operation : type.getDeclaredOperations()) {
			if (!mapping.containsKey(operation)) {
				markOne = true;
				mapping.put(operation, "getSkill(" + type.getSimpleName() //$NON-NLS-1$
					+ ")." + operation.getSimpleName()); //$NON-NLS-1$
			}
		}
		if (markOne) {
			for (final JvmTypeReference superTypeReference : type.getExtendedInterfaces()) {
				if (processed.add(superTypeReference.getIdentifier())
					&& superTypeReference.getType() instanceof JvmDeclaredType) {
					buffer.addLast((JvmDeclaredType) superTypeReference.getType());
				}
			}
		}
	}
	this.useCapacityMapping = mapping;
}
 
Example 6
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAbstractMethod() throws Exception {
	String typeName = AbstractMethods.class.getName();
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	assertEquals(3, size(type.getDeclaredOperations()));
	for (JvmOperation op : type.getDeclaredOperations()) {
		if (op.getSimpleName().startsWith("abstract")) {
			assertTrue(op.isAbstract());
		} else {
			assertFalse(op.isAbstract());
		}
	}
}
 
Example 7
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAbstractMethod() throws Exception {
	String typeName = AbstractMethods.class.getName();
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	assertEquals(3, size(type.getDeclaredOperations()));
	for (JvmOperation op : type.getDeclaredOperations()) {
		if (op.getSimpleName().startsWith("abstract")) {
			assertTrue(op.isAbstract());
		} else {
			assertFalse(op.isAbstract());
		}
	}
}
 
Example 8
Source File: IndexedJvmTypeAccessTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private JvmOperation getOperation(JvmDeclaredType type, String name) {
	for (JvmOperation op : type.getDeclaredOperations()) {
		if (name.equals(op.getSimpleName())) {
			return op;
		}
	}
	return null;
}
 
Example 9
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAbstractMethod() throws Exception {
	String typeName = AbstractMethods.class.getName();
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	assertEquals(3, size(type.getDeclaredOperations()));
	for (JvmOperation op : type.getDeclaredOperations()) {
		if (op.getSimpleName().startsWith("abstract")) {
			assertTrue(op.isAbstract());
		} else {
			assertFalse(op.isAbstract());
		}
	}
}
 
Example 10
Source File: SARLReentrantTypeResolver.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static JvmOperation findOperation(JvmDeclaredType type, String operationName) {
	// For capacity call redirection
	for (final JvmOperation declaredOperation : type.getDeclaredOperations()) {
		if (declaredOperation.getSimpleName().equals(operationName)) {
			return declaredOperation;
		}
	}
	return null;
}