blob: c89bf9a941561f02c15f6e4216a21e632352a64d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.treeeditor.properties.util;
import java.util.HashSet;
import java.util.Iterator;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.core.IModelManager;
public class LegacyHelper {
/**
* Returns a modelelement's instances as a ; delimited string.
*
* @param e
* the modelelement whose instances we want
* @return the instances as a ; delimited string
*/
public static String getInstancesAsString(IModelElement e) {
String r = "";
Iterator i = e.getInstances().iterator();
while (i.hasNext()) {
r += ((IModelElement) i.next()).getFullyQualifiedName();
if (i.hasNext())
r += "; ";
}
return r;
}
/**
* Returns a modelelement's subtypes as a ; delimited string.
*
* @param e
* the modelelement whose subtypes we want
* @return the subtypes as a ; delimited string
*/
public static String getSubtypesAsString(IModelElement e) {
String r = "";
Iterator i = e.getSubtypes().iterator();
while (i.hasNext()) {
r += ((IModelElement) i.next()).getFullyQualifiedName();
if (i.hasNext())
r += "; ";
}
return r;
}
/**
* Returns a modelelement's supertypes as a ; delimited string.
*
* @param e
* the modelelement whose supertypes we want
* @return the supertypes as a ; delimited string
*/
public static String getSupertypesAsString(IModelElement e) {
String r = "";
Iterator i = e.getSupertypes().iterator();
while (i.hasNext()) {
r += ((IModelElement) i.next()).getFullyQualifiedName();
if (i.hasNext())
r += "; ";
}
return r;
}
/**
* Returns a modelelement's types as a ; delimited string.
*
* @param e
* the modelelement whose types we want
* @return the types as a ; delimited string
*/
public static String getTypesAsString(IModelElement e) {
String r = "";
Iterator i = e.getTypes().iterator();
while (i.hasNext()) {
r += ((IModelElement) i.next()).getFullyQualifiedName();
if (i.hasNext())
r += "; ";
}
return r;
}
/**
* Convert a String array containing fully qualified names of modelelements
* to a HashSet of corresponding IModelElements.
*
* @param elements
* the string array containing fq names of modelelements
* @param allowEmptyStringMatchOnRoot
* if true, parser will match the root entity on an empty string
* @return the HashSet of ImplVMModelElements
*/
@SuppressWarnings("unchecked")
public static HashSet<IModelElement> convertStringArrayToSetOfElements(String[] elements,
boolean allowEmptyStringMatchOnRoot, IModelManager iManager) {
HashSet resultset = new HashSet<IModelElement>();
int matched = 0; // non-empty string (\"") counter
for (int i = 0; i < elements.length; i++) {
if (allowEmptyStringMatchOnRoot) {
matched++;
// System.out.println("[ViatraEditor]\t"+getName()+"::getElementFromStringArray:
// parsing "+elements[i]);
IModelElement e = iManager.getElementByName(elements[i]);
if (e != null)
resultset.add(e);
} else {
if (elements[i].length() > 0) {
matched++;
// System.out.println("[ViatraEditor]\t"+getName()+"::getElementFromStringArray:
// parsing "+elements[i]);
IModelElement e = iManager.getElementByName(elements[i]);
if (e != null)
resultset.add(e);
}
}
}
if (matched > 0 && resultset.isEmpty())
return null; // if there was something in the array, but no match
// was found, signal an arror by returning null
return resultset;
}
}