aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Piech2012-11-07 13:57:31 (EST)
committerPaul Webster2012-11-07 13:57:31 (EST)
commit68d64830f5798cba21a7f0f14abea3a72df91a59 (patch)
tree4bd4532ca24ea952f7a6f0689e1526dd1cf3c50b
parent64127a67cbfbac1225a1bc73d56a87406648de16 (diff)
downloadeclipse.platform.runtime-68d64830f5798cba21a7f0f14abea3a72df91a59.zip
eclipse.platform.runtime-68d64830f5798cba21a7f0f14abea3a72df91a59.tar.gz
eclipse.platform.runtime-68d64830f5798cba21a7f0f14abea3a72df91a59.tar.bz2
optionally use .getAdapter If the adaptable class can see the requested class.
-rw-r--r--bundles/org.eclipse.core.expressions/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.core.expressions/pom.xml2
-rw-r--r--bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/AdaptExpression.java22
-rw-r--r--tests/org.eclipse.core.expressions.tests/META-INF/MANIFEST.MF2
-rw-r--r--tests/org.eclipse.core.expressions.tests/pom.xml2
-rw-r--r--tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/AdaptableAdaptee.java29
-rw-r--r--tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/Adapter.java1
-rw-r--r--tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java8
8 files changed, 59 insertions, 9 deletions
diff --git a/bundles/org.eclipse.core.expressions/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.expressions/META-INF/MANIFEST.MF
index 334fcae..6d10047 100644
--- a/bundles/org.eclipse.core.expressions/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.core.expressions/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.core.expressions; singleton:=true
-Bundle-Version: 3.4.401.qualifier
+Bundle-Version: 3.4.500.qualifier
Bundle-ClassPath: .
Bundle-Activator: org.eclipse.core.internal.expressions.ExpressionPlugin
Bundle-Vendor: %providerName
diff --git a/bundles/org.eclipse.core.expressions/pom.xml b/bundles/org.eclipse.core.expressions/pom.xml
index 3a152a0..985db45 100644
--- a/bundles/org.eclipse.core.expressions/pom.xml
+++ b/bundles/org.eclipse.core.expressions/pom.xml
@@ -22,7 +22,7 @@
</parent>
<groupId>org.eclipse.platform.runtime</groupId>
<artifactId>org.eclipse.core.expressions</artifactId>
- <version>3.4.401-SNAPSHOT</version>
+ <version>3.4.500-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
diff --git a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/AdaptExpression.java b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/AdaptExpression.java
index 5302ab9..95b45b1 100644
--- a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/AdaptExpression.java
+++ b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/AdaptExpression.java
@@ -18,6 +18,7 @@ import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
@@ -74,10 +75,23 @@ public class AdaptExpression extends CompositeExpression {
if (Expressions.isInstanceOf(var, fTypeName)) {
adapted= var;
} else {
- if (!manager.hasAdapter(var, fTypeName))
- return EvaluationResult.FALSE;
-
- adapted= manager.getAdapter(var, fTypeName);
+ if (manager.hasAdapter(var, fTypeName)) {
+ adapted= manager.getAdapter(var, fTypeName);
+ } else {
+ // if the adapter manager doesn't have an adapter contributed,
+ // try to see if the variable itself implements IAdaptable
+ if (var instanceof IAdaptable) {
+ try {
+ Class typeClazz= Class.forName(fTypeName, false, var.getClass().getClassLoader());
+ adapted= ((IAdaptable)var).getAdapter(typeClazz);
+ } catch (ClassNotFoundException e) {
+ }
+ }
+ if (adapted == null) {
+ // all attempts failed, return false
+ return EvaluationResult.FALSE;
+ }
+ }
}
// the adapted result is null but hasAdapter returned true check
// if the adapter is loaded.
diff --git a/tests/org.eclipse.core.expressions.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.core.expressions.tests/META-INF/MANIFEST.MF
index e53c828..849f208 100644
--- a/tests/org.eclipse.core.expressions.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.core.expressions.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.core.expressions.tests; singleton:=true
-Bundle-Version: 3.4.100.qualifier
+Bundle-Version: 3.4.200.qualifier
Bundle-ClassPath: expressionstests.jar
Bundle-Activator: org.eclipse.core.internal.expressions.tests.ExpressionTestPlugin
Bundle-ActivationPolicy: lazy
diff --git a/tests/org.eclipse.core.expressions.tests/pom.xml b/tests/org.eclipse.core.expressions.tests/pom.xml
index 1c772f3..ef2d913 100644
--- a/tests/org.eclipse.core.expressions.tests/pom.xml
+++ b/tests/org.eclipse.core.expressions.tests/pom.xml
@@ -21,6 +21,6 @@
</parent>
<groupId>org.eclipse.platform.runtime</groupId>
<artifactId>org.eclipse.core.expressions.tests</artifactId>
- <version>3.4.100-SNAPSHOT</version>
+ <version>3.4.200-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
</project>
diff --git a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/AdaptableAdaptee.java b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/AdaptableAdaptee.java
new file mode 100644
index 0000000..f95723f
--- /dev/null
+++ b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/AdaptableAdaptee.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.expressions.tests;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ *
+ */
+public class AdaptableAdaptee implements IAdaptable {
+
+ private Adapter fAdapter = new Adapter();
+
+ public Object getAdapter(Class adapter) {
+ if (adapter.isInstance(fAdapter)) {
+ return fAdapter;
+ }
+ return null;
+ }
+
+}
diff --git a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/Adapter.java b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/Adapter.java
index a738566..6e44153 100644
--- a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/Adapter.java
+++ b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/Adapter.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.core.internal.expressions.tests;
-
public class Adapter {
}
diff --git a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java
index ad7c3d4..460c504 100644
--- a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java
+++ b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java
@@ -170,6 +170,14 @@ public class ExpressionTests extends TestCase {
assertTrue(result == EvaluationResult.TRUE);
}
+ public void testAdaptExpressionAdaptable() throws Exception {
+ AdaptExpression expression= new AdaptExpression("org.eclipse.core.internal.expressions.tests.Adapter"); //$NON-NLS-1$
+ expression.add(new InstanceofExpression("org.eclipse.core.internal.expressions.tests.Adapter")); //$NON-NLS-1$
+ EvaluationResult result= expression.evaluate(new EvaluationContext(null, new AdaptableAdaptee()));
+ assertTrue(result == EvaluationResult.TRUE);
+ }
+
+
public void testAdaptExpressionNotEqual() throws Exception {
AdaptExpression expression1 = new AdaptExpression(
"org.eclipse.core.internal.expressions.tests.Adapter"); //$NON-NLS-1$