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
Source File: AbstractRelationshipRenderer.java From textuml with Eclipse Public License 1.0 | 6 votes |
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 2
Source File: SCTHotModelReplacementManager.java From statecharts with Eclipse Public License 1.0 | 6 votes |
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 3
Source File: DiagramPartitioningUtil.java From statecharts with Eclipse Public License 1.0 | 6 votes |
/** * 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 4
Source File: FoldIncomingActionsRefactoring.java From statecharts with Eclipse Public License 1.0 | 6 votes |
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 5
Source File: UniqueContainerIdConstraint.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@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 6
Source File: ModelHelper.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * @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 7
Source File: StructureGenerator.java From textuml with Eclipse Public License 1.0 | 5 votes |
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 8
Source File: RefactorContractInputOperation.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
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 9
Source File: SubmachineDecorationProvider.java From statecharts with Eclipse Public License 1.0 | 5 votes |
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 10
Source File: ParseTreeConstructorUtil.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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 11
Source File: RefactorContractInputOperation.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
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 12
Source File: ComparisonExpressionUtil.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
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 13
Source File: CoreFunction.java From statecharts with Eclipse Public License 1.0 | 4 votes |
@FunctionMethod(NOT_EQUALS) public Boolean notEquals(EObject e1, EObject e2) { return !EcoreUtil.equals(e1, e2); }
Example 14
Source File: BotGefProcessDiagramEditor.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
/** * @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); }
Example 15
Source File: CoreFunction.java From statecharts with Eclipse Public License 1.0 | 4 votes |
@FunctionMethod(EQUALS) public Boolean equals(EObject e1, EObject e2) { return EcoreUtil.equals(e1, e2); }
Example 16
Source File: AbstractPortableURIsTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
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
Source File: URIsInEcoreFilesXtendTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
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
Source File: AbstractPortableURIsTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
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 19
Source File: AbstractPortableURIsTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
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 20
Source File: AbstractPortableURIsTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
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()); } }