Removed depedency to runtime.compatibility
diff --git a/bundles/org.eclipse.core.expressions/plugin.xml b/bundles/org.eclipse.core.expressions/plugin.xml
index 7b96620..a386064 100644
--- a/bundles/org.eclipse.core.expressions/plugin.xml
+++ b/bundles/org.eclipse.core.expressions/plugin.xml
@@ -15,7 +15,7 @@
</runtime>
<requires>
- <import plugin="org.eclipse.core.runtime.compatibility"/>
+ <import plugin="org.eclipse.core.runtime"/>
</requires>
<extension-point id="propertyTesters" name="%propertyTesterExtensionPoint" schema="schema/propertyTesters.exsd"/>
diff --git a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/ExpressionPlugin.java b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/ExpressionPlugin.java
index 401a941..379e2a1 100644
--- a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/ExpressionPlugin.java
+++ b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/ExpressionPlugin.java
@@ -10,17 +10,19 @@
*******************************************************************************/
package org.eclipse.core.internal.expressions;
-import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
public class ExpressionPlugin extends Plugin {
private static ExpressionPlugin fgDefault;
- public ExpressionPlugin(IPluginDescriptor descriptor) {
- super(descriptor);
+ private BundleContext fBundleContext;
+
+ public ExpressionPlugin() {
fgDefault= this;
- }
+ }
public static ExpressionPlugin getDefault() {
return fgDefault;
@@ -29,4 +31,23 @@
public static String getPluginId() {
return getDefault().getDescriptor().getUniqueIdentifier();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ fBundleContext= context;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ }
+
+ public BundleContext getBundleContext() {
+ return fBundleContext;
+ }
}
diff --git a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/TypeExtension.java b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/TypeExtension.java
index 1f40bce..de26fab 100644
--- a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/TypeExtension.java
+++ b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/TypeExtension.java
@@ -10,21 +10,13 @@
******************************************************************************/
package org.eclipse.core.internal.expressions;
-import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IPluginRegistry;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.expressions.IPropertyTester;
import org.eclipse.core.expressions.PropertyTester;
public class TypeExtension {
- private static final String TYPE= "type"; //$NON-NLS-1$
- private static final IPropertyTester[] EMPTY_TYPE_EXTENDER_ARRAY= new IPropertyTester[0];
private static final TypeExtension[] EMPTY_TYPE_EXTENSION_ARRAY= new TypeExtension[0];
/* a special property tester instance that used to signal that method searching has to continue */
@@ -48,7 +40,7 @@
/* a special type extension instance that marks the end of an evaluation chain */
private static final TypeExtension END_POINT= new TypeExtension() {
- /* package */ IPropertyTester findTypeExtender(TypeExtensionManager manager, String namespace, String name, String extPoint, boolean staticMethod) throws CoreException {
+ /* package */ IPropertyTester findTypeExtender(TypeExtensionManager manager, String namespace, String name, boolean staticMethod) throws CoreException {
return CONTINUE;
}
};
@@ -72,10 +64,11 @@
fType= type;
}
- /* package */ IPropertyTester findTypeExtender(TypeExtensionManager manager, String namespace, String method, String extPoint, boolean staticMethod) throws CoreException {
+ /* package */ IPropertyTester findTypeExtender(TypeExtensionManager manager, String namespace, String method, boolean staticMethod) throws CoreException {
synchronized (this) {
- if (fExtenders == null)
- initialize(extPoint);
+ if (fExtenders == null) {
+ fExtenders= manager.loadTesters(fType);
+ }
}
IPropertyTester result;
@@ -131,7 +124,7 @@
}
}
}
- result= fExtends.findTypeExtender(manager, namespace, method, extPoint, staticMethod);
+ result= fExtends.findTypeExtender(manager, namespace, method, staticMethod);
if (result != CONTINUE)
return result;
@@ -150,28 +143,10 @@
}
}
for (int i= 0; i < fImplements.length; i++) {
- result= fImplements[i].findTypeExtender(manager, namespace, method, extPoint, staticMethod);
+ result= fImplements[i].findTypeExtender(manager, namespace, method, staticMethod);
if (result != CONTINUE)
return result;
}
return CONTINUE;
}
-
- private void initialize(String extPoint) {
- IPluginRegistry registry= Platform.getPluginRegistry();
- IConfigurationElement[] ces= registry.getConfigurationElementsFor(
- ExpressionPlugin.getPluginId(),
- extPoint);
- String fTypeName= fType.getName();
- List result= new ArrayList(2);
- for (int i= 0; i < ces.length; i++) {
- IConfigurationElement config= ces[i];
- if (fTypeName.equals(config.getAttribute(TYPE)))
- result.add(new PropertyTesterDescriptor(config));
- }
- if (result.size() == 0)
- fExtenders= EMPTY_TYPE_EXTENDER_ARRAY;
- else
- fExtenders= (IPropertyTester[])result.toArray(new IPropertyTester[result.size()]);
- }
}
diff --git a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/TypeExtensionManager.java b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/TypeExtensionManager.java
index f0bcbf2..2cbb1c7 100644
--- a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/TypeExtensionManager.java
+++ b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/TypeExtensionManager.java
@@ -10,10 +10,15 @@
*******************************************************************************/
package org.eclipse.core.internal.expressions;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPluginRegistry;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.expressions.IPropertyTester;
@@ -21,12 +26,18 @@
private String fExtensionPoint;
+ private static final String TYPE= "type"; //$NON-NLS-1$
+
+ private static final IPropertyTester[] EMPTY_PROPERTY_TESTER_ARRAY= new IPropertyTester[0];
+
/*
* Map containing all already created type extension object. Key is
* of type <code>Class</code>, value is of type <code>TypeExtension</code>.
*/
private final Map/*<Class, TypeExtension>*/ fTypeExtensionMap= new HashMap();
+ private Map/*<String, List<IConfigurationElement>>*/ fConfigurationElementMap= null;
+
/*
* A cache to give fast access to the last 1000 method invocations.
*/
@@ -63,7 +74,7 @@
fPropertyCache.remove(cached);
}
TypeExtension extension= get(clazz);
- IPropertyTester extender= extension.findTypeExtender(this, namespace, method, fExtensionPoint, receiver instanceof Class);
+ IPropertyTester extender= extension.findTypeExtender(this, namespace, method, receiver instanceof Class);
if (extender == TypeExtension.CONTINUE || extender == null) {
throw new CoreException(new ExpressionStatus(
ExpressionStatus.TYPE_EXTENDER_UNKOWN_METHOD,
@@ -82,7 +93,7 @@
return result;
}
- public TypeExtension get(Class clazz) {
+ /* package */ TypeExtension get(Class clazz) {
synchronized(fTypeExtensionMap) {
TypeExtension result= (TypeExtension)fTypeExtensionMap.get(clazz);
if (result == null) {
@@ -91,5 +102,71 @@
}
return result;
}
- }
+ }
+
+ /* package */ IPropertyTester[] loadTesters(Class type) {
+ synchronized(this) {
+ if (fConfigurationElementMap == null) {
+ fConfigurationElementMap= new HashMap();
+ IPluginRegistry registry= Platform.getPluginRegistry();
+ IConfigurationElement[] ces= registry.getConfigurationElementsFor(
+ ExpressionPlugin.getPluginId(),
+ fExtensionPoint);
+ for (int i= 0; i < ces.length; i++) {
+ IConfigurationElement config= ces[i];
+ String typeAttr= config.getAttribute(TYPE);
+ List typeConfigs= (List)fConfigurationElementMap.get(typeAttr);
+ if (typeConfigs == null) {
+ typeConfigs= new ArrayList();
+ fConfigurationElementMap.put(typeAttr, typeConfigs);
+ }
+ typeConfigs.add(config);
+ }
+ }
+ }
+ synchronized(fConfigurationElementMap) {
+ String typeName= type.getName();
+ List typeConfigs= (List)fConfigurationElementMap.get(typeName);
+ if (typeConfigs == null)
+ return EMPTY_PROPERTY_TESTER_ARRAY;
+ else {
+ IPropertyTester[] result= new IPropertyTester[typeConfigs.size()];
+ for (int i= 0; i < result.length; i++) {
+ IConfigurationElement config= (IConfigurationElement)typeConfigs.get(i);
+ result[i]= new PropertyTesterDescriptor(config);
+ }
+ fConfigurationElementMap.remove(typeName);
+ return result;
+ }
+ }
+ }
+
+ /*
+ private void addRegistryListener() {
+ Platform.getExtensionRegistry().addRegistryChangeListener(new IRegistryChangeListener() {
+ public void registryChanged(IRegistryChangeEvent aEvent) {
+ processRegistryDelta(aEvent.getExtensionDeltas());
+ }
+ });
+ }
+
+ private void processRegistryDelta(IExtensionDelta[] deltas) {
+ for (int i= 0; i < deltas.length; i++) {
+ IExtensionDelta delta= deltas[i];
+ int kind = delta.getKind();
+ if (delta.getExtensionPoint().getUniqueIdentifier().equals(OP_EXT_ID)) {
+ IConfigurationElement[] elements= delta.getExtension().getConfigurationElements();
+ if (kind == IExtensionDelta.ADDED) {
+ for (int j= 0; j < elements.length; j++) {
+ }
+ }
+ if (kind == IExtensionDelta.REMOVED) {
+ for (int j= 0; j < elements.length; j++) {
+ final IConfigurationElement element= elements[j];
+ }
+ }
+ }
+ }
+ }
+ */
}
diff --git a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/PropertyTesterTests.java b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/PropertyTesterTests.java
index 76ab13f..10495d7 100644
--- a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/PropertyTesterTests.java
+++ b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/PropertyTesterTests.java
@@ -19,13 +19,14 @@
import org.eclipse.core.internal.expressions.Property;
import org.eclipse.core.internal.expressions.TypeExtensionManager;
-
public class PropertyTesterTests extends TestCase {
private A a;
private B b;
private I i;
+ private static final TypeExtensionManager fgManager= new TypeExtensionManager("propertyTesters");
+
public static Test suite() {
return new TestSuite(PropertyTesterTests.class);
}
@@ -38,11 +39,16 @@
public void testSimple() throws Exception {
assertTrue(test(a, "simple", null,"simple"));
+ // second pass to check if cache is populated correctly
+ assertTrue(test(a, "simple", null,"simple"));
}
public void testInherited() throws Exception {
assertTrue(test(b, "simple", null, "simple"));
assertTrue(test(i, "simple", null, "simple"));
+ // second pass to check if cache is populated correctly
+ assertTrue(test(b, "simple", null, "simple"));
+ assertTrue(test(i, "simple", null, "simple"));
}
public void testUnknown() throws Exception {
@@ -60,22 +66,34 @@
A b_as_a= b;
assertTrue(test(b_as_a, "overridden", null, "B"));
assertTrue(test(i, "overridden", null, "B"));
+ // second pass to check if cache is populated correctly
+ assertTrue(test(a, "overridden", null, "A"));
+ assertTrue(test(b, "overridden", null, "B"));
+ assertTrue(test(b_as_a, "overridden", null, "B"));
+ assertTrue(test(i, "overridden", null, "B"));
}
public void testOdering() throws Exception {
assertTrue(test(b, "ordering", null, "A"));
I other= new I() {};
assertTrue(test(other, "ordering", null, "I"));
+ // second pass to check if cache is populated correctly
+ assertTrue(test(b, "ordering", null, "A"));
+ assertTrue(test(other, "ordering", null, "I"));
}
public void testChaining() throws Exception {
assertTrue(test(a, "chaining", null, "A2"));
+ // second pass to check if cache is populated correctly
+ assertTrue(test(a, "chaining", null, "A2"));
}
// This test is questionable. It depends on if core runtime can
// guaratee any ordering in the plug-in registry.
public void testChainOrdering() throws Exception {
assertTrue(test(a, "chainOrdering", null, "A"));
+ // second pass to check if cache is populated correctly
+ assertTrue(test(a, "chainOrdering", null, "A"));
}
public void testWrongNameSpace() throws Exception {
@@ -92,15 +110,13 @@
}
private boolean test(Object receiver, String property, Object[] args, Object expectedValue) throws CoreException {
- TypeExtensionManager manager= new TypeExtensionManager("propertyTesters");
- Property p= manager.getProperty(receiver, "org.eclipse.core.internal.expressions.tests", property);
+ Property p= fgManager.getProperty(receiver, "org.eclipse.core.internal.expressions.tests", property);
assertTrue(p.isLoaded());
return p.test(receiver, args, expectedValue);
}
private boolean test(String namespace, Object receiver, String property, Object[] args, Object expectedValue) throws CoreException {
- TypeExtensionManager manager= new TypeExtensionManager("propertyTesters");
- Property p= manager.getProperty(receiver, namespace, property);
+ Property p= fgManager.getProperty(receiver, namespace, property);
assertTrue(p.isLoaded());
return p.test(receiver, args, expectedValue);
}