Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Delaigue2016-04-01 14:13:48 +0000
committerPierre-Charles David2016-04-07 12:42:48 +0000
commit9c37bdb8f6a2ae6af51467e7b2749c6b77aca4b9 (patch)
treef8ba6dafcd2bc43245eb82e97133ee3fcec3f024
parentbafe5404124ad7e62de465e9a0b91a46d362344d (diff)
downloadorg.eclipse.sirius-9c37bdb8f6a2ae6af51467e7b2749c6b77aca4b9.tar.gz
org.eclipse.sirius-9c37bdb8f6a2ae6af51467e7b2749c6b77aca4b9.tar.xz
org.eclipse.sirius-9c37bdb8f6a2ae6af51467e7b2749c6b77aca4b9.zip
[490983] Improve perf when many roots in resource
Only check the first root to analyze a Resource which is not an instance AirdResource could still be a representation/session resource. Also fix potential IllegalStateExceptions. Bug: 490983 Cherry-picked-from: 490908 Change-Id: I50bb181ea644b8184440188fe09fd1e99b9bfaba Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr> Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr> (cherry picked from commit 94e9f3293ad6893b8cd489fcb4ef386356e2ba7c)
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java34
1 files changed, 19 insertions, 15 deletions
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java
index 7ba0eb1220..44202323a8 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java
@@ -94,21 +94,13 @@ public class ResourceQuery {
*/
public boolean isRepresentationsResource() {
boolean isRepresentationsResource = false;
- try {
- isRepresentationsResource = resource.getURI() != null;
- } catch (IllegalStateException e) {
- // Silent catch: if an issue occurred while getting this Resource's
- // URI, then it will not be considered as a representation resource
- }
- isRepresentationsResource = isRepresentationsResource && new FileQuery(resource.getURI().fileExtension()).isSessionResourceFile();
+ URI uri = getUri();
+ isRepresentationsResource = uri != null && new FileQuery(uri.fileExtension()).isSessionResourceFile();
isRepresentationsResource = isRepresentationsResource || resource instanceof AirdResource;
if (!isRepresentationsResource && !resource.getContents().isEmpty()) {
- for (EObject contentEObject : resource.getContents()) {
- if (contentEObject instanceof DAnalysis) {
- isRepresentationsResource = true;
- break;
- }
- }
+ // Bug #490908: only check the 1st root since Sirius always puts
+ // DAnalysis as 1st root of the representation resources.
+ isRepresentationsResource = resource.getContents().get(0) instanceof DAnalysis;
}
return isRepresentationsResource;
}
@@ -120,9 +112,21 @@ public class ResourceQuery {
* @return true if it is a modeler resource
*/
public boolean isModelerResource() {
- if (resource.getURI() != null) {
- return new FileQuery(resource.getURI().fileExtension()).isVSMFile();
+ URI uri = getUri();
+ if (uri != null) {
+ return new FileQuery(uri.fileExtension()).isVSMFile();
}
return false;
}
+
+ private URI getUri() {
+ URI uri = null;
+ try {
+ uri = resource.getURI();
+ } catch (IllegalStateException e) {
+ // Silent catch: if an issue occurred while getting this Resource's
+ // URI, then it will not be considered as a representation resource
+ }
+ return uri;
+ }
}

Back to the top