Java Code Examples for org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures#getDeclaredOperations()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures#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: ResolvedFeaturesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAllOperationsIncludeDeclaredOperations() { final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class); final List<IResolvedOperation> declared = resolvedOperations.getDeclaredOperations(); final List<IResolvedOperation> all = resolvedOperations.getAllOperations(); Assert.assertFalse(all.isEmpty()); Assert.assertEquals(1, declared.size()); Assert.assertSame(IterableExtensions.<IResolvedOperation>head(declared), IterableExtensions.<IResolvedOperation>head(all)); }
Example 2
Source File: ResolvedFeaturesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testDeclaredOperationsAreIncludedInAllOperations() { final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class); final List<IResolvedOperation> all = resolvedOperations.getAllOperations(); final List<IResolvedOperation> declared = resolvedOperations.getDeclaredOperations(); Assert.assertFalse(all.isEmpty()); Assert.assertEquals(1, declared.size()); Assert.assertSame(IterableExtensions.<IResolvedOperation>head(declared), IterableExtensions.<IResolvedOperation>head(all)); }
Example 3
Source File: ResolvedFeaturesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testDeclaredOperationsErasedSignatureAreIncludedInAllOperations() { final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class); final List<IResolvedOperation> all = resolvedOperations.getAllOperations(ResolvedFeaturesTest.DERIVED_CLASS_METHOD_ERASED_SIGNATURE); final List<IResolvedOperation> declared = resolvedOperations.getDeclaredOperations(ResolvedFeaturesTest.DERIVED_CLASS_METHOD_ERASED_SIGNATURE); Assert.assertFalse(all.isEmpty()); Assert.assertEquals(1, declared.size()); Assert.assertSame(IterableExtensions.<IResolvedOperation>head(declared), IterableExtensions.<IResolvedOperation>head(all)); }
Example 4
Source File: ResolvedFeaturesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testAllOperationsErasedSignatureIncludeDeclaredOperations() { final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class); final List<IResolvedOperation> declared = resolvedOperations.getDeclaredOperations(ResolvedFeaturesTest.DERIVED_CLASS_METHOD_ERASED_SIGNATURE); final List<IResolvedOperation> all = resolvedOperations.getAllOperations(ResolvedFeaturesTest.DERIVED_CLASS_METHOD_ERASED_SIGNATURE); Assert.assertFalse(all.isEmpty()); Assert.assertEquals(1, declared.size()); Assert.assertSame(IterableExtensions.<IResolvedOperation>head(declared), IterableExtensions.<IResolvedOperation>head(all)); }
Example 5
Source File: AbstractXtendOutlineTreeBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void buildInheritedMembers(final JvmDeclaredType inferredType, final IXtendOutlineContext context) { ResourceSet _resourceSet = inferredType.eResource().getResourceSet(); final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, _resourceSet); final LightweightTypeReference typeReference = owner.toLightweightTypeReference(inferredType); final List<LightweightTypeReference> superTypes = typeReference.getAllSuperTypes(); IXtendOutlineContext superTypeContext = context; for (final LightweightTypeReference superTypeRef : superTypes) { { superTypeContext = superTypeContext.increaseInheritanceDepth(); final ResolvedFeatures resolvedFeatures = new ResolvedFeatures(superTypeRef); List<IResolvedField> _declaredFields = resolvedFeatures.getDeclaredFields(); for (final IResolvedField jvmField : _declaredFields) { boolean _skipFeature = this.skipFeature(jvmField.getDeclaration()); boolean _not = (!_skipFeature); if (_not) { this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, jvmField, superTypeContext); } } List<IResolvedConstructor> _declaredConstructors = resolvedFeatures.getDeclaredConstructors(); for (final IResolvedConstructor constructor : _declaredConstructors) { boolean _skipFeature_1 = this.skipFeature(constructor.getDeclaration()); boolean _not_1 = (!_skipFeature_1); if (_not_1) { this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, constructor, superTypeContext); } } List<IResolvedOperation> _declaredOperations = resolvedFeatures.getDeclaredOperations(); for (final IResolvedOperation operation : _declaredOperations) { if (((!this.skipFeature(operation.getDeclaration())) && (!superTypeContext.isProcessed(operation.getDeclaration())))) { this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, operation, superTypeContext); } } final JvmType declaredType = superTypeRef.getType(); if ((declaredType instanceof JvmDeclaredType)) { final IXtendOutlineContext nestedTypeContext = superTypeContext.hideInherited(); final Consumer<JvmDeclaredType> _function = (JvmDeclaredType it) -> { this.buildJvmType(it, nestedTypeContext); }; Iterables.<JvmDeclaredType>filter(((JvmDeclaredType)declaredType).getMembers(), JvmDeclaredType.class).forEach(_function); } } } }
Example 6
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void doCheckOverriddenMethods(XtendTypeDeclaration xtendType, JvmGenericType inferredType, ResolvedFeatures resolvedFeatures, Set<EObject> flaggedOperations) { List<IResolvedOperation> operationsMissingImplementation = null; boolean doCheckAbstract = !inferredType.isAbstract(); if (doCheckAbstract) { operationsMissingImplementation = Lists.newArrayList(); } IVisibilityHelper visibilityHelper = new ContextualVisibilityHelper(this.visibilityHelper, resolvedFeatures.getType()); boolean flaggedType = false; for (IResolvedOperation operation : resolvedFeatures.getAllOperations()) { JvmDeclaredType operationDeclaringType = operation.getDeclaration().getDeclaringType(); if (operationDeclaringType != inferredType) { if (operationsMissingImplementation != null && operation.getDeclaration().isAbstract()) { operationsMissingImplementation.add(operation); } if (visibilityHelper.isVisible(operation.getDeclaration())) { String erasureSignature = operation.getResolvedErasureSignature(); List<IResolvedOperation> declaredOperationsWithSameErasure = resolvedFeatures.getDeclaredOperations(erasureSignature); for (IResolvedOperation localOperation : declaredOperationsWithSameErasure) { if (!localOperation.isOverridingOrImplementing(operation.getDeclaration()).isOverridingOrImplementing()) { EObject source = findPrimarySourceElement(localOperation); if (operation.getDeclaration().isStatic() && !localOperation.getDeclaration().isStatic()) { if (!isInterface(operationDeclaringType)) { if (flaggedOperations.add(source)) { error("The instance method " + localOperation.getSimpleSignature() + " cannot override the static method " + operation.getSimpleSignature() + " of type " + getDeclaratorName(operation.getDeclaration()) + ".", source, nameFeature(source), DUPLICATE_METHOD); } } } else if (!operation.getDeclaration().isStatic() && localOperation.getDeclaration().isStatic()) { if (flaggedOperations.add(source)) { error("The static method " + localOperation.getSimpleSignature() + " cannot hide the instance method " + operation.getSimpleSignature() + " of type " + getDeclaratorName(operation.getDeclaration()) + ".", source, nameFeature(source), DUPLICATE_METHOD); } } else if (flaggedOperations.add(source)) { error("Name clash: The method " + localOperation.getSimpleSignature() + " of type " + inferredType.getSimpleName() + " has the same erasure as " + operation.getSimpleSignature() + " of type " + getDeclaratorName(operation.getDeclaration()) + " but does not override it.", source, nameFeature(source), DUPLICATE_METHOD); } } } if (operation instanceof ConflictingDefaultOperation && contributesToConflict(inferredType, (ConflictingDefaultOperation) operation) && !flaggedType) { IResolvedOperation conflictingOperation = ((ConflictingDefaultOperation) operation).getConflictingOperations() .get(0); // Include the declaring class in the issue code in order to give better quick fixes String[] uris = new String[] { getDeclaratorName(operation.getDeclaration()) + "|" + EcoreUtil.getURI(operation.getDeclaration()).toString(), getDeclaratorName(conflictingOperation.getDeclaration()) + "|" + EcoreUtil.getURI(conflictingOperation.getDeclaration()).toString() }; if (!operation.getDeclaration().isAbstract() && !conflictingOperation.getDeclaration().isAbstract()) { error("The type " + inferredType.getSimpleName() + " inherits multiple implementations of the method " + conflictingOperation.getSimpleSignature() + " from " + getDeclaratorName(conflictingOperation.getDeclaration()) + " and " + getDeclaratorName(operation.getDeclaration()) + ".", xtendType, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, CONFLICTING_DEFAULT_METHODS, uris); } else { // At least one of the operations is non-abstract IResolvedOperation abstractOp, nonabstractOp; if (operation.getDeclaration().isAbstract()) { abstractOp = operation; nonabstractOp = conflictingOperation; } else { abstractOp = conflictingOperation; nonabstractOp = operation; } error("The non-abstract method " + nonabstractOp.getSimpleSignature() + " inherited from " + getDeclaratorName(nonabstractOp.getDeclaration()) + " conflicts with the method " + abstractOp.getSimpleSignature() + " inherited from " + getDeclaratorName(abstractOp.getDeclaration()) + ".", xtendType, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, CONFLICTING_DEFAULT_METHODS, uris); } flaggedType = true; } } } } if (operationsMissingImplementation != null && !operationsMissingImplementation.isEmpty() && !flaggedType) { reportMissingImplementations(xtendType, inferredType, operationsMissingImplementation); } }
Example 7
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void doCheckFunctionOverrides(ResolvedFeatures resolvedFeatures, Set<EObject> flaggedOperations) { for(IResolvedOperation operation: resolvedFeatures.getDeclaredOperations()) { doCheckFunctionOverrides(operation, flaggedOperations); } }