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

The following are Jave code examples for showing how to use getURI() of the org.eclipse.emf.ecore.util.EcoreUtil class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: n4js   File: ConcreteSyntaxAwareReferenceFinder.java   View Source Code Vote up 6 votes
@Override
protected EObject toValidInstanceOrNull(Resource resource, Predicate<URI> targetURIs, EObject value) {
	EObject result = value;
	if (result.eIsProxy()) {
		URI proxyURI = EcoreUtil.getURI(result);
		if (uriEncoder.isCrossLinkFragment(resource, proxyURI.fragment())) {
			INode node = uriEncoder.decode(resource, proxyURI.fragment()).getThird();
			String string = linkingHelper.getCrossRefNodeAsString(node, true);
			if (((TargetURIs) targetURIs).getUserData(TargetURIKey.KEY).isMatchingConcreteSyntax(string)) {
				result = resolveInternalProxy(value, resource);
			} else {
				result = null;
			}
		} else {
			result = resolveInternalProxy(value, resource);
		}
	}
	return result;
}
 
Example 2
Project: gemoc-studio-modeldebugging   File: DSLThreadAdapter.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
 */
public IBreakpoint[] getBreakpoints() {
	final List<IBreakpoint> res = new ArrayList<IBreakpoint>();

	if (isSuspended()) {
		final URI instructionUri = EcoreUtil.getURI(getHost().getTopStackFrame().getCurrentInstruction());
		for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(
				getModelIdentifier())) {
			if (breakpoint instanceof DSLBreakpoint
					&& (((DSLBreakpoint)breakpoint).getURI().equals(instructionUri))) {
				res.add(breakpoint);
			}
		}
	}

	return res.toArray(new IBreakpoint[res.size()]);
}
 
Example 3
Project: gemoc-studio-modeldebugging   File: DSLToggleBreakpointsUtils.java   View Source Code Vote up 6 votes
/**
 * Gets the {@link DSLBreakpoint} for the given {@link EObject instruction}.
 * 
 * @param instruction
 *            the {@link EObject instruction}
 * @return the {@link DSLBreakpoint} for the given {@link EObject instruction} if nay, <code>null</code>
 *         otherwise
 */
protected DSLBreakpoint getBreakpoint(EObject instruction) {
	DSLBreakpoint res = null;

	IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager()
			.getBreakpoints(identifier);
	final URI instructionURI = EcoreUtil.getURI(instruction);
	for (IBreakpoint breakpoint : breakpoints) {
		if (breakpoint instanceof DSLBreakpoint && ((DSLBreakpoint)breakpoint).getURI() != null
				&& ((DSLBreakpoint)breakpoint).getURI().equals(instructionURI)) {
			res = (DSLBreakpoint)breakpoint;
			break;
		}
	}

	return res;
}
 
Example 4
Project: neoscada   File: MasterSelectionDialog.java   View Source Code Vote up 6 votes
@Override
public boolean close ()
{
    if ( getReturnCode () == OK )
    {
        final MasterServer master = getMaster ();
        if ( master != null )
        {
            final URI uri = EcoreUtil.getURI ( master );
            if ( uri != null )
            {
                this.dialogSettings.put ( SETTINGS_LAST_SELECTION, uri.toString () );
            }
        }
    }
    return super.close ();
}
 
Example 5
Project: n4js   File: TestDiscoveryUIUtils.java   View Source Code Vote up 5 votes
/**
 * Derives a location URI as expected by {@link TestDiscoveryHelper#collectTests(URI...)} from an editor input.
 */
public static final URI getLocationForEditorInput(IFileEditorInput fileEditorInput) {

	if (null == fileEditorInput) {
		return null;
	}

	final XtextEditor editor = getActiveEditor(XtextEditor.class).orNull();
	if (null != editor && fileEditorInput.equals(editor.getEditorInput())) {
		if (currentThread() == getDefault().getThread()) { // Iff accessed from the UI thread
			if (editor.getSelectionProvider().getSelection() instanceof ITextSelection) {
				final ITextSelection textSelection = (ITextSelection) editor.getSelectionProvider().getSelection();
				final EObject selectedElement = getSelectedElement(editor, textSelection);
				if (selectedElement instanceof N4MethodDeclaration) {
					final N4MethodDeclaration method = (N4MethodDeclaration) selectedElement;
					if (!method.eIsProxy() && TEST_METHOD.hasAnnotation(method)) {
						final TModule module = N4JSResource.getModule(method.eResource());
						if (null != module) {
							return EcoreUtil.getURI(method);
						}
					}
				}
			}
		}
	}

	return getFileURI(fileEditorInput);
}
 
Example 6
Project: n4js   File: ASTGraphProvider.java   View Source Code Vote up 5 votes
@Override
public Node getNode(Object element) {
	final String type;
	final String name;
	final String desc;
	if (element instanceof Resource) {
		// case: Resource
		final URI uri = ((Resource) element).getURI();
		type = "Resource";
		name = uri != null ? uri.lastSegment() : null;
		desc = null;
	} else if (element instanceof EObject) {
		final EObject eobj = (EObject) element;
		if (eobj.eIsProxy()) {
			// case: proxy
			type = "PROXY(" + eobj.eClass().getName() + ")";
			name = null;
			desc = "proxy URI:\n" + EcoreUtil.getURI(eobj);
		} else {
			// case: non-proxy EObject
			type = eobj.eClass().getName();
			name = getName(eobj);
			desc = getDescription(eobj);
		}
	} else {
		// case: any POJO
		type = element.getClass().getSimpleName();
		name = null;
		desc = null;
	}
	final String title = type + (name != null ? " " + name : "");
	return new Node(element, title, desc);
}
 
Example 7
Project: gemoc-studio-modeldebugging   File: DSLBreakpoint.java   View Source Code Vote up 5 votes
/**
 * Constructor.
 * 
 * @param identifier
 *            the debug model identifier
 * @param instruction
 *            the {@link EObject} representing the instruction
 * @param persistent
 *            should be persisted
 * @throws CoreException
 *             if marker can't be installed
 */
public DSLBreakpoint(String identifier, EObject instruction, boolean persistent) throws CoreException {
	super();
	this.identifier = identifier;
	this.instructionUri = EcoreUtil.getURI(instruction);
	final URI resourceURI = ((EObject)instruction).eResource().getURI();
	final String pathString = resourceURI.toPlatformString(true);
	final IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(pathString));

	if (resource != null) {
		IWorkspaceRunnable runnable = new CreateMarker(resource, instruction, persistent);
		run(getMarkerRule(resource), runnable);
	}
}
 
Example 8
Project: gemoc-studio-modeldebugging   File: DSLDebugModelPresentation.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.debug.ui.IDebugEditorPresentation#addAnnotations(org.eclipse.ui.IEditorPart,
 *      org.eclipse.debug.core.model.IStackFrame)
 */
public boolean addAnnotations(IEditorPart editorPart, IStackFrame frame) {
	if (frame instanceof DSLStackFrameAdapter) {
		final EObject instruction = ((DSLStackFrameAdapter)frame).getCurrentInstruction();
		final URI instructionUri = EcoreUtil.getURI(instruction);
		EMFEditorUtils.selectInstruction(editorPart, instructionUri);
	}
	return true;
}
 
Example 9
Project: gemoc-studio-modeldebugging   File: AbstractGemocAnimatorServices.java   View Source Code Vote up 5 votes
/**
 * Tells if the given {@link EObject instruction} is a currently
 * {@link IModelAnimator#activate(LogicalStep) activated}.
 * 
 * This service works in a similar way as {@link  AbstractGemocDebuggerServices isCurrentInstruction} 
 * but will be activated even if the engine in not paused in order to act as an animation.
 * 
 * @param instruction
 *            the {@link EObject instruction}
 * @return <code>true</code> if the given {@link EObject instruction} is a
 *         currently {@link IModelAnimator#activate(LogicalStep) activated},
 *         <code>false</code> otherwise
 */
public boolean hasBeenActivated(EObject instruction) {
	boolean res = false;

	final URI uri = EcoreUtil.getURI(instruction);
	for (Set<URI> instructions : ANIMATOR.activatedInstructions.values()) {
		if (instructions.contains(uri)) {
			res = true;
			break;
		}
	}

	return res;
}
 
Example 10
Project: n4js   File: N4JSValidationTestHelper.java   View Source Code Vote up 4 votes
private static final String getErrorInfoForDanglingEObject(EObject base, EReference ref) {
	return "in " + base.eClass().getName() + " at " + EcoreUtil.getURI(base) + " via reference " + ref.getName();
}
 
Example 11
Project: n4js   File: TestDiscoveryHelper.java   View Source Code Vote up 4 votes
private TestCase createTestCase(final TMethod method, final TModule module, final String clazzFqnStr) {
	final TestCase testCase = new TestCase(createTestCaseId(clazzFqnStr, method), clazzFqnStr,
			module.getProjectId(), method.getName(), method.getName(), EcoreUtil.getURI(method));
	return testCase;
}
 
Example 12
Project: gemoc-studio-modeldebugging   File: DSLDebugModelPresentation.java   View Source Code Vote up 4 votes
@Override
public IEditorInput getEditorInput(Object element) {
	final IEditorInput res;

	final URI instructionURI;
	if (element instanceof EObject) {
		instructionURI = EcoreUtil.getURI((EObject)element);
	} else if (element instanceof DSLBreakpoint) {
		instructionURI = ((DSLBreakpoint)element).getURI();
	} else {
		instructionURI = null;
	}

	editor = null;
	if (instructionURI != null) {

		final Session session;
		final Session inSession;
		if (element instanceof EObject) {
			inSession = SessionManager.INSTANCE.getSession((EObject)element);
		} else {
			inSession = null;
		}
		if (inSession != null) {
			session = inSession;
		} else {
			List<Session> sessions = SiriusEditorUtils.getSessions(instructionURI);
			if (sessions.size() > 1) {
				session = selectSession(sessions);
			} else if (sessions.size() == 1) {
				session = sessions.get(0);
			} else {
				session = null;
			}
		}

		if (session != null) {
			List<DRepresentation> representations = SiriusEditorUtils.getRepresentations(session,
					instructionURI);

			final DRepresentation representation;
			if (representations.size() > 1) {
				representation = selectRepresentation(representations);
			} else if (representations.size() == 1) {
				representation = representations.get(0);
			} else {
				representation = null;
			}

			if (representation != null) {
				editor = DialectUIManager.INSTANCE.openEditor(session, representation,
						new NullProgressMonitor());
				res = editor.getEditorInput();
			} else {
				res = super.getEditorInput(instructionURI);
			}
		} else {
			res = super.getEditorInput(instructionURI);
		}
	} else {
		return null;
	}

	return res;
}