Java Code Examples for org.eclipse.xtext.xbase.lib.IterableExtensions#toSet()

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#toSet() . 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: WorkspaceChanges.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** Merges the given changes into this instance */
public void merge(WorkspaceChanges changes) {
	this.namesOrDependenciesChanged |= changes.namesOrDependenciesChanged;
	this.removedURIs = newArrayList(concat(this.removedURIs, changes.removedURIs));
	this.addedURIs = newArrayList(concat(this.addedURIs, changes.addedURIs));
	this.changedURIs = newArrayList(concat(this.changedURIs, changes.changedURIs));
	this.removedSourceFolders = newArrayList(concat(this.removedSourceFolders, changes.removedSourceFolders));
	this.addedSourceFolders = newArrayList(concat(this.addedSourceFolders, changes.addedSourceFolders));
	this.removedProjects = newArrayList(concat(this.removedProjects, changes.removedProjects));
	this.addedProjects = newArrayList(concat(this.addedProjects, changes.addedProjects));
	this.projectsWithChangedDependencies = newArrayList(concat(this.projectsWithChangedDependencies,
			changes.projectsWithChangedDependencies));

	// ensure consistency of 'projectsWithChangedDependencies'
	Set<String> addedRemovedProjects = IterableExtensions
			.toSet(Iterables.transform(concat(this.removedProjects, this.addedProjects), IProjectConfig::getName));
	this.projectsWithChangedDependencies.removeIf(pc -> addedRemovedProjects.contains(pc.getName()));
}
 
Example 2
Source File: ResourceURICollector.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected Set<URI> collectResources(Iterable<URI> roots, Set<String> fileExtensions) {
	Set<String> extensions = new HashSet<>(fileExtensions);
	extensions.add("java");

	List<String> paths = stream(roots.spliterator(), false).map(URI::toFileString).collect(toList());
	Multimap<String, URI> modelsFound = new PathTraverser().resolvePathes(paths, uri -> extensions.contains(uri.fileExtension()));
	
	modelsFound.asMap().forEach( (path, resource) -> {
		File file = new File(path);
		if (resource != null && !file.isDirectory() && file.getName().endsWith(".jar")) {
			registerBundle(file);
		}
	});

	return IterableExtensions.toSet(modelsFound.values());
}
 
Example 3
Source File: ContentAssistFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public Set<String> getFQFeatureNamesToExclude(final Grammar g) {
  Set<String> _xifexpression = null;
  Grammar _nonTerminalsSuperGrammar = GrammarUtil2.getNonTerminalsSuperGrammar(g);
  boolean _tripleNotEquals = (_nonTerminalsSuperGrammar != null);
  if (_tripleNotEquals) {
    Sets.SetView<String> _xblockexpression = null;
    {
      final Set<String> thisGrammarFqFeatureNames = IterableExtensions.<String>toSet(this.computeFQFeatureNames(g));
      final Function1<Grammar, Iterable<String>> _function = (Grammar it) -> {
        return this.computeFQFeatureNames(it);
      };
      final Set<String> superGrammarsFqFeatureNames = IterableExtensions.<String>toSet(Iterables.<String>concat(ListExtensions.<Grammar, Iterable<String>>map(GrammarUtil.allUsedGrammars(g), _function)));
      _xblockexpression = Sets.<String>intersection(thisGrammarFqFeatureNames, superGrammarsFqFeatureNames);
    }
    _xifexpression = _xblockexpression;
  } else {
    _xifexpression = CollectionLiterals.<String>emptySet();
  }
  return _xifexpression;
}
 
Example 4
Source File: FormatterTester.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected ArrayList<TextReplacement> createMissingEditReplacements(XtextResource res, Collection<TextReplacement> edits, int offset,
		int length) {
	Set<Integer> offsets = IterableExtensions
			.toSet(Iterables.transform(edits, (TextReplacement it) -> Integer.valueOf(it.getOffset())));
	ArrayList<TextReplacement> result = new ArrayList<>();
	int lastOffset = 0;
	IParseResult parseResult = res.getParseResult();
	if (parseResult != null) {
		ICompositeNode rootNode = parseResult.getRootNode();
		if (rootNode != null) {
			for (ILeafNode leaf : rootNode.getLeafNodes()) {
				if (!leaf.isHidden() || !StringExtensions.isNullOrEmpty(leaf.getText().trim())) {
					ITextRegion leafRegion = leaf.getTextRegion();
					if (lastOffset >= offset && leafRegion.getOffset() <= offset + length && !offsets.contains(Integer.valueOf(lastOffset))) {
						result.add(new TextReplacement(lastOffset, leafRegion.getOffset() - lastOffset, "!!"));
					}
					lastOffset = leafRegion.getOffset() + leafRegion.getLength();
				}
			}
		}
	}
	return result;
}
 
Example 5
Source File: ProjectDescriptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.15 (changed return value use 'path' of 'SourceFolderDescriptor' to get same result as before)
 */
public Set<SourceFolderDescriptor> getSourceFolders() {
  final Function1<Outlet, SourceFolderDescriptor> _function = (Outlet it) -> {
    String _sourceFolder = this.sourceFolder(it);
    boolean _isTest = this.isTest(it);
    return new SourceFolderDescriptor(_sourceFolder, _isTest);
  };
  return IterableExtensions.<SourceFolderDescriptor>toSet(ListExtensions.<Outlet, SourceFolderDescriptor>map(Collections.<Outlet>unmodifiableList(CollectionLiterals.<Outlet>newArrayList(Outlet.MAIN_JAVA, Outlet.MAIN_RESOURCES, Outlet.MAIN_SRC_GEN, Outlet.MAIN_XTEND_GEN)), _function));
}
 
Example 6
Source File: TestProjectDescriptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Set<SourceFolderDescriptor> getSourceFolders() {
  final Function1<Outlet, SourceFolderDescriptor> _function = (Outlet it) -> {
    String _sourceFolder = this.sourceFolder(it);
    boolean _isTest = this.isTest(it);
    return new SourceFolderDescriptor(_sourceFolder, _isTest);
  };
  return IterableExtensions.<SourceFolderDescriptor>toSet(ListExtensions.<Outlet, SourceFolderDescriptor>map(Collections.<Outlet>unmodifiableList(CollectionLiterals.<Outlet>newArrayList(Outlet.TEST_JAVA, Outlet.TEST_RESOURCES, Outlet.TEST_SRC_GEN, Outlet.TEST_XTEND_GEN)), _function));
}
 
Example 7
Source File: UiProjectDescriptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Set<? extends ProjectDescriptor> getUpstreamProjects() {
  RuntimeProjectDescriptor _runtimeProject = this.getConfig().getRuntimeProject();
  IdeProjectDescriptor _ideProject = this.getConfig().getIdeProject();
  final Function1<ProjectDescriptor, Boolean> _function = (ProjectDescriptor it) -> {
    return Boolean.valueOf(it.isEnabled());
  };
  return IterableExtensions.toSet(IterableExtensions.filter(Collections.<ProjectDescriptor>unmodifiableList(CollectionLiterals.<ProjectDescriptor>newArrayList(_runtimeProject, _ideProject)), _function));
}
 
Example 8
Source File: XtendMemberDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Set<Modifier> getModifiers() {
  final Function1<String, Modifier> _function = (String it) -> {
    return Modifier.valueOf(it.toUpperCase());
  };
  return IterableExtensions.<Modifier>toSet(ListExtensions.<String, Modifier>map(this.getDelegate().getModifiers(), _function));
}
 
Example 9
Source File: FileLocationsImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Set<Path> getProjectSourceFolders(final Path path) {
  final Function1<ISourceFolder, Path> _function = (ISourceFolder it) -> {
    return this.getProjectFolder(path).append(it.getName());
  };
  return IterableExtensions.<Path>toSet(IterableExtensions.map(this.getProjectConfig(path).getSourceFolders(), _function));
}
 
Example 10
Source File: TypeUsageCollectorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void hasUnresolvedTypeSuffix(final CharSequence xtendFile, final String... suffix) {
  try {
    final Resource resource = this.file(xtendFile.toString()).eResource();
    final TypeUsages typeUsages = this.typeUsageCollector.collectTypeUsages(((XtextResource) resource));
    final Function1<TypeUsage, String> _function = (TypeUsage it) -> {
      return it.getSuffix();
    };
    final Set<String> foundSuffix = IterableExtensions.<String>toSet(ListExtensions.<TypeUsage, String>map(typeUsages.getUnresolvedTypeUsages(), _function));
    Assert.assertEquals(IterableExtensions.<String>toSet(((Iterable<String>)Conversions.doWrapArray(suffix))), foundSuffix);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
Source File: TypeUsageCollectorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void hasUnresolvedType(final Resource resource, final String... typeNames) {
  final TypeUsages typeUsages = this.typeUsageCollector.collectTypeUsages(((XtextResource) resource));
  final Function1<TypeUsage, String> _function = (TypeUsage it) -> {
    return it.getUsedTypeName();
  };
  final Set<String> usedNames = IterableExtensions.<String>toSet(ListExtensions.<TypeUsage, String>map(typeUsages.getUnresolvedTypeUsages(), _function));
  Assert.assertEquals(IterableExtensions.<String>toSet(((Iterable<String>)Conversions.doWrapArray(typeNames))), usedNames);
}
 
Example 12
Source File: TraceRegionMergerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public TraceRegionMergerTest.AssertBuilder region(final int offset, final int length, final int startLine, final int endLine, final List<String> uris, final Procedure1<? super TraceRegionMergerTest.AssertBuilder> init) {
  TraceRegionMergerTest.AssertBuilder _xblockexpression = null;
  {
    final AbstractTraceRegion head = this.regions.poll();
    Assert.assertEquals(head.toString(), offset, head.getMyOffset());
    Assert.assertEquals(head.toString(), length, head.getMyLength());
    Assert.assertEquals(head.toString(), startLine, head.getMyLineNumber());
    Assert.assertEquals(head.toString(), endLine, head.getMyEndLineNumber());
    final Function1<ILocationData, SourceRelativeURI> _function = (ILocationData it) -> {
      return it.getSrcRelativePath();
    };
    final Set<SourceRelativeURI> associatedLocations = IterableExtensions.<SourceRelativeURI>toSet(ListExtensions.<ILocationData, SourceRelativeURI>map(head.getAssociatedLocations(), _function));
    Assert.assertEquals(head.toString(), ((Object[])Conversions.unwrapArray(uris, Object.class)).length, ((Object[])Conversions.unwrapArray(associatedLocations, Object.class)).length);
    for (final String uri : uris) {
      URI _createURI = URI.createURI(uri);
      SourceRelativeURI _sourceRelativeURI = new SourceRelativeURI(_createURI);
      Assert.assertTrue(("Missing " + uri), associatedLocations.contains(_sourceRelativeURI));
    }
    if ((init == null)) {
      Assert.assertTrue(head.getNestedRegions().isEmpty());
    } else {
      LinkedList<AbstractTraceRegion> _newLinkedList = CollectionLiterals.<AbstractTraceRegion>newLinkedList(((AbstractTraceRegion[])Conversions.unwrapArray(head.getNestedRegions(), AbstractTraceRegion.class)));
      final TraceRegionMergerTest.AssertBuilder child = new TraceRegionMergerTest.AssertBuilder(this.testBuilder, _newLinkedList);
      init.apply(child);
      child.thatsIt();
    }
    _xblockexpression = this;
  }
  return _xblockexpression;
}
 
Example 13
Source File: DelegateProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public Set<TypeReference> getImplementedInterfaces(final TypeReference it) {
  Set<TypeReference> _xblockexpression = null;
  {
    final LinkedHashSet<TypeReference> seen = CollectionLiterals.<TypeReference>newLinkedHashSet();
    this.collectAllSuperTypes(it, seen);
    final Function1<TypeReference, Boolean> _function = (TypeReference it_1) -> {
      Type _type = it_1.getType();
      return Boolean.valueOf((_type instanceof InterfaceDeclaration));
    };
    _xblockexpression = IterableExtensions.<TypeReference>toSet(IterableExtensions.<TypeReference>filter(seen, _function));
  }
  return _xblockexpression;
}
 
Example 14
Source File: XbaseResourceDescriptionStrategyTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNoReferenceDescriptionsForPackageFragments() throws Exception {
	XExpression expression = expression("java::lang::String::valueOf(\"\")");
	Resource resource = expression.eResource();
	IResourceDescription description = resourceDescriptionManager.getResourceDescription(resource);
	Set<String> referenceDescriptions = IterableExtensions
			.toSet(IterableExtensions.map(description.getReferenceDescriptions(), it -> it.getTargetEObjectUri().toString()));
	Assert.assertEquals(2, referenceDescriptions.size());
	Set<String> expectation = Sets.newHashSet("java:/Objects/java.lang.String#java.lang.String",
			"java:/Objects/java.lang.String#java.lang.String.valueOf(java.lang.Object)");
	Assert.assertEquals(expectation, referenceDescriptions);
}
 
Example 15
Source File: ContentAssistFragmentExtensions.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public static Set<String> getFqFeatureNamesToExclude(Grammar grammar) {
	Set<String> toExclude = new HashSet<>();
	Grammar superGrammar = ContentAssistFragmentExtensions.getSuperGrammar(grammar);
	if (superGrammar != null) {
		Set<String> superGrammarsFqFeatureNames = ContentAssistFragmentExtensions
				.computeFqFeatureNamesFromSuperGrammars(grammar);
		Set<String> thisGrammarFqFeatureNames = IterableExtensions
				.toSet(ContentAssistFragmentExtensions.computeFqFeatureNames(grammar));
		toExclude = Sets.intersection(thisGrammarFqFeatureNames, superGrammarsFqFeatureNames);
	}
	return toExclude;
}
 
Example 16
Source File: JavaResourceDescriptionManager.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isAffected(Collection<IResourceDescription.Delta> deltas, IResourceDescription candidate,
		IResourceDescriptions context) throws IllegalArgumentException {
	Collection<QualifiedName> importedNames = IterableExtensions.<QualifiedName>toSet(candidate.getImportedNames());
	for (IResourceDescription.Delta delta : deltas) {
		if (hasChanges(delta, candidate)) {
			if (isAffected(importedNames, delta.getNew()) || isAffected(importedNames, delta.getOld())) {
				return true;
			}
		}
	}
	return false;
}
 
Example 17
Source File: Ecore2XtextExtensions.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static Set<EPackage> allReferencedEPackages(final EPackage ePack, final boolean includeCrossRefs) {
  final Function1<EClassifier, EPackage> _function = (EClassifier it) -> {
    return it.getEPackage();
  };
  return IterableExtensions.<EPackage>toSet(IterableExtensions.<EPackage>filterNull(IterableExtensions.<EClassifier, EPackage>map(Ecore2XtextExtensions.allReferencedClassifiers(ePack, includeCrossRefs), _function)));
}
 
Example 18
Source File: ContentAssistFragmentExtensions.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private static Set<String> computeFqFeatureNamesFromSuperGrammars(Grammar grammar) {
	HashSet<Grammar> superGrammars = new HashSet<>();
	ContentAssistFragmentExtensions.computeAllSuperGrammars(grammar, superGrammars);
	return IterableExtensions.toSet(Iterables.concat(
			Iterables.transform(superGrammars, g -> ContentAssistFragmentExtensions.computeFqFeatureNames(g))));
}
 
Example 19
Source File: Ecore2XtextExtensions.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static Collection<EPackage> allReferencedEPackages(final Ecore2XtextConfiguration prjInfo) {
  final Function1<EPackageInfo, Set<EPackage>> _function = (EPackageInfo it) -> {
    return Ecore2XtextExtensions.allReferencedEPackages(it.getEPackage(), true);
  };
  return IterableExtensions.<EPackage>toSet(Iterables.<EPackage>concat(IterableExtensions.<EPackageInfo, Set<EPackage>>map(prjInfo.getEPackageInfos(), _function)));
}
 
Example 20
Source File: ProjectDescriptor.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Set<String> getImportedPackages() {
  final Function1<ExternalDependency, Set<String>> _function = (ExternalDependency it) -> {
    return it.getP2().getPackages();
  };
  return IterableExtensions.<String>toSet(Iterables.<String>concat(IterableExtensions.<ExternalDependency, Set<String>>map(this.getExternalDependencies(), _function)));
}