summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-04-01 12:37:22 (EDT)
committer sefftinge2009-04-01 12:37:22 (EDT)
commita6d9990a14bfa0a71820cf6e3bc9f1d801c696da (patch)
tree8aeaffe381646798e2a135a60905e4f74a56fee2
parent59ade4c4dbaf762048c57362ce831d6738b79772 (diff)
downloadorg.eclipse.xtext-a6d9990a14bfa0a71820cf6e3bc9f1d801c696da.zip
org.eclipse.xtext-a6d9990a14bfa0a71820cf6e3bc9f1d801c696da.tar.gz
org.eclipse.xtext-a6d9990a14bfa0a71820cf6e3bc9f1d801c696da.tar.bz2
Migration to google collections
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java15
-rw-r--r--plugins/org.eclipse.xtext.xtend/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/check/AbstractCheckValidator.java18
-rw-r--r--plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Services.ext4
-rw-r--r--plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java12
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/SimpleAttributeResolverTest.java6
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/lazy/LazyLinkingTestLanguageScopeProvider.java10
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java10
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/ToEcoreTrafoTest.java9
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java8
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/XtextGrammarComparingTest.java12
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/epatch/EpatchComparingTest.java11
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ChainedIteratorTest.java30
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java20
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/MappingIteratorTest.java12
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/PolymorphicDispatcherTest.java17
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/SimpleCacheTest.java5
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/valueconverter/ParserComparingTest.java14
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ExceptionTest.java7
-rw-r--r--tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java11
20 files changed, 131 insertions, 103 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java
index b3aae9f..5da2edc 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java
@@ -10,8 +10,6 @@ package org.eclipse.xtext.ui.common.editor.contentassist.impl;
import static java.lang.Math.max;
import static org.eclipse.xtext.parsetree.ParseTreeUtil.getCurrentOrFollowingNodeByOffset;
import static org.eclipse.xtext.parsetree.ParseTreeUtil.getLastCompleteNodeByOffset;
-import static org.eclipse.xtext.util.CollectionUtils.addAllIfNotNull;
-import static org.eclipse.xtext.util.CollectionUtils.addIfNotNull;
import java.util.ArrayList;
import java.util.Arrays;
@@ -48,6 +46,8 @@ import org.eclipse.xtext.ui.common.editor.contentassist.ITemplateContentAssistPr
import org.eclipse.xtext.ui.core.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.core.editor.model.UnitOfWork;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
import com.google.inject.Inject;
/**
@@ -136,6 +136,11 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
return completionProposalList;
}
+ private <T> void addAllIfNotNull(List<T> completionProposalList,
+ List<? extends T> proposals) {
+ Iterables.addAll(completionProposalList, Iterables.filter(proposals, Predicates.notNull()));
+ }
+
protected List<TemplateContextType> collectTemplateContextTypes(List<AbstractElement> computeProposalElements,
IContentAssistContext contentAssistContext) {
List<TemplateContextType> templateContextTypes = new ArrayList<TemplateContextType>();
@@ -162,6 +167,12 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
}
return templateContextTypes;
}
+
+ private <T> void addIfNotNull(List<T> result, T obj) {
+ if (obj != null)
+ result.add(obj);
+ }
+
/**
* Adds templates to the list of proposals,
*
diff --git a/plugins/org.eclipse.xtext.xtend/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtext.xtend/META-INF/MANIFEST.MF
index 048d5d0..ae0900e 100644
--- a/plugins/org.eclipse.xtext.xtend/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.xtext.xtend/META-INF/MANIFEST.MF
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jface.text,
org.eclipse.xtend.typesystem.emf;bundle-version="0.7.0",
org.eclipse.xtext.log4j;bundle-version="1.2.15",
- org.eclipse.xtend.util.stdlib;bundle-version="0.7.0";visibility:=reexport
+ org.eclipse.xtend.util.stdlib;bundle-version="0.7.0";visibility:=reexport,
+ com.google.collect;bundle-version="0.8.0";visibility:=reexport
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.xtext.check,
diff --git a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/check/AbstractCheckValidator.java b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/check/AbstractCheckValidator.java
index 683e8bd..6a37303 100644
--- a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/check/AbstractCheckValidator.java
+++ b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/check/AbstractCheckValidator.java
@@ -8,8 +8,10 @@
package org.eclipse.xtext.check;
import java.util.Collections;
-import java.util.List;
+import java.util.EnumMap;
+import java.util.LinkedHashSet;
import java.util.Map;
+import java.util.Set;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.ecore.EClass;
@@ -19,7 +21,6 @@ import org.eclipse.emf.mwe.core.issues.IssuesImpl;
import org.eclipse.emf.mwe.core.issues.MWEDiagnostic;
import org.eclipse.xtend.check.CheckFacade;
import org.eclipse.xtend.expression.ExecutionContext;
-import org.eclipse.xtext.util.MultiMap;
import org.eclipse.xtext.validator.AbstractInjectableValidator;
import org.eclipse.xtext.validator.CheckMode;
import org.eclipse.xtext.validator.CheckType;
@@ -38,14 +39,19 @@ public abstract class AbstractCheckValidator extends AbstractInjectableValidator
this.ctx = ctx;
}
- private final MultiMap<CheckType, String> checkFiles = new MultiMap<CheckType, String>();
+ private final EnumMap<CheckType, Set<String>> checkFiles = new EnumMap<CheckType, Set<String>>(CheckType.class);
public void addCheckFile(String checkFile, CheckType checkType) {
- checkFiles.put(checkType, checkFile);
+ Set<String> checks = checkFiles.get(checkType);
+ if(checks == null) {
+ checks = new LinkedHashSet<String>();
+ checkFiles.put(checkType, checks);
+ }
+ checks.add(checkFile);
}
public void addCheckFile(String checkFile) {
- checkFiles.put(CheckType.FAST, checkFile);
+ addCheckFile(checkFile, CheckType.FAST);
}
public boolean validate(EClass eClass, EObject eObject, final DiagnosticChain diagnostics, Map<Object, Object> context) {
@@ -53,7 +59,7 @@ public abstract class AbstractCheckValidator extends AbstractInjectableValidator
Issues issues = new IssuesImpl();
for (CheckType type: checkFiles.keySet()) {
if (mode.shouldCheck(type)) {
- List<String> list = checkFiles.get(type);
+ Set<String> list = checkFiles.get(type);
for (String string : list) {
CheckFacade.checkAll(string, Collections.singleton(eObject), ctx, issues);
}
diff --git a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Services.ext b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Services.ext
index 6ddba23..8d8bb4f 100644
--- a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Services.ext
+++ b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/Services.ext
@@ -29,6 +29,6 @@ List[emf::EObject] allElements(emf::EObject this) :
IScope getScope(IScopeProvider this, Object obj, Object ref) :
JAVA org.eclipse.xtext.xtend.contentassist.ContentAssistHelper.getScope(org.eclipse.xtext.crossref.IScopeProvider, java.lang.Object, java.lang.Object);
-List toList(Iterable i):
- JAVA org.eclipse.xtext.util.CollectionUtils.list(java.lang.Iterable);
+List toList(Iterable this):
+ JAVA com.google.common.^collect.Lists.newArrayList(java.lang.Iterable);
diff --git a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java
index 2bf94ab..6c309c6 100644
--- a/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java
+++ b/plugins/org.eclipse.xtext.xtend/src/org/eclipse/xtext/xtend/crossref/AbstractXtendScopeProvider.java
@@ -7,8 +7,6 @@
*******************************************************************************/
package org.eclipse.xtext.xtend.crossref;
-import static org.eclipse.xtext.util.CollectionUtils.*;
-
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -21,9 +19,11 @@ import org.eclipse.xtext.crossref.IScope;
import org.eclipse.xtext.crossref.IScopeProvider;
import org.eclipse.xtext.crossref.IScopedElement;
import org.eclipse.xtext.crossref.impl.SimpleNestedScope;
-import org.eclipse.xtext.util.Filter;
import org.eclipse.xtext.xtend.AbstractXtendService;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
/**
* @author Jan Köhnlein - Initial contribution and API
*/
@@ -38,15 +38,15 @@ public abstract class AbstractXtendScopeProvider extends AbstractXtendService im
List<IScopedElement> scopedElements = invokeExtension(extensionName(context, reference), Collections
.singletonList(context));
final Collection<String> names = new HashSet<String>(scopedElements.size());
- return new SimpleNestedScope(list(filter(scopedElements, new Filter<IScopedElement>() {
- public boolean accept(IScopedElement param) {
+ return new SimpleNestedScope(Iterables.filter(scopedElements, new Predicate<IScopedElement>() {
+ public boolean apply(IScopedElement param) {
boolean result = reference.getEReferenceType().isSuperTypeOf(param.element().eClass());
if (result) {
result = names.add(param.name());
}
return result;
}
- })));
+ }));
}
catch (Throwable e) {
log.error("Error invoking scope extension", e);
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/SimpleAttributeResolverTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/SimpleAttributeResolverTest.java
index 08b943d..27256be 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/SimpleAttributeResolverTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/SimpleAttributeResolverTest.java
@@ -26,10 +26,10 @@ public class SimpleAttributeResolverTest extends TestCase {
private EcoreFactory factory;
- private SimpleAttributeResolver<String> nameResolver;
+ private SimpleAttributeResolver<EObject, String> nameResolver;
@SuppressWarnings("unchecked")
- private SimpleAttributeResolver<EList> superClassResolver;
+ private SimpleAttributeResolver<EObject, EList> superClassResolver;
@Override
protected void setUp() throws Exception {
@@ -69,7 +69,7 @@ public class SimpleAttributeResolverTest extends TestCase {
EClass clazzNoMatch = factory.createEClass();
clazzMatch.setName("ClassName");
clazzNoMatch.setName("NoMatchClassName");
- Iterable<EObject> res = nameResolver.getMatches(Arrays.asList(clazzMatch, clazzNoMatch), "ClassName");
+ Iterable<EObject> res = nameResolver.getMatches(Arrays.<EObject>asList(clazzMatch, clazzNoMatch), "ClassName");
assertNotNull("res", res);
Iterator<EObject> iter = res.iterator();
assertTrue(iter.hasNext());
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/lazy/LazyLinkingTestLanguageScopeProvider.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/lazy/LazyLinkingTestLanguageScopeProvider.java
index 089e2f1..3adc014 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/lazy/LazyLinkingTestLanguageScopeProvider.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/lazy/LazyLinkingTestLanguageScopeProvider.java
@@ -16,8 +16,9 @@ import org.eclipse.xtext.crossref.impl.ScopedElement;
import org.eclipse.xtext.crossref.impl.SimpleNestedScope;
import org.eclipse.xtext.crossrefs.lazy.lazyLinking.Property;
import org.eclipse.xtext.crossrefs.lazy.lazyLinking.Type;
-import org.eclipse.xtext.util.CollectionUtils;
-import org.eclipse.xtext.util.Function;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
/**
* @author Sven Efftinge - Initial contribution and API
@@ -26,9 +27,8 @@ import org.eclipse.xtext.util.Function;
public class LazyLinkingTestLanguageScopeProvider extends DeclarativeScopeProvider {
public IScope scope_Property(Type t, EReference ref) {
- return new SimpleNestedScope(CollectionUtils.map(t.getExtends().getProperties(), new Function<Property, IScopedElement>(){
-
- public IScopedElement exec(Property param) {
+ return new SimpleNestedScope(Iterables.transform(t.getExtends().getProperties(), new Function<Property, IScopedElement>(){
+ public IScopedElement apply(Property param) {
return ScopedElement.create(param.getName(), param);
}
}));
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java
index 9f37dd6..138a5f3 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/InheritanceTest.java
@@ -8,8 +8,6 @@
*******************************************************************************/
package org.eclipse.xtext.grammarinheritance;
-import static org.eclipse.xtext.util.CollectionUtils.map;
-
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
@@ -23,7 +21,9 @@ import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.TypeRef;
import org.eclipse.xtext.grammarinheritance.ametamodel.AmetamodelPackage;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.util.Function;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
public class InheritanceTest extends AbstractGeneratorTest {
@@ -52,8 +52,8 @@ public class InheritanceTest extends AbstractGeneratorTest {
assertEquals("AType2", clazz.getName());
assertEquals(2, clazz.getESuperTypes().size());
Set<String> expectedNames = new HashSet<String>(Arrays.asList(new String[]{"AType", "RootRule"}));
- Iterator<String> iter = map(clazz.getESuperTypes(), new Function<EClass, String>(){
- public String exec(EClass param) {
+ Iterator<String> iter = Iterables.transform(clazz.getESuperTypes(), new Function<EClass, String>(){
+ public String apply(EClass param) {
return param.getName();
}
}).iterator();
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/ToEcoreTrafoTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/ToEcoreTrafoTest.java
index 9e2a19e..c26e486 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/ToEcoreTrafoTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/grammarinheritance/ToEcoreTrafoTest.java
@@ -20,10 +20,11 @@ import org.eclipse.xtext.XtextStandaloneSetup;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.util.CollectionUtils;
-import org.eclipse.xtext.util.Filter;
import org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
public class ToEcoreTrafoTest extends AbstractGeneratorTest {
private static final Logger logger = Logger.getLogger(ToEcoreTrafoTest.class);
@@ -72,8 +73,8 @@ public class ToEcoreTrafoTest extends AbstractGeneratorTest {
XtextResource r = getResource("classpath:/" + ConcreteTestLanguage.class.getName().replace('.', '/') + ".xtext");
EObject element = r.getParseResult().getRootASTElement();
Grammar g = (Grammar) element;
- List<AbstractMetamodelDeclaration> mms = CollectionUtils.list(
- CollectionUtils.filter(g.getMetamodelDeclarations(), Filter.Util.<AbstractMetamodelDeclaration>instanceOf(GeneratedMetamodel.class)));
+ List<AbstractMetamodelDeclaration> mms = Lists.<AbstractMetamodelDeclaration>newArrayList(
+ Iterables.filter(g.getMetamodelDeclarations(), GeneratedMetamodel.class));
assertNotNull(mms);
assertEquals(1, mms.size());
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java
index c18a389..7190f84 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java
@@ -7,6 +7,8 @@
*******************************************************************************/
package org.eclipse.xtext.parser;
+import java.util.Iterator;
+
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.xtext.ISetup;
import org.eclipse.xtext.parsetree.ParsetreePackage;
@@ -43,7 +45,7 @@ public abstract class AbstractParserComparingTest extends AbstractGeneratorTest
protected abstract IParser createFirstParser();
protected abstract IParser createSecondParser();
- protected abstract Iterable<Pair<String, String>> getAllModels();
+ protected abstract Iterator<Pair<String, String>> getAllModels();
public void testCompareAllModels() throws Exception {
final Wrapper<String> modelName = Wrapper.forType(String.class);
@@ -53,7 +55,9 @@ public abstract class AbstractParserComparingTest extends AbstractGeneratorTest
return modelName.get() + " - " + super.getErrorMessage();
}
};
- for(Pair<String, String> pair: getAllModels()) {
+ Iterator<Pair<String, String>> iter = getAllModels();
+ while(iter.hasNext()) {
+ Pair<String, String> pair = iter.next();
String model = pair.getSecond();
modelName.set(pair.getFirst() + "(" + getFirstParserName() + " / " + getSecondParserName() + ")");
try {
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/XtextGrammarComparingTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/XtextGrammarComparingTest.java
index 0531bfb..fcf1ded 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/XtextGrammarComparingTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/XtextGrammarComparingTest.java
@@ -9,26 +9,28 @@ package org.eclipse.xtext.parser;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.xtext.GenerateAllTestGrammars;
import org.eclipse.xtext.ISetup;
import org.eclipse.xtext.XtextStandaloneSetup;
-import org.eclipse.xtext.util.CollectionUtils;
-import org.eclipse.xtext.util.Function;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
+
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
public class XtextGrammarComparingTest extends AbstractParserComparingTest {
@Override
- protected Iterable<Pair<String, String>> getAllModels() {
+ protected Iterator<Pair<String, String>> getAllModels() {
List<Class<?>> classes = Arrays.asList(GenerateAllTestGrammars.getTestGrammarClasses());
- return CollectionUtils.map(classes, new Function<Class<?>, Pair<String, String>>() {
- public Pair<String, String> exec(Class<?> param) {
+ return Iterators.transform(classes.iterator(), new Function<Class<?>, Pair<String, String>>() {
+ public Pair<String, String> apply(Class<?> param) {
String filename = GenerateAllTestGrammars.getGrammarFileName(param);
String model;
try {
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/epatch/EpatchComparingTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/epatch/EpatchComparingTest.java
index df6b6f2..73903d3 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/epatch/EpatchComparingTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/epatch/EpatchComparingTest.java
@@ -13,21 +13,22 @@ import java.util.Iterator;
import org.eclipse.xtext.ISetup;
import org.eclipse.xtext.parser.AbstractParserComparingTest;
import org.eclipse.xtext.parser.IParser;
-import org.eclipse.xtext.util.CollectionUtils;
-import org.eclipse.xtext.util.Function;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
+
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
public class EpatchComparingTest extends AbstractParserComparingTest {
@Override
- protected Iterable<Pair<String, String>> getAllModels() {
+ protected Iterator<Pair<String, String>> getAllModels() {
Iterator<String> resources = getAllEpatchTestcases();
- return CollectionUtils.map(resources, new Function<String, Pair<String, String>>() {
- public Pair<String, String> exec(String filename) {
+ return Iterators.transform(resources, new Function<String, Pair<String, String>>() {
+ public Pair<String, String> apply(String filename) {
String model;
try {
model = readFileIntoString(filename);
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ChainedIteratorTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ChainedIteratorTest.java
index bc606b5..c82b6cc 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ChainedIteratorTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ChainedIteratorTest.java
@@ -7,43 +7,41 @@
*******************************************************************************/
package org.eclipse.xtext.util;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.Iterator;
-import org.eclipse.xtext.util.ChainedIterator;
+import com.google.common.base.Join;
+import com.google.common.collect.Iterators;
import junit.framework.TestCase;
public class ChainedIteratorTest extends TestCase {
+ @SuppressWarnings("unchecked")
public void testSimple() throws Exception {
- ChainedIterator<String> iter = new ChainedIterator<String>(new ChainedIterator<String>(iter("a","b"),iter("c")),iter("d"));
- assertEquals("abcd",concat(iter));
+ Iterator<String> iter = Iterators.concat(iter("a","b"), iter("c"), iter("d"));
+ assertEquals("abcd", Join.join("", iter));
}
+ @SuppressWarnings("unchecked")
public void testSecondArgNull() throws Exception {
- ChainedIterator<String> iter = new ChainedIterator<String>(new ChainedIterator<String>(iter("a","b"),null),null);
- assertEquals("ab",concat(iter));
+ try {
+ Iterators.concat(iter("a","b"), null, null);
+ fail("NPE expected.");
+ } catch(NullPointerException ex) {
+ // expected
+ }
}
public void testFirstArgNull() throws Exception {
try {
- new ChainedIterator<String>(null, Collections.<String>emptyList().iterator());
+ Iterators.concat(null, iter("a","b"));
fail("nullpointer exception expected");
} catch (NullPointerException npe){
//expected
}
}
- private String concat(Iterator<String> iter) {
- String r = "";
- while (iter.hasNext())
- r+=iter.next();
- return r;
- }
-
private Iterator<String> iter(String ... elements) {
- return Arrays.asList(elements).iterator();
+ return Iterators.forArray(elements, 0, elements.length);
}
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java
index 0a99136..1293712 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java
@@ -12,15 +12,15 @@ import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.xtext.util.Filter;
-import org.eclipse.xtext.util.FilteringIterator;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
import junit.framework.TestCase;
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
-public class FilteringIteratorTest extends TestCase implements Filter<String> {
+public class FilteringIteratorTest extends TestCase implements Predicate<String> {
private String matchMe;
@@ -33,17 +33,17 @@ public class FilteringIteratorTest extends TestCase implements Filter<String> {
list = new ArrayList<String>();
}
- public boolean accept(String param) {
+ public boolean apply(String param) {
return param.equals(matchMe);
}
public void testEmptyList() {
- Iterator<String> iter = new FilteringIterator<String>(list, this);
+ Iterator<String> iter = Iterators.filter(list.iterator(), this);
assertFalse(iter.hasNext());
}
public void testConcurrentModificationException() {
- Iterator<String> iter = new FilteringIterator<String>(list, this);
+ Iterator<String> iter = Iterators.filter(list.iterator(), this);
list.add("null");
try {
iter.hasNext();
@@ -54,7 +54,7 @@ public class FilteringIteratorTest extends TestCase implements Filter<String> {
public void testRemove() {
list.add(matchMe);
- Iterator<String> iter = new FilteringIterator<String>(list, this);
+ Iterator<String> iter = Iterators.filter(list.iterator(), this);
iter.next();
try {
iter.remove();
@@ -67,7 +67,7 @@ public class FilteringIteratorTest extends TestCase implements Filter<String> {
list.add("null");
list.add(matchMe);
list.add("null");
- Iterator<String> iter = new FilteringIterator<String>(list, this);
+ Iterator<String> iter = Iterators.filter(list.iterator(), this);
assertTrue(iter.hasNext());
assertTrue(iter.hasNext());
assertEquals(matchMe, iter.next());
@@ -79,7 +79,7 @@ public class FilteringIteratorTest extends TestCase implements Filter<String> {
list.add(matchMe);
list.add("null");
list.add(matchMe);
- Iterator<String> iter = new FilteringIterator<String>(list, this);
+ Iterator<String> iter = Iterators.filter(list.iterator(), this);
assertTrue(iter.hasNext());
assertEquals(matchMe, iter.next());
assertTrue(iter.hasNext());
@@ -92,7 +92,7 @@ public class FilteringIteratorTest extends TestCase implements Filter<String> {
list.add(matchMe);
list.add("null");
list.add(matchMe);
- Iterator<String> iter = new FilteringIterator<String>(list, this);
+ Iterator<String> iter = Iterators.filter(list.iterator(), this);
assertEquals(matchMe, iter.next());
assertEquals(matchMe, iter.next());
assertFalse(iter.hasNext());
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/MappingIteratorTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/MappingIteratorTest.java
index 260ee5e..7204ec8 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/MappingIteratorTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/MappingIteratorTest.java
@@ -10,8 +10,8 @@ package org.eclipse.xtext.util;
import java.util.Arrays;
import java.util.Iterator;
-import org.eclipse.xtext.util.Function;
-import org.eclipse.xtext.util.MappingIterator;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
import junit.framework.TestCase;
@@ -20,7 +20,7 @@ import junit.framework.TestCase;
*/
public class MappingIteratorTest extends TestCase implements Function<String, String> {
- public String exec(String param) {
+ public String apply(String param) {
return param + "->" + param;
}
@@ -46,7 +46,7 @@ public class MappingIteratorTest extends TestCase implements Function<String, St
public void testNullIter() {
try {
- new MappingIterator<String, String>(null, this);
+ Iterators.transform(null, this);
fail("NPE expected");
} catch(NullPointerException e) {
// expected
@@ -55,14 +55,14 @@ public class MappingIteratorTest extends TestCase implements Function<String, St
public void testNullFunction() {
try {
- new MappingIterator<String, String>(createMappingIterator("a"), null);
+ Iterators.transform(createMappingIterator("a"), null);
} catch(NullPointerException e) {
// expected
}
}
private Iterator<String> createMappingIterator(String ...strings) {
- return new MappingIterator<String, String>(Arrays.asList(strings).iterator(), this);
+ return Iterators.transform(Arrays.asList(strings).iterator(), this);
}
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/PolymorphicDispatcherTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/PolymorphicDispatcherTest.java
index 681f31d..c2acac7 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/PolymorphicDispatcherTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/PolymorphicDispatcherTest.java
@@ -8,8 +8,6 @@
*******************************************************************************/
package org.eclipse.xtext.util;
-import static org.eclipse.xtext.util.CollectionUtils.list;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -17,6 +15,9 @@ import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.math.BigInteger;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+
import junit.framework.TestCase;
/**
@@ -54,7 +55,7 @@ public class PolymorphicDispatcherTest extends TestCase {
return "Object_" + i;
}
};
- PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>("label", list(first, second));
+ PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>("label", Lists.newArrayList(first, second));
assertEquals("Integer_first_3", dispatcher.invoke(new Integer(3)));
assertEquals("Number_from_superclass_3", dispatcher.invoke(new Long(3)));
@@ -76,7 +77,7 @@ public class PolymorphicDispatcherTest extends TestCase {
return "Object_" + i;
}
};
- PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>("label", 1, 2, list(o1),
+ PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>("label", 1, 2, Lists.newArrayList(o1),
new PolymorphicDispatcher.ErrorHandler<String>(){
public String handle(Object[] params, Throwable throwable) {
return null;
@@ -100,7 +101,7 @@ public class PolymorphicDispatcherTest extends TestCase {
return Comparable.class.getSimpleName();
}
};
- PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>("label", list(o1));
+ PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>("label", Lists.newArrayList(o1));
try {
dispatcher.invoke("string");
fail("exception expected, due to ambigous methods");
@@ -119,7 +120,7 @@ public class PolymorphicDispatcherTest extends TestCase {
return "Number_" + n;
}
};
- PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>("label", list(o1));
+ PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>("label", Lists.newArrayList(o1));
assertEquals("Integer_17", dispatcher.invoke(new Integer(17)));
assertEquals("Number_42", dispatcher.invoke(BigInteger.valueOf(42)));
}
@@ -139,8 +140,8 @@ public class PolymorphicDispatcherTest extends TestCase {
return "Number_" + n;
}
};
- PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>(list(o1), new Filter<Method>() {
- public boolean accept(Method param) {
+ PolymorphicDispatcher<String> dispatcher = new PolymorphicDispatcher<String>(Lists.newArrayList(o1), new Predicate<Method>() {
+ public boolean apply(Method param) {
return ( (param.getName().equals("label")) || (param.getAnnotation(TestLabelAnnotation.class) != null));
}
});
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/SimpleCacheTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/SimpleCacheTest.java
index fb922db..b693111 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/SimpleCacheTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/SimpleCacheTest.java
@@ -7,9 +7,10 @@
*******************************************************************************/
package org.eclipse.xtext.util;
-import org.eclipse.xtext.util.Function;
import org.eclipse.xtext.util.SimpleCache;
+import com.google.common.base.Function;
+
import junit.framework.TestCase;
/**
@@ -30,7 +31,7 @@ public class SimpleCacheTest extends TestCase implements Function<String, String
callCount = 0;
}
- public String exec(String param) {
+ public String apply(String param) {
assertEquals(expectedParam, param);
callCount++;
return param + param;
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/valueconverter/ParserComparingTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/valueconverter/ParserComparingTest.java
index 2021d60..c3712e6 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/valueconverter/ParserComparingTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/valueconverter/ParserComparingTest.java
@@ -8,15 +8,17 @@
package org.eclipse.xtext.valueconverter;
import java.util.Arrays;
+import java.util.Iterator;
import org.eclipse.xtext.ISetup;
import org.eclipse.xtext.parser.AbstractParserComparingTest;
import org.eclipse.xtext.parser.IParser;
-import org.eclipse.xtext.util.CollectionUtils;
-import org.eclipse.xtext.util.Function;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
@@ -67,12 +69,12 @@ public class ParserComparingTest extends AbstractParserComparingTest {
}
@Override
- protected Iterable<Pair<String, String>> getAllModels() {
- return CollectionUtils.map(Arrays.asList(testModels), new Function<String, Pair<String, String>>(){
- public Pair<String, String> exec(String param) {
+ protected Iterator<Pair<String, String>> getAllModels() {
+ return Iterables.transform(Arrays.asList(testModels), new Function<String, Pair<String, String>>(){
+ public Pair<String, String> apply(String param) {
return Tuples.create(param, param);
}
- });
+ }).iterator();
}
@Override
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ExceptionTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ExceptionTest.java
index 94a9372..4a52c63 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ExceptionTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ExceptionTest.java
@@ -8,12 +8,11 @@
package org.eclipse.xtext.xtext;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.xtext.XtextStandaloneSetup;
import org.eclipse.xtext.diagnostics.ExceptionDiagnostic;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.util.CollectionUtils;
-import org.eclipse.xtext.util.Filter;
+
+import com.google.common.collect.Iterables;
/**
* @author Sebastian Zarnekow - Initial contribution and API
@@ -69,7 +68,7 @@ public class ExceptionTest extends AbstractGeneratorTest {
private void assertNoException(String model) throws Exception {
Resource r = getResourceFromString(model);
- Iterable<Diagnostic> filtered = CollectionUtils.filter(r.getErrors(), Filter.Util.<Diagnostic>instanceOf(ExceptionDiagnostic.class));
+ Iterable<ExceptionDiagnostic> filtered = Iterables.filter(r.getErrors(), ExceptionDiagnostic.class);
assertNotNull(filtered);
assertFalse(filtered.iterator().hasNext());
}
diff --git a/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java b/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java
index aed0f23..b9dfe16 100644
--- a/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java
+++ b/tests/org.eclipse.xtext.xtend.tests/src/org/eclipse/xtext/xtend/crossref/CrossrefTest.java
@@ -7,8 +7,6 @@
*******************************************************************************/
package org.eclipse.xtext.xtend.crossref;
-import static org.eclipse.xtext.util.CollectionUtils.*;
-
import java.util.List;
import org.eclipse.emf.ecore.EObject;
@@ -19,7 +17,10 @@ import org.eclipse.xtext.crossref.IScopeProvider;
import org.eclipse.xtext.crossref.IScopedElement;
import org.eclipse.xtext.junit.AbstractXtextTests;
import org.eclipse.xtext.testlanguages.ReferenceGrammarTestLanguageStandaloneSetup;
-import org.eclipse.xtext.util.Function;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
/**
* @author Jan Köhnlein - Initial contribution and API
@@ -53,8 +54,8 @@ public class CrossrefTest extends AbstractXtextTests {
IScopeProvider scopeProvider = getScopeProvider();
assertTrue(scopeProvider instanceof AbstractXtendScopeProvider);
IScope scope = scopeProvider.getScope(familie, (EReference) eReference);
- List<String> namesInScope = list(map(scope.getContents(), new Function<IScopedElement, String>() {
- public String exec(IScopedElement param) {
+ List<String> namesInScope = Lists.newArrayList(Iterables.transform(scope.getContents(), new Function<IScopedElement, String>() {
+ public String apply(IScopedElement param) {
return param.name();
}
}));