com.google.common.collect.ForwardingMap#org.eclipse.xtext.resource.IEObjectDescription源码实例Demo

下面列出了com.google.common.collect.ForwardingMap#org.eclipse.xtext.resource.IEObjectDescription 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: n4js   文件: BuiltInTypeScopeTest.java
@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);
}
 
源代码2 项目: xtext-xtend   文件: NestedTypesScope.java
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;
}
 
@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());
}
 
源代码4 项目: dsl-devkit   文件: PrefixedContainerBasedScope.java
@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);
}
 
源代码5 项目: xtext-core   文件: XtextScopeProvider.java
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;
}
 
@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);
}
 
源代码7 项目: xtext-eclipse   文件: XbaseProposalProvider.java
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);
	}
 
@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);
  }
}
 
源代码9 项目: xtext-core   文件: SuperCallScopeTest.java
@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);
}
 
/** {@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
  }
}
 
源代码11 项目: xtext-eclipse   文件: XtextProposalProvider.java
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);
		}
	}
}
 
源代码12 项目: xtext-extras   文件: AbstractTypeScope.java
@Override
public Iterable<IEObjectDescription> getElements(QualifiedName name) {
	IEObjectDescription result = getSingleElement(name);
	if (result != null)
		return singleton(result);
	return emptySet();
}
 
源代码13 项目: n4js   文件: BuiltInTypeScopePluginTest.java
@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);
}
 
源代码14 项目: xtext-eclipse   文件: BuilderStateUtil.java
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());
	}
}
 
源代码15 项目: xtext-extras   文件: AbstractConstructorScope.java
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
	Iterable<IEObjectDescription> byName = getElements(name);
	Iterator<IEObjectDescription> iterator = byName.iterator();
	if (iterator.hasNext())
		return iterator.next();
	return null;
}
 
源代码16 项目: xtext-extras   文件: AbstractTypeScopeTest.java
@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());
}
 
源代码17 项目: n4js   文件: AbstractMemberScope.java
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
	IEObjectDescription single = getSingleLocalElementByName(name); // getSingleElement(name);
	if (single == null) {
		return Collections.emptyList();
	}
	return Collections.singletonList(single);
}
 
源代码18 项目: n4js   文件: N4JSResourceDescription.java
@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;
		}
	}
 
@Override
public IEObjectDescription getLocalElement(QualifiedName name) {
	JvmIdentifiableElement result = map.get(name);
	if (result != null)
		return EObjectDescription.create(name, result);
	return super.getLocalElement(name);
}
 
源代码20 项目: xtext-extras   文件: CompositeScope.java
@Override
protected List<IEObjectDescription> getAllLocalElements() {
	List<IEObjectDescription> result = Lists.newArrayList();
	for(AbstractSessionBasedScope delegate: delegates) {
		addToList(delegate.getAllLocalElements(), result);
	}
	return result;
}
 
@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());
}
 
源代码22 项目: xtext-xtend   文件: TypeParameterScope.java
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;
}
 
源代码23 项目: xtext-core   文件: AbstractLiveContainerTest.java
@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());
}
 
源代码24 项目: gama   文件: BuiltinGlobalScopeProvider.java
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;
}
 
源代码25 项目: xtext-extras   文件: LocalVariableScope.java
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
	IEObjectDescription localElement = getSession().getLocalElement(name);
	if (localElement != null)
		return localElement;
	return super.getSingleElement(name);
}
 
源代码26 项目: xtext-core   文件: DocumentSymbolService.java
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);
	});
}
 
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;
}
 
源代码28 项目: gama   文件: BuiltinGlobalScopeProvider.java
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());

}
 
源代码29 项目: xtext-extras   文件: NestedTypeLiteralScope.java
@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;
}
 
源代码30 项目: xtext-extras   文件: ExpressionScopeTest.java
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)));
}