aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Walter2013-05-06 11:43:24 (EDT)
committerGerrit Code Review @ Eclipse.org2013-05-07 06:02:03 (EDT)
commit6ac8b46aee3817d463eddd346fdfdaa4a6915c3d (patch)
treecadc2bad3f0d3b71689d6ebc71299ddea592da46
parenta913bea94505b1412c1776431b16a75911984437 (diff)
downloadorg.eclipse.xtext-6ac8b46aee3817d463eddd346fdfdaa4a6915c3d.zip
org.eclipse.xtext-6ac8b46aee3817d463eddd346fdfdaa4a6915c3d.tar.gz
org.eclipse.xtext-6ac8b46aee3817d463eddd346fdfdaa4a6915c3d.tar.bz2
[importedNames] filtered primitive typesrefs/changes/40/12540/2
Filtered primitive types from importedNames to optimize the list
-rw-r--r--plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/XtendRuntimeModule.java7
-rw-r--r--plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/resource/XtendResourceDescriptionManager.xtend40
-rw-r--r--plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/resource/XtendResourceDescription.java47
-rw-r--r--plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/resource/XtendResourceDescriptionManager.java15
-rw-r--r--tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.xtend38
-rw-r--r--tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.java86
6 files changed, 233 insertions, 0 deletions
diff --git a/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/XtendRuntimeModule.java b/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/XtendRuntimeModule.java
index 03783e9..b0de3fb 100644
--- a/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/XtendRuntimeModule.java
+++ b/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/XtendRuntimeModule.java
@@ -13,6 +13,7 @@ import org.eclipse.xtend.core.jvmmodel.XtendJvmModelInferrer;
import org.eclipse.xtend.core.linking.XtendLinkingDiagnosticMessageProvider;
import org.eclipse.xtend.core.naming.XtendQualifiedNameProvider;
import org.eclipse.xtend.core.resource.XtendLocationInFileProvider;
+import org.eclipse.xtend.core.resource.XtendResourceDescriptionManager;
import org.eclipse.xtend.core.resource.XtendResourceDescriptionStrategy;
import org.eclipse.xtend.core.scoping.XtendImportedNamespaceScopeProvider;
import org.eclipse.xtend.core.scoping.XtendScopeProvider;
@@ -30,6 +31,7 @@ import org.eclipse.xtext.linking.ILinkingDiagnosticMessageProvider;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
import org.eclipse.xtext.resource.ILocationInFileProvider;
+import org.eclipse.xtext.resource.IResourceDescription.Manager;
import org.eclipse.xtext.scoping.IScopeProvider;
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
import org.eclipse.xtext.validation.CompositeEValidator;
@@ -158,6 +160,11 @@ public class XtendRuntimeModule extends org.eclipse.xtend.core.AbstractXtendRunt
}
@Override
+ public Class<? extends Manager> bindIResourceDescription$Manager() {
+ return XtendResourceDescriptionManager.class;
+ }
+
+ @Override
public void configure(Binder binder) {
super.configure(binder);
binder.bind(boolean.class).annotatedWith(
diff --git a/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/resource/XtendResourceDescriptionManager.xtend b/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/resource/XtendResourceDescriptionManager.xtend
new file mode 100644
index 0000000..be1d872
--- /dev/null
+++ b/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/resource/XtendResourceDescriptionManager.xtend
@@ -0,0 +1,40 @@
+package org.eclipse.xtend.core.resource
+
+import org.eclipse.xtext.resource.DerivedStateAwareResourceDescriptionManager
+import org.eclipse.xtext.resource.impl.DefaultResourceDescription
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy
+import org.eclipse.xtext.resource.impl.EObjectDescriptionLookUp
+import org.eclipse.xtext.naming.QualifiedName
+
+class XtendResourceDescriptionManager extends DerivedStateAwareResourceDescriptionManager {
+
+ override protected createResourceDescription(Resource resource, IDefaultResourceDescriptionStrategy strategy) {
+ return new XtendResourceDescription(resource, strategy)
+ }
+}
+
+class XtendResourceDescription extends DefaultResourceDescription {
+
+ val primitivesFilter = #['boolean', 'int', 'char', 'byte', 'short', 'long']
+
+ new(Resource resource, IDefaultResourceDescriptionStrategy strategy) {
+ super(resource, strategy)
+ }
+
+ override protected getLookUp() {
+ if (lookup == null)
+ lookup = new EObjectDescriptionLookUp(computeExportedObjects());
+ return lookup;
+ }
+
+ def override Iterable<QualifiedName> getImportedNames() {
+ var originalImportedNames = super.getImportedNames();
+
+ var filteredImportedNames = originalImportedNames.filter [
+ !primitivesFilter.contains(it.lastSegment)
+ ]
+
+ return filteredImportedNames;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/resource/XtendResourceDescription.java b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/resource/XtendResourceDescription.java
new file mode 100644
index 0000000..b2cb441
--- /dev/null
+++ b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/resource/XtendResourceDescription.java
@@ -0,0 +1,47 @@
+package org.eclipse.xtend.core.resource;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.resource.impl.DefaultResourceDescription;
+import org.eclipse.xtext.resource.impl.EObjectDescriptionLookUp;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+@SuppressWarnings("all")
+public class XtendResourceDescription extends DefaultResourceDescription {
+ private final List<String> primitivesFilter = Collections.<String>unmodifiableList(Lists.<String>newArrayList("boolean", "int", "char", "byte", "short", "long"));
+
+ public XtendResourceDescription(final Resource resource, final IDefaultResourceDescriptionStrategy strategy) {
+ super(resource, strategy);
+ }
+
+ protected EObjectDescriptionLookUp getLookUp() {
+ boolean _equals = Objects.equal(this.lookup, null);
+ if (_equals) {
+ List<IEObjectDescription> _computeExportedObjects = this.computeExportedObjects();
+ EObjectDescriptionLookUp _eObjectDescriptionLookUp = new EObjectDescriptionLookUp(_computeExportedObjects);
+ this.lookup = _eObjectDescriptionLookUp;
+ }
+ return this.lookup;
+ }
+
+ public Iterable<QualifiedName> getImportedNames() {
+ Iterable<QualifiedName> originalImportedNames = super.getImportedNames();
+ final Function1<QualifiedName,Boolean> _function = new Function1<QualifiedName,Boolean>() {
+ public Boolean apply(final QualifiedName it) {
+ String _lastSegment = it.getLastSegment();
+ boolean _contains = XtendResourceDescription.this.primitivesFilter.contains(_lastSegment);
+ boolean _not = (!_contains);
+ return Boolean.valueOf(_not);
+ }
+ };
+ Iterable<QualifiedName> filteredImportedNames = IterableExtensions.<QualifiedName>filter(originalImportedNames, _function);
+ return filteredImportedNames;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/resource/XtendResourceDescriptionManager.java b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/resource/XtendResourceDescriptionManager.java
new file mode 100644
index 0000000..fbfeb06
--- /dev/null
+++ b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/resource/XtendResourceDescriptionManager.java
@@ -0,0 +1,15 @@
+package org.eclipse.xtend.core.resource;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.xtend.core.resource.XtendResourceDescription;
+import org.eclipse.xtext.resource.DerivedStateAwareResourceDescriptionManager;
+import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
+import org.eclipse.xtext.resource.IResourceDescription;
+
+@SuppressWarnings("all")
+public class XtendResourceDescriptionManager extends DerivedStateAwareResourceDescriptionManager {
+ protected IResourceDescription createResourceDescription(final Resource resource, final IDefaultResourceDescriptionStrategy strategy) {
+ XtendResourceDescription _xtendResourceDescription = new XtendResourceDescription(resource, strategy);
+ return _xtendResourceDescription;
+ }
+}
diff --git a/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.xtend b/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.xtend
new file mode 100644
index 0000000..61cbb0e
--- /dev/null
+++ b/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.xtend
@@ -0,0 +1,38 @@
+package org.eclipse.xtend.core.tests.resource
+
+import org.eclipse.xtend.core.tests.AbstractXtendTestCase
+import org.junit.Test
+import org.eclipse.xtext.resource.IResourceDescription
+import com.google.inject.Inject
+
+class ImportedNamesTest extends AbstractXtendTestCase {
+ @Inject
+ IResourceDescription$Manager resourceDescriptionManager
+
+ val primitives = #["boolean", "int", "char", "byte", "short", "long"]
+
+ @Test
+ def void testPrimitvesNotIncluded () {
+ val file = this.file('''
+ package testPackage
+
+ import hubbabubba.*
+ import java.util.*
+
+ class TestCase {
+ String x;
+ int i;
+ boolean b;
+ char c;
+ short s;
+ long l;
+ byte t;
+
+ List<Object> l;
+ }
+ ''')
+ val description = resourceDescriptionManager.getResourceDescription(file.eResource)
+ //println(description.getImportedNames.toString().replace(',','\n'))
+ assertFalse(description.importedNames.exists[ primitives.contains(it.lastSegment) ]);
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.java b/tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.java
new file mode 100644
index 0000000..2f63f7d
--- /dev/null
+++ b/tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/resource/ImportedNamesTest.java
@@ -0,0 +1,86 @@
+package org.eclipse.xtend.core.tests.resource;
+
+import com.google.common.collect.Lists;
+import com.google.inject.Inject;
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.xtend.core.tests.AbstractXtendTestCase;
+import org.eclipse.xtend.core.xtend.XtendFile;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.resource.IResourceDescription;
+import org.eclipse.xtext.resource.IResourceDescription.Manager;
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.junit.Assert;
+import org.junit.Test;
+
+@SuppressWarnings("all")
+public class ImportedNamesTest extends AbstractXtendTestCase {
+ @Inject
+ private Manager resourceDescriptionManager;
+
+ private final List<String> primitives = Collections.<String>unmodifiableList(Lists.<String>newArrayList("boolean", "int", "char", "byte", "short", "long"));
+
+ @Test
+ public void testPrimitvesNotIncluded() {
+ try {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package testPackage");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("import hubbabubba.*");
+ _builder.newLine();
+ _builder.append("import java.util.*");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class TestCase {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("String x;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("int i;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("boolean b;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("char c;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("short s;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("long l;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("byte t;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("List<Object> l;");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ final XtendFile file = this.file(_builder.toString());
+ Resource _eResource = file.eResource();
+ final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(_eResource);
+ Iterable<QualifiedName> _importedNames = description.getImportedNames();
+ final Function1<QualifiedName,Boolean> _function = new Function1<QualifiedName,Boolean>() {
+ public Boolean apply(final QualifiedName it) {
+ String _lastSegment = it.getLastSegment();
+ boolean _contains = ImportedNamesTest.this.primitives.contains(_lastSegment);
+ return Boolean.valueOf(_contains);
+ }
+ };
+ boolean _exists = IterableExtensions.<QualifiedName>exists(_importedNames, _function);
+ Assert.assertFalse(_exists);
+ } catch (Throwable _e) {
+ throw Exceptions.sneakyThrow(_e);
+ }
+ }
+}