Skip to content
Snippets Groups Projects
Commit 1a3a744c authored by Dongyue Mou's avatar Dongyue Mou
Browse files

moved some util methods to kernel and base

replaced the icon of CA
improved constraint checker by allowing multi results in one apply
added a base class for contraint violation
added helper operator in the mira model
overall code clean up in mira
refs 301
parent e16f660d
No related branches found
No related tags found
No related merge requests found
Showing
with 152 additions and 9 deletions
......@@ -24,6 +24,7 @@ import java.util.List;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IHiddenSpecification;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.element.IHierarchicElementContainer;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
/**
......@@ -57,4 +58,18 @@ public class ModelElementUtils {
parent.getConnectionsList().remove(child);
}
/**
* Return the index of the given {@link IHierarchicElement} in its parent
* {@link IHierarchicElementContainer}
*/
public static int getIndex(IHierarchicElement e) {
IHierarchicElementContainer container = e.getContainer();
if (container != null) {
return container.getContainedElementsList().indexOf(e);
}
return -1;
}
}
......@@ -29,6 +29,7 @@ import org.eclipse.jface.resource.ImageDescriptor;
* @version $Rev$
* @ConQAT.Rating RED Hash: 2BA72A5FAFFBBF746808612946F56A18
*/
// TODO @review Moudy: use generic type for target field?
public abstract class EObjectActionBase extends Action {
/** Stores the target {@link EObject}. */
......
......@@ -17,6 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.extension;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation;
import org.fortiss.tooling.kernel.service.IConstraintCheckerService;
......@@ -47,5 +49,5 @@ public interface IConstraintChecker<C extends EObject> extends IEObjectAware<C>
boolean isApplicable(C modelElement);
/** Applies the constraint checker to the given model element. */
IConstraintViolation<? extends EObject> apply(C modelElement);
List<? extends IConstraintViolation<? extends EObject>> apply(C modelElement);
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.extension.base;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.IConstraintChecker;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation;
/**
* Base implementation for {@link IConstraintChecker}. It checks the model
* element against null and returns an unmodifiable empty list.
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class ConstraintCheckerBase<T extends EObject> implements
IConstraintChecker<T> {
/** {@inheritDoc} */
@Override
public boolean isApplicable(T modelElement) {
return modelElement != null;
}
/** {@inheritDoc} */
@Override
public List<? extends IConstraintViolation<? extends EObject>> apply(
T modelElement) {
return Collections.emptyList();
}
}
......@@ -37,9 +37,18 @@ public abstract class ConstraintViolationBase<T extends EObject> implements
/** Stores the model element. */
private final T source;
/** Stores the explanation */
private final String explanation;
/** Stors the severity */
private final ESeverity severity;
/** Constructor. */
public ConstraintViolationBase(T source) {
public ConstraintViolationBase(T source, ESeverity severity,
String explanation) {
this.source = source;
this.explanation = explanation;
this.severity = severity;
}
/** {@inheritDoc} */
......@@ -48,6 +57,18 @@ public abstract class ConstraintViolationBase<T extends EObject> implements
return source;
}
/** {@inheritDoc} */
@Override
public String getExplanation() {
return explanation;
}
/** {@inheritDoc} */
@Override
public ESeverity getSeverity() {
return severity;
}
/** {@inheritDoc} */
@Override
public IQuickFixHandler getQuickFixHandler() {
......
......@@ -88,10 +88,10 @@ public class ConstraintCheckerService extends
}
for (IConstraintChecker<EObject> checker : handlers) {
if (checker.isApplicable(modelElement)) {
IConstraintViolation<? extends EObject> violation = checker
List<? extends IConstraintViolation<? extends EObject>> violation = checker
.apply(modelElement);
if (violation != null) {
violationList.add(violation);
violationList.addAll(violation);
}
}
}
......
......@@ -20,7 +20,6 @@ package org.fortiss.tooling.kernel.utils;
import java.util.Iterator;
import java.util.StringTokenizer;
import org.conqat.lib.commons.reflect.ReflectionUtils;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.model.IIdLabeled;
import org.fortiss.tooling.kernel.model.IIdLabeledReference;
......@@ -36,6 +35,8 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
* @version $Rev$
* @ConQAT.Rating RED Hash: 0785670F62456B6486FFF0E0EA9B2E5A
*/
// @review Moudy: there are two ModelElementUtils, this and one in base-project.
// Should they be merged together or get a different name?
public final class ModelElementUtils {
/**
......@@ -52,12 +53,13 @@ public final class ModelElementUtils {
*/
public static <T extends IProjectRootElement> T getRootElement(
EObject element, Class<T> clazz) {
return ReflectionUtils.pickInstanceOf(clazz,
return EcoreUtils.pickFirstInstanceOf(clazz,
IPersistencyService.INSTANCE.getTopLevelElementFor(element)
.getRootModelElement().eContents());
}
/**
*
* Returns the model element with the given qualified name or
* <code>null</code> if no such element exists. The search is started from
* the given element's top-level parent. A qualified name is a /-separated
......@@ -70,6 +72,8 @@ public final class ModelElementUtils {
* a model element contained in the model to be searched.
* @return the element identified by the given qualified name
*/
// TODO @review Moudy: this method can not handle names contain /-token.
// And it seems never be used in our projects
public static EObject findElementByName(String qualifiedName,
EObject element) {
StringTokenizer tizer = new StringTokenizer(qualifiedName, "/");
......@@ -79,9 +83,9 @@ public final class ModelElementUtils {
while (found && tizer.hasMoreElements()) {
String name = tizer.nextToken();
found = false;
for (EObject child : current.eContents()) {
if (child instanceof INamedElement
&& name.equals(((INamedElement) child).getName())) {
for (INamedElement child : EcoreUtils.pickInstanceOf(
INamedElement.class, current.eContents())) {
if (name.equals(child.getName())) {
current = child;
found = true;
break;
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.utils;
/**
* Utility class for eclipse relevant tasks
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public final class ResourceUtils {
/**
* Generate the platform URI based on the given plugin ID and an absolute
* path.
*
* @param pluginId
* The plugin ID
* @param absPath
* The absolute path in the plugin
* @return a resource URI
*/
public static String getResourceURI(String pluginId, String absPath) {
if (pluginId == null)
throw new NullPointerException("The plugin ID must not be null!");
if (absPath == null)
throw new NullPointerException("The path must not be null!");
if (!absPath.startsWith("/"))
throw new IllegalArgumentException(
"The path is not a absolute path.");
return "platform:/plugin/" + pluginId + absPath;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment