Java Code Examples for org.eclipse.xtext.naming.QualifiedName#equals()

The following examples show how to use org.eclipse.xtext.naming.QualifiedName#equals() . 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: ContainerTypesHelper.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns true if the given container type is a polyfill of the bottom type.
 * <p>
 * Note: we compare via FQN here, since the bottom type may not stem from the index but from the type model
 * derived from the AST. In that case, the type instance, although similar, differs from the type instance
 * from the index.
 */
private boolean isDirectPolyfill(ContainerType<?> containerType) {
	if (!containerType.isStaticPolyfill() || !(bottomType instanceof TClassifier)) {
		return false;
	}
	QualifiedName qn = N4TSQualifiedNameProvider.getStaticPolyfillFQN((TClassifier) bottomType,
			qualifiedNameProvider);
	if (containerType instanceof TClass) { // short cut
		return qn.equals(qualifiedNameProvider.getFullyQualifiedName(containerType));
	}
	if (containerType instanceof TN4Classifier) {
		return Iterables.any(((TN4Classifier) containerType).getSuperClassifierRefs(),
				ref -> qn.equals(qualifiedNameProvider.getFullyQualifiedName(ref.getDeclaredType())));

	}
	return false;
}
 
Example 2
Source File: ContainerBasedScope.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("PMD.UseLocaleWithCaseConversions")
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(final QualifiedName name) {
  if (nameFunctions != null && nameFunctions.size() == 1 && nameFunctions.contains(NameFunctions.exportNameFunction())) {
    final boolean ignoreCase = isIgnoreCase();
    final QualifiedName lookupName = ignoreCase ? name.toLowerCase() : name;
    QualifiedName namePattern = criteria.getNamePattern();
    if (namePattern != null && ignoreCase) {
      namePattern = namePattern.toLowerCase();
    }
    if (namePattern == null || namePattern.equals(lookupName)
        || (namePattern instanceof QualifiedNamePattern && ((QualifiedNamePattern) namePattern).matches(lookupName))) {
      final ContainerQuery copy = ((ContainerQuery.Builder) criteria).copy().name(lookupName).ignoreCase(ignoreCase);
      return copy.execute(container);
    }
    return Collections.<IEObjectDescription> emptyList();
  } else {
    return super.getLocalElementsByName(name);
  }
}
 
Example 3
Source File: PatternAwareEObjectDescriptionLookUp.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getExportedObjects(final EClass type, final QualifiedName name, final boolean ignoreCase) {
  QualifiedName lowerCase = name.toLowerCase(); // NOPMD UseLocaleWithCaseConversions not a String!
  QualifiedNameLookup<IEObjectDescription> lookup = getNameToObjectsLookup();
  Collection<IEObjectDescription> values;
  final boolean isPattern = lowerCase instanceof QualifiedNamePattern;
  if (isPattern) {
    values = lookup.get((QualifiedNamePattern) lowerCase, false);
  } else {
    values = lookup.get(lowerCase);
  }
  if (values == null) {
    return Collections.emptyList();
  }
  Predicate<IEObjectDescription> predicate = ignoreCase ? input -> EcoreUtil2.isAssignableFrom(type, input.getEClass())
      : input -> isPattern ? EcoreUtil2.isAssignableFrom(type, input.getEClass()) && ((QualifiedNamePattern) name).matches(name)
          : name.equals(input.getName()) && EcoreUtil2.isAssignableFrom(type, input.getEClass());
  return Collections2.filter(values, predicate);
}
 
Example 4
Source File: ImportNormalizer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public QualifiedName deresolve(QualifiedName fullyQualifiedName) {
	if (hasWildCard) {
		if (!ignoreCase) {
			if (fullyQualifiedName.startsWith(importedNamespacePrefix) 
					&& fullyQualifiedName.getSegmentCount() != importedNamespacePrefix.getSegmentCount()) {
				return fullyQualifiedName.skipFirst(importedNamespacePrefix.getSegmentCount());
			}
		} else {
			if (fullyQualifiedName.startsWithIgnoreCase(importedNamespacePrefix) 
				&& fullyQualifiedName.getSegmentCount() != importedNamespacePrefix.getSegmentCount()) {
				return fullyQualifiedName.skipFirst(importedNamespacePrefix.getSegmentCount());
			}
		}
	} else {
		if (!ignoreCase) {
			if (fullyQualifiedName.equals(importedNamespacePrefix))
				return QualifiedName.create(fullyQualifiedName.getLastSegment());
		} else {
			if (fullyQualifiedName.equalsIgnoreCase(importedNamespacePrefix))
				return QualifiedName.create(fullyQualifiedName.getLastSegment());
		}
	}
	return null;
}
 
Example 5
Source File: SlotEntry.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean matches(Set<EClass> eclasses, IEObjectDescription desc) {
	boolean valid = eclasses.isEmpty();
	for (Iterator<EClass> iterator = eclasses.iterator(); !valid && iterator.hasNext();) {
		EClass eClass = iterator.next();
		valid = valid || EcorePackage.Literals.EOBJECT == eClass || eClass.isSuperTypeOf(desc.getEClass());
	}
	if (name != null) {
		if (Strings.isEmpty(namespaceDelimiter)) {
			return valid && name.equals(desc.getName().toString());
		} else {
			QualifiedName qualifiedName = QualifiedName.create(name.split(Pattern.quote(getNamespaceDelimiter())));
			return valid && (qualifiedName == null || qualifiedName.equals(desc.getName()));
		}
	} 
	return valid;
}
 
Example 6
Source File: KnownTypesScope.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmType getExactMatch(JvmType type, int index, QualifiedName name) {
	String qn = type.getQualifiedName();
	if (Strings.isEmpty(qn)) {
		return null;
	}
	QualifiedName typeName = QualifiedName.create(Strings.split(qn, '.'));
	if (name.equals(typeName)) {
		return type;
	}
	if (name.startsWith(typeName)) {
		JvmType result = findNestedType(type, index, name.skipFirst(typeName.getSegmentCount()-1));
		return result;
	}
	if (name.getSegmentCount() > typeName.getSegmentCount()) {
		if (typeName.skipLast(1).equals(name.skipLast(1))) {
			if (typeName.getLastSegment().equals(name.skipFirst(typeName.getSegmentCount() - 1).toString("$"))) {
				return type;
			}
		}
	}
	return null;
}
 
Example 7
Source File: TypeScopeWithWildcardImports.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doGetElements(JvmType type, List<IEObjectDescription> result) {
	if (!(type instanceof JvmDeclaredType)) {
		return;
	}
	JvmDeclaredType declaredType = (JvmDeclaredType) type;
	String packageName = declaredType.getPackageName();
	if (!Strings.isEmpty(packageName)) {
		QualifiedName qualifiedPackageName = QualifiedName.create(Strings.split(packageName, '.'));
		QualifiedName withDot = null;
		String withDollar = null; 
		for(int i = 0; i < imports.length; i++) {
			ImportNormalizer[] chunk = imports[i];
			for(int j = 0; j < chunk.length; j++) {
				ImportNormalizer normalizer = chunk[j];
				QualifiedName namespacePrefix = normalizer.getImportedNamespacePrefix();
				if (namespacePrefix.equals(qualifiedPackageName)) {
					if (withDot == null) {
						withDot = QualifiedName.create(Strings.split(type.getQualifiedName('.'), '.'));
						withDollar = type.eContainer() instanceof JvmType ? type.getQualifiedName('$').substring(packageName.length() + 1) : null;
					}
					result.add(EObjectDescription.create(withDot.skipFirst(qualifiedPackageName.getSegmentCount()), type));
					if (withDollar != null) {
						result.add(EObjectDescription.create(withDollar, type));	
					}
				}
			}
		}
	}
	if (parent != null) {
		parent.doGetElements(type, result);
	} else {
		Iterables.addAll(result, typeScope.getElements(type));
	}
}
 
Example 8
Source File: ContainerBasedScope.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings({"PMD.UseLocaleWithCaseConversions", "PMD.NPathComplexity"})
@Override
public synchronized IEObjectDescription getSingleElement(final QualifiedName name) {
  if (nameFunctions != null && nameFunctions.contains(NameFunctions.exportNameFunction())) {
    final boolean ignoreCase = isIgnoreCase();
    final QualifiedName lookupName = ignoreCase ? name.toLowerCase() : name;
    final IEObjectDescription cachedResult = contentByNameCache.get(lookupName);
    if (cachedResult != null) {
      if (cachedResult != NULL_DESCRIPTION) {
        return cachedResult;
      }
      // Otherwise check for aliasing and if yes revert to normal behavior or delegate or parent otherwise
    } else {
      QualifiedName namePattern = criteria.getNamePattern();
      if (namePattern != null && ignoreCase) {
        namePattern = namePattern.toLowerCase();
      }
      if (namePattern == null || namePattern.equals(lookupName)
          || (namePattern instanceof QualifiedNamePattern && ((QualifiedNamePattern) namePattern).matches(lookupName))) {
        final ContainerQuery copy = ((ContainerQuery.Builder) criteria).copy().name(lookupName).ignoreCase(ignoreCase);
        final Iterable<IEObjectDescription> queryResult = copy.execute(container);
        IEObjectDescription description = Iterables.getFirst(queryResult, null);
        if (description != null) {
          contentByNameCache.put(lookupName, description);
          return description;
        }
        contentByNameCache.put(lookupName, NULL_DESCRIPTION);
      }
    }
    // in case of aliasing revert to normal behavior
    return nameFunctions.size() > 1 ? super.getSingleElement(name) : getParent().getSingleElement(name);
  } else {
    return super.getSingleElement(name);
  }
}
 
Example 9
Source File: ImportScope.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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 10
Source File: ReferenceResolutionFinder.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return true iff the {@link QualifiedName} of the given objDescr equals the given qName */
private boolean isEqualCandidateName(IEObjectDescription objDescr, QualifiedName qName) {
	QualifiedName qnOfEObject = getCompleteQualifiedName(objDescr);
	if (qnOfEObject == null) {
		return false;
	}
	return qnOfEObject.equals(qName);
}
 
Example 11
Source File: EcoreRefactoringParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private URI findPlatformResourceURI(QualifiedName name, EClass type) {
	for (IResourceDescription resourceDescription : resourceDescriptions.getAllResourceDescriptions()) {
		if (Strings.equal("ecore", resourceDescription.getURI().fileExtension())) {
			for (IEObjectDescription eObjectDescription : resourceDescription.getExportedObjectsByType(type)) {
				if (name.equals(eObjectDescription.getQualifiedName())) {
					return eObjectDescription.getEObjectURI();
				}
			}
		}
	}
	return null;
}
 
Example 12
Source File: NestedTypeAwareImportNormalizerWithDotSeparator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public QualifiedName deresolve(QualifiedName fullyQualifiedName) {
	if (hasWildCard()) {
		if (fullyQualifiedName.startsWith(getImportedNamespacePrefix()) 
				&& fullyQualifiedName.getSegmentCount() != getImportedNamespacePrefix().getSegmentCount()) {
			return fullyQualifiedName.skipFirst(getImportedNamespacePrefix().getSegmentCount());
		}
	} else {
		if (fullyQualifiedName.equals(getImportedNamespacePrefix())) {
			return QualifiedName.create(fullyQualifiedName.getLastSegment());
		}
		if (fullyQualifiedName.startsWith(getImportedNamespacePrefix())) {
			return fullyQualifiedName.skipFirst(getImportedNamespacePrefix().getSegmentCount() - 1);
		}
		int segmentCount = fullyQualifiedName.getSegmentCount();
		List<String> segments = Lists.newArrayListWithExpectedSize(segmentCount);
		for(int i = 0; i < segmentCount; i++) {
			String segment = fullyQualifiedName.getSegment(i);
			segments.addAll(Strings.split(segment, '$'));
		}
		if (segments.size() > segmentCount) {
			QualifiedName withoutDollars = QualifiedName.create(segments);
			if (withoutDollars.startsWith(getImportedNamespacePrefix())) {
				return withoutDollars.skipFirst(getImportedNamespacePrefix().getSegmentCount() - 1);
			}
		}
	}
	return null;
}
 
Example 13
Source File: OperatorMapping.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isUnaryOperator(QualifiedName operator) {
	return operator.equals(PLUS_PLUS) 
			|| operator.equals(MINUS_MINUS)
			|| operator.equals(MINUS)
			|| operator.equals(PLUS)
			|| operator.equals(NOT);
}
 
Example 14
Source File: NonResolvingImportScope.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
	List<IEObjectDescription> result = newArrayList();
	QualifiedName resolvedQualifiedName = null;
	ISelectable importFrom = getImportFrom();
	for (ImportNormalizer normalizer : myNormalizers) {
		final QualifiedName resolvedName = normalizer.resolve(name);
		if (resolvedName != null) {
			Iterable<IEObjectDescription> resolvedElements = importFrom.getExportedObjects(myType, resolvedName,
					isIgnoreCase());
			for (IEObjectDescription resolvedElement : resolvedElements) {
				if (resolvedQualifiedName == null)
					resolvedQualifiedName = resolvedName;
				else if (!resolvedQualifiedName.equals(resolvedName)) {
					// change is here
					if (result.get(0).getEObjectURI().equals(resolvedElement.getEObjectURI())) {
						return emptyList();
					}
					// change is above
				}
				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 15
Source File: XbaseReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isLocalVarOrFormalParameter(IEObjectDescription desc) {
	QualifiedName name = desc.getQualifiedName();
	return !name.equals(IFeatureNames.THIS) && !name.equals(IFeatureNames.SUPER);
}
 
Example 16
Source File: OperatorMapping.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public boolean isBinaryOperator(QualifiedName operator) {
	return operator.equals(MINUS) || operator.equals(PLUS) || !isUnaryOperator(operator);
}
 
Example 17
Source File: AbstractRecursiveScope.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public synchronized IEObjectDescription getSingleElement(final QualifiedName name) { // NOPMD NPathComplexity
  if (name == null) {
    throw new IllegalArgumentException("Null name in getContentByName"); //$NON-NLS-1$
  }
  try {
    if (DEBUG && !invocationTrace.add(name)) {
      throw new IllegalStateException(Messages.bind(CYCLIC_DEPENDENCY_MESSAGE, String.valueOf(name)));
    }
    final QualifiedName lookupName = isIgnoreCase() ? name.toLowerCase() : name; // NOPMD UseLocaleWithCaseConversions
    IEObjectDescription result = null;
    result = nameCache.get(lookupName);
    if (result != null) {
      return result == NULL_DESCRIPTION ? null : result; // NOPMD CompareObjectsWithEquals
    }

    if (contentsIterator == null) {
      contentsIterator = getAllLocalElements().iterator();
    }

    while (result == null && contentsIterator.hasNext()) {
      result = contentsIterator.next();
      QualifiedName thisName = result.getName();
      if (isIgnoreCase()) {
        thisName = thisName.toLowerCase(); // NOPMD UseLocaleWithCaseConversions
      }
      if (!isIgnoreCase() || nameCache.get(thisName) == null) {
        nameCache.put(thisName, result);
      }
      if (!lookupName.equals(thisName)) {
        result = null; // NOPMD NullAssignment
      }
    }

    if (result == null) {
      result = getParent().getSingleElement(name);
      // Possibly cache this result, too. For the time being, let the outer scope use its own cache, otherwise we'll duplicate
      // a lot.
    }
    if (result == null) {
      nameCache.put(lookupName, NULL_DESCRIPTION);
      // } else {
      // ScopeTrace.addTrace(result, getId());
    }
    return result;
  } catch (ConcurrentModificationException e) {
    // cache invalidated: retry
    reset();
    // Remove name from invocation trace, otherwise the intended retry recursive call will fail
    if (DEBUG) {
      invocationTrace.remove(name);
    }
    return getSingleElement(name);
  } finally {
    if (DEBUG) {
      invocationTrace.remove(name);
    }
  }
}