Java Code Examples for org.eclipse.xtext.resource.IEObjectDescription#getName()

The following examples show how to use org.eclipse.xtext.resource.IEObjectDescription#getName() . 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: STextNamesAreUniqueValidationHelper.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void checkDescriptionForDuplicatedName(IEObjectDescription description,
		ValidationMessageAcceptor acceptor) {
	if (!shouldValidateEClass(description.getEClass())) {
		return;
	}
	QualifiedName qName = description.getName();
	// check for exactly equal names
	IEObjectDescription existing = nameMap.put(qName, description);
	// check for names that only differ in case, like 'x' and 'X'
	IEObjectDescription existingLowerCase = caseInsensitiveMap.put(qName.toLowerCase(), description);
	// check for names where the qualifier is different but the name is the
	// same, like 'region1.StateA' and 'region2.StateA'.
	IEObjectDescription existingLastElement = lastElementMap.put(qName.getLastSegment(), description);
	if (existing != null) {
		validateEqualName(description, existing, acceptor);
	} else if (existingLowerCase != null) {
		validateCapitonym(description, existingLowerCase, acceptor);
	}
	if (existingLastElement != null) {
		duplicateLastElement(description, existingLastElement, acceptor);
	}
}
 
Example 2
Source File: Scopes.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static Iterable<IEObjectDescription> filterDuplicates(Iterable<IEObjectDescription> filtered) {
	Map<QualifiedName, IEObjectDescription> result = Maps.newLinkedHashMap();
	for (IEObjectDescription e : filtered) {
		QualifiedName qualifiedName = e.getName();
		if (result.containsKey(qualifiedName)) {
			result.put(qualifiedName, null);
		} else {
			result.put(qualifiedName, e);
		}
	}
	return Iterables.filter(result.values(), Predicates.notNull());
}
 
Example 3
Source File: LinkingService.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 4
Source File: AbstractCachingResourceDescriptionManager.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void addExportedNames(final Set<QualifiedName> resolvedNames, final Set<QualifiedName> unresolvedNames, final IResourceDescription resourceDescriptor) {
  if (resourceDescriptor == null) {
    return;
  }
  for (final IEObjectDescription obj : resourceDescriptor.getExportedObjects()) {
    final QualifiedName name = obj.getName();
    resolvedNames.add(name); // compare with resolved names
    // If we're using qualified names, then let's add also only the last component here. For unresolved links, we may not
    // have a qualified name to look for, but maybe only a simple name.
    unresolvedNames.add(QualifiedNames.toUnresolvedName(name)); // compare with unresolved names
  }
}
 
Example 5
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 6
Source File: MultimapBasedScope.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected boolean isShadowed(IEObjectDescription fromParent) {
	QualifiedName name = fromParent.getName();
	if (isIgnoreCase()) {
		name = name.toLowerCase();
	}
	boolean result = elements.containsKey(name);
	return result;
}
 
Example 7
Source File: NamesAreUniqueValidationHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @deprecated Use
 *             {@link #doCheckUniqueIn(IEObjectDescription, org.eclipse.xtext.validation.INamesAreUniqueValidationHelper.Context, ValidationMessageAcceptor)}
 *             instead.
 */
@Deprecated
protected void checkDescriptionForDuplicatedName(IEObjectDescription description,
		Map<EClass, Map<QualifiedName, IEObjectDescription>> clusterTypeToName,
		ValidationMessageAcceptor acceptor) {
	EObject object = description.getEObjectOrProxy();
	EClass eClass = object.eClass();
	QualifiedName qualifiedName = description.getName();
	EClass clusterType = getAssociatedClusterType(eClass);
	Map<QualifiedName, IEObjectDescription> nameToDescription = clusterTypeToName.get(clusterType);
	if (nameToDescription == null) {
		nameToDescription = Maps.newHashMap();
		nameToDescription.put(qualifiedName, description);
		clusterTypeToName.put(clusterType, nameToDescription);
	} else {
		if (nameToDescription.containsKey(qualifiedName)) {
			IEObjectDescription prevDescription = nameToDescription.get(qualifiedName);
			if (prevDescription != null) {
				createDuplicateNameError(prevDescription, clusterType, acceptor);
				nameToDescription.put(qualifiedName, null);
			}
			createDuplicateNameError(description, clusterType, acceptor);
		} else {
			nameToDescription.put(qualifiedName, description);
		}
	}
}
 
Example 8
Source File: XtendImportingTypesProposalProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ConfigurableCompletionProposal.IReplacementTextApplier createTextApplier(final ContentAssistContext context, final IScope typeScope, final IQualifiedNameConverter qualifiedNameConverter, final IValueConverter<String> valueConverter) {
  final Predicate<IEObjectDescription> _function = (IEObjectDescription it) -> {
    QualifiedName _name = it.getName();
    return (!Objects.equal(_name, XtendImportedNamespaceScopeProvider.OLD_DATA_ANNOTATION));
  };
  final FilteringScope scope = new FilteringScope(typeScope, _function);
  return super.createTextApplier(context, scope, qualifiedNameConverter, valueConverter);
}
 
Example 9
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected StyledString getStyledDisplayString(IEObjectDescription description) {
	if (EcorePackage.Literals.EPACKAGE == description.getEClass()) {
		if ("true".equals(description.getUserData("nsURI"))) {
			String name = description.getUserData("name");
			if (name == null) {
				return new StyledString(description.getName().toString());
			}
			String string = name + " - " + description.getName();
			return new StyledString(string);
		}
	} else if(XtextPackage.Literals.GRAMMAR == description.getEClass()){
		QualifiedName qualifiedName = description.getQualifiedName();
		if(qualifiedName.getSegmentCount() >1) {
			return new StyledString(qualifiedName.getLastSegment() + " - " + qualifiedName.toString());
		}
		return new StyledString(qualifiedName.toString());
	} else if (XtextPackage.Literals.ABSTRACT_RULE.isSuperTypeOf(description.getEClass())) {
		EObject object = description.getEObjectOrProxy();
		if (!object.eIsProxy()) {
			AbstractRule rule = (AbstractRule) object;
			Grammar grammar = GrammarUtil.getGrammar(rule);
			if (description instanceof EnclosingGrammarAwareDescription) {
				if (grammar == ((EnclosingGrammarAwareDescription) description).getGrammar()) {
					return getStyledDisplayString(rule, null, rule.getName());
				}
			}
			return getStyledDisplayString(rule,
					grammar.getName() + "." + rule.getName(),
					description.getName().toString().replace(".", "::"));	
		}
		
	}
	return super.getStyledDisplayString(description);
}
 
Example 10
Source File: EObjectDescriptionBasedStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getJavaFileName(IEObjectDescription description) {
	if (!isJvmDeclaredType(description)) {
		return null;
	}
	QualifiedName typeName = description.getName();
	return Strings.concat("/", typeName.getSegments()) + ".java";
}
 
Example 11
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 12
Source File: N4JSResourceDescriptionDelta.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean equals(IEObjectDescription oldObj, IEObjectDescription newObj) {
	if (oldObj == newObj)
		return true;
	if (oldObj.getEClass() != newObj.getEClass())
		return false;
	if (oldObj.getName() != null && !oldObj.getName().equals(newObj.getName()))
		return false;
	if (!oldObj.getEObjectURI().equals(newObj.getEObjectURI()))
		return false;
	String[] oldKeys = oldObj.getUserDataKeys();
	String[] newKeys = newObj.getUserDataKeys();
	if (oldKeys.length != newKeys.length)
		return false;
	for (String key : oldKeys) {
		// ------------------------------------------------ START of changes w.r.t. super class
		if (isIgnoredUserDataKey(key)) {
			continue;
		}
		// ------------------------------------------------ END of changes w.r.t. super class
		if (!Arrays.contains(newKeys, key))
			return false;
		String oldValue = oldObj.getUserData(key);
		String newValue = newObj.getUserData(key);
		if (oldValue == null) {
			if (newValue != null)
				return false;
		} else if (!oldValue.equals(newValue)) {
			return false;
		}
	}
	return true;
}
 
Example 13
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);
    }
  }
}
 
Example 14
Source File: TypeLiteralScope.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean isShadowed(IEObjectDescription fromParent) {
	if (fromParent.getName() == null)
		return true;
	return super.isShadowed(fromParent);
}
 
Example 15
Source File: ImportScope.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected QualifiedName getIgnoreCaseAwareQualifiedName(IEObjectDescription from) {
	return isIgnoreCase() ? from.getName().toLowerCase() : from.getName();
}
 
Example 16
Source File: CheckDescriptionLabelProvider.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String text(final IEObjectDescription element) {
  return element.getName() + " - " + element.getEClass().getName();
}
 
Example 17
Source File: ConstructorTypeScopeWrapper.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected ConstructorDescription createConstructorDescription(IEObjectDescription typeDescription, JvmConstructor constructor, boolean visible) {
	ConstructorDescription constructorDescription = new ConstructorDescription(
			typeDescription.getName(), constructor, ConstructorScopes.CONSTRUCTOR_BUCKET, visible);
	return constructorDescription;
}
 
Example 18
Source File: ConditionModelDescriptionLabelProvider.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public String text(IEObjectDescription ele) {
  return "my "+ele.getName();
}
 
Example 19
Source File: SimpleScope.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @return the key of the given description, which makes it shadowing others
 */
protected Object getShadowingKey(IEObjectDescription description) {
	if (isIgnoreCase())
		return description.getName().toLowerCase();
	return description.getName();
}
 
Example 20
Source File: NameFunctions.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public QualifiedName apply(final IEObjectDescription from) {
  return from.getName();
}