Java Code Examples for org.eclipse.xtext.resource.IEObjectDescription#getEObjectOrProxy()
The following examples show how to use
org.eclipse.xtext.resource.IEObjectDescription#getEObjectOrProxy() .
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: TestLanguageReferenceUpdater.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public void updateReference(ITextRegionDiffBuilder rewriter, IUpdatableReference ref) { if (rewriter.isModified(ref.getReferenceRegion())) { return; } IScope scope = scopeProvider.getScope(ref.getSourceEObject(), ref.getEReference()); ISemanticRegion region = ref.getReferenceRegion(); QualifiedName oldName = nameConverter.toQualifiedName(region.getText()); IEObjectDescription oldDesc = scope.getSingleElement(oldName); if (oldDesc != null && oldDesc.getEObjectOrProxy() == ref.getTargetEObject()) { return; } String newName = findValidName(ref, scope); if (newName != null) { if (oldName.getSegmentCount() > 1) { newName = oldName.skipLast(1).append(newName).toString(); } rewriter.replace(region, newName); } }
Example 2
Source File: IndexedJvmTypeAccess.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Read and resolve the EObject from the given description and navigate to its children according * to the given fragment. * @since 2.8 */ protected EObject getAccessibleType(IEObjectDescription description, String fragment, ResourceSet resourceSet) throws UnknownNestedTypeException { EObject typeProxy = description.getEObjectOrProxy(); if (typeProxy.eIsProxy()) { typeProxy = EcoreUtil.resolve(typeProxy, resourceSet); } if (!typeProxy.eIsProxy() && typeProxy instanceof JvmType) { if (fragment != null) { EObject result = resolveJavaObject((JvmType) typeProxy, fragment); if (result != null) return result; } else return typeProxy; } return null; }
Example 3
Source File: VisibilityAwareIdentifiableScope.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected boolean isAccepted(IEObjectDescription description) { if (TVariable.class.isAssignableFrom(description.getEClass().getInstanceClass())) { EObject proxyOrInstance = description.getEObjectOrProxy(); if (proxyOrInstance instanceof TVariable && !proxyOrInstance.eIsProxy()) { TVariable type = (TVariable) proxyOrInstance; TypeVisibility visibility = checker.isVisible(this.contextResource, type); if (!visibility.visibility) { this.accessModifierSuggestionStore.put(description.getEObjectURI().toString(), visibility.accessModifierSuggestion); } return visibility.visibility; } } return super.isAccepted(description); }
Example 4
Source File: AbstractScope.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public final Iterable<IEObjectDescription> getElements(EObject object) { if (!(object instanceof JvmType) || object.eIsProxy()) { throw new IllegalArgumentException(String.valueOf(object)); } List<IEObjectDescription> result = Lists.newLinkedList(); doGetElements((JvmType) object, result); Iterator<IEObjectDescription> iterator = result.iterator(); while(iterator.hasNext()) { IEObjectDescription description = iterator.next(); IEObjectDescription lookUp = getSingleElement(description.getName()); if (lookUp == null || lookUp.getEObjectOrProxy() != object) { iterator.remove(); } } return result; }
Example 5
Source File: VisibilityAwareCtorScope.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected boolean isAccepted(IEObjectDescription description) { EObject proxyOrInstance = description.getEObjectOrProxy(); if (proxyOrInstance != null && !proxyOrInstance.eIsProxy()) { if (proxyOrInstance instanceof TClassifier) { TClassifier ctorClassifier = (TClassifier) proxyOrInstance; if (ctorClassifier.isAbstract()) { return true; // avoid duplicate error messages } // If the class is found, check if the visibility of the constructor is valid TMethod usedCtor = containerTypesHelper.fromContext(context).findConstructor(ctorClassifier); if (usedCtor != null && usedCtor.isConstructor()) { return checker.isConstructorVisible(context, TypeUtils.createTypeRef(ctorClassifier), usedCtor); } } } return true; }
Example 6
Source File: ValidScopingTest.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Tests that validations may be declared on existing EClass and EStructuralFeature instances. */ @Test public void testEStructuralFeatureScope() throws IOException { final ValidModel validModel = (ValidModel) getTestSource().getModel(); final NativeContext context = getXtextTestUtil().getFirstInstanceOf(validModel, NativeContext.class); // Check context feature reference IScope scope = scopeProvider.getScope(context, ValidPackage.Literals.CONTEXT__CONTEXT_FEATURE); IEObjectDescription name = scope.getSingleElement(QualifiedName.create("name")); assertNotNull("Found valid EStructuralFeature \"name\"", name); final EObject resolvedName = name.getEObjectOrProxy(); assertNotNull("Valid EStructuralFeature \"name\" can be resolved", resolvedName); // Check context type reference scope = scopeProvider.getScope(context, ValidPackage.Literals.CONTEXT__CONTEXT_TYPE); assertEquals("Scope provider returns correct context type", context.getContextType(), scope.getSingleElement(QualifiedName.create("Model")).getEObjectOrProxy()); assertEquals("Container of \"name\" reference instance is \"Model\" instance", resolvedName.eContainer(), scope.getSingleElement(QualifiedName.create("Model")).getEObjectOrProxy()); // Check marker type reference scope = scopeProvider.getScope(context, ValidPackage.Literals.NATIVE_CONTEXT__MARKER_TYPE); assertEquals("Scope provider returns correct marker type", context.getMarkerType(), scope.getSingleElement(QualifiedName.create("Element")).getEObjectOrProxy()); // Check marker feature reference scope = scopeProvider.getScope(context, ValidPackage.Literals.NATIVE_CONTEXT__MARKER_FEATURE); assertEquals("Scope provider returns correct marker feature", context.getMarkerFeature(), scope.getSingleElement(QualifiedName.create("name")).getEObjectOrProxy()); }
Example 7
Source File: ReferenceAcceptor.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void computeExportedObjectsMap(EObject source) { Resource resource = source.eResource(); IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry .getResourceServiceProvider(resource.getURI()); if (resourceServiceProvider != null) { exportedContainersInCurrentResource = new HashMap<>(); Iterable<IEObjectDescription> exportedObjects = resourceServiceProvider.getResourceDescriptionManager() .getResourceDescription(resource).getExportedObjects(); for (IEObjectDescription description : exportedObjects) { EObject instance = description.getEObjectOrProxy(); if (instance.eIsProxy()) { instance = resource.getEObject(description.getEObjectURI().fragment()); } exportedContainersInCurrentResource.put(instance, description.getEObjectURI()); } } else { exportedContainersInCurrentResource = Collections.emptyMap(); } }
Example 8
Source File: NamesAreUniqueValidationHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.22 */ protected void doCheckUniqueIn(IEObjectDescription description, Context context, ValidationMessageAcceptor acceptor) { EObject object = description.getEObjectOrProxy(); Preconditions.checkArgument(!object.eIsProxy()); EClass clusterType = getClusterType(description); if (clusterType == null) { return; } ISelectable validationScope = context.getValidationScope(description, clusterType); if (validationScope.isEmpty()) { return; } boolean caseSensitive = context.isCaseSensitive(object, clusterType); Iterable<IEObjectDescription> sameNames = validationScope.getExportedObjects(clusterType, description.getName(), !caseSensitive); if (sameNames instanceof Collection<?>) { if (((Collection<?>) sameNames).size() <= 1) { return; } } for (IEObjectDescription candidate : sameNames) { EObject otherObject = candidate.getEObjectOrProxy(); if (object != otherObject && getAssociatedClusterType(candidate.getEClass()) == clusterType && !otherObject.eIsProxy() || !candidate.getEObjectURI().equals(description.getEObjectURI())) { if (isDuplicate(description, candidate)) { createDuplicateNameError(description, clusterType, acceptor); return; } } } }
Example 9
Source File: AbstractTypeScopeTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetElementByInstance_03() { IEObjectDescription mapEntryDescription = getTypeScope().getSingleElement(QualifiedName.create("java", "util", "Map$Entry")); EObject mapEntry = mapEntryDescription.getEObjectOrProxy(); IEObjectDescription lookupDescription = getTypeScope().getSingleElement(mapEntry); assertNotNull(lookupDescription); assertEquals(QualifiedName.create("java", "util", "Map", "Entry"), lookupDescription.getName()); }
Example 10
Source File: FeatureScopes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected IScope createDynamicExtensionsScope(QualifiedName implicitFirstArgumentName, IEObjectDescription firstArgumentDescription, EObject featureCall, IFeatureScopeSession captureLayer, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { JvmIdentifiableElement feature = (JvmIdentifiableElement) firstArgumentDescription.getEObjectOrProxy(); if (feature instanceof JvmType && THIS.equals(implicitFirstArgumentName) && !session.isInstanceContext()) { return parent; } LightweightTypeReference type = resolvedTypes.getActualType(feature); if (type != null && !type.isUnknown()) { XFeatureCall implicitArgument = xbaseFactory.createXFeatureCall(); implicitArgument.setFeature(feature); return createDynamicExtensionsScope(featureCall, implicitArgument, type, true, parent, captureLayer); } return parent; }
Example 11
Source File: ImportScope.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) { List<IEObjectDescription> result = newArrayList(); QualifiedName resolvedQualifiedName = null; ISelectable importFrom = getImportFrom(); for (ImportNormalizer normalizer : normalizers) { final QualifiedName resolvedName = normalizer.resolve(name); if (resolvedName != null) { Iterable<IEObjectDescription> resolvedElements = importFrom.getExportedObjects(type, resolvedName, isIgnoreCase()); for (IEObjectDescription resolvedElement : resolvedElements) { if (resolvedQualifiedName == null) resolvedQualifiedName = resolvedName; else if (!resolvedQualifiedName.equals(resolvedName)) { if (result.get(0).getEObjectOrProxy() != resolvedElement.getEObjectOrProxy()) { return emptyList(); } } QualifiedName alias = normalizer.deresolve(resolvedElement.getName()); if (alias == null) throw new IllegalStateException("Couldn't deresolve " + resolvedElement.getName() + " with import " + normalizer); final AliasedEObjectDescription aliasedEObjectDescription = new AliasedEObjectDescription(alias, resolvedElement); result.add(aliasedEObjectDescription); } } } return result; }
Example 12
Source File: TypeLookupImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private Type findTypeOnScope(final String typeName, final Function1<? super IEObjectDescription, ? extends Boolean> filter) { final QualifiedName qualifiedName = this.compilationUnit.getQualifiedNameConverter().toQualifiedName(typeName); final IEObjectDescription result = this.compilationUnit.getScopeProvider().getScope(this.compilationUnit.getXtendFile(), XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE).getSingleElement(qualifiedName); if ((((result != null) && TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(result.getEClass())) && (filter.apply(result)).booleanValue())) { EObject _eObjectOrProxy = result.getEObjectOrProxy(); return this.compilationUnit.toType(((JvmType) _eObjectOrProxy)); } return null; }
Example 13
Source File: VisibilityAwareCtorScope.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected IEObjectDescriptionWithError wrapFilteredDescription(IEObjectDescription originalDescr) { EObject proxyOrInstance = originalDescr.getEObjectOrProxy(); // The cast to TClassifier always works (see the method isAccepted below). TClassifier ctorClassifier = (TClassifier) proxyOrInstance; return new InvisibleCtorDescription(originalDescr, ctorClassifier); }
Example 14
Source File: ConstructorDelegateScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected List<IEObjectDescription> getLocalElementsByName(QualifiedName name) { if (THIS.equals(name) || SUPER.equals(name)) { IEObjectDescription description = getSession().getLocalElement(name); if (description != null) { EObject objectOrProxy = description.getEObjectOrProxy(); if (objectOrProxy instanceof JvmGenericType && !objectOrProxy.eIsProxy()) { return createConstructorDescriptions(name, (JvmGenericType) objectOrProxy, SUPER.equals(name)); } } } return Collections.emptyList(); }
Example 15
Source File: AbstractTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected IIdentifiableElementDescription toIdentifiableDescription(IEObjectDescription description) { if (description instanceof IIdentifiableElementDescription) return (IIdentifiableElementDescription) description; if (!(description.getEObjectOrProxy() instanceof JvmIdentifiableElement)) { throw new IllegalStateException("Given description does not describe an identifable element"); } return new SimpleIdentifiableElementDescription(description); }
Example 16
Source File: ConstructorTypeScopeWrapper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected EObject getResolvedProxy(IEObjectDescription description) { EObject proxy = description.getEObjectOrProxy(); if (proxy.eIsProxy()) { proxy = EcoreUtil.resolve(proxy, context); } return proxy; }
Example 17
Source File: TypingStrategyFilterDesc.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public boolean apply(IEObjectDescription description) { final TypingStrategy typingStrategy = delegate.getTypingStrategy(); if (typingStrategy == TypingStrategy.DEFAULT || typingStrategy == TypingStrategy.NOMINAL) { return true; } EObject proxyOrInstance = description.getEObjectOrProxy(); if (proxyOrInstance == null || proxyOrInstance.eIsProxy()) { return true; } if (!(proxyOrInstance instanceof TMember)) { return true; } return delegate.apply((TMember) proxyOrInstance); }
Example 18
Source File: ComposedMemberDescriptionWithError.java From n4js with Eclipse Public License 1.0 | 5 votes |
private boolean initialize() { if (message == null) { List<TypeRef> typeRefs = composedTypeRef.getTypeRefs(); IEObjectDescription[] descriptions = new IEObjectDescription[subScopes.length]; MapOfIndexes<String> indexesPerMemberType = new MapOfIndexes<>(); // use string here, since EnumLiteral is // not a TMember! MapOfIndexes<String> indexesPerCode = new MapOfIndexes<>(); List<String> missingFrom = new ArrayList<>(); final QualifiedName name = getName(); boolean readOnlyField = false; for (int i = 0; i < max; i++) { IEObjectDescription description = subScopes[i].getSingleElement(name); if (description != null) { descriptions[i] = description; EObject eobj = description.getEObjectOrProxy(); boolean structFieldInitMode = typeRefs.get(i) .getTypingStrategy() == TypingStrategy.STRUCTURAL_FIELD_INITIALIZER; String type = getMemberTypeName(eobj, structFieldInitMode); indexesPerMemberType.add(type, i); if (IEObjectDescriptionWithError.isErrorDescription(description)) { String subCode = IEObjectDescriptionWithError.getDescriptionWithError(description) .getIssueCode(); indexesPerCode.add(subCode, i); } if ("field".equals(type)) { readOnlyField |= !((TField) eobj).isWriteable(); } } else { missingFrom.add(getNameForSubScope(i)); } } return initMessageAndCode(missingFrom, indexesPerMemberType, name, readOnlyField, descriptions, indexesPerCode); } return false; }
Example 19
Source File: ResourceSetBasedResourceDescriptionsTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public EObject apply(IEObjectDescription from) { return from.getEObjectOrProxy(); }
Example 20
Source File: XtextProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
private EObject resolve(IEObjectDescription input, final ContentAssistContext context) { EObject object = input.getEObjectOrProxy(); if (object.eIsProxy()) object = context.getResource().getResourceSet().getEObject(input.getEObjectURI(), true); return object; }