org.eclipse.xtext.naming.QualifiedName Java Examples

The following examples show how to use org.eclipse.xtext.naming.QualifiedName. 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: ValidationJobSchedulerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IResourceDescription getResourceDescription(final URI uri) {
	return new AbstractResourceDescription() {

		@Override
		public Iterable<QualifiedName> getImportedNames() {
			return Collections.emptyList();
		}

		@Override
		public Iterable<IReferenceDescription> getReferenceDescriptions() {
			return Collections.emptyList();
		}

		@Override
		public URI getURI() {
			return uri;
		}

		@Override
		protected List<IEObjectDescription> computeExportedObjects() {
			return Collections.singletonList(EObjectDescription.create(exportedName, EcoreFactory.eINSTANCE.createEObject()));
		}
		
	};
}
 
Example #2
Source File: EObjectDescriptionImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case BuilderStatePackage.EOBJECT_DESCRIPTION__ECLASS:
			setEClass((EClass)newValue);
			return;
		case BuilderStatePackage.EOBJECT_DESCRIPTION__NAME:
			setName((QualifiedName)newValue);
			return;
		case BuilderStatePackage.EOBJECT_DESCRIPTION__FRAGMENT:
			setFragment((String)newValue);
			return;
		case BuilderStatePackage.EOBJECT_DESCRIPTION__USER_DATA:
			((EStructuralFeature.Setting)getUserData()).set(newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #3
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the given action has a valid name.
 *
 * @param action the action to test.
 * @see SARLFeatureNameValidator
 */
@Check(CheckType.FAST)
public void checkActionName(SarlAction action) {
	final JvmOperation inferredOperation = this.associations.getDirectlyInferredOperation(action);
	final QualifiedName name = QualifiedName.create(inferredOperation.getQualifiedName('.').split("\\.")); //$NON-NLS-1$
	if (isReallyDisallowedName(name)) {
		final String validName = Utils.fixHiddenMember(action.getName());
		error(MessageFormat.format(
				Messages.SARLValidator_39,
				action.getName()),
				action,
				XTEND_FUNCTION__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				INVALID_MEMBER_NAME,
				validName);
	} else if (!isIgnored(DISCOURAGED_FUNCTION_NAME)
			&& this.featureNames_.isDiscouragedName(name)) {
		warning(MessageFormat.format(
				Messages.SARLValidator_39,
				action.getName()),
				action,
				XTEND_FUNCTION__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				DISCOURAGED_FUNCTION_NAME);
	}
}
 
Example #4
Source File: ResourceSetBasedResourceDescriptionsTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOneElement_Match() {
	QualifiedName qualifiedName = QualifiedName.create("SomeName");
	EClass type = EcorePackage.Literals.EPACKAGE;
	Resource resource = createResource();
	ENamedElement element = createNamedElement(qualifiedName, type, resource);
	Iterable<IEObjectDescription> iterable = container.getExportedObjectsByType(EcorePackage.Literals.EPACKAGE);
	assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
	iterable = container.getExportedObjectsByType(EcorePackage.Literals.EOBJECT);
	assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
	iterable = container.getExportedObjects(EcorePackage.Literals.EPACKAGE, qualifiedName, false);
	assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
	iterable = container.getExportedObjects(EcorePackage.Literals.ENAMED_ELEMENT, qualifiedName, false);
	assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
	iterable = container.getExportedObjects(EcorePackage.Literals.EOBJECT, qualifiedName, false);
	assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
}
 
Example #5
Source File: ImportScopeTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testImports_01() throws Exception {
	final IEObjectDescription desc1 = EObjectDescription.create(QualifiedName.create("com","foo","bar"), EcorePackage.Literals.EANNOTATION);
	final IEObjectDescription desc2 = EObjectDescription.create(QualifiedName.create("de","foo"), EcorePackage.Literals.EATTRIBUTE);
	SimpleScope outer = new SimpleScope(newArrayList(desc1,desc2), false);
	ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("com"), true, false);
	ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("de","foo"), false, false);
	TestableImportScope scope = new TestableImportScope(newArrayList(n1,n2), outer, new ScopeBasedSelectable(outer), EcorePackage.Literals.EOBJECT, false);
	
	final Iterable<IEObjectDescription> elements = scope.getAllElements();
	Iterator<IEObjectDescription> iterator = elements.iterator();
	assertEquals("foo.bar", iterator.next().getName().toString());
	assertEquals("foo", iterator.next().getName().toString());
	assertSame(desc1,iterator.next());
	assertSame(desc2,iterator.next());
	assertFalse(iterator.hasNext());
}
 
Example #6
Source File: TestLanguageReferenceUpdater.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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 #7
Source File: SyntaxFilteredScope.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("serial")
public SyntaxFilteredScope(IScope parent, List<String> values) {
	this.parent = parent;
	this.values = new HashSet<QualifiedName>() {
		@Override
		public boolean contains(Object o) {
			if (o instanceof IEObjectDescription) {
				return super.contains(((IEObjectDescription) o).getName());
			}
			return super.contains(o);
		}
	};
	for(String value: values) {
		this.values.add(QualifiedName.create(value));
	}
}
 
Example #8
Source File: UniquenessValidationHelper.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Find and returns duplicate objects from a candidate list (iterable).
 *
 * @param possiblyDuplicateObjects
 *          an Iterable into which to look for duplicates
 * @return a set of duplicate objects
 */
public Set<T> findDuplicates(final Iterable<T> possiblyDuplicateObjects) {
  if (possiblyDuplicateObjects == null) {
    return Collections.emptySet();
  }

  final Map<QualifiedName, T> nameToEObjectMap = Maps.newHashMap();
  final Set<T> duplicateEObjects = Sets.newHashSet();

  for (final T object : possiblyDuplicateObjects) {
    if (object.eIsProxy()) {
      continue;
    }
    final QualifiedName name = nameFunction.apply(object);
    if (name == null) {
      continue;
    }
    T oldObject = nameToEObjectMap.put(name, object);
    if (oldObject != null) {
      // Register both EObjects with name
      duplicateEObjects.add(object);
      duplicateEObjects.add(oldObject);
    }
  }
  return duplicateEObjects;
}
 
Example #9
Source File: ImportsAwareReferenceProposalCreator.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** In case of main module, adjust the qualified name, e.g. index.Element -> react.Element */
private QualifiedName getCandidateName(IEObjectDescription candidate, String tmodule) {
	QualifiedName candidateName;
	IN4JSProject project = n4jsCore.findProject(candidate.getEObjectURI()).orNull();
	if (project != null && tmodule != null && tmodule.equals(project.getMainModule())) {
		N4JSProjectName projectName = project.getProjectName();
		N4JSProjectName definesPackage = project.getDefinesPackageName();
		if (definesPackage != null) {
			projectName = definesPackage;
		}
		String lastSegmentOfQFN = candidate.getQualifiedName().getLastSegment().toString();
		candidateName = QualifiedName.create(projectName.getRawName(), lastSegmentOfQFN);
	} else {
		candidateName = candidate.getQualifiedName();
	}
	return candidateName;
}
 
Example #10
Source File: ImportRewriter.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings({ "unused", "deprecation" })
private AliasLocation enhanceExistingImportDeclaration(ImportDeclaration importDeclaration,
		QualifiedName qualifiedName,
		String optionalAlias, MultiTextEdit result) {

	addImportSpecifier(importDeclaration, qualifiedName, optionalAlias);
	ICompositeNode replaceMe = NodeModelUtils.getNode(importDeclaration);
	int offset = replaceMe.getOffset();
	AliasLocationAwareBuffer observableBuffer = new AliasLocationAwareBuffer(
			optionalAlias,
			offset,
			grammarAccess);

	try {
		serializer.serialize(
				importDeclaration,
				observableBuffer,
				SaveOptions.newBuilder().noValidation().getOptions());
	} catch (IOException e) {
		throw new RuntimeException("Should never happen since we write into memory", e);
	}
	result.addChild(new ReplaceEdit(offset, replaceMe.getLength(), observableBuffer.toString()));
	return observableBuffer.getAliasLocation();
}
 
Example #11
Source File: EcoreQualifiedNameProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public QualifiedName getFullyQualifiedName(final EObject obj) {
	return cache.get(Tuples.pair(obj, getCacheKey()), obj.eResource(), new Provider<QualifiedName>() {

		@Override
		public QualifiedName get() {
			EObject temp = obj;
			String name = nameDispatcher.invoke(temp);
			if (Strings.isEmpty(name))
				return null;
			QualifiedName qualifiedName = QualifiedName.create(name);
			if(!isRecurseParent(obj))
				return qualifiedName;
			QualifiedName parentsQualifiedName = getFullyQualifiedName(obj.eContainer());
			if (parentsQualifiedName == null)
				return null;
			else 
				return parentsQualifiedName.append(qualifiedName);
		}

	});
}
 
Example #12
Source File: OpenTypeSelectionDialog.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@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);
		}
	});
}
 
Example #13
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 #14
Source File: NewFeatureNameUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public String getDefaultName(XExpression expression) {
	String baseName = getBaseName(expression);
	final List<String> candidates = newArrayList();
	Set<String> excludedNames = new HashSet<String>(allKeywords); 
	for(IEObjectDescription featureDescription: featureCallScope.getAllElements()) {
		QualifiedName featureQName = featureDescription.getQualifiedName();
		if(featureQName.getSegmentCount() == 1)
			excludedNames.add(featureQName.getLastSegment());
	}
	jdtVariableCompletions.getVariableProposals(baseName, expression, VariableType.LOCAL_VAR, excludedNames, new CompletionDataAcceptor() {
		@Override
		public void accept(String replaceText, StyledString label, Image img) {
			candidates.add(replaceText);
		}
	});
	return candidates.isEmpty() ? "dingenskirchen" : candidates.get(0);
}
 
Example #15
Source File: QualifiedNameSegmentTreeLookup.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the mapped values of all nodes starting with the node for {@code lower} and up to (in depth-first search order) but excluding {@code upper}.
 *
 * @param lower
 *          name of first node to visit, must not be {@code null}
 * @param lowerIdx
 *          index into {@code lower} used for recursion, initially 0 (when receiver is root node)
 * @param upper
 *          marker node to know when to stop search (not given to visitor), must not be {@code null}
 * @param recursive
 *          whether to return {@link QualifiedNamePattern#isRecursivePattern() recursive matches} or not
 * @param excludeDuplicates
 *          whether duplicate values should be excluded in the result
 * @return collection of all values mapped by the nodes in the given range, never {@code null}
 */
@SuppressWarnings("unchecked")
public <T> Collection<T> matches(final QualifiedName lower, final int lowerIdx, final SegmentNode upper, final boolean recursive, final boolean excludeDuplicates) {
  final Collection<T> result = excludeDuplicates ? Sets.<T> newHashSet() : Lists.<T> newArrayList();
  Visitor visitor = new Visitor() {
    @Override
    public void visit(final SegmentNode node) {
      if (node.values != null) {
        for (Object value : node.values) {
          result.add((T) value);
        }
      }
    }
  };
  collectMatches(lower, lowerIdx, upper, recursive, visitor);
  return result;
}
 
Example #16
Source File: XExpressionHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<QualifiedName> getMethodNames(XAbstractFeatureCall featureCall, QualifiedName operatorSymbol) {
	List<QualifiedName> methodNames = new ArrayList<QualifiedName>();
	methodNames.add(operatorMapping.getMethodName(operatorSymbol));
	if (featureCall instanceof XBinaryOperation) {
		XBinaryOperation binaryOperation = (XBinaryOperation) featureCall;
		if (binaryOperation.isReassignFirstArgument()) {
			QualifiedName simpleOperator = operatorMapping.getSimpleOperator(operatorSymbol);
			if (simpleOperator != null) {
				methodNames.add(operatorMapping.getMethodName(simpleOperator));
			}
		}
	}
	return methodNames;
}
 
Example #17
Source File: RuleEvaluationContext.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object getValue(QualifiedName qualifiedName) {
    Object value = super.getValue(qualifiedName);
    if (value == null && this.globalContext != null) {
        value = globalContext.getValue(qualifiedName);
    }
    return value;
}
 
Example #18
Source File: Scopes.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * indexes the IEObject description using the given
 */
public static Multimap<QualifiedName,IEObjectDescription> index(Iterable<IEObjectDescription> descriptions) {
	return index(descriptions, new Function<IEObjectDescription, QualifiedName>() {
		@Override
		public QualifiedName apply(IEObjectDescription from) {
			return from.getName().toLowerCase();
		}
	});
}
 
Example #19
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies if the given operator is a reassignment operator.
 * A reassignment operator changes its left operand.
 *
 * @param operator the operator.
 * @return {@code true} if the operator changes its left operand.
 */
protected boolean isReassignmentOperator(XBinaryOperation operator) {
	if (operator.isReassignFirstArgument()) {
		return true;
	}
	final QualifiedName operatorName = this.operatorMapping.getOperator(
			QualifiedName.create(operator.getFeature().getSimpleName()));
	final QualifiedName compboundOperatorName = this.operatorMapping.getSimpleOperator(operatorName);
	return compboundOperatorName != null;
}
 
Example #20
Source File: PyGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Generate the given object.
 *
 * @param enumeration the enumeration.
 * @param context the context.
 */
protected void _generate(SarlEnumeration enumeration, IExtraLanguageGeneratorContext context) {
	final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(enumeration);
	final PyAppendable appendable = createAppendable(jvmType, context);
	if (generateEnumerationDeclaration(enumeration, appendable, context)) {
		final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(enumeration);
		writeFile(name, appendable, context);
	}
}
 
Example #21
Source File: ConstructorDescription.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public ConstructorDescription(
		QualifiedName qualifiedName, 
		JvmConstructor constructor,
		int bucketId,
		boolean visible) {
	this(qualifiedName, constructor, bucketId, visible, false);
}
 
Example #22
Source File: IndexAwareNameEnvironment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) {
	List<String> segments = Arrays.stream(packageName).map(String::valueOf).collect(Collectors.toList());
	segments.add(String.valueOf(typeName));
	QualifiedName className = QualifiedName.create(segments);
	return findType(className);
}
 
Example #23
Source File: SGraphNameProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public QualifiedName qualifiedName(Entry ele) {

		QualifiedName name = DEFAULT_ENTRY_NAME;
		if (ele.getName() != null && !ele.getName().isEmpty()) {
			name = QualifiedName.create(ele.getName());
		}

		return getParentQualifiedName(ele, name);
	}
 
Example #24
Source File: ResourceSetBasedResourceDescriptionsTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private ENamedElement createNamedElement(QualifiedName qualifiedName, EClass type, Resource resource) {
	ENamedElement result = (ENamedElement) EcoreUtil.create(type);
	if (qualifiedName != null)
		result.setName(qualifiedName.getFirstSegment());
	else
		result.setName("" + nameCount++);
	if (resource != null)
		resource.getContents().add(result);
	return result;
}
 
Example #25
Source File: XtextScopeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected IScope createClassifierScope(Iterable<EClassifier> classifiers) {
	return new SimpleScope(
			IScope.NULLSCOPE,Iterables.transform(classifiers, new Function<EClassifier, IEObjectDescription>() {
				@Override
				public IEObjectDescription apply(EClassifier param) {
					return EObjectDescription.create(QualifiedName.create(param.getName()), param);
				}
			}));
}
 
Example #26
Source File: ReceiverFeatureScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected IEObjectDescription createDescription(QualifiedName name, JvmFeature feature, TypeBucket bucket) {
	if (implicit) {
		return new InstanceFeatureDescriptionWithImplicitReceiver(name, feature, receiver, receiverType, getReceiverTypeParameterMapping(), bucket.getFlags(), bucket.getId(), isVisible(feature), validStaticState);
	} else {
		return new InstanceFeatureDescription(name, feature, receiver, receiverType, getReceiverTypeParameterMapping(), bucket.getFlags(), bucket.getId(), isVisible(feature));
	}
}
 
Example #27
Source File: SuperConstructorDescription.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public SuperConstructorDescription(
		QualifiedName qualifiedName, 
		JvmConstructor constructor,
		Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping,
		int bucketId, 
		boolean visible) {
	super(qualifiedName, constructor, bucketId, visible);
	this.typeParameterMapping = typeParameterMapping;
}
 
Example #28
Source File: AbstractConstructorScopeTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetElementByName_01() {
	IEObjectDescription objectElement = getConstructorScope().getSingleElement(QualifiedName.create(Object.class.getName()));
	assertNotNull(objectElement);
	assertFalse(objectElement.getEObjectOrProxy().eIsProxy());
	assertEquals(TypesPackage.Literals.JVM_CONSTRUCTOR, objectElement.getEClass());
	assertEquals(QualifiedName.create("java.lang.Object"), objectElement.getName());
}
 
Example #29
Source File: FormatQualifiedNameProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Qualified name for FormatConfiguration.
 *
 * @param element
 *          the FormatConfiguration
 * @return the qualified name
 */
public QualifiedName qualifiedName(final FormatConfiguration element) {
  if (element.eResource() != null && element.eResource().getURI() != null) {
    StringBuilder grammarNameBuilder = new StringBuilder();
    for (INode node : NodeModelUtils.findNodesForFeature(element, FormatPackage.Literals.FORMAT_CONFIGURATION__TARGET_GRAMMAR)) {
      grammarNameBuilder.append(NodeModelUtils.getTokenText(node));
    }
    return getConverter().toQualifiedName(grammarNameBuilder.toString());
  }
  return null;
}
 
Example #30
Source File: ExpressionScopeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertContains(IScope scope, QualifiedName name) {
	Iterable<IEObjectDescription> elements = scope.getAllElements();
	String toString = elements.toString();
	assertNotNull(toString, scope.getSingleElement(name));
	assertFalse(toString, Iterables.isEmpty(scope.getElements(name)));
	assertTrue(toString, IterableExtensions.exists(elements, it -> Objects.equal(it.getName(), name)));
}