Java Code Examples for org.eclipse.emf.ecore.util.EcoreUtil#equals()

The following examples show how to use org.eclipse.emf.ecore.util.EcoreUtil#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Returns the {@link Diagram} that contains a given semantic element.
 */
public static Diagram getDiagramContaining(EObject element) {
	Assert.isNotNull(element);
	Resource eResource = element.eResource();
	Collection<Diagram> objects = EcoreUtil.getObjectsByType(eResource.getContents(),
			NotationPackage.Literals.DIAGRAM);
	for (Diagram diagram : objects) {
		TreeIterator<EObject> eAllContents = diagram.eAllContents();
		while (eAllContents.hasNext()) {
			EObject next = eAllContents.next();
			if (next instanceof View) {
				if (EcoreUtil.equals(((View) next).getElement(), element)) {
					return ((View) next).getDiagram();
				}
			}
		}
	}
	return null;
}
 
Example 2
@Override
protected IStatus performBatchValidation(final IValidationContext ctx) {
    final EObject eObj = ctx.getTarget();
    if (eObj instanceof Pool) {
        for (final Element el : ((Container) eObj.eContainer()).getElements()) {
            if (!el.equals(eObj) && el.getName().equals(((Element) eObj).getName())
                    && ((AbstractProcess) el).getVersion().equals(((AbstractProcess) eObj).getVersion())) {
                return ctx.createFailureStatus(new Object[] { Messages.Validation_Element_SameName + ": " + el.getName() });
            }
        }

        final Pool p = (Pool) eObj;
        final DiagramRepositoryStore diagramStore = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
        final List<AbstractProcess> allProcesses = diagramStore.getAllProcesses();
        for (final AbstractProcess other_p : allProcesses) {
            if (!EcoreUtil.equals(p, other_p)
                    && !sameEObjectId(p, other_p)
                    && p.getName().equals(other_p.getName())
                    && p.getVersion().equals(other_p.getVersion())) {
                return ctx.createFailureStatus(new Object[] { Messages.bind(Messages.Validation_Duplicate_Process, p.getName(), p.getVersion()) });
            }
        }
    }

    return ctx.createSuccessStatus();
}
 
Example 3
private Expression getLastFoldableAction(
		List<List<Expression>> allActions, int indexFromBack) {
	Expression actionToCheck = null;
	for (List<Expression> actionList : allActions) {
		if (actionList.size() - 1 - indexFromBack < 0) {
			return null;
		}
		Expression lastAction = actionList.get(actionList.size() - 1
				- indexFromBack);
		if (actionToCheck == null) {
			actionToCheck = lastAction;
		} else if (!EcoreUtil.equals(actionToCheck, lastAction)) {
			return null;
		}
	}
	return actionToCheck;
}
 
Example 4
private void handleHotModelReplacement() {
	// first implementation: If the underlying model does not change
	// semantically, no notification is required...

	List<IDebugTarget> targets = getAffectedTargets();
	List<IDebugTarget> modelReplacementFailedTargets = new ArrayList<IDebugTarget>();
	for (IDebugTarget sctDebugTarget : targets) {
		// Reload the Statechart form the changes resource
		Statechart newStatechart = ResourceUtil.loadStatechart(((SCTDebugElement) sctDebugTarget)
				.getResourceString());
		if (!EcoreUtil.equals(newStatechart, (EObject) sctDebugTarget.getAdapter(EObject.class))) {
			// The model semantically changed, we have to create a
			// notificiation for that....
			modelReplacementFailedTargets.add(sctDebugTarget);
		}
	}

	if (modelReplacementFailedTargets.size() > 0) {
		notifyHotModelReplacementFailed(targets);
	}

}
 
Example 5
protected boolean shouldRender(IRenderingSession<Element> context, Element source, Element destination) {
    boolean isModelLibrary = MDDUtil.getRootPackage(destination.getNearestPackage()).isModelLibrary();
    boolean showModelLibraries = context.getSettings().getBoolean(SHOW_ELEMENTS_IN_LIBRARIES);
    if (isModelLibrary && !showModelLibraries)
        return false;

    ShowCrossPackageElementOptions crossPackageElementOption = context.getSettings().getSelection(
            ShowCrossPackageElementOptions.class);
    switch (crossPackageElementOption) {
    case Never:
        return EcoreUtil.equals(source.getNearestPackage(), destination.getNearestPackage());
    case Immediate:
        return EcoreUtil.isAncestor(context.getRoot(), source);
    case Always:
        return true;
    case Local:
        return ElementUtils.sameRepository(context.getRoot(), destination);
    }
    // should never run
    return false;
}
 
Example 6
public static boolean crossReferenceExistsWithDifferentTerminal(CrossReference cr) {
	List<CrossReference> crossRefs = getCrossReferencesWithSameEReference(cr);
	if (crossRefs.isEmpty())
		return false;
	for (CrossReference c : crossRefs)
		if (!EcoreUtil.equals(cr.getTerminal(), c.getTerminal()))
			return true;
	return false;
}
 
Example 7
private Predicate<ScriptContainer<?>> inContractContainer(final ContractContainer contractContainer) {
    return new Predicate<ScriptContainer<?>>() {

        @Override
        public boolean apply(ScriptContainer<?> sc) {
            return EcoreUtil.equals(ModelHelper.getFirstContainerOfType(sc.getModelElement(), ContractContainer.class),
                    contractContainer);
        }
    };
}
 
Example 8
private Diagram getDiagramForSemanticElement(EObject state) {
	Collection<Diagram> diagrams = EcoreUtil2.getObjectsByType(state.eResource().getContents(),
			NotationPackage.Literals.DIAGRAM);
	for (Diagram diagram : diagrams) {
		if (EcoreUtil.equals(diagram.getElement(), state)) {
			return diagram;
		}
	}
	return null;
}
 
Example 9
private Predicate<ContractInputRefactorPair> matches(final Expression expression) {
    return new Predicate<ContractInputRefactorPair>() {

        @Override
        public boolean apply(final ContractInputRefactorPair refactorPair) {
            return refactorPair.getOldValueName().equals(expression.getName())
                    && EcoreUtil.equals(ModelHelper.getFirstContainerOfType(expression, ContractContainer.class),
                            ModelHelper.getFirstContainerOfType(refactorPair.getOldValue(), ContractContainer.class));
        }
    };
}
 
Example 10
public static EObject getResolvedDependency(final EObject context, final Expression_ProcessRef ref) {
    EObject dep = resolveProxy(context, ref.getValue());
    final List<EObject> orignalDep = ModelHelper.getAllItemsOfType( ModelHelper.getMainProcess(context), dep.eClass());
    for(final EObject d : orignalDep){
        if(EcoreUtil.equals(dep, d)){
            dep = d;
            break;
        }
    }
    return dep;
}
 
Example 11
private boolean ensureNameAvailable(String name, Node node, EClass... eClasses) {
    Namespace namespace = namespaceTracker.currentNamespace(null);
    if (name == null || namespace == null)
        return true;
    for (EClass expected : eClasses) {
        final NamedElement found = namespace.getOwnedMember(name, false, expected);
        if (found != null && EcoreUtil.equals(found.getNamespace(), namespace)) {
            problemBuilder.addProblem(new DuplicateSymbol(name, found.eClass()), node);
            return false;
        }
    }
    return true;
}
 
Example 12
/**
 * @param elementToDisplay
 * @param referencedElement
 * @return
 */
public static boolean isSameElement(final EObject elementToDisplay, final EObject referencedElement) {
    if (elementToDisplay.eContainer() != null) {
        return ((Element) referencedElement).getName().equals(((Element) elementToDisplay).getName())
                && isSameContainer(referencedElement, elementToDisplay);
    } else {
        return EcoreUtil.equals(elementToDisplay, referencedElement);
    }
}
 
Example 13
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}
 
Example 14
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}
 
Example 15
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}
 
Example 16
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}
 
Example 17
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}
 
Example 18
@FunctionMethod(EQUALS)
public Boolean equals(EObject e1, EObject e2) {
	return EcoreUtil.equals(e1, e2);
}
 
Example 19
@FunctionMethod(NOT_EQUALS)
public Boolean notEquals(EObject e1, EObject e2) {
	return !EcoreUtil.equals(e1, e2);
}
 
Example 20
/**
 * @param sourceName
 * @param targetName
 */
public BotGefProcessDiagramEditor selectFlowBetween(final String sourceName, final String targetName) {
    final SWTBotGefEditPart source = gmfEditor.getEditPart(sourceName).parent();
    final SWTBotGefEditPart target = gmfEditor.getEditPart(targetName).parent();
    for (final SWTBotGefConnectionEditPart outFlow : source.sourceConnections()) {
        for (final SWTBotGefConnectionEditPart inFlow : target.targetConnections()) {
            final ConnectionEditPart inPart = inFlow.part();
            final ConnectionEditPart outPart = outFlow.part();
            final RunnableWithResult<Boolean> runnableWithResult = new RunnableWithResult<Boolean>() {

                Boolean res = false;

                @Override
                public void run() {
                    res = EcoreUtil.equals((EObject) inPart.getModel(), (EObject) outPart.getModel());
                }

                @Override
                public Boolean getResult() {
                    return res;
                }

                @Override
                public void setStatus(final IStatus status) {
                }

                @Override
                public IStatus getStatus() {
                    return Status.OK_STATUS;
                }
            };
            Display.getDefault().syncExec(runnableWithResult);
            if (runnableWithResult.getResult()) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        inFlow.part().getViewer().deselectAll();
                        inFlow.part().setFocus(true);
                        inFlow.part().getViewer().setSelection(new StructuredSelection(inFlow.part()));

                    }
                });
                return this;
            }
        }
    }
    throw new IllegalStateException("No Flow found between " + sourceName + " and " + targetName);
}