@Override protected boolean isAccepted(IEObjectDescription description) { 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); }
/** * Returns description for given element, name is assumed to consist of a single segment containing the simple name * of the member. If no subScope contains a member with given name, null is returned. In other error cases (no or * wrong access, mixed types etc.), {@link IEObjectDescriptionWithError}, and in particular * {@link UnionMemberDescriptionWithError}, will be returned. */ @Override protected IEObjectDescription getSingleLocalElementByName(QualifiedName qualifiedName) { String name = qualifiedName.getLastSegment(); TMember member = getOrCreateComposedMember(name); if (member == null) { // no such member, no need for "merging" descriptions, there won't be any return null; } if (isErrorPlaceholder(member)) { return createComposedMemberDescriptionWithErrors(EObjectDescription.create(member.getName(), member)); } IEObjectDescription description = getCheckedDescription(name, member); return description; }
@Override @SuppressWarnings({ "rawtypes", "unchecked", "static-access" }) protected Comparator getItemsComparator() { return Ordering.natural().nullsLast().from(new Comparator() { @Override public int compare(final Object o1, final Object o2) { if (o1 instanceof IEObjectDescription && o2 instanceof IEObjectDescription) { final IEObjectDescription d1 = (IEObjectDescription) o1; final IEObjectDescription d2 = (IEObjectDescription) o2; final QualifiedName fqn1 = d1.getQualifiedName(); final QualifiedName fqn2 = d2.getQualifiedName(); if (null != fqn1 && null != fqn2) { return nullToEmpty(fqn1.getLastSegment()).compareToIgnoreCase( nullToEmpty(fqn2.getLastSegment())); } } return Objects.hashCode(o1) - Objects.hashCode(o2); } }); }
/** * Factory method to produce a scope. The factory pattern allows to bypass the explicit object creation if the * produced scope would be empty. * * @param canLoadFromDescriptionHelper * utility to decide if a resource must be loaded from source or may be loaded from the index. */ public static IScope createScope( IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase, ResourceSet resourceSet, CanLoadFromDescriptionHelper canLoadFromDescriptionHelper, IContainer container) { if (selectable == null || selectable.isEmpty()) return outer; IScope scope = new UserDataAwareScope(outer, selectable, filter, type, ignoreCase, resourceSet, canLoadFromDescriptionHelper, container); return scope; }
private void setupDialog() { browseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { SingleClassSelectionDialog dialog = singleClassSelectionDialogProvider.get(); dialog.setInitialPattern(model.getSuperClass().getFullSpecifier()); dialog.open(); if (dialog.getReturnCode() == Window.CANCEL) { return; } Object result = dialog.getFirstResult(); if (result instanceof IEObjectDescription) { IEObjectDescription objectDescription = (IEObjectDescription) result; URI objectUri = ((IEObjectDescription) result).getEObjectURI(); model.setSuperClass( new ClassifierReference(objectDescription.getQualifiedName(), objectUri)); } } }); }
private boolean isSignificantChange(IResourceDescription.Delta delta) { if (delta.haveEObjectDescriptionsChanged()) { IResourceDescription newDescription = delta.getNew(); IResourceDescription oldDescription = delta.getOld(); if ((newDescription != null) != (oldDescription != null)) { return true; } if (newDescription == null || oldDescription == null) { throw new IllegalStateException(); } List<IEObjectDescription> newDescriptions = Lists.newArrayList(newDescription.getExportedObjects()); List<IEObjectDescription> oldDescriptions = Lists.newArrayList(oldDescription.getExportedObjects()); if (newDescriptions.size() != oldDescriptions.size()) { return true; } URI resourceURI = delta.getUri(); for (int i = 0; i < newDescriptions.size(); i++) { if (!equalDescriptions(newDescriptions.get(i), oldDescriptions.get(i), resourceURI)) { return true; } } } return false; }
public ArrayList<IEObjectDescription> getTypes(final Extension ext) { ArrayList<IEObjectDescription> _xblockexpression = null; { ArrayList<IEObjectDescription> res = new ArrayList<IEObjectDescription>(); EList<DataType> _types = ext.getTypes(); for (final DataType k : _types) { res.add(EObjectDescription.create(QualifiedName.create(k.getName()), k)); } EList<Extension> _import = ext.getImport(); for (final Extension importExtension : _import) { EList<DataType> _types_1 = importExtension.getTypes(); for (final DataType k_1 : _types_1) { res.add(EObjectDescription.create(QualifiedName.create(importExtension.getName(), k_1.getName()), k_1)); } } _xblockexpression = res; } return _xblockexpression; }
@SuppressWarnings("unchecked") @Override protected void registerDescription(final IResourceDescription description, final Map<QualifiedName, Object> target) { for (final IEObjectDescription object : description.getExportedObjects()) { final QualifiedName lowerCase = object.getName().toLowerCase(); final Object existing = target.put(lowerCase, description); if (existing != null && existing != description) { Set<IResourceDescription> set = null; if (existing instanceof IResourceDescription) { // The linked hash set is the difference comparing to the super class. set = Sets.newLinkedHashSetWithExpectedSize(2); set.add((IResourceDescription) existing); } else { set = (Set<IResourceDescription>) existing; } set.add(description); target.put(lowerCase, set); } } }
@Override public boolean createEObjectDescriptions(final EObject eObject, IAcceptor<IEObjectDescription> acceptor) { if (getQualifiedNameProvider() == null) return false; if (eObject instanceof TModule) { TModule module = (TModule) eObject; internalCreateEObjectDescriptionForRoot(module, acceptor); for (Type type : module.getTopLevelTypes()) { internalCreateEObjectDescription(type, acceptor); } for (TVariable variable : module.getVariables()) { internalCreateEObjectDescription(variable, acceptor); } } // export is only possible for top-level elements return false; }
@SuppressWarnings("javadoc") @Test public void testResolveSuperTypeOfBuiltInType() { BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet); IEObjectDescription intDescription = scope.getSingleElement(QualifiedName.create("i18nKey")); // trigger loading PrimitiveType intType = (PrimitiveType) intDescription.getEObjectOrProxy(); PrimitiveType assCompatType = intType.getAssignmentCompatible(); Assert.assertFalse(assCompatType.eIsProxy()); Assert.assertEquals("string", assCompatType.getName()); }
/** * Finds a launch configuration with the given name from the current EMF index. The index contains all * launch configurations from projects that have the Xtext nature. Launch configurations from projects * without the Xtext nature are not found. Use {@link #findLaunchConfig(String, IFile)} in this case. * * @param name the name of the configuration to find * @return the configuration or <code>null</code> */ public LaunchConfig findLaunchConfig(String name) { Iterable<IEObjectDescription> indexed = index.getExportedObjectsByType(LcDslPackage.eINSTANCE.getLaunchConfig()); for (IEObjectDescription o : indexed) { if (o.getName().getLastSegment().equals(name)) { EObject obj = EcoreUtil.resolve(o.getEObjectOrProxy(), rsProvider.get()); EcoreUtil.resolveAll(obj); return (LaunchConfig) obj; } } return null; }
@Override public Iterable<IEObjectDescription> getElements(final QualifiedName name) { return new Iterable<IEObjectDescription>() { @Override public Iterator<IEObjectDescription> iterator() { getImportedNames().add(name); final Iterable<IEObjectDescription> elements = delegate.getElements(name); return elements.iterator(); } }; }
@Override public Iterable<IEObjectDescription> getElements(QualifiedName name) { Iterable<IEObjectDescription> parent = super.getElements(name); return Iterables.transform(parent, new Function<IEObjectDescription, IEObjectDescription>() { @Override public IEObjectDescription apply(IEObjectDescription input) { return resolve(input); } }); }
@Override protected Iterable<IEObjectDescription> getAllLocalElements() { if (elements == null) { elements = createElements(); } return elements.values(); }
/** * Returns a reference to the instance with the given qualified name. * * @return an optional reference. */ protected <T extends EObject> T getEObjectOrProxy(QualifiedName qn) { IEObjectDescription description = getSingleElement(qn); if (description == null) throw new IllegalStateException(qn + " is not contained in this scope"); @SuppressWarnings("unchecked") T result = (T) description.getEObjectOrProxy(); return result; }
@Override public Iterable<IEObjectDescription> getElements(QualifiedName name) { Iterable<IEObjectDescription> parentResult = parent.getElements(name); if (Iterables.isEmpty(parentResult)) { return Collections.<IEObjectDescription> singletonList(new UnresolvableObjectDescription(name)); } return parentResult; }
@Override protected IScope getScope(IScope parent, final Resource context, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) { // we are only interested in the builtin types // and don't care about other types from the index / available on the classpath return parent; }
/** * If the type is a {@link Type} a new {@link BuiltInTypeScope} is created. */ @Override protected IScope getScope(Resource context, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) { if (isSubtypeOfType(type)) { return getScope(getBuiltInTypeScope(context), context, ignoreCase, type, filter); } // do not call super but directly redirect with nullscope, using IScopeExt.NULLSCOPE instead of IScope.NULLSCOPE return getScope(IScope.NULLSCOPE, context, ignoreCase, type, filter); }
/** * Creates this scope if container is present, otherwise parent is returned. */ public static IScope createPolyfillAwareScope(IScope parent, IContainer container, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) { if (container == null || container.isEmpty()) return parent; return new PolyfillAwareSelectableBasedScope(parent, container, filter, type, ignoreCase); }
/** * {@inheritDoc} Always returns false for polyfills, otherwise super method is called. */ @Override protected boolean isShadowed(IEObjectDescription fromParent) { if (fromParent != null && N4TSQualifiedNameProvider.isPolyfill(fromParent.getName())) { return false; } return super.isShadowed(fromParent); }
@Override protected Iterable<IEObjectDescription> getAllLocalElements() { List<EObject> result = Lists.newArrayList(); result.addAll(functionMembers()); result.addAll(contractMembers()); return Scopes.scopedElementsFor(result); }
@Override protected IScope getResourceScope(Resource res, EReference reference) { EObject context = res.getContents().get(0); // ||-- changed super-impl here: // IDE-662 filtering ArgumentsType & EnumBaseType from globalScobe, since it is a VirtualBaseType. Predicate<IEObjectDescription> filter = p -> { String name = p.getName().toString(); return !("ArgumentsType".equals(name) || "EnumBaseType".equals(name)); }; IScope globalScope = getGlobalScope(res, reference, filter); // -- done change --|| List<ImportNormalizer> normalizers = getImplicitImports(isIgnoreCase(reference)); // IDE-1735 adding support for static-polyfills: TModule module = (TModule) res.getContents().get(1); if (module.isStaticPolyfillModule()) { // limit to situations of resources, that contain at least // one @StaticPolyfill normalizers.add(createImportedNamespaceResolver( module.getQualifiedName() + N4JSQualifiedNameConverter.DELIMITER + "*", false)); } if (!normalizers.isEmpty()) { globalScope = createImportScope(globalScope, normalizers, null, reference.getEReferenceType(), isIgnoreCase(reference)); } IScope resScope = getResourceScope(globalScope, context, reference); return resScope; }
private Optional<TClass> loadTClass(final ResourceSet resSet, final IEObjectDescription objDesc) { if (T_CLASS.isSuperTypeOf(objDesc.getEClass())) { final EObject objectOrProxy = objDesc.getEObjectOrProxy(); final EObject object = objectOrProxy.eIsProxy() ? EcoreUtil.resolve(objectOrProxy, resSet) : objectOrProxy; if (!object.eIsProxy()) { return fromNullable((TClass) object); } } return absent(); }
@Override public IEObjectDescription getSingleElement(QualifiedName name) { IEObjectDescription result = parent.getSingleElement(name); if (result == null) { return new UnresolvableObjectDescription(name); } return result; }
@Override public IEObjectDescription getSingleElement(EObject object) { IEObjectDescription result = parent.getSingleElement(object); if (result == null || isAccepted(result)) { return result; } return wrapFilteredDescription(result); }
/** * Creates a new instance of this wrapping description. * * @param delegate * the decorated description. */ public ComposedMemberDescriptionWithError(IEObjectDescription delegate, ComposedTypeRef composedTypeRef, IScope[] subScopes, boolean writeAccess) { super(delegate); this.composedTypeRef = composedTypeRef; this.subScopes = subScopes; max = subScopes.length; this.writeAccess = writeAccess; }
/** * Decorates all descriptions which are filtered with error markers. Since * {@link #wrapFilteredDescription(IEObjectDescription)} may return null, null values are filtered out. * * @param originalDescriptions * the original unfiltered descriptions. */ protected Iterable<IEObjectDescription> decorateWithErrorIfFiltered( Iterable<IEObjectDescription> originalDescriptions) { // warning produced here is a bug, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=445465 // explicitly declaring type of element fixes the warning Iterable<IEObjectDescription> filteredResult = Iterables.transform(originalDescriptions, (IEObjectDescription it) -> { if (it == null || isAccepted(it)) { return it; } else { return wrapFilteredDescription(it); } }); return Iterables.filter(filteredResult, it -> it != null); }
@Override public Set<LcDslLaunchObject> getLaunchObjects() { IResourceDescriptions index = LcDslHelper.getInjector().getInstance(IResourceDescriptions.class); ResourceSet set = LcDslHelper.getInjector().getInstance(ResourceSet.class); Set<LcDslLaunchObject> result = new TreeSet<>(); Iterable<IEObjectDescription> descs = index.getExportedObjectsByType(LcDslPackage.eINSTANCE.getLaunchConfig()); for (IEObjectDescription obj : descs) { EObject lc = EcoreUtil2.resolve(obj.getEObjectOrProxy(), set); if (lc instanceof LaunchConfig) { LaunchConfig l = (LaunchConfig) lc; if (l.isAbstract()) { continue; } LcDslLaunchObject o = new LcDslLaunchObject((LaunchConfig) lc); if (o.getType() == null) { // unsupported type continue; } // only hide manual if there is no other object it would be (properly) hiding if (hideManual && l.isManual() && findLaunchConfiguration(o.getType(), generator.fullName(l)) == null) { continue; } result.add(o); } } return result; }
/** * Helper method to be used instead of instanceof-checks, as it also covers {@link AliasedEObjectDescription}s. * * @return true if given description is an (aliased) IEObjectDescriptionWithError */ public static boolean isErrorDescription(final IEObjectDescription eObjectDescription) { if (eObjectDescription instanceof IEObjectDescriptionWithError) { return true; } if (eObjectDescription instanceof AliasedEObjectDescription) { return isErrorDescription(((AliasedEObjectDescription) eObjectDescription).getAliasedEObjectDescription()); } return false; }
/** * Helper method to be used casting to IEObjectDescriptionWithError as it also covers * {@link AliasedEObjectDescription}s. * * @return the casted (or delegated) IEObjectDescriptionWithError, or null if description does not contain an error. */ public static IEObjectDescriptionWithError getDescriptionWithError(final IEObjectDescription eObjectDescription) { if (eObjectDescription instanceof IEObjectDescriptionWithError) { return (IEObjectDescriptionWithError) eObjectDescription; } if (eObjectDescription instanceof AliasedEObjectDescription) { return getDescriptionWithError(((AliasedEObjectDescription) eObjectDescription) .getAliasedEObjectDescription()); } return null; }
@Override public boolean matchItem(final Object item) { if (item instanceof IEObjectDescription) { final QualifiedName fqn = ((IEObjectDescription) item).getQualifiedName(); if (null != fqn) { return matches(fqn.getLastSegment()) || matches(fqn.toString()); } } return false; }
@Override public IEObjectDescription getSingleElement(EObject object) { IEObjectDescription result = parent.getSingleElement(object); if (result == null) { if (object instanceof IdentifiableElement) { return EObjectDescription .create(QualifiedName.create(((IdentifiableElement) object).getName()), object); } } return result; }
@Override public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) { if (eObject instanceof Operation) { super.createEObjectDescriptions(eObject, acceptor); return false; } return super.createEObjectDescriptions(eObject, acceptor); }
@Override protected void storeItemToMemento(final Object item, final IMemento memento) { if (item instanceof IEObjectDescription) { final URI uri = ((IEObjectDescription) item).getEObjectURI(); memento.putString(MEMENTO_URI_KEY, uri.toString()); } }
/** * Searches for a member of the given name and for the given access in the sub-scope with index 'subScopeIdx'. */ private TMember findMemberInSubScope(IScope subScope, String name) { final IEObjectDescription currElem = subScope.getSingleElement(QualifiedName.create(name)); if (currElem != null) { final EObject objOrProxy = currElem.getEObjectOrProxy(); if (objOrProxy != null && !objOrProxy.eIsProxy() && objOrProxy instanceof TMember) { final TMember currM = (TMember) objOrProxy; return currM; } } return null; }
@Override public String getText(final Object element) { if (element instanceof IEObjectDescription) { final IEObjectDescription description = (IEObjectDescription) element; final StringBuilder sb = new StringBuilder(getFqn(description)); if (description instanceof EObject && null != ((EObject) description).eContainer()) { final EObject container = ((EObject) description).eContainer(); if (container instanceof IResourceDescription) { final URI uri = ((IResourceDescription) container).getURI(); final IN4JSEclipseProject project = core.findProject(uri).orNull(); if (null != project && project.exists()) { sb.append(" ["); sb.append(project.getProjectId()); sb.append("]"); if (project.isExternal()) { final IProject resourceProject = project.getProject(); sb.append(" External library: "); sb.append(resourceProject.getLocation().toFile().getAbsolutePath()); } } } } return sb.toString(); } else { return ""; } }
@Override public String getText(final Object element) { if (element instanceof IEObjectDescription) { final String text = labelProvider.getText(element); if (isDuplicateElement(element)) { final String fqn = delegate.getText(element); return new StringBuilder(text).append(NAME_SEPARATOR).append(fqn).toString(); } return text; } return null; }
/** * {@inheritDoc} Always returns false for polyfills, otherwise super method is called. */ @Override protected boolean isShadowed(IEObjectDescription fromParent) { if (fromParent != null) { String userData = fromParent.getUserData(N4JSResourceDescriptionStrategy.MAIN_MODULE_KEY); if (userData != null) { boolean describesMainModule = Boolean.parseBoolean(userData); if (describesMainModule) { return false;// main modules are never shadowed } } } return super.isShadowed(fromParent); }
@Override public boolean apply(IEObjectDescription candidate) { QualifiedName qualifiedName = candidate.getQualifiedName(); // Don't propose any erroneous descriptions. return !AbstractDescriptionWithError.isErrorDescription_XTEND_MVN_BUG_HACK(candidate) && !N4TSQualifiedNameProvider.GLOBAL_NAMESPACE_SEGMENT.equals(qualifiedName.getFirstSegment()) && !N4TSQualifiedNameProvider.isModulePolyfill(qualifiedName) && !N4TSQualifiedNameProvider.isPolyfill(qualifiedName); }