org.eclipse.xtext.resource.IEObjectDescription Java Examples

The following examples show how to use org.eclipse.xtext.resource.IEObjectDescription. 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 Project: n4js   Author: eclipse   File: BuiltInTypeScopeTest.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
	BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
	IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
	Assert.assertNotNull(anyType);
	String s = "";
	for (Resource resource : resourceSet.getResources()) {
		if (resource.getErrors().size() > 0) {
			for (Diagnostic d : resource.getErrors()) {
				s += "\n  " + d.getMessage() + " at " + resource.getURI() + ":" + d.getLine();
			}
		}
	}

	Assert.assertEquals("Resources definine built-in types must have no error.", "", s);
}
 
Example #2
Source Project: xtext-xtend   Author: eclipse   File: NestedTypesScope.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected IEObjectDescription doGetSingleElement(JvmDeclaredType declarator, QualifiedName name, String firstSegment, int dollarIndex) {
	if (declarator.isLocal()) {
		JvmTypeReference superTypeReference = Iterables.getLast(declarator.getSuperTypes());
		if (InferredTypeIndicator.isInferred(superTypeReference))
			return findNestedTypeInLocalTypeNonResolving(declarator, name, firstSegment, dollarIndex);
	}
	
	Iterable<JvmDeclaredType> nestedTypes = declarator.findAllNestedTypesByName(firstSegment);
	for(JvmDeclaredType nested: nestedTypes) {
		JvmType nestedType = findNestedType(nested, 0, name);
		if (nestedType != null) {
			return toDescription(name, nestedType, dollarIndex, 0);
		}
	}
	return null;
}
 
Example #3
Source Project: xtext-core   Author: eclipse   File: DefaultResourceDescriptionTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testGetExportedObject_2() throws Exception {
	strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() {
		@Override
		public QualifiedName getFullyQualifiedName(EObject obj) {
			if (obj instanceof EClassifier)
				return QualifiedName.create(((EClassifier) obj).getName());
			return null;
		}
	});

	Iterable<IEObjectDescription> iterable = description.getExportedObjects();
	ArrayList<IEObjectDescription> list = Lists.newArrayList(iterable);
	assertEquals(2, list.size());
	assertEquals(eClass.getName(), list.get(0).getName().toString());
	assertEquals(eClass, list.get(0).getEObjectOrProxy());
	assertEquals(dtype.getName(), list.get(1).getName().toString());
	assertEquals(dtype, list.get(1).getEObjectOrProxy());
}
 
Example #4
Source Project: dsl-devkit   Author: dsldevkit   File: PrefixedContainerBasedScope.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("PMD.UseLocaleWithCaseConversions")
@Override
public synchronized IEObjectDescription getSingleElement(final QualifiedName name) {
  final boolean ignoreCase = isIgnoreCase();
  final QualifiedName lookupName = ignoreCase ? name.toLowerCase() : name;
  final IEObjectDescription result = contentByNameCache.get(lookupName);
  if (result != null && result != NULL_DESCRIPTION) {
    return result;
  } else if (result == null) {
    final ContainerQuery copy = ((ContainerQuery.Builder) criteria).copy().name(prefix.append(lookupName)).ignoreCase(ignoreCase);
    final Iterable<IEObjectDescription> res = copy.execute(container);
    IEObjectDescription desc = Iterables.getFirst(res, null);
    if (desc != null) {
      IEObjectDescription aliased = new AliasingEObjectDescription(name, desc);
      contentByNameCache.put(lookupName, aliased);
      return aliased;
    }
    contentByNameCache.put(lookupName, NULL_DESCRIPTION);
  }

  // in case of aliasing revert to normal ContainerBasedScope behavior (using name pattern)
  if (nameFunctions.size() > 1) {
    return super.getSingleElement(name);
  }
  return getParent().getSingleElement(name);
}
 
Example #5
Source Project: xtext-core   Author: eclipse   File: XtextScopeProvider.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected IScope createScope(final Grammar grammar, EClass type, IScope current) {
	if (EcorePackage.Literals.EPACKAGE == type) {
		return createEPackageScope(grammar);
	} else if (AbstractMetamodelDeclaration.class.isAssignableFrom(type.getInstanceClass())) {
		return new SimpleScope(IScope.NULLSCOPE,Iterables.transform(grammar.getMetamodelDeclarations(),
						new Function<AbstractMetamodelDeclaration,IEObjectDescription>(){
							@Override
							public IEObjectDescription apply(AbstractMetamodelDeclaration from) {
								String name = from.getAlias() != null ? from.getAlias() : "";
								return EObjectDescription.create(QualifiedName.create(name), from);
							}
						}));
	}
	final List<Grammar> allGrammars = getAllGrammars(grammar);
	for (int i = allGrammars.size() - 1; i >= 0; i--) {
		current = doCreateScope(allGrammars.get(i), type, current);
	}
	return current;
}
 
Example #6
Source Project: xtext-extras   Author: eclipse   File: XbaseIdeContentProposalPriorities.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public int getCrossRefPriority(IEObjectDescription objectDesc, ContentAssistEntry entry) {
	if (entry != null) {
		if (objectDesc instanceof SimpleIdentifiableElementDescription) {
			if (!"this".equals(entry.getProposal()) && !"super".equals(entry.getProposal())) {
				return adjustPriority(entry, getCrossRefPriority() + 70);
			}
		} else if (objectDesc instanceof StaticFeatureDescriptionWithTypeLiteralReceiver) {
			return adjustPriority(entry, getCrossRefPriority() + 60);
		} else if (objectDesc instanceof IIdentifiableElementDescription) {
			JvmIdentifiableElement element = ((IIdentifiableElementDescription) objectDesc).getElementOrProxy();
			if (element instanceof JvmField) {
				return adjustPriority(entry, getCrossRefPriority() + 50);
			} else if (element instanceof JvmExecutable) {
				return adjustPriority(entry, getCrossRefPriority() + 20);
			}
		}
	}
	return super.getCrossRefPriority(objectDesc, entry);
}
 
Example #7
Source Project: xtext-eclipse   Author: eclipse   File: XbaseProposalProvider.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void createReceiverProposals(XExpression receiver, CrossReference crossReference, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
//		long time = System.currentTimeMillis();
		String ruleName = getConcreteSyntaxRuleName(crossReference);
		Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(ruleName, contentAssistContext);
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(receiver);
		LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
		if (receiverType == null || receiverType.isPrimitiveVoid()) {
			return;
		}
		IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
		// TODO exploit the type name information
		IScope scope;
		if (contentAssistContext.getCurrentModel() != receiver) {
			EObject currentModel = contentAssistContext.getCurrentModel();
			if (currentModel instanceof XMemberFeatureCall && ((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver) {
				scope = filterByConcreteSyntax(expressionScope.getFeatureScope((XAbstractFeatureCall) currentModel), crossReference);
			} else {
				scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference);
			}
		} else {
			scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference);
		}
		getCrossReferenceProposalCreator().lookupCrossReference(scope, receiver, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
//		System.out.printf("XbaseProposalProvider.createReceiverProposals = %d\n", System.currentTimeMillis() - time);
	}
 
Example #8
Source Project: xtext-core   Author: eclipse   File: LiveShadowedChunkedContainerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDeleteElement() {
  try {
    this._parseHelper.parse("foo", this.fooURI, this.rs1).eResource().getContents().clear();
    final Function1<IEObjectDescription, String> _function = (IEObjectDescription it) -> {
      return it.getQualifiedName().toString();
    };
    Assert.assertEquals("", IterableExtensions.join(IterableExtensions.<IEObjectDescription, String>map(this.fooContainer.getExportedObjects(), _function), ","));
    Assert.assertEquals(1, IterableExtensions.size(this.fooContainer.getResourceDescriptions()));
    Assert.assertEquals(1, this.fooContainer.getResourceDescriptionCount());
    Assert.assertEquals(0, IterableExtensions.size(this.fooContainer.getExportedObjects()));
    Assert.assertEquals(1, IterableExtensions.size(this.barContainer.getResourceDescriptions()));
    Assert.assertEquals(1, this.barContainer.getResourceDescriptionCount());
    this.assertGlobalDescriptionsAreUnaffected();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #9
Source Project: xtext-core   Author: eclipse   File: SuperCallScopeTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testGetElementsByEObject_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("Rule: name=ID;");
  _builder.newLine();
  _builder.append("terminal ID: super;");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  EObject _model = this.getModel(grammarAsString);
  final Grammar grammar = ((Grammar) _model);
  final SuperCallScope scope = new SuperCallScope(grammar);
  final AbstractRule id = GrammarUtil.findRuleForName(grammar, "test.Lang.ID");
  Iterable<IEObjectDescription> _elements = scope.getElements(id);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "test.Lang.ID");
  Pair<String, AbstractRule> _mappedTo = Pair.<String, AbstractRule>of("Lang.ID", _findRuleForName);
  AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "test.Lang.ID");
  Pair<String, AbstractRule> _mappedTo_1 = Pair.<String, AbstractRule>of("test.Lang.ID", _findRuleForName_1);
  this.assertElements(_elements, _mappedTo, _mappedTo_1);
}
 
Example #10
Source Project: dsl-devkit   Author: dsldevkit   File: AbstractCachingResourceDescriptionManager.java    License: 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 #11
Source Project: xtext-eclipse   Author: eclipse   File: XtextProposalProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void createClassifierProposals(AbstractMetamodelDeclaration declaration, EObject model,
		ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	String alias = declaration.getAlias();
	QualifiedName prefix = (!Strings.isEmpty(alias)) ? QualifiedName.create(getValueConverter().toString(alias,
			grammarAccess.getValidIDRule().getName())) : null;
	boolean createDatatypeProposals = !(model instanceof AbstractElement)
			&& modelOrContainerIs(model, AbstractRule.class);
	boolean createEnumProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, EnumRule.class);
	boolean createClassProposals = modelOrContainerIs(model, ParserRule.class, CrossReference.class, Action.class);
	Function<IEObjectDescription, ICompletionProposal> factory = new DefaultProposalCreator(context, null, classifierQualifiedNameConverter);
	for (EClassifier classifier : declaration.getEPackage().getEClassifiers()) {
		if (classifier instanceof EDataType && createDatatypeProposals || classifier instanceof EEnum
				&& createEnumProposals || classifier instanceof EClass && createClassProposals) {
			String classifierName = getValueConverter().toString(classifier.getName(), grammarAccess.getValidIDRule().getName());
			QualifiedName proposalQualifiedName = (prefix != null) ? prefix.append(classifierName) : QualifiedName
					.create(classifierName);
			IEObjectDescription description = EObjectDescription.create(proposalQualifiedName, classifier);
			ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description);
			if (proposal != null) {
				if (prefix != null)
					proposal.setDisplayString(classifier.getName() + " - " + alias);
				proposal.setPriority(proposal.getPriority() * 2);
			}
			acceptor.accept(proposal);
		}
	}
}
 
Example #12
Source Project: xtext-extras   Author: eclipse   File: AbstractTypeScope.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getElements(QualifiedName name) {
	IEObjectDescription result = getSingleElement(name);
	if (result != null)
		return singleton(result);
	return emptySet();
}
 
Example #13
Source Project: n4js   Author: eclipse   File: BuiltInTypeScopePluginTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
	XtextResourceSet resourceSet = (XtextResourceSet) resourceSetProvider.get(null);
	resourceSet.setClasspathURIContext(N4JSResource.class.getClassLoader());
	BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
	IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
	Assert.assertNotNull(anyType);
}
 
Example #14
Source Project: xtext-eclipse   Author: eclipse   File: BuilderStateUtil.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static void copyExportedObject(IResourceDescription from, ResourceDescriptionImpl result) {
	Iterator<IEObjectDescription> sourceExportedObjects = from.getExportedObjects().iterator();
	if (sourceExportedObjects.hasNext()) {
		InternalEList<IEObjectDescription> targetExportedObjects = (InternalEList<IEObjectDescription>) result.getExportedObjects();
		do {
			targetExportedObjects.addUnique(BuilderStateUtil.create(sourceExportedObjects.next()));
		} while(sourceExportedObjects.hasNext());
	}
}
 
Example #15
Source Project: xtext-extras   Author: eclipse   File: AbstractConstructorScope.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
	Iterable<IEObjectDescription> byName = getElements(name);
	Iterator<IEObjectDescription> iterator = byName.iterator();
	if (iterator.hasNext())
		return iterator.next();
	return null;
}
 
Example #16
Source Project: xtext-extras   Author: eclipse   File: AbstractTypeScopeTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetElementByInstance_03() {
	IEObjectDescription mapEntryDescription = getTypeScope().getSingleElement(QualifiedName.create("java", "util", "Map$Entry"));
	EObject mapEntry = mapEntryDescription.getEObjectOrProxy();
	IEObjectDescription lookupDescription = getTypeScope().getSingleElement(mapEntry);
	assertNotNull(lookupDescription);
	assertEquals(QualifiedName.create("java", "util", "Map", "Entry"), lookupDescription.getName());
}
 
Example #17
Source Project: n4js   Author: eclipse   File: AbstractMemberScope.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
	IEObjectDescription single = getSingleLocalElementByName(name); // getSingleElement(name);
	if (single == null) {
		return Collections.emptyList();
	}
	return Collections.singletonList(single);
}
 
Example #18
Source Project: n4js   Author: eclipse   File: N4JSResourceDescription.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
	protected List<IEObjectDescription> computeExportedObjects() {
		final N4JSResource res = getResource() instanceof N4JSResource ? (N4JSResource) getResource() : null;
		if (res == null || !res.isLoadedFromDescription()) {
			// default behavior
			return super.computeExportedObjects();
		} else {
			// we have an N4JSResource that is loaded from the Xtext index (AST is proxy but TModule in place)

			// ORIGINAL CODE FROM SUPER-CLASS:
			if (!getResource().isLoaded()) {
				try {
					getResource().load(null);
				} catch (IOException e) {
					log.error(e.getMessage(), e);
					return Collections.<IEObjectDescription> emptyList();
				}
			}
			final List<IEObjectDescription> exportedEObjects = newArrayList();
			IAcceptor<IEObjectDescription> acceptor = new IAcceptor<>() {
				@Override
				public void accept(IEObjectDescription eObjectDescription) {
					exportedEObjects.add(eObjectDescription);
				}
			};
			// ADJUSTED:
			strategy.createEObjectDescriptions(res.getModule(), acceptor);
			// ORIGINAL CODE FROM SUPER-CLASS:
// @formatter:off
//			TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(getResource(), false);
//			while (allProperContents.hasNext()) {
//				EObject content = allProperContents.next(); // <=== this would trigger demand-load of AST!
//				if (!strategy.createEObjectDescriptions(content, acceptor))
//					allProperContents.prune();
//			}
// @formatter:on
			return exportedEObjects;
		}
	}
 
Example #19
Source Project: xtext-extras   Author: eclipse   File: FeatureScopeSessionWithLocalElements.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IEObjectDescription getLocalElement(QualifiedName name) {
	JvmIdentifiableElement result = map.get(name);
	if (result != null)
		return EObjectDescription.create(name, result);
	return super.getLocalElement(name);
}
 
Example #20
Source Project: xtext-extras   Author: eclipse   File: CompositeScope.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<IEObjectDescription> getAllLocalElements() {
	List<IEObjectDescription> result = Lists.newArrayList();
	for(AbstractSessionBasedScope delegate: delegates) {
		addToList(delegate.getAllLocalElements(), result);
	}
	return result;
}
 
Example #21
Source Project: xtext-extras   Author: eclipse   File: AbstractConstructorScopeTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetElementsByName_01() {
	Iterable<IEObjectDescription> descriptions = getConstructorScope().getElements(QualifiedName.create("java", "util", "Hashtable$Entry"));
	IEObjectDescription hashMapEntry = Iterables.getOnlyElement(descriptions);
	assertNotNull(hashMapEntry);
	assertFalse(hashMapEntry.getEObjectOrProxy().eIsProxy());
	assertEquals(TypesPackage.Literals.JVM_CONSTRUCTOR, hashMapEntry.getEClass());
	assertEquals(QualifiedName.create("java", "util", "Hashtable$Entry"), hashMapEntry.getName());
}
 
Example #22
Source Project: xtext-xtend   Author: eclipse   File: TypeParameterScope.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected IEObjectDescription doGetSingleElement(QualifiedName name) {
	if (name.getSegmentCount() == 1) {
		String singleSegment = name.getFirstSegment();
		for(int i = 0; i < typeParameters.size(); i++) {
			List<JvmTypeParameter> chunk = typeParameters.get(i);
			for(int j = 0; j < chunk.size(); j++) {
				JvmTypeParameter candidate = chunk.get(j);
				if (singleSegment.equals(candidate.getSimpleName())) {
					return EObjectDescription.create(name, candidate);
				}	
			}
		}
	}
	return null;
}
 
Example #23
Source Project: xtext-core   Author: eclipse   File: AbstractLiveContainerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
public void testNonNormalizedURIs() throws Exception {
	ResourceSet resourceSet = new XtextResourceSet();
	parser.parse("B", URI.createURI("a." + parser.fileExtension), resourceSet);
	parser.parse("B", URI.createURI("b." + parser.fileExtension), resourceSet);
	IResourceDescriptions index = descriptionsProvider.getResourceDescriptions(resourceSet);
	IResourceDescription rd = index.getResourceDescription(URI.createURI("a." + parser.fileExtension));
	List<IContainer> containers = containerManager.getVisibleContainers(rd, index);
	List<IEObjectDescription> objects = Lists.newArrayList();
	EClass type = (EClass) grammarAccess.getGrammar().getRules().get(0).getType().getClassifier();
	for (IContainer container : containers)
		Iterables.addAll(objects, container.getExportedObjects(type, QualifiedName.create("B"), false));
	assertEquals(2, objects.size());
}
 
Example #24
Source Project: gama   Author: gama-platform   File: BuiltinGlobalScopeProvider.java    License: GNU General Public License v3.0 5 votes vote down vote up
public TerminalMapBasedScope getGlobalScope(final EClass eClass) {
	if (GLOBAL_SCOPES.containsKey(eClass)) { return GLOBAL_SCOPES.get(eClass); }
	IMap<QualifiedName, IEObjectDescription> descriptions = getEObjectDescriptions(eClass);
	if (descriptions == null) {
		descriptions = EMPTY_MAP;
	}
	final TerminalMapBasedScope result = new TerminalMapBasedScope(descriptions);
	GLOBAL_SCOPES.put(eClass, result);
	return result;
}
 
Example #25
Source Project: xtext-extras   Author: eclipse   File: LocalVariableScope.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
	IEObjectDescription localElement = getSession().getLocalElement(name);
	if (localElement != null)
		return localElement;
	return super.getSingleElement(name);
}
 
Example #26
Source Project: xtext-core   Author: eclipse   File: DocumentSymbolService.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void createSymbol(IEObjectDescription description, IReferenceFinder.IResourceAccess resourceAccess,
		Procedure1<? super SymbolInformation> acceptor) {
	String name = getSymbolName(description);
	if (name == null) {
		return;
	}
	SymbolKind kind = getSymbolKind(description);
	if (kind == null) {
		return;
	}
	getSymbolLocation(description, resourceAccess, (Location location) -> {
		SymbolInformation symbol = new SymbolInformation(name, kind, location);
		acceptor.apply(symbol);
	});
}
 
Example #27
Source Project: xtext-core   Author: eclipse   File: EObjectDescriptionDeltaProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isUserDataEqual(IEObjectDescription oldObj, IEObjectDescription newObj) {
	String[] oldKeys = oldObj.getUserDataKeys();
	String[] newKeys = newObj.getUserDataKeys();
	if (oldKeys.length != newKeys.length)
		return false;
	for (String key : oldKeys) {
		if (!Arrays.contains(newKeys, key))
			return false;
		String oldValue = oldObj.getUserData(key);
		String newValue = newObj.getUserData(key);
		if (!Objects.equal(oldValue, newValue))
			return false;
	}
	return true;
}
 
Example #28
Source Project: gama   Author: gama-platform   File: BuiltinGlobalScopeProvider.java    License: GNU General Public License v3.0 5 votes vote down vote up
static void addType(final EClass eClass, final String t, final IType type) {
	final GamlDefinition stub = (GamlDefinition) EGaml.getInstance().getFactory().create(eClass);
	// TODO Add the fields definition here
	stub.setName(t);
	resources.get(eClass).getContents().add(stub);
	final Map<String, String> doc = new ImmutableMap("title", "Type " + type, "type", "type");
	final IEObjectDescription e = EObjectDescription.create(t, stub, doc);
	descriptions.get(eClass).put(e.getName(), e);
	allNames.add(e.getName());

}
 
Example #29
Source Project: xtext-extras   Author: eclipse   File: NestedTypeLiteralScope.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<IEObjectDescription> getAllLocalElements() {
	List<IEObjectDescription> result = Lists.newArrayListWithExpectedSize(2);
	if (rawEnclosingType instanceof JvmDeclaredType) {
		for(JvmMember member: ((JvmDeclaredType) rawEnclosingType).getMembers()) {
			if (member instanceof JvmDeclaredType) {
				IEObjectDescription description = EObjectDescription.create(member.getSimpleName(), member);
				addToList(new TypeLiteralDescription(description, enclosingType, isVisible((JvmType) member)), result);
			}
		}
	}
	return result;
}
 
Example #30
Source Project: xtext-extras   Author: eclipse   File: ExpressionScopeTest.java    License: 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)));
}