Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hallgren2009-12-29 11:09:34 +0000
committerThomas Hallgren2009-12-29 11:09:34 +0000
commit1be21bb4f35f708303ded61922e5faaa186fd7cf (patch)
tree5f6aa52a2d4690f8a4ad1de1f36f918c9db94d63 /bundles/org.eclipse.equinox.p2.ql
parentf669d20c4b764018aca26e2f9685a0efc3fd939e (diff)
downloadrt.equinox.p2-1be21bb4f35f708303ded61922e5faaa186fd7cf.tar.gz
rt.equinox.p2-1be21bb4f35f708303ded61922e5faaa186fd7cf.tar.xz
rt.equinox.p2-1be21bb4f35f708303ded61922e5faaa186fd7cf.zip
298458: Add Java 5 Generics to the p2 code base
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.ql')
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/.classpath2
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/.settings/org.eclipse.jdt.core.prefs14
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/META-INF/MANIFEST.MF7
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/build.properties4
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/CapabilityIndex.java96
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/Everything.java32
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/FlattenIterator.java24
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/IRepeatableIterator.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/MatchIteratorFilter.java25
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/ParameterContext.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/QueryContext.java45
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/RepeatableIterator.java123
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/TranslationSupport.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/All.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/And.java6
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Array.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/At.java12
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CapabilityIndexFunction.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Collect.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CollectionFilter.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Constant.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ContextExpression.java21
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Exists.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Expression.java42
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ExpressionFactory.java14
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/First.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Flatten.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Latest.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Limit.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Matches.java26
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Member.java17
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Or.java5
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Select.java6
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/SetFunction.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Traverse.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Unique.java19
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Variable.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/WrappedIQuery.java11
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/parser/ExpressionParser.java32
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/ICapabilityIndex.java12
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IContextExpression.java12
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpression.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionFactory.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionParser.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IQueryContext.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QL.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLContextQuery.java81
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLMatchQuery.java61
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLQuery.java23
-rw-r--r--bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QueryResult.java57
50 files changed, 453 insertions, 496 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ql/.classpath b/bundles/org.eclipse.equinox.p2.ql/.classpath
index 2fbb7a23e..64c5e31b7 100644
--- a/bundles/org.eclipse.equinox.p2.ql/.classpath
+++ b/bundles/org.eclipse.equinox.p2.ql/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
diff --git a/bundles/org.eclipse.equinox.p2.ql/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.p2.ql/.settings/org.eclipse.jdt.core.prefs
index c8a5bb1a1..3801a0f64 100644
--- a/bundles/org.eclipse.equinox.p2.ql/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.p2.ql/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Sun Dec 06 23:10:54 EST 2009
+#Tue Dec 22 17:40:14 CET 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
@@ -7,17 +7,17 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch
org.eclipse.jdt.core.circularClasspath=error
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
@@ -26,7 +26,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
@@ -89,7 +89,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
diff --git a/bundles/org.eclipse.equinox.p2.ql/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.ql/META-INF/MANIFEST.MF
index 946ba908c..d846f2a90 100644
--- a/bundles/org.eclipse.equinox.p2.ql/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.ql/META-INF/MANIFEST.MF
@@ -6,15 +6,18 @@ Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
-Bundle-RequiredExecutionEnvironment: J2SE-1.4,
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,
+ J2SE-1.4,
CDC-1.1/Foundation-1.1
Bundle-ActivationPolicy: lazy
-Import-Package: org.eclipse.equinox.internal.p2.metadata,
+Import-Package: org.eclipse.equinox.internal.p2.core.helpers,
+ org.eclipse.equinox.internal.p2.metadata,
org.eclipse.equinox.internal.provisional.p2.metadata,
org.eclipse.equinox.internal.provisional.p2.metadata.query,
org.eclipse.equinox.p2.metadata,
org.eclipse.equinox.p2.metadata.query,
org.eclipse.equinox.p2.repository.artifact,
+ org.eclipse.osgi.service.localization,
org.osgi.framework
Export-Package: org.eclipse.equinox.internal.p2.ql.expression;x-internal:=true,
org.eclipse.equinox.p2.ql
diff --git a/bundles/org.eclipse.equinox.p2.ql/build.properties b/bundles/org.eclipse.equinox.p2.ql/build.properties
index 230777f9a..d6f73676c 100644
--- a/bundles/org.eclipse.equinox.p2.ql/build.properties
+++ b/bundles/org.eclipse.equinox.p2.ql/build.properties
@@ -2,7 +2,7 @@
# <copyright>
# </copyright>
#
-# $Id$
+# $Id: build.properties,v 1.1 2009/12/01 17:41:31 helindbe Exp $
bin.includes = .,\
META-INF/,\
@@ -13,3 +13,5 @@ source.. = src/
output.. = bin/
src.includes = about.html,\
model/
+javacTarget=jsr14
+javacSource=1.5
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/CapabilityIndex.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/CapabilityIndex.java
index f39aa62f8..fd32fbf9b 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/CapabilityIndex.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/CapabilityIndex.java
@@ -11,9 +11,11 @@
package org.eclipse.equinox.internal.p2.ql;
import java.util.*;
+import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.internal.provisional.p2.metadata.IProvidedCapability;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.ql.ICapabilityIndex;
/**
@@ -21,7 +23,7 @@ import org.eclipse.equinox.p2.ql.ICapabilityIndex;
*/
public class CapabilityIndex implements ICapabilityIndex {
- private final Map capabilityMap;
+ private final Map<String, Object> capabilityMap;
private static class IUCapability {
final IInstallableUnit iu;
@@ -33,24 +35,24 @@ public class CapabilityIndex implements ICapabilityIndex {
}
}
- public CapabilityIndex(Iterator itor) {
- HashMap index = new HashMap();
+ public CapabilityIndex(Iterator<IInstallableUnit> itor) {
+ HashMap<String, Object> index = new HashMap<String, Object>();
while (itor.hasNext()) {
- IInstallableUnit iu = (IInstallableUnit) itor.next();
- IProvidedCapability[] pcs = iu.getProvidedCapabilities();
- int idx = pcs.length;
+ IInstallableUnit iu = itor.next();
+ List<IProvidedCapability> pcs = iu.getProvidedCapabilities();
+ int idx = pcs.size();
while (--idx >= 0) {
- IProvidedCapability pc = pcs[idx];
+ IProvidedCapability pc = pcs.get(idx);
IUCapability iuCap = new IUCapability(iu, pc);
String name = pc.getName();
Object prev = index.put(name, iuCap);
if (prev != null) {
- ArrayList lst;
- if (prev instanceof ArrayList)
- lst = (ArrayList) prev;
+ ArrayList<IUCapability> lst;
+ if (prev instanceof ArrayList<?>)
+ lst = (ArrayList<IUCapability>) prev;
else {
- lst = new ArrayList(4);
- lst.add(prev);
+ lst = new ArrayList<IUCapability>(4);
+ lst.add((IUCapability) prev);
}
lst.add(iuCap);
index.put(name, lst);
@@ -60,84 +62,82 @@ public class CapabilityIndex implements ICapabilityIndex {
this.capabilityMap = index;
}
- public Iterator satisfiesAny(Iterator requirements) {
+ public Iterator<IInstallableUnit> satisfiesAny(Iterator<IRequirement> requirements) {
if (!requirements.hasNext())
- return Collections.EMPTY_LIST.iterator();
+ return CollectionUtils.<IInstallableUnit> emptyList().iterator();
- List collector = new ArrayList();
+ List<IInstallableUnit> collector = new ArrayList<IInstallableUnit>();
do {
- Object nxt = requirements.next();
- if (!(nxt instanceof IRequiredCapability))
- throw new IllegalArgumentException();
+ IRequirement nxt = requirements.next();
collectMatchingIUs((IRequiredCapability) nxt, collector);
} while (requirements.hasNext());
return collector.iterator();
}
- public Iterator satisfiesAll(Iterator requirements) {
+ public Iterator<IInstallableUnit> satisfiesAll(Iterator<IRequirement> requirements) {
if (!requirements.hasNext())
- return Collections.EMPTY_LIST.iterator();
-
- Set collector = new HashSet();
- Object nxt = requirements.next();
- if (!(nxt instanceof IRequiredCapability))
- throw new IllegalArgumentException();
- collectMatchingIUs((IRequiredCapability) nxt, collector);
-
- while (requirements.hasNext() && !collector.isEmpty()) {
- nxt = requirements.next();
- if (!(nxt instanceof IRequiredCapability))
- throw new IllegalArgumentException();
- collector = retainMatchingIUs((IRequiredCapability) nxt, collector);
- }
+ return CollectionUtils.<IInstallableUnit> emptyList().iterator();
+
+ Set<IInstallableUnit> collector = new HashSet<IInstallableUnit>();
+ collectMatchingIUs(requirements.next(), collector);
+
+ while (requirements.hasNext() && !collector.isEmpty())
+ collector = retainMatchingIUs(requirements.next(), collector);
return collector.iterator();
}
- private void collectMatchingIUs(IRequiredCapability rc, Collection collector) {
+ private void collectMatchingIUs(IRequirement requirement, Collection<IInstallableUnit> collector) {
+ if (!(requirement instanceof IRequiredCapability))
+ return;
+ IRequiredCapability rc = (IRequiredCapability) requirement;
Object v = capabilityMap.get(rc.getName());
if (v == null)
return;
if (v instanceof IUCapability) {
IUCapability iuc = (IUCapability) v;
- if (rc.satisfiedBy(iuc.capability))
+ if (iuc.capability.satisfies(requirement))
collector.add(iuc.iu);
} else {
- List iucs = (List) v;
+ List<IUCapability> iucs = (List<IUCapability>) v;
int idx = iucs.size();
while (--idx >= 0) {
- IUCapability iuc = (IUCapability) iucs.get(idx);
- if (rc.satisfiedBy(iuc.capability))
+ IUCapability iuc = iucs.get(idx);
+ if (iuc.capability.satisfies(requirement))
collector.add(iuc.iu);
}
}
}
- private Set retainMatchingIUs(IRequiredCapability rc, Set collector) {
+ private Set<IInstallableUnit> retainMatchingIUs(IRequirement requirement, Set<IInstallableUnit> collector) {
+ if (!(requirement instanceof IRequiredCapability))
+ return CollectionUtils.emptySet();
+
+ IRequiredCapability rc = (IRequiredCapability) requirement;
Object v = capabilityMap.get(rc.getName());
if (v == null)
- return Collections.EMPTY_SET;
+ return CollectionUtils.emptySet();
- Set retained = null;
+ Set<IInstallableUnit> retained = null;
if (v instanceof IUCapability) {
IUCapability iuc = (IUCapability) v;
- if (rc.satisfiedBy(iuc.capability) && collector.contains(iuc.iu)) {
+ if (iuc.capability.satisfies(requirement) && collector.contains(iuc.iu)) {
if (retained == null)
- retained = new HashSet();
+ retained = new HashSet<IInstallableUnit>();
retained.add(iuc.iu);
}
} else {
- List iucs = (List) v;
+ List<IUCapability> iucs = (List<IUCapability>) v;
int idx = iucs.size();
while (--idx >= 0) {
- IUCapability iuc = (IUCapability) iucs.get(idx);
- if (rc.satisfiedBy(iuc.capability) && collector.contains(iuc.iu)) {
+ IUCapability iuc = iucs.get(idx);
+ if (iuc.capability.satisfies(requirement) && collector.contains(iuc.iu)) {
if (retained == null)
- retained = new HashSet();
+ retained = new HashSet<IInstallableUnit>();
retained.add(iuc.iu);
}
}
}
- return retained == null ? Collections.EMPTY_SET : retained;
+ return retained == null ? CollectionUtils.<IInstallableUnit> emptySet() : retained;
}
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/Everything.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/Everything.java
index 382e9038b..4f3fc819b 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/Everything.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/Everything.java
@@ -10,48 +10,50 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.ql;
-import java.util.*;
+import java.util.Collection;
+import java.util.Iterator;
+import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
/**
* The immutable context used when evaluating an expression.
*/
-public final class Everything extends MatchIteratorFilter implements IRepeatableIterator {
+public final class Everything<T> extends MatchIteratorFilter<T> implements IRepeatableIterator<T> {
private boolean atStart = true;
- private final Class elementClass;
+ private final Class<T> elementClass;
- public Everything(Class elementClass, Collection collection) {
- super(RepeatableIterator.create(collection == null ? Collections.EMPTY_LIST : collection));
+ public Everything(Class<T> elementClass, Collection<T> collection) {
+ super(RepeatableIterator.<T> create(collection == null ? CollectionUtils.<T> emptyList() : collection));
this.elementClass = elementClass;
}
- public Everything(Class elementClass, Iterator iterator, boolean needsRepeat) {
+ public Everything(Class<T> elementClass, Iterator<? extends T> iterator, boolean needsRepeat) {
super(needsRepeat ? RepeatableIterator.create(iterator) : iterator);
this.elementClass = elementClass;
}
- public IRepeatableIterator getCopy() {
- Iterator iterator = getInnerIterator();
- if (iterator instanceof IRepeatableIterator)
- return new Everything(elementClass, ((IRepeatableIterator) iterator).getCopy(), false);
+ public IRepeatableIterator<T> getCopy() {
+ Iterator<? extends T> iterator = getInnerIterator();
+ if (iterator instanceof IRepeatableIterator<?>)
+ return new Everything<T>(elementClass, ((IRepeatableIterator<? extends T>) iterator).getCopy(), false);
if (atStart)
return this;
throw new UnsupportedOperationException();
}
- public Object next() {
+ public T next() {
atStart = false;
return super.next();
}
public Object getIteratorProvider() {
- Iterator iterator = getInnerIterator();
- if (iterator instanceof IRepeatableIterator)
- return ((IRepeatableIterator) iterator).getIteratorProvider();
+ Iterator<? extends T> iterator = getInnerIterator();
+ if (iterator instanceof IRepeatableIterator<?>)
+ return ((IRepeatableIterator<?>) iterator).getIteratorProvider();
return this;
}
- protected boolean isMatch(Object val) {
+ protected boolean isMatch(T val) {
return elementClass.isInstance(val);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/FlattenIterator.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/FlattenIterator.java
index e2d659bb1..f41e20c1b 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/FlattenIterator.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/FlattenIterator.java
@@ -18,14 +18,14 @@ import java.util.NoSuchElementException;
* elements that can be represented as iterators. The elements of those iterators
* will be returned in sequence, thus removing one iterator dimension.
*/
-public class FlattenIterator implements Iterator {
+public class FlattenIterator<T> implements Iterator<T> {
private static final Object NO_ELEMENT = new Object();
- private final Iterator iteratorIterator;
- private Iterator currentIterator;
+ private final Iterator<? extends Object> iteratorIterator;
+ private Iterator<T> currentIterator;
- private Object nextObject = NO_ELEMENT;
+ private T nextObject = noElement();
- public FlattenIterator(Iterator iterator) {
+ public FlattenIterator(Iterator<? extends Object> iterator) {
this.iteratorIterator = iterator;
}
@@ -33,12 +33,12 @@ public class FlattenIterator implements Iterator {
return positionNext();
}
- public Object next() {
+ public T next() {
if (!positionNext())
throw new NoSuchElementException();
- Object nxt = nextObject;
- nextObject = NO_ELEMENT;
+ T nxt = nextObject;
+ nextObject = noElement();
return nxt;
}
@@ -46,6 +46,7 @@ public class FlattenIterator implements Iterator {
throw new UnsupportedOperationException();
}
+ @SuppressWarnings("unchecked")
private boolean positionNext() {
if (nextObject != NO_ELEMENT)
return true;
@@ -55,9 +56,14 @@ public class FlattenIterator implements Iterator {
return false;
Object nextItor = iteratorIterator.next();
- currentIterator = (nextItor instanceof Iterator) ? (Iterator) nextItor : RepeatableIterator.create(nextItor);
+ currentIterator = (nextItor instanceof Iterator<?>) ? (Iterator<T>) nextItor : RepeatableIterator.<T> create(nextItor);
}
nextObject = currentIterator.next();
return true;
}
+
+ @SuppressWarnings("unchecked")
+ private static <T> T noElement() {
+ return (T) NO_ELEMENT;
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/IRepeatableIterator.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/IRepeatableIterator.java
index 7190c241f..1f8fa8655 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/IRepeatableIterator.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/IRepeatableIterator.java
@@ -12,14 +12,14 @@ package org.eclipse.equinox.internal.p2.ql;
import java.util.Iterator;
-public interface IRepeatableIterator extends Iterator {
+public interface IRepeatableIterator<T> extends Iterator<T> {
/**
* Returns a copy that will iterate over the same elements
* as this iterator. The contents or position of this iterator
* is left unchanged.
* @return A re-initialized copy of this iterator.
*/
- IRepeatableIterator getCopy();
+ IRepeatableIterator<T> getCopy();
Object getIteratorProvider();
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/MatchIteratorFilter.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/MatchIteratorFilter.java
index 684fdc5ab..1f7b00d2a 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/MatchIteratorFilter.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/MatchIteratorFilter.java
@@ -16,14 +16,14 @@ import java.util.NoSuchElementException;
/**
* An iterator filter using a boolean {@link #isMatch(Object)} method.
*/
-public abstract class MatchIteratorFilter implements Iterator {
+public abstract class MatchIteratorFilter<T> implements Iterator<T> {
private static final Object NO_ELEMENT = new Object();
- private final Iterator innerIterator;
+ private final Iterator<? extends T> innerIterator;
- private Object nextObject = NO_ELEMENT;
+ private T nextObject = noElement();
- public MatchIteratorFilter(Iterator iterator) {
+ public MatchIteratorFilter(Iterator<? extends T> iterator) {
this.innerIterator = iterator;
}
@@ -31,12 +31,12 @@ public abstract class MatchIteratorFilter implements Iterator {
return positionNext();
}
- public Object next() {
+ public T next() {
if (!positionNext())
throw new NoSuchElementException();
- Object nxt = nextObject;
- nextObject = NO_ELEMENT;
+ T nxt = nextObject;
+ nextObject = noElement();
return nxt;
}
@@ -44,18 +44,18 @@ public abstract class MatchIteratorFilter implements Iterator {
throw new UnsupportedOperationException();
}
- protected Iterator getInnerIterator() {
+ protected Iterator<? extends T> getInnerIterator() {
return innerIterator;
}
- protected abstract boolean isMatch(Object val);
+ protected abstract boolean isMatch(T val);
private boolean positionNext() {
if (nextObject != NO_ELEMENT)
return true;
while (innerIterator.hasNext()) {
- Object nxt = innerIterator.next();
+ T nxt = innerIterator.next();
if (isMatch(nxt)) {
nextObject = nxt;
return true;
@@ -63,4 +63,9 @@ public abstract class MatchIteratorFilter implements Iterator {
}
return false;
}
+
+ @SuppressWarnings("unchecked")
+ private static <T> T noElement() {
+ return (T) NO_ELEMENT;
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/ParameterContext.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/ParameterContext.java
index db16a17ed..653c103ad 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/ParameterContext.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/ParameterContext.java
@@ -31,7 +31,7 @@ public final class ParameterContext implements IEvaluationContext {
}
public Object getParameter(String key) {
- return parameters.length == 1 && parameters[0] instanceof Map ? ((Map) parameters[0]).get(key) : null;
+ return parameters.length == 1 && parameters[0] instanceof Map<?, ?> ? ((Map<?, ?>) parameters[0]).get(key) : null;
}
public Object getValue(IExpression variable) {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/QueryContext.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/QueryContext.java
index 3d7b5b703..adf2393fa 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/QueryContext.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/QueryContext.java
@@ -3,49 +3,58 @@ package org.eclipse.equinox.internal.p2.ql;
import java.util.*;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
+import org.eclipse.equinox.internal.provisional.p2.metadata.query.ContextQuery;
+import org.eclipse.equinox.internal.provisional.p2.metadata.query.IQueryable;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.query.IQuery;
import org.eclipse.equinox.p2.metadata.query.IQueryResult;
import org.eclipse.equinox.p2.ql.IQueryContext;
import org.eclipse.equinox.p2.ql.ITranslationSupport;
+import org.eclipse.osgi.service.localization.LocaleProvider;
-public class QueryContext implements IQueryContext {
+public class QueryContext<T> implements IQueryContext<T> {
- private final IQueryable queryable;
+ private final IQueryable<T> queryable;
- private Map translationSupports;
+ private Map<Locale, TranslationSupport> translationSupports;
- public QueryContext(IQueryable queryable) {
+ public QueryContext(IQueryable<T> queryable) {
this.queryable = queryable;
}
- public QueryContext(Iterator iterator) {
- final IRepeatableIterator repeatable = RepeatableIterator.create(iterator);
- this.queryable = new IQueryable() {
- public IQueryResult query(IQuery query, IProgressMonitor monitor) {
+ public QueryContext(Iterator<T> iterator) {
+ final IRepeatableIterator<T> repeatable = RepeatableIterator.create(iterator);
+ this.queryable = new IQueryable<T>() {
+ public IQueryResult<T> query(IQuery<T> query, IProgressMonitor monitor) {
return query.perform(repeatable.getCopy());
}
};
}
- public synchronized ITranslationSupport getTranslationSupport(Locale locale) {
+ public synchronized ITranslationSupport getTranslationSupport(final Locale locale) {
if (translationSupports == null)
- translationSupports = new HashMap();
+ translationSupports = new HashMap<Locale, TranslationSupport>();
- TranslationSupport ts = (TranslationSupport) translationSupports.get(locale);
+ TranslationSupport ts = translationSupports.get(locale);
if (ts == null) {
ts = new TranslationSupport();
- ts.setTranslationSource(queryable);
- ts.setLocale(locale);
+ ts.setTranslationSource((IQueryable<IInstallableUnit>) queryable);
+ ts.setLocaleProvider(new LocaleProvider() {
+ public Locale getLocale() {
+ // TODO Auto-generated method stub
+ return locale;
+ }
+ });
translationSupports.put(locale, ts);
}
return ts;
}
- public Iterator iterator() {
- final Iterator[] iteratorCatcher = new Iterator[1];
- queryable.query(new ContextQuery() {
- public IQueryResult perform(Iterator iterator) {
+ public Iterator<T> iterator() {
+ @SuppressWarnings("unchecked")
+ final Iterator<T>[] iteratorCatcher = new Iterator[1];
+ queryable.query(new ContextQuery<T>() {
+ public IQueryResult<T> perform(Iterator<T> iterator) {
iteratorCatcher[0] = iterator;
return null;
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/RepeatableIterator.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/RepeatableIterator.java
index e1419e9a9..743a04c7f 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/RepeatableIterator.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/RepeatableIterator.java
@@ -11,61 +11,62 @@
package org.eclipse.equinox.internal.p2.ql;
import java.util.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector;
+import org.eclipse.equinox.p2.metadata.query.IQueryResult;
-public class RepeatableIterator implements IRepeatableIterator {
- private final List values;
+public class RepeatableIterator<T> implements IRepeatableIterator<T> {
+ private final List<T> values;
private int position = -1;
- public static IRepeatableIterator create(Object unknown) {
+ @SuppressWarnings("unchecked")
+ public static <T> IRepeatableIterator<T> create(Object unknown) {
if (unknown.getClass().isArray())
- return create((Object[]) unknown);
- if (unknown instanceof Iterator)
- return create((Iterator) unknown);
- if (unknown instanceof List)
- return create((List) unknown);
- if (unknown instanceof Collection)
- return create((Collection) unknown);
- if (unknown instanceof Map)
- return create(((Map) unknown).entrySet());
- if (unknown instanceof Collector)
- return create((Collector) unknown);
+ return create((T[]) unknown);
+ if (unknown instanceof Iterator<?>)
+ return create((Iterator<T>) unknown);
+ if (unknown instanceof List<?>)
+ return create((List<T>) unknown);
+ if (unknown instanceof Collection<?>)
+ return create((Collection<T>) unknown);
+ if (unknown instanceof Map<?, ?>)
+ return create((Set<T>) ((Map<?, ?>) unknown).entrySet());
+ if (unknown instanceof IQueryResult<?>)
+ return create((IQueryResult<T>) unknown);
throw new IllegalArgumentException("Cannot convert a " + unknown.getClass().getName() + " into an iterator"); //$NON-NLS-1$ //$NON-NLS-2$
}
- public static IRepeatableIterator create(Iterator iterator) {
- return iterator instanceof IRepeatableIterator ? ((IRepeatableIterator) iterator).getCopy() : new ElementRetainingIterator(iterator);
+ public static <T> IRepeatableIterator<T> create(Iterator<T> iterator) {
+ return iterator instanceof IRepeatableIterator<?> ? ((IRepeatableIterator<T>) iterator).getCopy() : new ElementRetainingIterator<T>(iterator);
}
- public static IRepeatableIterator create(List values) {
- return new RepeatableIterator(values);
+ public static <T> IRepeatableIterator<T> create(List<T> values) {
+ return new RepeatableIterator<T>(values);
}
- public static IRepeatableIterator create(Collection values) {
- return new CollectionIterator(values);
+ public static <T> IRepeatableIterator<T> create(Collection<T> values) {
+ return new CollectionIterator<T>(values);
}
- public static IRepeatableIterator create(Collector values) {
- return new CollectorIterator(values);
+ public static <T> IRepeatableIterator<T> create(IQueryResult<T> values) {
+ return new QueryResultIterator<T>(values);
}
- public static IRepeatableIterator create(Object[] values) {
- return new ArrayIterator(values);
+ public static <T> IRepeatableIterator<T> create(T[] values) {
+ return new ArrayIterator<T>(values);
}
- RepeatableIterator(List values) {
+ RepeatableIterator(List<T> values) {
this.values = values;
}
- public IRepeatableIterator getCopy() {
- return new RepeatableIterator(values);
+ public IRepeatableIterator<T> getCopy() {
+ return new RepeatableIterator<T>(values);
}
public boolean hasNext() {
return position + 1 < values.size();
}
- public Object next() {
+ public T next() {
if (++position == values.size()) {
--position;
throw new NoSuchElementException();
@@ -85,15 +86,15 @@ public class RepeatableIterator implements IRepeatableIterator {
this.position = position;
}
- List getValues() {
+ List<T> getValues() {
return values;
}
- static class ArrayIterator implements IRepeatableIterator {
- private final Object[] array;
+ static class ArrayIterator<T> implements IRepeatableIterator<T> {
+ private final T[] array;
private int position = -1;
- public ArrayIterator(Object[] array) {
+ public ArrayIterator(T[] array) {
this.array = array;
}
@@ -105,7 +106,7 @@ public class RepeatableIterator implements IRepeatableIterator {
return position + 1 < array.length;
}
- public Object next() {
+ public T next() {
if (++position >= array.length)
throw new NoSuchElementException();
return array[position];
@@ -115,23 +116,23 @@ public class RepeatableIterator implements IRepeatableIterator {
throw new UnsupportedOperationException();
}
- public IRepeatableIterator getCopy() {
- return new ArrayIterator(array);
+ public IRepeatableIterator<T> getCopy() {
+ return new ArrayIterator<T>(array);
}
}
- static class CollectionIterator implements IRepeatableIterator {
- private final Collection collection;
+ static class CollectionIterator<T> implements IRepeatableIterator<T> {
+ private final Collection<T> collection;
- private final Iterator iterator;
+ private final Iterator<T> iterator;
- CollectionIterator(Collection collection) {
+ CollectionIterator(Collection<T> collection) {
this.collection = collection;
this.iterator = collection.iterator();
}
- public IRepeatableIterator getCopy() {
- return new CollectionIterator(collection);
+ public IRepeatableIterator<T> getCopy() {
+ return new CollectionIterator<T>(collection);
}
public Object getIteratorProvider() {
@@ -142,7 +143,7 @@ public class RepeatableIterator implements IRepeatableIterator {
return iterator.hasNext();
}
- public Object next() {
+ public T next() {
return iterator.next();
}
@@ -151,29 +152,29 @@ public class RepeatableIterator implements IRepeatableIterator {
}
}
- static class CollectorIterator implements IRepeatableIterator {
- private final Collector collector;
+ static class QueryResultIterator<T> implements IRepeatableIterator<T> {
+ private final IQueryResult<T> queryResult;
- private final Iterator iterator;
+ private final Iterator<T> iterator;
- CollectorIterator(Collector collector) {
- this.collector = collector;
- this.iterator = collector.iterator();
+ QueryResultIterator(IQueryResult<T> queryResult) {
+ this.queryResult = queryResult;
+ this.iterator = queryResult.iterator();
}
- public IRepeatableIterator getCopy() {
- return new CollectorIterator(collector);
+ public IRepeatableIterator<T> getCopy() {
+ return new QueryResultIterator<T>(queryResult);
}
public Object getIteratorProvider() {
- return collector;
+ return queryResult;
}
public boolean hasNext() {
return iterator.hasNext();
}
- public Object next() {
+ public T next() {
return iterator.next();
}
@@ -182,12 +183,12 @@ public class RepeatableIterator implements IRepeatableIterator {
}
}
- static class ElementRetainingIterator extends RepeatableIterator {
+ static class ElementRetainingIterator<T> extends RepeatableIterator<T> {
- private Iterator innerIterator;
+ private Iterator<T> innerIterator;
- ElementRetainingIterator(Iterator iterator) {
- super(new ArrayList());
+ ElementRetainingIterator(Iterator<T> iterator) {
+ super(new ArrayList<T>());
innerIterator = iterator;
}
@@ -201,16 +202,16 @@ public class RepeatableIterator implements IRepeatableIterator {
return super.hasNext();
}
- public synchronized Object next() {
+ public synchronized T next() {
if (innerIterator != null) {
- Object val = innerIterator.next();
+ T val = innerIterator.next();
getValues().add(val);
return val;
}
return super.next();
}
- public synchronized IRepeatableIterator getCopy() {
+ public synchronized IRepeatableIterator<T> getCopy() {
// If the current iterator still exists, we must exhaust it first
//
exhaustInnerIterator();
@@ -224,7 +225,7 @@ public class RepeatableIterator implements IRepeatableIterator {
private void exhaustInnerIterator() {
if (innerIterator != null) {
- List values = getValues();
+ List<T> values = getValues();
int savePos = values.size() - 1;
while (innerIterator.hasNext())
values.add(innerIterator.next());
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/TranslationSupport.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/TranslationSupport.java
index 2eac137ab..1ece8acfa 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/TranslationSupport.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/TranslationSupport.java
@@ -1,7 +1,11 @@
package org.eclipse.equinox.internal.p2.ql;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.ql.ITranslationSupport;
-public class TranslationSupport extends org.eclipse.equinox.p2.common.TranslationSupport implements ITranslationSupport {
- // The default implementation just uses the common TranslationSupport and adds nothing to the mix.
+public class TranslationSupport extends org.eclipse.equinox.internal.p2.metadata.TranslationSupport implements ITranslationSupport {
+
+ public String getIUProperty(IInstallableUnit iu, String key) {
+ return getIUProperty(iu, key, null);
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/All.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/All.java
index 73784486e..a8181dc2c 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/All.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/All.java
@@ -26,7 +26,7 @@ final class All extends CollectionFilter {
return TYPE_ALL;
}
- Object evaluate(IEvaluationContext context, Iterator itor) {
+ Object evaluate(IEvaluationContext context, Iterator<?> itor) {
Variable variable = lambda.getItemVariable();
while (itor.hasNext()) {
variable.setValue(context, itor.next());
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/And.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/And.java
index 4ecf87efe..992ad9be5 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/And.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/And.java
@@ -45,10 +45,10 @@ final class And extends NAry {
}
// Not a boolean. Assume that we can use an iterator on all values
- Set resultSet = asSet(firstValue, false); // Safe since it will not be modified
+ Set<?> resultSet = asSet(firstValue, false); // Safe since it will not be modified
for (int idx = 1; idx < operands.length && !resultSet.isEmpty(); ++idx) {
- Iterator itor = operands[idx].evaluateAsIterator(context);
- Set retained = new HashSet();
+ Iterator<?> itor = operands[idx].evaluateAsIterator(context);
+ Set<Object> retained = new HashSet<Object>();
while (itor.hasNext()) {
Object value = itor.next();
if (resultSet.contains(value))
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Array.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Array.java
index 0ec90059b..ebba0e5ca 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Array.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Array.java
@@ -19,7 +19,7 @@ import org.eclipse.equinox.p2.ql.IEvaluationContext;
* An array of expressions
*/
final class Array extends NAry {
- final class ArrayIterator implements Iterator {
+ final class ArrayIterator implements Iterator<Object> {
private final IEvaluationContext context;
private int pos = -1;
@@ -64,7 +64,7 @@ final class Array extends NAry {
return evaluateAsIterator(context);
}
- public Iterator evaluateAsIterator(IEvaluationContext context) {
+ public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
return new ArrayIterator(context);
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/At.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/At.java
index f4ae7004c..70b97119f 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/At.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/At.java
@@ -48,18 +48,18 @@ final class At extends Binary {
if (lval == null)
throw new IllegalArgumentException("Unable to use [] on null"); //$NON-NLS-1$
- if (lval instanceof Map)
- return ((Map) lval).get(rval);
+ if (lval instanceof Map<?, ?>)
+ return ((Map<?, ?>) lval).get(rval);
if (rval instanceof Number) {
- if (lval instanceof List)
- return ((List) lval).get(((Number) rval).intValue());
+ if (lval instanceof List<?>)
+ return ((List<?>) lval).get(((Number) rval).intValue());
if (lval != null && lval.getClass().isArray())
return ((Object[]) lval)[((Number) rval).intValue()];
}
- if (lval instanceof Dictionary)
- return ((Dictionary) lval).get(rval);
+ if (lval instanceof Dictionary<?, ?>)
+ return ((Dictionary<?, ?>) lval).get(rval);
throw new IllegalArgumentException("Unable to use [] on a " + lval.getClass().getName()); //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CapabilityIndexFunction.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CapabilityIndexFunction.java
index bd01ae714..99e37e985 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CapabilityIndexFunction.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CapabilityIndexFunction.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.ql.expression;
+import java.util.Iterator;
import org.eclipse.equinox.internal.p2.ql.CapabilityIndex;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.ql.IEvaluationContext;
@@ -26,7 +27,7 @@ final class CapabilityIndexFunction extends Function {
}
public Object evaluate(IEvaluationContext context) {
- return new CapabilityIndex(operands[0].evaluateAsIterator(context));
+ return new CapabilityIndex((Iterator<IInstallableUnit>) operands[0].evaluateAsIterator(context));
}
String getOperator() {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Collect.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Collect.java
index 1e858bcaf..fddda5dd5 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Collect.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Collect.java
@@ -17,14 +17,14 @@ import org.eclipse.equinox.p2.ql.IExpression;
/**
*/
final class Collect extends CollectionFilter {
- final class CollectIterator implements Iterator {
+ final class CollectIterator implements Iterator<Object> {
private final IEvaluationContext context;
private final IExpression variable;
- private final Iterator innerIterator;
+ private final Iterator<?> innerIterator;
- public CollectIterator(IEvaluationContext context, Iterator iterator) {
+ public CollectIterator(IEvaluationContext context, Iterator<?> iterator) {
this.context = context;
this.variable = lambda.getItemVariable();
this.innerIterator = iterator;
@@ -48,11 +48,11 @@ final class Collect extends CollectionFilter {
super(collection, lambda);
}
- Object evaluate(IEvaluationContext context, Iterator itor) {
+ Object evaluate(IEvaluationContext context, Iterator<?> itor) {
return evaluateAsIterator(context, itor);
}
- Iterator evaluateAsIterator(IEvaluationContext context, Iterator itor) {
+ Iterator<?> evaluateAsIterator(IEvaluationContext context, Iterator<?> itor) {
return new CollectIterator(context, itor);
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CollectionFilter.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CollectionFilter.java
index 325f43f74..b33b28aee 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CollectionFilter.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/CollectionFilter.java
@@ -40,13 +40,13 @@ abstract class CollectionFilter extends Unary {
}
public final Object evaluate(IEvaluationContext context) {
- Iterator lval = operand.evaluateAsIterator(context);
+ Iterator<?> lval = operand.evaluateAsIterator(context);
context = lambda.prolog(context);
return evaluate(context, lval);
}
- public final Iterator evaluateAsIterator(IEvaluationContext context) {
- Iterator lval = operand.evaluateAsIterator(context);
+ public final Iterator<?> evaluateAsIterator(IEvaluationContext context) {
+ Iterator<?> lval = operand.evaluateAsIterator(context);
context = lambda.prolog(context);
return evaluateAsIterator(context, lval);
}
@@ -61,9 +61,9 @@ abstract class CollectionFilter extends Unary {
return super.countReferenceToEverything() + lambda.countReferenceToEverything();
}
- abstract Object evaluate(final IEvaluationContext context, Iterator iterator);
+ abstract Object evaluate(final IEvaluationContext context, Iterator<?> iterator);
- Iterator evaluateAsIterator(IEvaluationContext context, Iterator iterator) {
+ Iterator<?> evaluateAsIterator(IEvaluationContext context, Iterator<?> iterator) {
throw new UnsupportedOperationException();
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Constant.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Constant.java
index fdb66aaa3..42c0fe266 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Constant.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Constant.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.internal.p2.ql.expression;
import java.util.*;
+import org.eclipse.equinox.p2.metadata.query.IQueryResult;
import org.eclipse.equinox.p2.ql.IEvaluationContext;
import org.eclipse.equinox.p2.ql.SimplePattern;
@@ -84,7 +85,7 @@ final class Constant extends Expression {
}
boolean isCollection() {
- return value instanceof Collection || value instanceof Map || value instanceof Iterator || value != null && value.getClass().isArray();
+ return value instanceof Collection<?> || value instanceof Map<?, ?> || value instanceof Iterator<?> || value instanceof IQueryResult<?> || value != null && value.getClass().isArray();
}
String getOperator() {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ContextExpression.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ContextExpression.java
index f50b4043d..031eb5017 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ContextExpression.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ContextExpression.java
@@ -19,29 +19,36 @@ import org.eclipse.equinox.p2.ql.*;
* variable 'everything' and initialized it with the iterator that represents all
* available items.
*/
-final class ContextExpression extends Unary implements IContextExpression {
+final class ContextExpression<T> extends Unary implements IContextExpression<T> {
- ContextExpression(Expression expression) {
+ private final Class<T> elementClass;
+
+ ContextExpression(Class<T> elementClass, Expression expression) {
super(expression);
+ this.elementClass = elementClass;
}
public void toString(StringBuffer bld) {
operand.toString(bld);
}
- public IEvaluationContext createContext(Class elementClass, Iterator iterator, Object[] params) {
+ public IEvaluationContext createContext(Iterator<T> iterator, Object[] params) {
IEvaluationContext context = new SingleVariableContext(new ParameterContext(params), Variable.EVERYTHING);
- context.setValue(Variable.EVERYTHING, new Everything(elementClass, iterator, operand.needsRepeatedIterations()));
+ context.setValue(Variable.EVERYTHING, new Everything<T>(elementClass, iterator, operand.needsRepeatedIterations()));
return context;
}
- public IEvaluationContext createContext(Class elementClass, Iterator iterator, Object[] params, ITranslationSupport ts) {
+ public IEvaluationContext createContext(Iterator<T> iterator, Object[] params, ITranslationSupport ts) {
IEvaluationContext context = new MultiVariableContext(new ParameterContext(params), new IExpression[] {Variable.EVERYTHING, Variable.TRANSLATIONS});
- context.setValue(Variable.EVERYTHING, new Everything(elementClass, iterator, operand.needsRepeatedIterations()));
+ context.setValue(Variable.EVERYTHING, new Everything<T>(elementClass, iterator, operand.needsRepeatedIterations()));
context.setValue(Variable.TRANSLATIONS, ts);
return context;
}
+ public Class<T> getElementClass() {
+ return elementClass;
+ }
+
public int getExpressionType() {
return operand.getExpressionType();
}
@@ -55,7 +62,7 @@ final class ContextExpression extends Unary implements IContextExpression {
}
Expression pipeFrom(Expression expr) {
- return new ContextExpression(operand.pipeFrom(expr));
+ return new ContextExpression<T>(elementClass, operand.pipeFrom(expr));
}
boolean isBoolean() {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Exists.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Exists.java
index 64a23d7f6..71e967aec 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Exists.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Exists.java
@@ -26,7 +26,7 @@ final class Exists extends CollectionFilter {
return TYPE_EXISTS;
}
- Object evaluate(IEvaluationContext context, Iterator itor) {
+ Object evaluate(IEvaluationContext context, Iterator<?> itor) {
Variable variable = lambda.getItemVariable();
while (itor.hasNext()) {
variable.setValue(context, itor.next());
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Expression.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Expression.java
index 46f542964..688ca7f3e 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Expression.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Expression.java
@@ -14,7 +14,7 @@ import java.util.*;
import org.eclipse.equinox.internal.p2.ql.IRepeatableIterator;
import org.eclipse.equinox.internal.p2.ql.RepeatableIterator;
import org.eclipse.equinox.internal.p2.ql.parser.IParserConstants;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector;
+import org.eclipse.equinox.p2.metadata.query.IQueryResult;
import org.eclipse.equinox.p2.ql.*;
/**
@@ -24,36 +24,36 @@ abstract class Expression implements IExpression, IParserConstants {
static final Expression[] emptyArray = new Expression[0];
- static Set asSet(Object val, boolean forcePrivateCopy) {
+ static Set<?> asSet(Object val, boolean forcePrivateCopy) {
if (val == null)
throw new IllegalArgumentException("Cannot convert null into an set"); //$NON-NLS-1$
- if (val instanceof IRepeatableIterator) {
- Object provider = ((IRepeatableIterator) val).getIteratorProvider();
+ if (val instanceof IRepeatableIterator<?>) {
+ Object provider = ((IRepeatableIterator<?>) val).getIteratorProvider();
if (!forcePrivateCopy) {
- if (provider instanceof Set)
- return (Set) provider;
- if (provider instanceof Collector)
- return ((Collector) provider).unmodifiableSet();
+ if (provider instanceof Set<?>)
+ return (Set<?>) provider;
+ if (provider instanceof IQueryResult<?>)
+ return ((IQueryResult<?>) provider).unmodifiableSet();
}
- if (provider instanceof Collection)
+ if (provider instanceof Collection<?>)
val = provider;
} else {
if (!forcePrivateCopy) {
- if (val instanceof Set)
- return (Set) val;
- if (val instanceof Collector)
- return ((Collector) val).unmodifiableSet();
+ if (val instanceof Set<?>)
+ return (Set<?>) val;
+ if (val instanceof IQueryResult<?>)
+ return ((IQueryResult<?>) val).unmodifiableSet();
}
}
- HashSet result;
- if (val instanceof Collection)
- result = new HashSet((Collection) val);
+ HashSet<Object> result;
+ if (val instanceof Collection<?>)
+ result = new HashSet<Object>((Collection<?>) val);
else {
- result = new HashSet();
- Iterator iterator = RepeatableIterator.create(val);
+ result = new HashSet<Object>();
+ Iterator<?> iterator = RepeatableIterator.create(val);
while (iterator.hasNext())
result.add(iterator.next());
}
@@ -77,11 +77,11 @@ abstract class Expression implements IExpression, IParserConstants {
*/
public abstract Object evaluate(IEvaluationContext context);
- public Iterator evaluateAsIterator(IEvaluationContext context) {
+ public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
Object value = evaluate(context);
- if (!(value instanceof Iterator))
+ if (!(value instanceof Iterator<?>))
value = RepeatableIterator.create(value);
- return (Iterator) value;
+ return (Iterator<?>) value;
}
/**
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ExpressionFactory.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ExpressionFactory.java
index e6dac860d..f603dd6e0 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ExpressionFactory.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/ExpressionFactory.java
@@ -9,11 +9,11 @@ import org.eclipse.equinox.p2.ql.*;
public class ExpressionFactory implements IExpressionFactory, IParserConstants {
public static final IExpressionFactory INSTANCE = new ExpressionFactory();
- private static final Map functionMap;
+ private static final Map<String, Constructor<?>> functionMap;
static {
- Class[] args = new Class[] {Expression[].class};
- Map f = new HashMap();
+ Class<?>[] args = new Class[] {Expression[].class};
+ Map<String, Constructor<?>> f = new HashMap<String, Constructor<?>>();
try {
f.put(KEYWORD_BOOLEAN, BooleanFunction.class.getConstructor(args));
f.put(KEYWORD_FILTER, FilterFunction.class.getConstructor(args));
@@ -71,8 +71,8 @@ public class ExpressionFactory implements IExpressionFactory, IParserConstants {
return Constant.create(value);
}
- public IContextExpression contextExpression(IExpression expr) {
- return new ContextExpression((Expression) expr);
+ public <T> IContextExpression<T> contextExpression(Class<T> elementClass, IExpression expr) {
+ return new ContextExpression<T>(elementClass, (Expression) expr);
}
public IExpression dynamicMember(IExpression target, String name) {
@@ -97,7 +97,7 @@ public class ExpressionFactory implements IExpressionFactory, IParserConstants {
public IExpression function(Object function, IExpression[] args) {
try {
- return (IExpression) ((Constructor) function).newInstance(new Object[] {convertArray(args)});
+ return (IExpression) ((Constructor<?>) function).newInstance(new Object[] {convertArray(args)});
} catch (IllegalArgumentException e) {
throw e;
} catch (InvocationTargetException e) {
@@ -112,7 +112,7 @@ public class ExpressionFactory implements IExpressionFactory, IParserConstants {
}
}
- public Map getFunctionMap() {
+ public Map<String, ? extends Object> getFunctionMap() {
return functionMap;
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/First.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/First.java
index ee20a1466..d587ab0bb 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/First.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/First.java
@@ -26,7 +26,7 @@ final class First extends CollectionFilter {
return TYPE_FIRST;
}
- Object evaluate(IEvaluationContext context, Iterator itor) {
+ Object evaluate(IEvaluationContext context, Iterator<?> itor) {
Variable variable = lambda.getItemVariable();
while (itor.hasNext()) {
Object each = itor.next();
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Flatten.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Flatten.java
index 2aaf288ed..bb94afcb7 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Flatten.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Flatten.java
@@ -23,8 +23,8 @@ final class Flatten extends UnaryCollectionFilter {
super(collection);
}
- public Iterator evaluateAsIterator(IEvaluationContext context) {
- return new FlattenIterator(operand.evaluateAsIterator(context));
+ public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
+ return new FlattenIterator<Object>(operand.evaluateAsIterator(context));
}
public int getExpressionType() {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Latest.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Latest.java
index d4ddc0032..c1557298a 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Latest.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Latest.java
@@ -25,17 +25,17 @@ final class Latest extends UnaryCollectionFilter {
super(collection);
}
- public Iterator evaluateAsIterator(IEvaluationContext context) {
- HashMap greatestIUVersion;
+ public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
+ HashMap<String, IVersionedId> greatestIUVersion;
if (operand instanceof Select) {
// Inline element evaluation here so that we don't build a map that is
// larger then it has to be
Select select = (Select) operand;
- Iterator iterator = select.operand.evaluateAsIterator(context);
+ Iterator<?> iterator = select.operand.evaluateAsIterator(context);
if (!iterator.hasNext())
return Collections.EMPTY_SET.iterator();
- greatestIUVersion = new HashMap();
+ greatestIUVersion = new HashMap<String, IVersionedId>();
LambdaExpression lambda = select.lambda;
context = lambda.prolog(context);
Variable variable = lambda.getItemVariable();
@@ -50,20 +50,20 @@ final class Latest extends UnaryCollectionFilter {
IVersionedId versionedID = (IVersionedId) next;
String id = versionedID.getId();
- IVersionedId prev = (IVersionedId) greatestIUVersion.put(id, versionedID);
+ IVersionedId prev = greatestIUVersion.put(id, versionedID);
if (prev == null)
continue;
if (prev.getVersion().compareTo(versionedID.getVersion()) > 0)
greatestIUVersion.put(id, prev);
}
} else {
- Iterator iterator = operand.evaluateAsIterator(context);
+ Iterator<?> iterator = operand.evaluateAsIterator(context);
if (iterator == null)
return null;
if (!iterator.hasNext())
return Collections.EMPTY_SET.iterator();
- greatestIUVersion = new HashMap();
+ greatestIUVersion = new HashMap<String, IVersionedId>();
while (iterator.hasNext()) {
Object next = iterator.next();
if (!(next instanceof IVersionedId))
@@ -72,7 +72,7 @@ final class Latest extends UnaryCollectionFilter {
IVersionedId versionedID = (IVersionedId) next;
String id = versionedID.getId();
- IVersionedId prev = (IVersionedId) greatestIUVersion.put(id, versionedID);
+ IVersionedId prev = greatestIUVersion.put(id, versionedID);
if (prev == null)
continue;
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Limit.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Limit.java
index 5c0ae42a3..926a073b4 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Limit.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Limit.java
@@ -22,11 +22,11 @@ final class Limit extends Binary {
/**
* An iterator that stops iterating after a given number of iterations.
*/
- static final class CountingIterator implements Iterator {
- private final Iterator innerIterator;
+ static final class CountingIterator<T> implements Iterator<T> {
+ private final Iterator<? extends T> innerIterator;
private int counter;
- public CountingIterator(Iterator iterator, int count) {
+ public CountingIterator(Iterator<? extends T> iterator, int count) {
this.innerIterator = iterator;
this.counter = count;
}
@@ -35,7 +35,7 @@ final class Limit extends Binary {
return counter > 0 && innerIterator.hasNext();
}
- public Object next() {
+ public T next() {
if (counter > 0) {
--counter;
return innerIterator.next();
@@ -65,7 +65,7 @@ final class Limit extends Binary {
limit = ((Integer) rval).intValue();
if (limit <= 0)
throw new IllegalArgumentException("limit expression did not evalutate to a positive integer"); //$NON-NLS-1$
- return new CountingIterator(lhs.evaluateAsIterator(context), limit);
+ return new CountingIterator<Object>(lhs.evaluateAsIterator(context), limit);
}
public int getExpressionType() {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Matches.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Matches.java
index b36aa1666..9f9a9e45c 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Matches.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Matches.java
@@ -11,9 +11,9 @@
package org.eclipse.equinox.internal.p2.ql.expression;
import java.util.*;
-import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.internal.provisional.p2.metadata.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.ql.IEvaluationContext;
import org.eclipse.equinox.p2.ql.SimplePattern;
import org.osgi.framework.Filter;
@@ -46,12 +46,12 @@ final class Matches extends Binary {
Object lval = lhs.evaluate(context);
Object rval = rhs.evaluate(context);
- if (rval instanceof IRequiredCapability) {
- IRequiredCapability cap = (IRequiredCapability) rval;
+ if (rval instanceof IRequirement) {
+ IRequirement requirement = (IRequirement) rval;
if (lval instanceof IInstallableUnit)
- return Boolean.valueOf(((IInstallableUnit) lval).satisfies(cap));
+ return Boolean.valueOf(((IInstallableUnit) lval).satisfies(requirement));
if (lval instanceof IProvidedCapability)
- return Boolean.valueOf(cap.satisfiedBy((IProvidedCapability) lval));
+ return Boolean.valueOf(((IProvidedCapability) lval).satisfies(requirement));
} else if (rval instanceof VersionRange) {
if (lval instanceof Version)
@@ -67,19 +67,19 @@ final class Matches extends Binary {
} else if (rval instanceof Filter) {
if (lval instanceof IInstallableUnit)
- return Boolean.valueOf(((Filter) rval).match(new Hashtable(((IInstallableUnit) lval).getProperties())));
- if (lval instanceof Dictionary)
- return Boolean.valueOf(((Filter) rval).match((Dictionary) lval));
- if (lval instanceof Map)
- return Boolean.valueOf(((Filter) rval).match(new Hashtable((Map) lval)));
+ return Boolean.valueOf(((Filter) rval).match(new Hashtable<String, String>(((IInstallableUnit) lval).getProperties())));
+ if (lval instanceof Dictionary<?, ?>)
+ return Boolean.valueOf(((Filter) rval).match((Dictionary<?, ?>) lval));
+ if (lval instanceof Map<?, ?>)
+ return Boolean.valueOf(((Filter) rval).match(new Hashtable<Object, Object>((Map<?, ?>) lval)));
} else if (rval instanceof Locale) {
if (lval instanceof String)
return Boolean.valueOf(matchLocaleVariants((Locale) rval, (String) lval));
- } else if (rval instanceof Class) {
- Class rclass = (Class) rval;
- return Boolean.valueOf(lval instanceof Class ? rclass.isAssignableFrom((Class) lval) : rclass.isInstance(lval));
+ } else if (rval instanceof Class<?>) {
+ Class<?> rclass = (Class<?>) rval;
+ return Boolean.valueOf(lval instanceof Class<?> ? rclass.isAssignableFrom((Class<?>) lval) : rclass.isInstance(lval));
}
if (lval == null || rval == null)
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Member.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Member.java
index ff8efbc88..21c99e40c 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Member.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Member.java
@@ -12,6 +12,7 @@ package org.eclipse.equinox.internal.p2.ql.expression;
import java.lang.reflect.*;
import java.util.Iterator;
+import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.ql.*;
/**
@@ -60,8 +61,9 @@ abstract class Member extends Unary {
super(operand, KEYWORD_SATISFIES_ANY, NAry.assertLength(argExpressions, 1, 1, KEYWORD_SATISFIES_ANY));
}
- public Iterator evaluateAsIterator(IEvaluationContext context) {
- return getSelf(context).satisfiesAny(argExpressions[0].evaluateAsIterator(context));
+ @SuppressWarnings("unchecked")
+ public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
+ return getSelf(context).satisfiesAny((Iterator<IRequirement>) argExpressions[0].evaluateAsIterator(context));
}
}
@@ -71,8 +73,9 @@ abstract class Member extends Unary {
super(operand, KEYWORD_SATISFIES_ALL, NAry.assertLength(argExpressions, 1, 1, KEYWORD_SATISFIES_ALL));
}
- public Iterator evaluateAsIterator(IEvaluationContext context) {
- return getSelf(context).satisfiesAll(argExpressions[0].evaluateAsIterator(context));
+ @SuppressWarnings("unchecked")
+ public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
+ return getSelf(context).satisfiesAll((Iterator<IRequirement>) argExpressions[0].evaluateAsIterator(context));
}
}
@@ -118,7 +121,7 @@ abstract class Member extends Unary {
}
static final class DynamicMember extends Member {
- private static final Class[] NO_ARG_TYPES = new Class[0];
+ private static final Class<?>[] NO_ARG_TYPES = new Class[0];
private static final String GET_PREFIX = "get"; //$NON-NLS-1$
private static final String IS_PREFIX = "is"; //$NON-NLS-1$
@@ -129,7 +132,7 @@ abstract class Member extends Unary {
this.methodName = name;
}
- private Class lastClass;
+ private Class<?> lastClass;
private Method method;
private String methodName;
@@ -145,7 +148,7 @@ abstract class Member extends Unary {
if (self == null)
throw new IllegalArgumentException("Cannot access member " + name + " in null"); //$NON-NLS-1$//$NON-NLS-2$
- Class c = self.getClass();
+ Class<?> c = self.getClass();
if (lastClass == null || !lastClass.isAssignableFrom(c)) {
Method m;
for (;;) {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Or.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Or.java
index c4fad533a..4892782be 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Or.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Or.java
@@ -47,9 +47,10 @@ final class Or extends NAry {
}
// Not a boolean. Assume that we can use an iterator on all values
- Set resultSet = asSet(firstValue, true);
+ @SuppressWarnings("unchecked")
+ Set<Object> resultSet = (Set<Object>) asSet(firstValue, true);
for (int idx = 1; idx < operands.length; ++idx) {
- Iterator itor = operands[idx].evaluateAsIterator(context);
+ Iterator<?> itor = operands[idx].evaluateAsIterator(context);
while (itor.hasNext())
resultSet.add(itor.next());
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Select.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Select.java
index 76ee0cacd..f54ced61d 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Select.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Select.java
@@ -27,12 +27,12 @@ final class Select extends CollectionFilter {
return TYPE_SELECT;
}
- Object evaluate(IEvaluationContext context, Iterator itor) {
+ Object evaluate(IEvaluationContext context, Iterator<?> itor) {
return evaluateAsIterator(context, itor);
}
- Iterator evaluateAsIterator(final IEvaluationContext context, Iterator itor) {
- return new MatchIteratorFilter(itor) {
+ Iterator<?> evaluateAsIterator(final IEvaluationContext context, Iterator<?> itor) {
+ return new MatchIteratorFilter<Object>(itor) {
protected boolean isMatch(Object val) {
lambda.getItemVariable().setValue(context, val);
return lambda.evaluate(context) == Boolean.TRUE;
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/SetFunction.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/SetFunction.java
index b8c83f10c..3b0fa5248 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/SetFunction.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/SetFunction.java
@@ -20,7 +20,7 @@ final class SetFunction extends Function {
}
public Object evaluate(IEvaluationContext context) {
- HashSet result = new HashSet();
+ HashSet<Object> result = new HashSet<Object>();
for (int idx = 0; idx < operands.length; ++idx)
result.add(operands[idx].evaluate(context));
return result;
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Traverse.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Traverse.java
index 27fad3ebc..fcb67d6b0 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Traverse.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Traverse.java
@@ -32,12 +32,12 @@ final class Traverse extends CollectionFilter {
return TYPE_TRAVERSE;
}
- Object evaluate(IEvaluationContext context, Iterator itor) {
+ Object evaluate(IEvaluationContext context, Iterator<?> itor) {
return evaluateAsIterator(context, itor);
}
- Iterator evaluateAsIterator(IEvaluationContext context, Iterator iterator) {
- HashSet collector = new HashSet();
+ Iterator<?> evaluateAsIterator(IEvaluationContext context, Iterator<?> iterator) {
+ HashSet<Object> collector = new HashSet<Object>();
while (iterator.hasNext())
traverse(collector, iterator.next(), context);
return collector.iterator();
@@ -47,12 +47,12 @@ final class Traverse extends CollectionFilter {
return IParserConstants.KEYWORD_TRAVERSE;
}
- void traverse(Set collector, Object parent, IEvaluationContext context) {
+ void traverse(Set<Object> collector, Object parent, IEvaluationContext context) {
if (collector.add(parent)) {
Variable variable = lambda.getItemVariable();
context = new SingleVariableContext(context, variable);
variable.setValue(context, parent);
- Iterator subIterator = lambda.evaluateAsIterator(context);
+ Iterator<?> subIterator = lambda.evaluateAsIterator(context);
while (subIterator.hasNext())
traverse(collector, subIterator.next(), context);
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Unique.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Unique.java
index 1d592792a..6d55ba1ec 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Unique.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Unique.java
@@ -19,15 +19,15 @@ import org.eclipse.equinox.p2.ql.IEvaluationContext;
* once throughout the whole query.
*/
final class Unique extends Binary {
- static class UniqueIterator extends MatchIteratorFilter {
- private final Set uniqueSet;
+ static class UniqueIterator<T> extends MatchIteratorFilter<T> {
+ private final Set<T> uniqueSet;
- public UniqueIterator(Iterator iterator, Set uniqueSet) {
+ public UniqueIterator(Iterator<? extends T> iterator, Set<T> uniqueSet) {
super(iterator);
this.uniqueSet = uniqueSet;
}
- protected boolean isMatch(Object val) {
+ protected boolean isMatch(T val) {
synchronized (uniqueSet) {
return uniqueSet.add(val);
}
@@ -40,18 +40,19 @@ final class Unique extends Binary {
assertNotBoolean(explicitCache, "cache"); //$NON-NLS-1$
}
+ @SuppressWarnings("unchecked")
public Object evaluate(IEvaluationContext context) {
Object explicitCache = rhs.evaluate(context);
- Set uniqueSet;
+ Set<Object> uniqueSet;
if (explicitCache == null)
// No cache, we just ensure that the iteration is unique
- uniqueSet = new HashSet();
+ uniqueSet = new HashSet<Object>();
else {
- if (!(explicitCache instanceof Set))
+ if (!(explicitCache instanceof Set<?>))
throw new IllegalArgumentException("Unique cache must be a java.util.Set"); //$NON-NLS-1$
- uniqueSet = (Set) explicitCache;
+ uniqueSet = (Set<Object>) explicitCache;
}
- return new UniqueIterator(lhs.evaluateAsIterator(context), uniqueSet);
+ return new UniqueIterator<Object>(lhs.evaluateAsIterator(context), uniqueSet);
}
public int getExpressionType() {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Variable.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Variable.java
index fcc51ff09..bce472fd0 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Variable.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/Variable.java
@@ -47,12 +47,12 @@ class Variable extends Expression {
return context.getValue(this);
}
- public Iterator evaluateAsIterator(IEvaluationContext context) {
+ public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
Object value = context.getValue(this);
- if (value instanceof IRepeatableIterator)
- return ((IRepeatableIterator) value).getCopy();
+ if (value instanceof IRepeatableIterator<?>)
+ return ((IRepeatableIterator<?>) value).getCopy();
- Iterator itor = RepeatableIterator.create(value);
+ Iterator<?> itor = RepeatableIterator.create(value);
setValue(context, itor);
return itor;
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/WrappedIQuery.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/WrappedIQuery.java
index 282fe452c..fcd3364c1 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/WrappedIQuery.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/expression/WrappedIQuery.java
@@ -23,28 +23,29 @@ final class WrappedIQuery extends Function {
assertNotCollection(operands[0], "parameter"); //$NON-NLS-1$
}
+ @SuppressWarnings("unchecked")
public Object evaluate(IEvaluationContext context) {
Object query = operands[0].evaluate(context);
- if (query instanceof IMatchQuery) {
+ if (query instanceof IMatchQuery<?>) {
Object value = null;
if (operands.length > 1)
value = operands[1].evaluate(context);
else
value = Variable.ITEM.evaluate(context);
- return Boolean.valueOf(((IMatchQuery) query).isMatch(value));
+ return Boolean.valueOf(((IMatchQuery<Object>) query).isMatch(value));
}
- if (!(query instanceof IQuery))
+ if (!(query instanceof IQuery<?>))
throw new IllegalArgumentException("iquery first argument must be an IQuery instance"); //$NON-NLS-1$
- Iterator iterator = null;
+ Iterator<?> iterator = null;
if (operands.length > 1)
iterator = operands[1].evaluateAsIterator(context);
else
iterator = Variable.EVERYTHING.evaluateAsIterator(context);
- return ((IQuery) query).perform(iterator);
+ return ((IQuery<Object>) query).perform((Iterator<Object>) iterator);
}
String getOperator() {
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/parser/ExpressionParser.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/parser/ExpressionParser.java
index 630b71983..bd37c6d2e 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/parser/ExpressionParser.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/internal/p2/ql/parser/ExpressionParser.java
@@ -10,12 +10,10 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.ql.parser;
-import org.eclipse.equinox.p2.ql.IExpression;
-
import java.util.*;
import org.eclipse.equinox.p2.ql.*;
-public class ExpressionParser extends Stack implements IParserConstants, IExpressionParser {
+public class ExpressionParser extends Stack<IExpression> implements IParserConstants, IExpressionParser {
private static final long serialVersionUID = 882034383978853143L;
private static final int TOKEN_OR = 1;
@@ -66,9 +64,9 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
private static final int TOKEN_END = 0;
private static final int TOKEN_ERROR = -1;
- private static final Map keywords;
+ private static final Map<String, Integer> keywords;
static {
- keywords = new HashMap();
+ keywords = new HashMap<String, Integer>();
keywords.put(KEYWORD_ALL, new Integer(TOKEN_ALL));
keywords.put(KEYWORD_COLLECT, new Integer(TOKEN_COLLECT));
keywords.put(KEYWORD_EXISTS, new Integer(TOKEN_EXISTS));
@@ -116,7 +114,7 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
}
}
- public synchronized IContextExpression parseQuery(String exprString) {
+ public synchronized <T> IContextExpression<T> parseQuery(Class<T> elementClass, String exprString) {
expression = exprString;
tokenPos = 0;
currentToken = 0;
@@ -128,7 +126,7 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
nextToken();
IExpression expr = parseCondition();
assertToken(TOKEN_END);
- return factory.contextExpression(expr);
+ return factory.contextExpression(elementClass, expr);
} finally {
popVariable(); // pop context
}
@@ -151,13 +149,13 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
if (currentToken != TOKEN_OR)
return expr;
- ArrayList exprs = new ArrayList();
+ ArrayList<IExpression> exprs = new ArrayList<IExpression>();
exprs.add(expr);
do {
nextToken();
exprs.add(parseAnd());
} while (currentToken == TOKEN_OR);
- return factory.or((IExpression[]) exprs.toArray(new IExpression[exprs.size()]));
+ return factory.or(exprs.toArray(new IExpression[exprs.size()]));
}
private IExpression parseAnd() {
@@ -165,13 +163,13 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
if (currentToken != TOKEN_AND)
return expr;
- ArrayList exprs = new ArrayList();
+ ArrayList<IExpression> exprs = new ArrayList<IExpression>();
exprs.add(expr);
do {
nextToken();
exprs.add(parseBinary());
} while (currentToken == TOKEN_AND);
- return factory.and((IExpression[]) exprs.toArray(new IExpression[exprs.size()]));
+ return factory.and(exprs.toArray(new IExpression[exprs.size()]));
}
private IExpression parseBinary() {
@@ -456,10 +454,10 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
int savePos = tokenPos;
int saveToken = currentToken;
Object saveTokenValue = tokenValue;
- List ids = null;
+ List<Object> ids = null;
while (currentToken == TOKEN_IDENTIFIER) {
if (ids == null)
- ids = new ArrayList();
+ ids = new ArrayList<Object>();
ids.add(tokenValue);
nextToken();
if (currentToken == TOKEN_COMMA) {
@@ -587,7 +585,7 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
if (currentToken != TOKEN_COMMA)
return new IExpression[] {expr};
- ArrayList operands = new ArrayList();
+ ArrayList<IExpression> operands = new ArrayList<IExpression>();
operands.add(expr);
do {
nextToken();
@@ -596,7 +594,7 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
break;
operands.add(parseCondition());
} while (currentToken == TOKEN_COMMA);
- return (IExpression[]) operands.toArray(new IExpression[operands.size()]);
+ return operands.toArray(new IExpression[operands.size()]);
}
private void assertToken(int token) {
@@ -607,7 +605,7 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
private IExpression getVariableOrRootMember(String id) {
int idx = size();
while (--idx >= 0) {
- IExpression v = (IExpression) get(idx);
+ IExpression v = get(idx);
if (id.equals(v.toString()))
return v;
}
@@ -815,7 +813,7 @@ public class ExpressionParser extends Stack implements IParserConstants, IExpres
while (tokenPos < top && Character.isJavaIdentifierPart(expression.charAt(tokenPos)))
++tokenPos;
String word = expression.substring(start, tokenPos);
- Integer token = (Integer) keywords.get(word);
+ Integer token = keywords.get(word);
if (token == null)
currentToken = TOKEN_IDENTIFIER;
else
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/ICapabilityIndex.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/ICapabilityIndex.java
index 813efe97c..8f6d4a5d1 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/ICapabilityIndex.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/ICapabilityIndex.java
@@ -11,27 +11,27 @@
package org.eclipse.equinox.p2.ql;
import java.util.Iterator;
-import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
/**
* An ICapabilityIndex implementation stores instances of {@link IInstallableUnit} so
- * that they are easily retrievable using instances of {@link IRequiredCapability}.
+ * that they are easily retrievable using instances of {@link IRequirement}.
*/
public interface ICapabilityIndex {
/**
* Returns an iterator that will yield all {@link IInstallableUnit} instances that
* satisfies at least one of the <code>requirements</code>.
- * @param requirements An iterator over {@link IRequiredCapability} instances.
+ * @param requirements An iterator over {@link IRequirement} instances.
* @return An iterator over {@link IInstallableUnit} instances. Possibly empty but never <code>null</code>
*/
- Iterator satisfiesAny(Iterator requirements);
+ Iterator<IInstallableUnit> satisfiesAny(Iterator<IRequirement> requirements);
/**
* Returns an iterator that will yield all {@link IInstallableUnit} instances that
* satisfies all of the <code>requirements</code>.
- * @param requirements An iterator over {@link IRequiredCapability} instances.
+ * @param requirements An iterator over {@link IRequirement} instances.
* @return An iterator over {@link IInstallableUnit} instances. Possibly empty but never <code>null</code>
*/
- Iterator satisfiesAll(Iterator requirements);
+ Iterator<IInstallableUnit> satisfiesAll(Iterator<IRequirement> requirements);
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IContextExpression.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IContextExpression.java
index d573863cc..027e39644 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IContextExpression.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IContextExpression.java
@@ -16,7 +16,13 @@ import java.util.Iterator;
* This is an expression that will need access to the global variable
* <code>everything</code>.
*/
-public interface IContextExpression extends IExpression {
+public interface IContextExpression<T> extends IExpression {
+ /**
+ * Returns the element class
+ * @return The element class
+ */
+ Class<T> getElementClass();
+
/**
* <p>Creates a new context to be passed to a subsequent evaluation. The context
* will have the variable 'everything' set to an expression that represents
@@ -28,7 +34,7 @@ public interface IContextExpression extends IExpression {
* @param params The parameters to use for the evaluation.
* @return A new evaluation context.
*/
- IEvaluationContext createContext(Class elementClass, Iterator everything, Object[] params);
+ IEvaluationContext createContext(Iterator<T> everything, Object[] params);
/**
* <p>Creates a new context to be passed to a subsequent evaluation. The context
@@ -42,5 +48,5 @@ public interface IContextExpression extends IExpression {
* @param translations A translation support object to be assigned to the variable 'translations'
* @return A new evaluation context.
*/
- IEvaluationContext createContext(Class elementClass, Iterator everything, Object[] params, ITranslationSupport translations);
+ IEvaluationContext createContext(Iterator<T> everything, Object[] params, ITranslationSupport translations);
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpression.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpression.java
index 040b0ead0..9f959f106 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpression.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpression.java
@@ -72,7 +72,7 @@ public interface IExpression {
* @param context The evaluation context
* @return The result of the evaluation.
*/
- Iterator evaluateAsIterator(IEvaluationContext context);
+ Iterator<?> evaluateAsIterator(IEvaluationContext context);
/**
* Returns the expression type (see TYPE_xxx constants).
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionFactory.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionFactory.java
index cceafffa2..3ca1ca331 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionFactory.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionFactory.java
@@ -91,7 +91,7 @@ public interface IExpressionFactory {
* @param expr The query
* @return A top level query expression
*/
- IContextExpression contextExpression(IExpression expr);
+ <T> IContextExpression<T> contextExpression(Class<T> elementClass, IExpression expr);
/**
* Create an expression that tests if <code>lhs</code> is equal to <code>rhs</code>.
@@ -142,7 +142,7 @@ public interface IExpressionFactory {
* method.
* @return A key/function map.
*/
- Map getFunctionMap();
+ Map<String, ? extends Object> getFunctionMap();
/**
* Create an expression that tests if <code>lhs</code> is greater than <code>rhs</code>.
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionParser.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionParser.java
index 69c507a5b..5dbaf6f57 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionParser.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IExpressionParser.java
@@ -31,5 +31,5 @@ public interface IExpressionParser {
* @return The resulting expression tree.
* @throws QLParseException
*/
- IContextExpression parseQuery(String exprString);
+ <T> IContextExpression<T> parseQuery(Class<T> elementClass, String exprString);
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IQueryContext.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IQueryContext.java
index efc48200d..3268df65f 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IQueryContext.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/IQueryContext.java
@@ -3,8 +3,8 @@ package org.eclipse.equinox.p2.ql;
import java.util.Iterator;
import java.util.Locale;
-public interface IQueryContext {
+public interface IQueryContext<T> {
ITranslationSupport getTranslationSupport(Locale locale);
- Iterator iterator();
+ Iterator<T> iterator();
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QL.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QL.java
index 5b951b683..48bb1aaec 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QL.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QL.java
@@ -41,8 +41,8 @@ public abstract class QL {
* @param queryable The queryable to use for the creation of the context
* @return A new context
*/
- public static IQueryContext newQueryContext(IQueryable queryable) {
- return new QueryContext(queryable);
+ public static <T> IQueryContext<T> newQueryContext(IQueryable<T> queryable) {
+ return new QueryContext<T>(queryable);
}
/**
@@ -50,7 +50,7 @@ public abstract class QL {
* @param iterator The iterator to use for the creation of the context
* @return A new context
*/
- public static IQueryContext newQueryContext(Iterator iterator) {
- return new QueryContext(iterator);
+ public static <T> IQueryContext<T> newQueryContext(Iterator<T> iterator) {
+ return new QueryContext<T>(iterator);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLContextQuery.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLContextQuery.java
index 9e3b765d8..d2cd897d1 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLContextQuery.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLContextQuery.java
@@ -11,14 +11,13 @@
package org.eclipse.equinox.p2.ql;
import java.util.Iterator;
-import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.equinox.p2.metadata.query.IQueryResult;
/**
* An IQuery 'context query' implementation that is based on the p2 query language.
*/
-public class QLContextQuery extends QLQuery {
- private final IContextExpression expression;
+public class QLContextQuery<T> extends QLQuery<T> {
+ private final IContextExpression<T> expression;
/**
* Creates a new query instance with indexed parameters.
@@ -26,8 +25,8 @@ public class QLContextQuery extends QLQuery {
* @param expression The expression that represents the query.
* @param parameters Parameters to use for the query.
*/
- public QLContextQuery(Class elementClass, IContextExpression expression, Object[] parameters) {
- super(elementClass, parameters);
+ public QLContextQuery(IContextExpression<T> expression, Object... parameters) {
+ super(expression.getElementClass(), parameters);
this.expression = expression;
}
@@ -37,68 +36,24 @@ public class QLContextQuery extends QLQuery {
* @param expression The expression that represents the query.
* @param parameters Parameters to use for the query.
*/
- public QLContextQuery(Class elementClass, String expression, Object[] parameters) {
- this(elementClass, parser.parseQuery(expression), parameters);
+ public QLContextQuery(Class<T> elementClass, String expression, Object... parameters) {
+ this(parser.parseQuery(elementClass, expression), parameters);
}
- /**
- * Convenience method that creates a new query instance without parameters.
- * The element class defaults to {@link IVersionedId}.
- * @param elementClass The class used for filtering elements in 'everything'
- * @param expression The expression string that represents the query.
- */
- public QLContextQuery(String expression) {
- this(IVersionedId.class, expression, noParameters);
- }
-
- /**
- * Convenience method that creates a new query instance with one parameter.
- * The element class defaults to {@link IVersionedId}.
- * @param elementClass The class used for filtering elements in 'everything'
- * @param expression The expression string that represents the query.
- * @param param The first parameter.
- */
- public QLContextQuery(String expression, Object param) {
- this(IVersionedId.class, expression, new Object[] {param});
- }
-
- /**
- * Convenience method that creates a new query instance with two parameters.
- * The element class defaults to {@link IVersionedId}.
- * @param elementClass The class used for filtering elements in 'everything'
- * @param expression The expression string that represents the query.
- * @param param1 The first parameter.
- * @param param2 The second parameter.
- */
- public QLContextQuery(String expression, Object param1, Object param2) {
- this(IVersionedId.class, expression, new Object[] {param1, param2});
- }
-
- /**
- * Convenience method that creates a new query instance with three parameters.
- * The element class defaults to {@link IVersionedId}.
- * @param elementClass The class used for filtering elements in 'everything'
- * @param expression The expression string that represents the query.
- * @param param1 The first parameter.
- * @param param2 The second parameter.
- * @param param2 The third parameter.
- */
- public QLContextQuery(String expression, Object param1, Object param2, Object param3) {
- this(IVersionedId.class, expression, new Object[] {param1, param2, param3});
- }
-
- public IQueryResult perform(Iterator iterator) {
- return new QueryResult(evaluate(iterator));
+ public IQueryResult<T> perform(Iterator<T> iterator) {
+ return new QueryResult<T>(evaluate(iterator));
}
- public Iterator evaluate(Iterator iterator) {
+ public Iterator<T> evaluate(Iterator<T> iterator) {
IEvaluationContext ctx;
if (expression.needsTranslations()) {
- IQueryContext queryContext = QL.newQueryContext(iterator);
- ctx = expression.createContext(elementClass, iterator, parameters, queryContext.getTranslationSupport(getLocale()));
+ IQueryContext<T> queryContext = QL.newQueryContext(iterator);
+ ctx = expression.createContext(iterator, parameters, queryContext.getTranslationSupport(getLocale()));
} else
- ctx = expression.createContext(elementClass, iterator, parameters);
- return expression.evaluateAsIterator(ctx);
+ ctx = expression.createContext(iterator, parameters);
+ @SuppressWarnings("unchecked")
+ Iterator<T> result = (Iterator<T>) expression.evaluateAsIterator(ctx);
+ return result;
}
/**
@@ -106,14 +61,14 @@ public class QLContextQuery extends QLQuery {
* @param queryContext The context for the query.
* @return The result of the query.
*/
- public Object query(IQueryContext queryContext) {
+ public Object query(IQueryContext<T> queryContext) {
// Check if we need translation support
//
IEvaluationContext ctx;
if (expression.needsTranslations())
- ctx = expression.createContext(elementClass, queryContext.iterator(), parameters, queryContext.getTranslationSupport(getLocale()));
+ ctx = expression.createContext(queryContext.iterator(), parameters, queryContext.getTranslationSupport(getLocale()));
else
- ctx = expression.createContext(elementClass, queryContext.iterator(), parameters);
+ ctx = expression.createContext(queryContext.iterator(), parameters);
return expression.evaluate(ctx);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLMatchQuery.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLMatchQuery.java
index b43dc2f7f..132db147e 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLMatchQuery.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLMatchQuery.java
@@ -13,13 +13,12 @@ package org.eclipse.equinox.p2.ql;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.equinox.internal.provisional.p2.metadata.query.IMatchQuery;
-import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.equinox.p2.metadata.query.IQueryResult;
/**
* An IQuery implementation that is based on the p2 query language.
*/
-public class QLMatchQuery extends QLQuery implements IMatchQuery {
+public class QLMatchQuery<T> extends QLQuery<T> implements IMatchQuery<T> {
private final IMatchExpression expression;
private IEvaluationContext context;
@@ -29,7 +28,7 @@ public class QLMatchQuery extends QLQuery implements IMatchQuery {
* @param expression The expression that represents the query.
* @param parameters Parameters to use for the query.
*/
- public QLMatchQuery(Class instanceClass, IMatchExpression expression, Object[] parameters) {
+ public QLMatchQuery(Class<T> instanceClass, IMatchExpression expression, Object... parameters) {
super(instanceClass, parameters);
this.expression = expression;
}
@@ -40,53 +39,11 @@ public class QLMatchQuery extends QLQuery implements IMatchQuery {
* @param expression The expression that represents the query.
* @param parameters Parameters to use for the query.
*/
- public QLMatchQuery(Class instanceClass, String expression, Object[] parameters) {
+ public QLMatchQuery(Class<T> instanceClass, String expression, Object ...parameters) {
this(instanceClass, parser.parsePredicate(expression), parameters);
}
/**
- * Convenience method that creates a new query instance without parameters.
- * The element class defaults to {@link IVersionedId}.
- * @param expression The expression string that represents the query.
- */
- public QLMatchQuery(String expression) {
- this(IVersionedId.class, expression, (Object[]) null);
- }
-
- /**
- * Convenience method that creates a new query instance with one parameter.
- * The element class defaults to {@link IVersionedId}.
- * @param expression The expression string that represents the query.
- * @param param The first parameter.
- */
- public QLMatchQuery(String expression, Object param1) {
- this(IVersionedId.class, expression, new Object[] {param1});
- }
-
- /**
- * Convenience method that creates a new query instance with two parameters.
- * The element class defaults to {@link IVersionedId}.
- * @param expression The expression string that represents the query.
- * @param param1 The first parameter.
- * @param param2 The second parameter.
- */
- public QLMatchQuery(String expression, Object param1, Object param2) {
- this(IVersionedId.class, expression, new Object[] {param1, param2});
- }
-
- /**
- * Convenience method that creates a new query instance with three parameters.
- * The element class defaults to {@link IVersionedId}.
- * @param expression The expression string that represents the query.
- * @param param1 The first parameter.
- * @param param2 The second parameter.
- * @param param2 The third parameter.
- */
- public QLMatchQuery(String expression, Object param1, Object param2, Object param3) {
- this(IVersionedId.class, parser.parsePredicate(expression), new Object[] {param1, param2, param3});
- }
-
- /**
* Checks if the <code>candidate</code> object is an instance of the <code>elementClass</code>
* used by this query. If it is, the result calling {@link IMatchExpression#isMatch(IEvaluationContext, Object)}
* on the contained expression is returned.
@@ -94,7 +51,7 @@ public class QLMatchQuery extends QLQuery implements IMatchQuery {
* @return <code>true</code> if <code>candidate</code> is an instance of the element class and the
* expression match test returns true.
*/
- public boolean isMatch(Object candidate) {
+ public boolean isMatch(T candidate) {
return elementClass.isInstance(candidate) && expression.isMatch(context, candidate);
}
@@ -106,22 +63,22 @@ public class QLMatchQuery extends QLQuery implements IMatchQuery {
//
}
- public IQueryResult perform(Iterator iterator) {
+ public IQueryResult<T> perform(Iterator<T> iterator) {
if (expression.needsTranslations()) {
- IQueryContext queryContext = QL.newQueryContext(iterator);
+ IQueryContext<T> queryContext = QL.newQueryContext(iterator);
context = expression.createContext(parameters, queryContext.getTranslationSupport(getLocale()));
} else
context = expression.createContext(parameters);
prePerform();
try {
- ArrayList result = new ArrayList();
+ ArrayList<T> result = new ArrayList<T>();
while (iterator.hasNext()) {
- Object candidate = iterator.next();
+ T candidate = iterator.next();
if (isMatch(candidate))
result.add(candidate);
}
- return new QueryResult(result);
+ return new QueryResult<T>(result);
} finally {
postPerform();
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLQuery.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLQuery.java
index 43942ae13..853c4cf41 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLQuery.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QLQuery.java
@@ -12,37 +12,24 @@ package org.eclipse.equinox.p2.ql;
import java.util.Locale;
import org.eclipse.equinox.internal.provisional.p2.metadata.query.QueryHelpers;
-import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.query.IQuery;
-import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
-import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
/**
* An IQuery 'context query' implementation that is based on the p2 query language.
*/
-public abstract class QLQuery implements IQuery {
+public abstract class QLQuery<T> implements IQuery<T> {
static final IExpressionParser parser = QL.newParser();
static final Object[] noParameters = new Object[0];
- final Class elementClass;
+ final Class<T> elementClass;
final Object[] parameters;
private Locale locale;
- protected QLQuery(Class elementClass, Object[] parameters) {
+ protected QLQuery(Class<T> elementClass, Object[] parameters) {
this.elementClass = elementClass;
this.parameters = parameters;
}
- public Object getProperty(String key) {
- if (IArtifactRepository.QUERY_EXCLUDE_KEYS.equals(key))
- return Boolean.valueOf(!elementClass.isAssignableFrom(IArtifactKey.class));
-
- if (IArtifactRepository.QUERY_EXCLUDE_DESCRIPTORS.equals(key))
- return Boolean.valueOf(!elementClass.isAssignableFrom(IArtifactDescriptor.class));
-
- return QueryHelpers.getProperty(this, key);
- }
-
public Locale getLocale() {
return locale == null ? Locale.getDefault() : locale;
}
@@ -57,4 +44,8 @@ public abstract class QLQuery implements IQuery {
public String getId() {
return QueryHelpers.getId(this);
}
+
+ public Object getProperty(String property) {
+ return QueryHelpers.getProperty(this, property);
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QueryResult.java b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QueryResult.java
index d634d405f..55b3baf8e 100644
--- a/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QueryResult.java
+++ b/bundles/org.eclipse.equinox.p2.ql/src/org/eclipse/equinox/p2/ql/QueryResult.java
@@ -9,15 +9,15 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector;
import org.eclipse.equinox.p2.metadata.query.IQuery;
import org.eclipse.equinox.p2.metadata.query.IQueryResult;
-class QueryResult implements IQueryResult {
+class QueryResult<T> implements IQueryResult<T> {
- private final IRepeatableIterator iterator;
+ private final IRepeatableIterator<T> iterator;
- QueryResult(Iterator iterator) {
+ QueryResult(Iterator<T> iterator) {
this.iterator = RepeatableIterator.create(iterator);
}
- QueryResult(Collection collection) {
+ QueryResult(Collection<T> collection) {
this.iterator = RepeatableIterator.create(collection);
}
@@ -25,53 +25,56 @@ class QueryResult implements IQueryResult {
return !iterator.hasNext();
}
- public Iterator iterator() {
+ public Iterator<T> iterator() {
return iterator.getCopy();
}
- public Object[] toArray(Class clazz) {
+ @SuppressWarnings("unchecked")
+ public T[] toArray(Class<? extends T> clazz) {
Object provider = iterator.getIteratorProvider();
if (provider.getClass().isArray())
- return (Object[]) provider;
+ return (T[]) provider;
- if (provider instanceof Collector)
- return ((Collector) provider).toArray(clazz);
+ if (provider instanceof Collector<?>)
+ return ((Collector<T>) provider).toArray(clazz);
- Collection c = (Collection) provider;
- return c.toArray((Object[]) Array.newInstance(clazz, c.size()));
+ Collection<T> c = (Collection<T>) provider;
+ return c.toArray((T[]) Array.newInstance(clazz, c.size()));
}
- public Set toSet() {
+ @SuppressWarnings("unchecked")
+ public Set<T> toSet() {
Object provider = iterator.getIteratorProvider();
if (provider.getClass().isArray()) {
- Object[] elems = (Object[]) provider;
+ T[] elems = (T[]) provider;
int idx = elems.length;
- HashSet copy = new HashSet(idx);
+ HashSet<T> copy = new HashSet<T>(idx);
while (--idx >= 0)
copy.add(elems[idx]);
return copy;
}
- if (provider instanceof Collector)
- return ((Collector) provider).toSet();
- if (provider instanceof Map)
- return new HashSet(((Map) provider).entrySet());
- return new HashSet((Collection) provider);
+ if (provider instanceof Collector<?>)
+ return ((Collector<T>) provider).toSet();
+ if (provider instanceof Map<?, ?>)
+ return new HashSet<T>((Set<T>) ((Map<?, ?>) provider).entrySet());
+ return new HashSet<T>((Collection<T>) provider);
}
- public IQueryResult query(IQuery query, IProgressMonitor monitor) {
+ public IQueryResult<T> query(IQuery<T> query, IProgressMonitor monitor) {
return query.perform(iterator());
}
- public Set unmodifiableSet() {
+ @SuppressWarnings("unchecked")
+ public Set<T> unmodifiableSet() {
Object provider = iterator.getIteratorProvider();
- if (provider instanceof Collector)
- return ((Collector) provider).unmodifiableSet();
+ if (provider instanceof Collector<?>)
+ return ((Collector<T>) provider).unmodifiableSet();
- if (provider instanceof Set)
- return Collections.unmodifiableSet((Set) provider);
+ if (provider instanceof Set<?>)
+ return Collections.unmodifiableSet((Set<T>) provider);
- if (provider instanceof Map)
- return Collections.unmodifiableSet(((Map) provider).entrySet());
+ if (provider instanceof Map<?, ?>)
+ return Collections.unmodifiableSet((Set<T>) ((Map<?, ?>) provider).entrySet());
return toSet();
}

Back to the top