[420821] Avoid loading irrelevant plugins
diff --git a/examples/org.eclipse.ocl.examples.xtext.completeocl.ui/src/org/eclipse/ocl/examples/xtext/completeocl/ui/commands/LoadCompleteOCLResourceHandler.java b/examples/org.eclipse.ocl.examples.xtext.completeocl.ui/src/org/eclipse/ocl/examples/xtext/completeocl/ui/commands/LoadCompleteOCLResourceHandler.java
index 2f1d13d..01f270e 100644
--- a/examples/org.eclipse.ocl.examples.xtext.completeocl.ui/src/org/eclipse/ocl/examples/xtext/completeocl/ui/commands/LoadCompleteOCLResourceHandler.java
+++ b/examples/org.eclipse.ocl.examples.xtext.completeocl.ui/src/org/eclipse/ocl/examples/xtext/completeocl/ui/commands/LoadCompleteOCLResourceHandler.java
@@ -189,7 +189,7 @@
Button browseRegisteredOCLFiles = new Button(buttonComposite, SWT.PUSH);
browseRegisteredOCLFiles.setText(CompleteOCLUIMessages.LoadCompleteOCLResource_browseOCLFiles);
prepareBrowseRegisteredOCLFiles(browseRegisteredOCLFiles);
- registeredURIsForResourceSet = CompleteOCLRegistry.getRegisteredResourceURIs(resourceSet);
+ registeredURIsForResourceSet = CompleteOCLRegistry.INSTANCE.getRegisteredResourceURIs(resourceSet);
if (registeredURIsForResourceSet.isEmpty()) {
browseRegisteredOCLFiles.setEnabled(false);
} else {
diff --git a/examples/org.eclipse.ocl.examples.xtext.completeocl/build.properties b/examples/org.eclipse.ocl.examples.xtext.completeocl/build.properties
index ee117ad..e75e1d5 100644
--- a/examples/org.eclipse.ocl.examples.xtext.completeocl/build.properties
+++ b/examples/org.eclipse.ocl.examples.xtext.completeocl/build.properties
@@ -16,6 +16,7 @@
plugin.xml,\
about.html,\
plugin.properties,\
- model/
+ model/,\
+ schema/
src.includes = about.html
additional.bundles = org.eclipse.jdt.annotation
diff --git a/examples/org.eclipse.ocl.examples.xtext.completeocl/schema/complete_ocl_registry.exsd b/examples/org.eclipse.ocl.examples.xtext.completeocl/schema/complete_ocl_registry.exsd
index 9b5aa3b..b7217be 100644
--- a/examples/org.eclipse.ocl.examples.xtext.completeocl/schema/complete_ocl_registry.exsd
+++ b/examples/org.eclipse.ocl.examples.xtext.completeocl/schema/complete_ocl_registry.exsd
@@ -18,7 +18,7 @@
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
- <element ref="completeOCLResource"/>
+ <element ref="document"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
@@ -47,12 +47,20 @@
</complexType>
</element>
- <element name="completeOCLResource">
+ <element name="document">
+ <annotation>
+ <documentation>
+ Declaration of a Complete OCL document
+ </documentation>
+ </annotation>
<complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="for"/>
+ </sequence>
<attribute name="resource" type="string" use="required">
<annotation>
<documentation>
- A completeOCL file.
+ The Complete OCL file.
</documentation>
<appInfo>
<meta.attribute kind="resource"/>
@@ -62,6 +70,23 @@
</complexType>
</element>
+ <element name="for">
+ <annotation>
+ <documentation>
+ Declaration of one of the Namepsace URIs for which the Complete OCL document contrubutes additional OCL rules.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="uri" type="string" use="required">
+ <annotation>
+ <documentation>
+ A Namespace URI for which the OCL dcoument may be used.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>
@@ -79,7 +104,7 @@
This could be used to register the CompleteOCL file "EcoreValidation.ocl" located within a "model" subfolder at the root of the plugin :
<extension point="org.eclipse.ocl.examples.xtext.completeocl.complete_ocl_registry">
- <completeOCLResource resource="model/EcoreValidation.ocl">
+ <completeOCLResource resource="model/EcoreValidation.ocl">
</completeOCLResource>
</documentation>
</annotation>
diff --git a/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/internal/registry/CompleteOCLRegistry.java b/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/internal/registry/CompleteOCLRegistry.java
index 40b965a..a981d09 100644
--- a/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/internal/registry/CompleteOCLRegistry.java
+++ b/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/internal/registry/CompleteOCLRegistry.java
@@ -10,8 +10,9 @@
*/
package org.eclipse.ocl.examples.xtext.completeocl.internal.registry;
-import java.util.Collections;
-import java.util.LinkedHashSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.eclipse.emf.common.util.TreeIterator;
@@ -20,9 +21,7 @@
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.ocl.examples.pivot.utilities.BaseResource;
-import org.eclipse.ocl.examples.xtext.base.basecs.impl.ImportCSImpl;
+import org.eclipse.jdt.annotation.NonNull;
/**
* This registry will be used to hold all complete ocl resources that have been
@@ -30,71 +29,69 @@
*
* @author <a href="mailto:marwa.rostren@obeo.fr">Marwa Rostren</a>
*/
-public class CompleteOCLRegistry {
- private static final Set<URI> REGISTERED_URIS = new LinkedHashSet<URI>();
+public class CompleteOCLRegistry
+{
+ public static final @NonNull CompleteOCLRegistry INSTANCE = new CompleteOCLRegistry();
+
+// private final @NonNull Map<URI, Set<String>> resourceURI2nsURIs = new HashMap<URI, Set<String>>();
+ private /*@Nullable*/ Map<String, Set<URI>> nsURI2resourceURIs = null;
private CompleteOCLRegistry() {
// prevents instantiation
}
- public static void addURI(URI resourceURI) {
- REGISTERED_URIS.add(resourceURI);
- }
-
- public static void removeURI(URI resourceURI) {
- REGISTERED_URIS.remove(resourceURI);
- }
-
- public static void clear() {
- REGISTERED_URIS.clear();
- }
-
- /**
- * Returns all registered URIs for a specific resources in resourceSet
- *
- * @param resourceSet
- * the resourceSet
- * @return all registered URIs for all resources in resourceSet
- */
- public static Set<URI> getRegisteredResourceURIs(ResourceSet resourceSet) {
- Set<URI> concernedRegisteredURIs = new LinkedHashSet<URI>();
-
- for (Resource resource : resourceSet.getResources()) {
- EPackage epack = resource.getContents().get(0).eClass().getEPackage();
- concernedRegisteredURIs.addAll(CompleteOCLRegistry
- .getRegisteredResourceURIs(epack.getNsURI()));
- }
- return Collections.unmodifiableSet(concernedRegisteredURIs);
- }
-
- /**
- * Returns a set of registered URIs for a specific model nsURI
- *
- * @param modelNsURI
- * a specific model nsURI
- * @return A set of registered URIs for a specific model nsURI
- */
- private static Set<URI> getRegisteredResourceURIs(String modelNsURI) {
- Set<URI> modelRegisteredURIs = new LinkedHashSet<URI>();
- ResourceSet resourceSet = new ResourceSetImpl();
-
- for (URI uri: REGISTERED_URIS){
- final BaseResource xtextResource;
- if (uri.isPlatformResource()) {
- xtextResource = (BaseResource) resourceSet.getResource(URI.createPlatformPluginURI(uri.toPlatformString(false), false), true);
- } else {
- xtextResource = (BaseResource) resourceSet.getResource(uri, true);
+ public void addURI(@NonNull URI resourceURI, @NonNull Iterable<String> moreNsURIs) {
+// Set<String> nsURIs = resourceURI2nsURIs.get(resourceURI);
+// if (nsURIs == null) {
+// nsURIs = new HashSet<String>();
+// resourceURI2nsURIs.put(resourceURI, nsURIs);
+// }
+ for (String nsURI : moreNsURIs) {
+ Set<URI> resourceURIs = nsURI2resourceURIs.get(nsURI);
+ if (resourceURIs == null) {
+ resourceURIs = new HashSet<URI>();
+ nsURI2resourceURIs.put(nsURI, resourceURIs);
}
- for (TreeIterator<EObject> iterator = xtextResource.getAllContents(); iterator.hasNext(); ) {
- EObject eObject = iterator.next();
- if (eObject instanceof ImportCSImpl) {
- ImportCSImpl importObject = (ImportCSImpl) eObject;
- if (("'" + modelNsURI + "'").equals(importObject.getPathName().toString())){
- modelRegisteredURIs.add(uri);
- }
+ resourceURIs.add(resourceURI);
+// nsURIs.add(nsURI);
+ }
+ }
+
+ public void clear() {
+// resourceURI2nsURIs.clear();
+ nsURI2resourceURIs.clear();
+ }
+
+ /**
+ * Returns all document URIs that provide content for any EPackege nsURI in resourceSet
+ */
+ public @NonNull Set<URI> getRegisteredResourceURIs(@NonNull ResourceSet resourceSet) {
+ if (nsURI2resourceURIs == null) {
+ nsURI2resourceURIs = new HashMap<String, Set<URI>>();
+ new CompleteOCLRegistryReader().readRegistry();
+ }
+ Set<EPackage> ePackages = new HashSet<EPackage>();
+ for (Resource resource : resourceSet.getResources()) {
+ for (TreeIterator<EObject> tit = resource.getAllContents(); tit.hasNext(); ) {
+ EObject eObject = tit.next();
+ EPackage ePackage = eObject.eClass().getEPackage();
+ ePackages.add(ePackage);
+ }
+ }
+ Set<URI> documentURIs = new HashSet<URI>();
+ for (EPackage ePackage : ePackages) {
+ String nsURI = ePackage.getNsURI();
+ if (nsURI != null) {
+ Set<URI> resourceURIs = nsURI2resourceURIs.get(nsURI);
+ if (resourceURIs != null) {
+ documentURIs.addAll(resourceURIs);
}
}
}
- return Collections.unmodifiableSet(modelRegisteredURIs);
+ return documentURIs;
+ }
+
+ public void removeURI(@NonNull URI resourceURI) {
+// resourceURI2nsURIs.remove(resourceURI);
}
}
diff --git a/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/internal/registry/CompleteOCLRegistryReader.java b/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/internal/registry/CompleteOCLRegistryReader.java
index a0e4a57..2a27c43 100644
--- a/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/internal/registry/CompleteOCLRegistryReader.java
+++ b/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/internal/registry/CompleteOCLRegistryReader.java
@@ -10,22 +10,27 @@
*/
package org.eclipse.ocl.examples.xtext.completeocl.internal.registry;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.plugin.RegistryReader;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.examples.xtext.completeocl.utilities.CompleteOCLPlugin;
/**
- * A plugin extension reader that populates the complete OCL resource registry.
+ * A plugin extension reader that populates the Complete OCL resource registry.
*
* @author <a href="mailto:marwa.rostren@obeo.fr">Marwa Rostren</a>
*/
-public class CompleteOCLRegistryReader
- extends RegistryReader {
- private static final String TAG_RESOURCE = "completeOCLResource";
-
- private static final String ATTRIBUTE_RESOURCE = "resource";
+public class CompleteOCLRegistryReader extends RegistryReader
+{
+ private static final @NonNull String TAG_DOCUMENT = "document";
+ private static final @NonNull String TAG_FOR = "for";
+ private static final @NonNull String ATTRIBUTE_RESOURCE = "resource";
+ private static final @NonNull String ATTRIBUTE_URI = "uri";
public CompleteOCLRegistryReader() {
super(Platform.getExtensionRegistry(), CompleteOCLPlugin.getPlugin()
@@ -35,35 +40,41 @@
@Override
protected boolean readElement(IConfigurationElement element, boolean add) {
- if (!TAG_RESOURCE.equals(element.getName())) {
+ String tagName = element.getName();
+ if (TAG_FOR.equals(tagName)) {
+ return true;
+ }
+ if (!TAG_DOCUMENT.equals(tagName)) {
return false;
}
-
final String filePath = element.getAttribute(ATTRIBUTE_RESOURCE);
- final boolean recognized;
+ boolean recognized = true;
if (filePath == null) {
logMissingAttribute(element, ATTRIBUTE_RESOURCE);
recognized = false;
} else {
- final URI fileURI = makeFileURI(element, filePath);
- if (add) {
- CompleteOCLRegistry.addURI(fileURI);
- } else {
- CompleteOCLRegistry.removeURI(fileURI);
+ Set<String> nsURIs = new HashSet<String>();
+ for (IConfigurationElement childElement : element.getChildren(TAG_FOR)) {
+ final String nsURI = childElement.getAttribute(ATTRIBUTE_URI);
+ if (nsURI == null) {
+ logMissingAttribute(childElement, ATTRIBUTE_URI);
+ recognized = false;
+ }
+ else {
+ nsURIs.add(nsURI);
+ }
}
- recognized = true;
+ URI declaredURI = URI.createURI(filePath);
+ String bundleName = "/" + element.getDeclaringExtension().getContributor().getName() + "/";
+ URI bundleURI = URI.createPlatformPluginURI(bundleName, true);
+ @SuppressWarnings("null")@NonNull URI fileURI = declaredURI.resolve(bundleURI);
+ if (add) {
+ CompleteOCLRegistry.INSTANCE.addURI(fileURI, nsURIs);
+ } else {
+ CompleteOCLRegistry.INSTANCE.removeURI(fileURI);
+ }
}
return recognized;
}
-
- private URI makeFileURI(IConfigurationElement element, String path) {
- URI resourceURI = URI.createURI(path);
- if (resourceURI.isRelative()) {
- resourceURI = URI.createPlatformPluginURI(element
- .getDeclaringExtension().getContributor().getName()
- + '/' + path, true);
- }
- return resourceURI;
- }
}
diff --git a/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/utilities/CompleteOCLPlugin.java b/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/utilities/CompleteOCLPlugin.java
index c23ab16..246a53f 100644
--- a/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/utilities/CompleteOCLPlugin.java
+++ b/examples/org.eclipse.ocl.examples.xtext.completeocl/src/org/eclipse/ocl/examples/xtext/completeocl/utilities/CompleteOCLPlugin.java
@@ -21,8 +21,9 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.util.ResourceLocator;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
-import org.eclipse.ocl.examples.xtext.completeocl.internal.registry.CompleteOCLRegistryReader;
import org.osgi.framework.BundleContext;
/**
@@ -31,17 +32,18 @@
* <!-- end-user-doc -->
* @generated
*/
-public final class CompleteOCLPlugin extends EMFPlugin {
- public static final String PLUGIN_ID = "org.eclipse.ocl.examples.xtext.completeocl";
- public static final String LANGUAGE_ID = "org.eclipse.ocl.examples.xtext.completeocl.CompleteOCL";
- public static final String OCL_RESOURCE_REGISTRY_PID = "complete_ocl_registry";
+public final class CompleteOCLPlugin extends EMFPlugin
+{
+ public static final @NonNull String PLUGIN_ID = "org.eclipse.ocl.examples.xtext.completeocl";
+ public static final @NonNull String LANGUAGE_ID = "org.eclipse.ocl.examples.xtext.completeocl.CompleteOCL";
+ public static final @NonNull String OCL_RESOURCE_REGISTRY_PID = "complete_ocl_registry";
/**
* Keep track of the singleton.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
- public static final CompleteOCLPlugin INSTANCE = new CompleteOCLPlugin();
+ public static final @NonNull CompleteOCLPlugin INSTANCE = new CompleteOCLPlugin();
/**
* Keep track of the singleton.
@@ -49,7 +51,7 @@
* <!-- end-user-doc -->
* @generated
*/
- private static Implementation plugin;
+ private static @Nullable Implementation plugin;
/**
* Create the instance.
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/plugin.xml b/tests/org.eclipse.ocl.examples.xtext.tests/plugin.xml
index 28f93bd..2386a67 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/plugin.xml
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/plugin.xml
@@ -153,5 +153,14 @@
uri="dummy-protocol://dummy-nsuri/ocl/test/Pivot/Company.ecore"
class="codegen.company.CodegencompanyPackage"/>
</extension>
+ <extension
+ point="org.eclipse.ocl.examples.xtext.completeocl.complete_ocl_registry">
+ <document
+ resource="model/ModelWithErrors.ocl">
+ <for
+ uri="http://www.eclipse.org/emf/2002/Ecore">
+ </for>
+ </document>
+ </extension>
</plugin>