Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/java/org.eclipse.papyrus.java.reverse/src/javagen/umlparser/ClassifierCatalog.java')
-rw-r--r--extraplugins/java/org.eclipse.papyrus.java.reverse/src/javagen/umlparser/ClassifierCatalog.java142
1 files changed, 77 insertions, 65 deletions
diff --git a/extraplugins/java/org.eclipse.papyrus.java.reverse/src/javagen/umlparser/ClassifierCatalog.java b/extraplugins/java/org.eclipse.papyrus.java.reverse/src/javagen/umlparser/ClassifierCatalog.java
index c5c9d74763a..74202217308 100644
--- a/extraplugins/java/org.eclipse.papyrus.java.reverse/src/javagen/umlparser/ClassifierCatalog.java
+++ b/extraplugins/java/org.eclipse.papyrus.java.reverse/src/javagen/umlparser/ClassifierCatalog.java
@@ -1,5 +1,5 @@
/**
- *
+ *
*/
package javagen.umlparser;
@@ -17,9 +17,9 @@ import org.eclipse.uml2.uml.Package;
* Instance of this class allows to lookup for a Classifier.
* Lookup is done in the provided paths.
* Classifier or Package are not created. An error is thrown when not found.
- *
+ *
* @author dumoulin
- *
+ *
* @TODO rename to ClasspathCatalog
*/
public class ClassifierCatalog {
@@ -51,12 +51,14 @@ public class ClassifierCatalog {
/**
* Constructor.
* Not used anymore
- * @param model The Resource containing the packages
+ *
+ * @param model
+ * The Resource containing the packages
*/
public ClassifierCatalog(Resource model, List<String> packageNames) {
this.model = model;
- for(String name : packageNames) {
- if("/".equals(name)) {
+ for (String name : packageNames) {
+ if ("/".equals(name)) {
paths.add(new ResourceSearchPackage());
} else {
List<String> qualifiedName = dirToQualifiedName(name);
@@ -70,17 +72,18 @@ public class ClassifierCatalog {
/**
* Constructor.
* search paths are relative to the specified package.
- *
- * @param modelRootPackage The model Package used as root.
+ *
+ * @param modelRootPackage
+ * The model Package used as root.
*/
public ClassifierCatalog(Package modelRootPackage, List<String> packageNames) {
this.modelRootPackage = modelRootPackage;
- for(String name : packageNames) {
- if("/".equals(name)) {
+ for (String name : packageNames) {
+ if ("/".equals(name)) {
paths.add(new ResourceSearchPackage());
} else {
List<String> qualifiedName = dirToQualifiedName(name);
- if( name.contains(WILDCARD)) {
+ if (name.contains(WILDCARD)) {
// Use search path with wildcard
paths.add(new RelativeSearchPackageWithWildcard(qualifiedName));
}
@@ -88,8 +91,8 @@ public class ClassifierCatalog {
// Get corresponding package if any
paths.add(new RelativeSearchPackage(qualifiedName));
}
-
-
+
+
}
}
@@ -97,7 +100,7 @@ public class ClassifierCatalog {
/**
* @param currentCompilationUnitPackage
- * the currentCompilationUnitPackage to set
+ * the currentCompilationUnitPackage to set
*/
public void setCurrentCompilationUnitPackage(Package currentCompilationUnitPackage) {
this.currentCompilationUnitPackage = currentCompilationUnitPackage;
@@ -106,7 +109,7 @@ public class ClassifierCatalog {
/**
* Get the qualified name from a directory like name.
* Name is splitted arround '/'
- *
+ *
* @param name
* @return
*/
@@ -118,7 +121,7 @@ public class ClassifierCatalog {
/**
* Get the classifier by its qname.
- *
+ *
* @param qualifiedName
* @return
*/
@@ -129,46 +132,48 @@ public class ClassifierCatalog {
/**
* Get the classifier by its qualified name.
- *
+ *
* @param qualifiedName
* @return
*/
public Classifier getClassifier(List<String> qualifiedName) {
return lookupNamedElement(qualifiedName, null);
- // for( Package path : paths)
- // {
- // NamedElement res = getNamedElement(path, qualifiedName);
- // if(res != null )
- // return (Classifier)res;
- // }
- //
- // return null;
+ // for( Package path : paths)
+ // {
+ // NamedElement res = getNamedElement(path, qualifiedName);
+ // if(res != null )
+ // return (Classifier)res;
+ // }
+ //
+ // return null;
}
/**
* Look for the specified element in each of the path of the model.
* Return the first corresponding element found in paths.
- *
+ *
* @param qualifiedName
- * Expected name.
+ * Expected name.
* @param type
- * Expected type or null.
+ * Expected type or null.
* @return
*/
private Classifier lookupNamedElement(List<String> qualifiedName, EClass type) {
// search on current CU
- if(currentCompilationUnitPackage != null) {
+ if (currentCompilationUnitPackage != null) {
Classifier res = UmlUtils.lookupClassifier(currentCompilationUnitPackage, qualifiedName, type);
- if(res != null)
+ if (res != null) {
return res;
+ }
}
// loop on searchpaths
- for(SearchPackage path : paths) {
+ for (SearchPackage path : paths) {
Classifier res = path.getUmlClassifier(qualifiedName, type);
- if(res != null)
+ if (res != null) {
return res;
+ }
}
return null;
@@ -177,9 +182,9 @@ public class ClassifierCatalog {
/**
* Class corresponding to one searchpath.
- *
+ *
* @author dumoulin
- *
+ *
*/
abstract private class SearchPackage {
@@ -206,9 +211,9 @@ public class ClassifierCatalog {
/**
* This class allows to search for uml element in specified packages relative to the Resource.
- *
+ *
* @author dumoulin
- *
+ *
*/
private class ResourceRelativeSearchPackage extends SearchPackage {
@@ -218,14 +223,15 @@ public class ClassifierCatalog {
/**
* Get the uml package corresponding to the path.
- *
+ *
* @return
*/
private Package getPathPackage() {
-
+
// Check if in cache
- if(umlPackage != null)
+ if (umlPackage != null) {
return umlPackage;
+ }
// No, Try to find package using the resource
umlPackage = UmlUtils.lookupPackage(model, packageQualifiedName);
@@ -238,8 +244,9 @@ public class ClassifierCatalog {
@Override
public Classifier getUmlClassifier(List<String> qualifiedName, EClass expectedType) {
Package p = getPathPackage();
- if(p == null)
+ if (p == null) {
return null;
+ }
return UmlUtils.lookupClassifier(p, qualifiedName, expectedType);
}
@@ -247,9 +254,9 @@ public class ClassifierCatalog {
/**
* This class allows to search for uml element in packages relative to the modelRootPackage.
- *
+ *
* @author dumoulin
- *
+ *
*/
private class RelativeSearchPackage extends SearchPackage {
@@ -260,13 +267,14 @@ public class ClassifierCatalog {
/**
* Get the uml package corresponding to the path.
* Search from the modelRootPackage.
- *
+ *
* @return
*/
private Package getPathPackage() {
// Check if in cache
- if(umlPackage != null)
+ if (umlPackage != null) {
return umlPackage;
+ }
// No, Try to find package using the root package
umlPackage = UmlUtils.lookupPackage(modelRootPackage, packageQualifiedName);
@@ -279,8 +287,9 @@ public class ClassifierCatalog {
@Override
public Classifier getUmlClassifier(List<String> qualifiedName, EClass expectedType) {
Package p = getPathPackage();
- if(p == null)
+ if (p == null) {
return null;
+ }
return UmlUtils.lookupClassifier(p, qualifiedName, expectedType);
}
@@ -289,17 +298,18 @@ public class ClassifierCatalog {
/**
* This class allows to search for uml element in packages relative to the modelRootPackage.
- *
+ *
* @author dumoulin
- *
+ *
*/
private class RelativeSearchPackageWithWildcard extends SearchPackage {
/**
- *
+ *
* Constructor.
*
- * @param searchpath Search path, with a wildcard.
+ * @param searchpath
+ * Search path, with a wildcard.
*/
public RelativeSearchPackageWithWildcard(List<String> searchpath) {
super(searchpath);
@@ -308,24 +318,25 @@ public class ClassifierCatalog {
/**
* Lookup the uml package corresponding to the path with WILDCARD.
* Search from the modelRootPackage.
- *
+ *
* @return
*/
private List<Package> lookupExistingPackages() {
-
-
+
+
// Lookup the package containing the wildcard, and put it in cache
- if(umlPackage == null) {
+ if (umlPackage == null) {
umlPackage = UmlUtils.lookupPackageBeforeWildcard(modelRootPackage, packageQualifiedName);
}
- if(umlPackage == null)
+ if (umlPackage == null) {
return Collections.emptyList();
-
+ }
+
// No, Try to find package using the root package
// Look for existing packages at the place of the wildcard.
List<Package> existingPackages = umlPackage.getNestedPackages();
-
+
return existingPackages;
}
@@ -334,20 +345,21 @@ public class ClassifierCatalog {
*/
@Override
public Classifier getUmlClassifier(List<String> qualifiedName, EClass expectedType) {
-
+
// Iterate on possible searchpaths
- int wildcardIndex = packageQualifiedName.indexOf(WILDCARD);
+ int wildcardIndex = packageQualifiedName.indexOf(WILDCARD);
// Get existing packages for the path, untill the wildcard
List<Package> existingPackages = lookupExistingPackages();
-
+
// Get the remaining path from ]index, size]
- List<String> remainingPath = qualifiedName.subList(wildcardIndex+1, qualifiedName.size());
+ List<String> remainingPath = qualifiedName.subList(wildcardIndex + 1, qualifiedName.size());
// Now do searching from the existing packages
- for(Package nestedPackage : existingPackages) {
-
+ for (Package nestedPackage : existingPackages) {
+
Classifier res = UmlUtils.lookupClassifier(nestedPackage, qualifiedName, expectedType);
- if(res != null)
+ if (res != null) {
return res;
+ }
}
// Not found
@@ -358,9 +370,9 @@ public class ClassifierCatalog {
/**
* This class allows to search for uml element in the resource.
- *
+ *
* @author dumoulin
- *
+ *
*/
private class ResourceSearchPackage extends SearchPackage {

Back to the top