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

The following examples show how to use org.eclipse.emf.ecore.EObject#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: SoliditySemanticHighlighter.java    From solidity-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void provideHighLightForNamedElement(NamedElement namedElement, INode nextNode, String textStyle,
		IHighlightedPositionAcceptor acceptor) {
	acceptor.addPosition(nextNode.getOffset(), nextNode.getLength(), textStyle);
	List<ElementReferenceExpression> references = EcoreUtil2.getAllContentsOfType(namedElement.eContainer(),
			ElementReferenceExpression.class);
	for (ElementReferenceExpression elementReferenceExpression : references) {
		EObject reference = elementReferenceExpression.getReference();
		if (reference.equals(namedElement)) {
			ICompositeNode referencingNode = NodeModelUtils.findActualNodeFor(elementReferenceExpression);
			BidiIterator<INode> bidiIterator = referencingNode.getChildren().iterator();
			while (bidiIterator.hasNext()) {
				INode currentNode = bidiIterator.next();
				if (currentNode.getText().trim().equals(namedElement.getName())) {
					acceptor.addPosition(currentNode.getOffset(), currentNode.getLength(), textStyle);
				}
			}
		}
	}
}
 
Example 2
Source File: IndentationAwareCompletionPrefixProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private PeekingIterator<ILeafNode> createReversedLeafIterator(INode root, INode candidate, LinkedList<ILeafNode> sameGrammarElement) {
	EObject grammarElement = null;
	PeekingIterator<ILeafNode> iterator = Iterators.peekingIterator(Iterators.filter(root.getAsTreeIterable().reverse().iterator(), ILeafNode.class));
	// traverse until we find the current candidate
	while(iterator.hasNext()) {
		ILeafNode next = iterator.next();
		if (candidate.equals(next)) {
			break;
		} else if (next.getTotalLength() == 0) {
			EObject otherGrammarElement = tryGetGrammarElementAsRule(next);
			if (grammarElement == null) {
				grammarElement = otherGrammarElement;
			}
			if (otherGrammarElement.equals(grammarElement)) {
				sameGrammarElement.add(next);
			} else {
				sameGrammarElement.removeLast();
			}
		}
	}
	return iterator;
}
 
Example 3
Source File: DiagramForElementRunnable.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    final TreeIterator<EObject> allContents = resource.getAllContents();
    EObject elementToFind = null;
    final Set<Diagram> diagrams = new HashSet<Diagram>();
    while (allContents.hasNext()) {
        final EObject eObject = allContents.next();
        if (EcoreUtil.equals(eObject, element)) {
            elementToFind = eObject;
        }
        if (eObject instanceof Diagram) {
            diagrams.add((Diagram) eObject);
        }
    }
    if (elementToFind == null) {
        return;
    }
    for (final Diagram diagram : diagrams) {
        final EObject diagramElement = diagram.getElement();
        if (diagramElement != null && diagramElement.equals(elementToFind)) {
            result = diagram;
            break;
        }
    }
}
 
Example 4
Source File: JvmModelAssociator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isPrimaryJvmElement(EObject jvmElement) {
	Set<EObject> sourceElements = getSourceElements(jvmElement);
	if (!sourceElements.isEmpty()) {
		EObject primaryJvmElement = getPrimaryJvmElement(sourceElements.iterator().next());
		return jvmElement.equals(primaryJvmElement);
	}
	return false;
}
 
Example 5
Source File: DefaultQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private CrossReference findCrossReference(EObject context, INode node) {
	if (node == null || (node.hasDirectSemanticElement() && context.equals(node.getSemanticElement())))
		return null;

	EObject grammarElement = node.getGrammarElement();
	if (grammarElement instanceof CrossReference) {
		return (CrossReference) grammarElement;
	} else
		return findCrossReference(context, node.getParent());
}
 
Example 6
Source File: AbstractFragmentProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public EObject getEObject(final Resource resource, final String fragment, final Fallback fallback) {
  try {
    FragmentSegmentIterator iterator = new FragmentSegmentIterator(fragment);
    String segment = iterator.next();
    int reps = iterator.repetitions();

    final int contentsIndex = Integer.parseUnsignedInt(segment);
    EObject container = resource.getContents().get(contentsIndex);

    while (iterator.hasNext() || reps > 1) {
      if (reps > 1) {
        reps--;
      } else {
        segment = iterator.next();
        reps = iterator.repetitions();
      }
      final EObject nextEObject = internalGetEObjectFromSegment(segment, container);
      if (nextEObject == null || nextEObject.equals(container)) {
        return null;
      }
      container = nextEObject;
    }
    return container;
  } catch (NumberFormatException e) {
    return fallback.getEObject(fragment);
  }
}
 
Example 7
Source File: ExtendedFormattingConfigBasedStream.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks if the given node represents a comment.
 *
 * @param node
 *          leaf node, possibly {@code null}
 * @return true if this is a comment, false otherwise
 */
private boolean isCommentNode(final INode node) {
  if (node instanceof ILeafNode && node.getGrammarElement() != null) {
    EObject grammarElement = node.getGrammarElement();
    return grammarElement.equals(formatter.getSLCommentRule()) || grammarElement.equals(formatter.getMLCommentRule());
  }
  return false;
}
 
Example 8
Source File: ActivitySwitchEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasIncomingConnection(){
	final EditPart host = getHost();
	final EObject element = ((IGraphicalEditPart)host).resolveSemanticElement();

	final List<Connection> connections = ModelHelper.getParentProcess(element).getConnections();
	for (final Connection connection : connections){
		final EObject target = connection.getTarget();
		if (target.equals(element)){
			return true;
		}
	}
	return false;
}
 
Example 9
Source File: ActivitySwitchEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasOutgoingConnection(){
	final EditPart host = getHost();
	final EObject element = ((IGraphicalEditPart)host).resolveSemanticElement();
	final List<Connection> connections = ModelHelper.getParentProcess(element).getConnections();
	for (final Connection connection : connections){
		final EObject source = connection.getSource();
        if (element.equals(source)) {
			return true;
		}
	}
	return false;
}
 
Example 10
Source File: AbstractProcessContentProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object[] getChildren(final Object element) {
    if (element instanceof MainProcess) {
        final List<Object> result = new ArrayList<Object>();
        for (final EObject process : ModelHelper.getAllItemsOfType((EObject) element, ProcessPackage.Literals.POOL)) {
            if (!process.equals(element)) {
                result.add(process);
            }
        }
        return result.toArray();
    }
    return null;
}
 
Example 11
Source File: PoolItemSemanticEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
	View view = (View) getHost().getModel();
	CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
	cmd.setTransactionNestingEnabled(false);
	for (Iterator<?> it = view.getTargetEdges().iterator(); it.hasNext();) {
		Edge incomingLink = (Edge) it.next();
		if (ProcessVisualIDRegistry.getVisualID(incomingLink) == TextAnnotationAttachmentEditPart.VISUAL_ID) {
			DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
			cmd.add(new DestroyElementCommand(r));
			cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
			continue;
		}
	}
	EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
	if (annotation == null) {
		// there are indirectly referenced children, need extra commands: false
		addDestroyChildNodesCommand(cmd);
		addDestroyShortcutsCommand(cmd, view);
		// delete host element
		cmd.add(new DestroyElementCommand(req));
	} else {
		cmd.add(new DeleteCommand(getEditingDomain(), view));
	}

	final EObject pool = req.getElementToDestroy();
	if (pool instanceof Pool) {
		for (MessageFlow f : ModelHelper.getMainProcess(pool).getMessageConnections()) {
			if (pool.equals(ModelHelper.getParentProcess(f.getSource()))) {
				cmd.add(new DestroyElementCommand(new DestroyElementRequest(f, false)));
			}
		}
	}

	return getGEFWrapper(cmd.reduce());
}
 
Example 12
Source File: SubProcessEvent2ItemSemanticEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
	View view = (View) getHost().getModel();
	CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
	cmd.setTransactionNestingEnabled(false);
	for (Iterator<?> it = view.getTargetEdges().iterator(); it.hasNext();) {
		Edge incomingLink = (Edge) it.next();
		if (ProcessVisualIDRegistry.getVisualID(incomingLink) == TextAnnotationAttachmentEditPart.VISUAL_ID) {
			DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
			cmd.add(new DestroyElementCommand(r));
			cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
			continue;
		}
	}
	EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
	if (annotation == null) {
		// there are indirectly referenced children, need extra commands: false
		addDestroyChildNodesCommand(cmd);
		addDestroyShortcutsCommand(cmd, view);
		// delete host element
		cmd.add(new DestroyElementCommand(req));
	} else {
		cmd.add(new DeleteCommand(getEditingDomain(), view));
	}

	final EObject pool = req.getElementToDestroy();
	if (pool instanceof Pool) {
		for (MessageFlow f : ModelHelper.getMainProcess(pool).getMessageConnections()) {
			if (pool.equals(ModelHelper.getParentProcess(f.getSource()))) {
				cmd.add(new DestroyElementCommand(new DestroyElementRequest(f, false)));
			}
		}
	}

	return getGEFWrapper(cmd.reduce());
}
 
Example 13
Source File: LaneItemSemanticEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
	View view = (View) getHost().getModel();
	CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
	cmd.setTransactionNestingEnabled(false);
	for (Iterator<?> it = view.getTargetEdges().iterator(); it.hasNext();) {
		Edge incomingLink = (Edge) it.next();
		if (ProcessVisualIDRegistry.getVisualID(incomingLink) == TextAnnotationAttachmentEditPart.VISUAL_ID) {
			DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
			cmd.add(new DestroyElementCommand(r));
			cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
			continue;
		}
	}
	EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
	if (annotation == null) {
		// there are indirectly referenced children, need extra commands: false
		addDestroyChildNodesCommand(cmd);
		addDestroyShortcutsCommand(cmd, view);
		// delete host element
		cmd.add(new DestroyElementCommand(req));
	} else {
		cmd.add(new DeleteCommand(getEditingDomain(), view));
	}

	final EObject pool = req.getElementToDestroy();
	if (pool instanceof Pool) {
		for (MessageFlow f : ModelHelper.getMainProcess(pool).getMessageConnections()) {
			if (pool.equals(ModelHelper.getParentProcess(f.getSource()))) {
				cmd.add(new DestroyElementCommand(new DestroyElementRequest(f, false)));
			}
		}
	}

	return getGEFWrapper(cmd.reduce());
}
 
Example 14
Source File: SubProcessEventItemSemanticEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
	View view = (View) getHost().getModel();
	CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
	cmd.setTransactionNestingEnabled(false);
	for (Iterator<?> it = view.getTargetEdges().iterator(); it.hasNext();) {
		Edge incomingLink = (Edge) it.next();
		if (ProcessVisualIDRegistry.getVisualID(incomingLink) == TextAnnotationAttachmentEditPart.VISUAL_ID) {
			DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
			cmd.add(new DestroyElementCommand(r));
			cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
			continue;
		}
	}
	EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
	if (annotation == null) {
		// there are indirectly referenced children, need extra commands: false
		addDestroyChildNodesCommand(cmd);
		addDestroyShortcutsCommand(cmd, view);
		// delete host element
		cmd.add(new DestroyElementCommand(req));
	} else {
		cmd.add(new DeleteCommand(getEditingDomain(), view));
	}

	final EObject pool = req.getElementToDestroy();
	if (pool instanceof Pool) {
		for (MessageFlow f : ModelHelper.getMainProcess(pool).getMessageConnections()) {
			if (pool.equals(ModelHelper.getParentProcess(f.getSource()))) {
				cmd.add(new DestroyElementCommand(new DestroyElementRequest(f, false)));
			}
		}
	}

	return getGEFWrapper(cmd.reduce());
}
 
Example 15
Source File: ConnectorViewPostPasteChildOperation.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @return
 * @throws Exception
 */
private EObject doPaste()
	throws Exception {

	View sourceView = getConnectorViewPasteOperation().getSourceView();
	View targetView = getConnectorViewPasteOperation().getTargetView();

	if ((sourceView == null) || (targetView == null)) {
		return null;
	}

	EObject sourceViewContainer = sourceView.eContainer();
	EObject targetViewContainer = targetView.eContainer();

	if ((sourceViewContainer == null) || (targetViewContainer == null)) {
		return null;
	}

	if (sourceViewContainer.equals(targetViewContainer) == false) {
		//not in the same container, let's try to see if they are in the
		// same diagram at least
		Diagram sourceViewDiagram = NotationClipboardOperationHelper
			.getContainingDiagram((View) sourceViewContainer);
		Diagram targetViewDiagram = NotationClipboardOperationHelper
			.getContainingDiagram((View) targetViewContainer);
		if ((sourceViewDiagram == null) || (targetViewDiagram == null)
			|| (sourceViewDiagram.equals(targetViewDiagram) == false)) {
			return null;
		}
	}
	
	Edge connectorView = getConnectorViewPasteOperation()
		.getConnectorView();

	if (pasteSemanticElement) {			
		EObject semanticElement = connectorView.getElement();
		if (semanticElement != null) {
			if (semanticElement.eIsProxy()) {
				semanticElement = ClipboardSupportUtil.resolve(semanticElement,
					getParentPasteProcess().getLoadedIDToEObjectMapCopy());
			}
			String loadedId = getLoadedEObjectID(semanticElement);
			if (loadedId != null) {
				//even if we failed to paste the semantic element, we'll
				// proceed to paste the edge view
				doPasteSemanticElement();
				//should have been pasted by now, if not then return
				String newId = getEObjectID(semanticElement);
				if (newId == null) {
					return null;
				}
			}
		}
	}
	EObject pastedElement = null;
	Diagram pasteTargetDiagram = NotationClipboardOperationHelper
		.getContainingDiagram((View) sourceViewContainer);
	if (pasteTargetDiagram != null) {
		//if we reached here then we should paste the connector and set
		// refs to it accordingly
		pastedElement = ClipboardSupportUtil.appendEObjectAt(
			pasteTargetDiagram, getContainmentFeature(), connectorView);
		if (pastedElement != null) {
			ClipboardSupportUtil.appendEObjectAt(sourceView,
				NotationPackage.eINSTANCE.getView_SourceEdges(),
				connectorView);
			ClipboardSupportUtil.appendEObjectAt(targetView,
				NotationPackage.eINSTANCE.getView_TargetEdges(),
				connectorView);
		}
	}

	return pastedElement;
}