Java Code Examples for org.eclipse.xtext.naming.QualifiedName#isEmpty()
The following examples show how to use
org.eclipse.xtext.naming.QualifiedName#isEmpty() .
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: XbaseImportedNamespaceScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Create a new {@link ImportNormalizer} for the given namespace. * @param namespace the namespace. * @param ignoreCase <code>true</code> if the resolver should be case insensitive. * @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be converted to a valid * qualified name. */ protected ImportNormalizer createImportedNamespaceResolver(final String namespace, boolean ignoreCase) { if (Strings.isEmpty(namespace)) return null; QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace); if (importedNamespace == null || importedNamespace.isEmpty()) { return null; } boolean hasWildCard = ignoreCase ? importedNamespace.getLastSegment().equalsIgnoreCase(getWildCard()) : importedNamespace.getLastSegment().equals(getWildCard()); if (hasWildCard) { if (importedNamespace.getSegmentCount() <= 1) return null; return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase); } else { return doCreateImportNormalizer(importedNamespace, false, ignoreCase); } }
Example 2
Source File: XImportSectionNamespaceScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Create a new {@link ImportNormalizer} for the given namespace. * @param namespace the namespace. * @param ignoreCase <code>true</code> if the resolver should be case insensitive. * @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be converted to a valid * qualified name. */ protected ImportNormalizer createImportedNamespaceResolver(final String namespace, boolean ignoreCase) { if (Strings.isEmpty(namespace)) return null; QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace); if (importedNamespace == null || importedNamespace.isEmpty()) { return null; } boolean hasWildcard = ignoreCase ? importedNamespace.getLastSegment().equalsIgnoreCase(getWildcard()) : importedNamespace.getLastSegment().equals(getWildcard()); if (hasWildcard) { if (importedNamespace.getSegmentCount() <= 1) return null; return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase); } else { return doCreateImportNormalizer(importedNamespace, false, ignoreCase); } }
Example 3
Source File: ImportNormalizer.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public QualifiedName resolve(QualifiedName relativeName) { if (relativeName.isEmpty()) return null; if (hasWildCard) { return importedNamespacePrefix.append(relativeName); } else { if (!ignoreCase) { if (relativeName.getSegmentCount()==1 && relativeName.getLastSegment().equals(importedNamespacePrefix.getLastSegment())) { return importedNamespacePrefix; } } else { if (relativeName.getSegmentCount()==1 && relativeName.getLastSegment().equalsIgnoreCase(importedNamespacePrefix.getLastSegment())) { return importedNamespacePrefix.skipLast(1).append(relativeName.getLastSegment()); } } } return null; }
Example 4
Source File: ImportedNamespaceAwareLocalScopeProvider.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * Create a new {@link ImportNormalizer} for the given namespace. * @param namespace the namespace. * @param ignoreCase <code>true</code> if the resolver should be case insensitive. * @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be converted to a valid * qualified name. */ protected ImportNormalizer createImportedNamespaceResolver(final String namespace, boolean ignoreCase) { if (Strings.isEmpty(namespace)) return null; QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace); if (importedNamespace == null || importedNamespace.isEmpty()) { return null; } boolean hasWildCard = ignoreCase ? importedNamespace.getLastSegment().equalsIgnoreCase(getWildCard()) : importedNamespace.getLastSegment().equals(getWildCard()); if (hasWildCard) { if (importedNamespace.getSegmentCount() <= 1) return null; return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase); } else { return doCreateImportNormalizer(importedNamespace, false, ignoreCase); } }
Example 5
Source File: QualifiedNameSegmentTreeLookup.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public Collection<T> get(final QualifiedName name) { if (name.isEmpty()) { return null; } SegmentNode result = root.find(name, 0, true); if (result != null && result.values != null) { hits++; return (Collection<T>) Arrays.asList(result.values); } else { misses++; return null; } }
Example 6
Source File: LinkingService.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Register a name as imported. * * @param context * context object within which a reference is being set to some object, must not be {@code null} * @param target * the associated target eObject. Its exported name is recorded as imported, must not be {@code null} * @param type * the lookup type, may be {@code null} */ public void importObject(final EObject context, final EObject target, final EClass type) { Resource eResource = target.eResource(); QualifiedName targetName = null; if (eResource instanceof LazyLinkingResource2) { IQualifiedNameProvider nameProvider = ((LazyLinkingResource2) eResource).getService(IQualifiedNameProvider.class); if (nameProvider != null) { targetName = nameProvider.getFullyQualifiedName(target); } } else { final IResourceDescriptions resourceDescriptions = provider.getResourceDescriptions(context.eResource()); Iterator<IEObjectDescription> exports = resourceDescriptions.getExportedObjectsByObject(target).iterator(); if (exports.hasNext()) { targetName = exports.next().getName(); } } if (targetName != null && !targetName.isEmpty()) { registerNamedType(context, targetName.toLowerCase(), type); // NOPMD targetName not a String! } }
Example 7
Source File: N4TSQualifiedNameProvider.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Return corresponding FQN for staticPolyfill (prefixed with !MPOLY * * @param name * non-filled name * @return fqn of filling, not present if name itself denotes a static polyfill or is null. */ public static Optional<QualifiedName> toStaticPolyfillFQN(QualifiedName name) { if (name != null && !name.isEmpty() && !MODULE_POLYFILL_SEGMENT.equals(name.getFirstSegment())) { return Optional.of(prepend(MODULE_POLYFILL_SEGMENT, name)); } else return Optional.empty(); }
Example 8
Source File: ScopeProviderAccess.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Returns a bunch of descriptions most of which are actually {@link IIdentifiableElementDescription describing identifiables}. * The provided iterable is never empty but it may contain a single {@link ErrorDescription error description}. * * @return the available descriptions. */ public Iterable<IEObjectDescription> getCandidateDescriptions(XExpression expression, EReference reference, /* @Nullable */ EObject toBeLinked, IFeatureScopeSession session, IResolvedTypes types) throws IllegalNodeException { if (toBeLinked == null) { return Collections.emptyList(); } if (!toBeLinked.eIsProxy()) { throw new IllegalStateException(expression + " was already linked to " + toBeLinked); } URI uri = EcoreUtil.getURI(toBeLinked); String fragment = uri.fragment(); if (encoder.isCrossLinkFragment(expression.eResource(), fragment)) { INode node = encoder.getNode(expression, fragment); final EClass requiredType = reference.getEReferenceType(); if (requiredType == null) return Collections.emptyList(); final String crossRefString = linkingHelper.getCrossRefNodeAsString(node, true); if (crossRefString != null && !crossRefString.equals("")) { QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString); if (!qualifiedLinkName.isEmpty()) { final IScope scope = session.getScope(expression, reference, types); Iterable<IEObjectDescription> descriptions = scope.getElements(qualifiedLinkName); if (Iterables.isEmpty(descriptions)) { INode errorNode = getErrorNode(expression, node); if (errorNode != node) { qualifiedLinkName = getErrorName(errorNode); } return Collections.<IEObjectDescription>singletonList(new ErrorDescription(getErrorNode(expression, node), qualifiedLinkName)); } return descriptions; } else { return Collections.<IEObjectDescription>singletonList(new ErrorDescription(null /* followUp problem */)); } } return Collections.emptyList(); } else { throw new IllegalStateException(expression + " uses unsupported uri fragment " + uri); } }
Example 9
Source File: ImportNormalizer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public ImportNormalizer(QualifiedName importedNamespace, boolean wildCard, boolean ignoreCase) { this.ignoreCase = ignoreCase; if (importedNamespace == null || importedNamespace.isEmpty()) { throw new IllegalArgumentException("Imported namespace must not be null / empty"); } hasWildCard = wildCard; this.importedNamespacePrefix = importedNamespace; }
Example 10
Source File: LinkingService.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Register a name as imported. * * @param context * context object within which a reference is being set to some object, must not be {@code null} * @param desc * the associated description. Its name is recorded as imported, must not be {@code null} * @param type * the lookup type, may be {@code null} */ public void importObject(final EObject context, final IEObjectDescription desc, final EClass type) { QualifiedName targetName; if (desc instanceof AliasingEObjectDescription) { targetName = ((AliasingEObjectDescription) desc).getOriginalName(); } else { targetName = desc.getName(); } if (targetName != null && !targetName.isEmpty()) { registerNamedType(context, targetName.toLowerCase(), type); // NOPMD targetName not a String! } }
Example 11
Source File: Index.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** {@inheritDoc} */ @Override public IIndex.Query newQuery(final EClass type, final QualifiedName namePattern) { if (type == null || namePattern == null || namePattern.isEmpty()) { throw new IllegalArgumentException(Messages.Index_NullArgumentInQuery); } return new Query(domainMapper, nameConverter, type).withName(namePattern); }
Example 12
Source File: AbstractResourceDescriptionStrategy.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Adds a description for the provided EObject to the resource description. * * @param object * EObject to create descriptor for * @param data * user data for descriptor * @param acceptor * acceptor to add description to */ protected void acceptEObjectDescription(final EObject object, final Map<String, String> data, final IAcceptor<IEObjectDescription> acceptor) { QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(object); if (name != null && !name.isEmpty()) { acceptor.accept(DetachableEObjectDescription.create(name, object, data)); } }
Example 13
Source File: AbstractResourceDescriptionStrategy.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Adds a description for the provided EObject to the resource description. * * @param object * EObject to create descriptor for * @param acceptor * acceptor to add description to */ protected void acceptEObjectDescription(final EObject object, final IAcceptor<IEObjectDescription> acceptor) { QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(object); if (name != null && !name.isEmpty()) { acceptor.accept(DetachableEObjectDescription.create(name, object)); } }
Example 14
Source File: AbstractExportedNameProvider.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Qualifies a simple name with that of the container (if any). * * @param obj * context object * @param name * simple name of object * @return qualified name of object */ protected QualifiedName qualifyWithContainerName(final EObject obj, final QualifiedName name) { final QualifiedName parentName = getContainerQualifiedName(obj); if (parentName != null && !parentName.isEmpty()) { return parentName.append(name); } return name; }
Example 15
Source File: N4TSQualifiedNameProvider.java From n4js with Eclipse Public License 1.0 | 2 votes |
/** * Checks if this qualified name denotes an element inside of a polyfill module. * * @param name * to investigate. * @return <code>true</code> if the first segment of name is {@link #MODULE_POLYFILL_SEGMENT} */ public static boolean isModulePolyfill(QualifiedName name) { if (name == null || name.isEmpty()) return false; return MODULE_POLYFILL_SEGMENT.equals(name.getFirstSegment()); }