Commit 03682a5b authored by Marco Konersmann's avatar Marco Konersmann

resolveTranslationModelElement was inefficient

parent e34eac58
......@@ -47,7 +47,8 @@ public class IDRegistry {
}
/**
* Registers an implementation model element in the registry and returns its new id.
* Registers an implementation model element in the registry and returns its new
* id.
*/
public String registerImplementationModelElement(IJavaElement codeElement, EObject implementationModelElement) {
final String codePath = codeElement != null ? codeElement.getHandleIdentifier() : null;
......@@ -59,8 +60,7 @@ public class IDRegistry {
}
/**
* Registers a translation model element in the registry and returns its
* new id.
* Registers a translation model element in the registry and returns its new id.
*/
public String registerTranslationModelElement(EObject translationModelElement) {
final String translationModelPath = getPath(translationModelElement);
......@@ -72,8 +72,8 @@ public class IDRegistry {
/**
* Adds a translation model language element to the registry for an existing
* implementation model element. If the path to the implementation model element does not
* exist in the registry, nothing is done.
* implementation model element. If the path to the implementation model element
* does not exist in the registry, nothing is done.
*/
public void addTranslationModelElement(EObject translationModelElement, EObject implementationModelElement) {
final String id = getIDFromImplementationModelElement(implementationModelElement);
......@@ -82,8 +82,8 @@ public class IDRegistry {
}
/**
* Adds a code element for a given implementation model element. If the model element is not
* known in the registry yet, it is created.
* Adds a code element for a given implementation model element. If the model
* element is not known in the registry yet, it is created.
*/
public void addCodeElement(EObject implementationModelElement, IJavaElement codeElement) {
if (codeElement == null)
......@@ -113,16 +113,17 @@ public class IDRegistry {
final String ilPath = translationModelElement == null ? null : getPath(translationModelElement);
if (ilPath == null && entries[2] != null
|| ilPath != null && (entries[2] == null || !ilPath.equals(entries[2])))
updateEntry(id, entries[0], entries[1], ilPath);
updateEntry(id, entries[0], entries[1], ilPath);
}
public void updateImplementationModelElement(String id, EObject implementationModelElement) {
String[] entries = id2paths.get(id);
if (entries == null)
throw new IllegalArgumentException(String.format("No registry entry for id %s exists.", id));
final String implementationModelPath = implementationModelElement == null ? null : getPath(implementationModelElement);
if (implementationModelPath == null && entries[1] != null
|| implementationModelPath != null && (entries[1] == null || !implementationModelPath.equals(entries[1])))
final String implementationModelPath = implementationModelElement == null ? null
: getPath(implementationModelElement);
if (implementationModelPath == null && entries[1] != null || implementationModelPath != null
&& (entries[1] == null || !implementationModelPath.equals(entries[1])))
updateEntry(id, entries[0], implementationModelPath, entries[2]);
}
......@@ -161,7 +162,8 @@ public class IDRegistry {
return null;
}
public EObject resolveImplementationModelElement(EObject translationModelElement, EObject implementationModelRootElement) {
public EObject resolveImplementationModelElement(EObject translationModelElement,
EObject implementationModelRootElement) {
final String translationModelPath = getPath(translationModelElement);
for (final Entry<String, String[]> e : id2paths.entrySet()) {
......@@ -235,7 +237,8 @@ public class IDRegistry {
while ((line = r.readLine()) != null) {
String[] cols = line.split("\\$");
// Line might end with two $ when no implementation model element and no translation model element is given.
// Line might end with two $ when no implementation model element and no
// translation model element is given.
if (cols.length < 3)
cols = new String[] { cols[0], cols[1], null, null };
......@@ -342,14 +345,11 @@ public class IDRegistry {
if (entry == null || entry[2] == null) {
return null;
} else {
for (final EObject root : translationModelRoots) {
final EObject resolvedObject = resolve(root, getPathWithoutRoot(entry[2]));
if (resolvedObject != null)
return resolvedObject;
}
}
final int rootIndex = getRootIndex(entry[2]);
final String path = getPathWithoutRoot(entry[2]);
return null;
return resolve(translationModelRoots.get(rootIndex), path);
}
}
private String getPathWithoutRoot(String entryPath) {
......@@ -360,7 +360,6 @@ public class IDRegistry {
final int secondSlashIndex = entryPath.substring(1).indexOf("/") + 1;
return entryPath.substring(secondSlashIndex);
}
}
private int getRootIndex(String entryPath) {
......@@ -376,13 +375,15 @@ public class IDRegistry {
}
public EObject resolveTranslationModelElement(EObject implementationModelElement, EObject translationModelRootElement) {
public EObject resolveTranslationModelElement(EObject implementationModelElement,
EObject translationModelRootElement) {
final LinkedList<EObject> roots = new LinkedList<>();
roots.add(translationModelRootElement);
return resolveTranslationModelElement(implementationModelElement, roots);
}
public EObject resolveTranslationModelElement(EObject implementationModelElement, List<EObject> translationModelRoots) {
public EObject resolveTranslationModelElement(EObject implementationModelElement,
List<EObject> translationModelRoots) {
final String implementationModelPath = getPath(implementationModelElement);
boolean foundImplementationModelElement = false;
......@@ -409,7 +410,8 @@ public class IDRegistry {
else
throw new IllegalArgumentException(String.format(
"Could not get an translation model element for implementation model element '%s'. The id registry contains an entry with a implementation model element path '%s', but it could not resolve any translation model element path of '%s'.",
implementationModelElement, implementationModelPath, Arrays.toString(translationModelPaths.toArray())));
implementationModelElement, implementationModelPath,
Arrays.toString(translationModelPaths.toArray())));
}
public IJavaElement getCodeElementFromImplementationModelElement(EObject modelElement) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment