Java Code Examples for org.eclipse.emf.common.util.URI#createURI()

The following examples show how to use org.eclipse.emf.common.util.URI#createURI() . 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: EObjectContentProviderTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Mocks XtextEditor and XtextElementSelectionListener to return an element selection that has:
 * - given EAttribute with a specific value (AttributeValuePair)
 * - given EStructuralFeature
 * - given EOperation.
 *
 * @param attributeValuePair
 *          EAttribute with a specific value
 * @param feature
 *          the EStructuralFeature
 * @param operation
 *          the EOperation
 * @return the EClass of the "selected" element
 */
@SuppressWarnings("unchecked")
private EClass mockSelectedElement(final AttributeValuePair attributeValuePair, final EStructuralFeature feature, final EOperation operation) {
  EClass mockSelectionEClass = mock(EClass.class);
  when(mockSelectionListener.getSelectedElementType()).thenReturn(mockSelectionEClass);
  // Mockups for returning AttributeValuePair
  URI elementUri = URI.createURI("");
  when(mockSelectionListener.getSelectedElementUri()).thenReturn(elementUri);
  XtextEditor mockEditor = mock(XtextEditor.class);
  when(mockSelectionListener.getEditor()).thenReturn(mockEditor);
  IXtextDocument mockDocument = mock(IXtextDocument.class);
  when(mockEditor.getDocument()).thenReturn(mockDocument);
  when(mockDocument.<ArrayList<AttributeValuePair>> readOnly(any(IUnitOfWork.class))).thenReturn(newArrayList(attributeValuePair));
  // Mockups for returning EOperation
  BasicEList<EOperation> mockEOperationsList = new BasicEList<EOperation>();
  mockEOperationsList.add(operation);
  when(mockSelectionEClass.getEAllOperations()).thenReturn(mockEOperationsList);
  // Mockups for returning EStructuralFeature
  BasicEList<EStructuralFeature> mockEStructuralFeatureList = new BasicEList<EStructuralFeature>();
  mockEStructuralFeatureList.add(feature);
  mockEStructuralFeatureList.add(attributeValuePair.getAttribute());
  when(mockSelectionEClass.getEAllStructuralFeatures()).thenReturn(mockEStructuralFeatureList);
  return mockSelectionEClass;
}
 
Example 2
Source File: LazyLinkerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testSingleValuedResolveProxiesReference() throws Exception {
	final EObject foo = newEObject("Foo");
	final EObject bar = newEObject("Bar");
	final Resource resource = new ResourceImpl(URI.createURI("http://foo/bar.ecore")) {
		@Override
		public EObject getEObject(String uriFragment) {
			return bar;
		}
	};
	resourceSet.getResources().add(resource);
	resource.getContents().add(foo);

	final EReference eReference = (EReference) foo.eClass().getEStructuralFeature("single");
	assertFalse(eReference.isResolveProxies());

	final INode leafNode = newCrossReferenceAssignmentNode(eReference.getName());
	final ICompositeNode adapter = newSimpleNodeAdapter(leafNode);
	foo.eAdapters().add((Adapter) adapter);
	linker.linkModel(foo, new ListBasedDiagnosticConsumer());
	assertEquals(bar, foo.eGet(eReference, false));
}
 
Example 3
Source File: ECMA6TestSuite.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * generated instances of the tests will use this base implementation
 */
@Override
@Test
public void test() throws Exception {
	if (this.parserN4JS == null) {
		throw new Error("parser instance is null");
	}

	String code = TestCodeProvider.getContentsFromFileEntry(config.entry, config.resourceName);
	if (code == null) {
		throw new Error("test data code instance is null");
	}

	Analyser analyser = createAnalyzer(code);
	XtextResourceSet resourceSet = resourceSetProvider.get();
	URI uri = URI.createURI(config.entry.getName());
	// ECMA 6 test suite was changed - "use strict" is synthesized by the test runner
	// we do the same here
	if (code.contains("flags: [onlyStrict]")) {
		// by using the proper file extension
		uri = uri.trimFileExtension().appendFileExtension("n4js");
	}
	Script script = doParse(code, uri, resourceSet, analyser);
	if (config.isValidator()) {
		// validation flag is bogus since it will produce linking issues
		// thus the negative tests will likely succeed for bogus reasons
		throw new IllegalStateException(config.entry.getName());
	}
	// try {
	analyser.analyse(script, config.entry.getName(), code);
	// } catch (AssertionError e) {
	// System.out.println(config.entry.getName());
	// throw e;
	// }
}
 
Example 4
Source File: GamlQuickfixProvider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Fix (IGamlIssue.IMPORT_ERROR)
public void gotoImport(final Issue issue, final IssueResolutionAcceptor acceptor) {
	final String[] data = issue.getData();
	if (data == null || data.length == 0) { return; }
	final String path = data[0];
	final URI uri = URI.createURI(path, false);
	acceptor.accept(issue, "Open " + uri.lastSegment() + "...", "Open file " + uri.lastSegment() + " to fix it", "",
			(IModification) context -> FileOpener.openFile(uri));

}
 
Example 5
Source File: WorkspaceClasspathUriResolverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testClasspathUriForFileInJarInWorkspace() throws Exception {
	_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
	_project = _javaProject.getProject();
	IFile jarFile = PluginUtil.copyFileToWorkspace(TestsActivator.getInstance(), "/testfiles/" + JAR_FILE, _project, "/"
			+ JAR_FILE);
	JavaProjectSetupUtil.addJarToClasspath(_javaProject, jarFile);
	URI classpathUri = URI.createURI("classpath:/model/" + MODEL_FILE);
	String expectedUri = "archive:platform:/resource/" + TEST_PROJECT_NAME + "/" + JAR_FILE + "!/model/" + MODEL_FILE;
	URI normalizedUri = _resolver.resolve(_project, classpathUri);
	assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
 
Example 6
Source File: AbstractLaunchConfigurationMainTab.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
 */
@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
	setMessage(null);
	setErrorMessage(null);

	final String uriStr;
	try {
		uriStr = launchConfig.getAttribute(getResourceRunConfigKey(), "");
	} catch (CoreException e1) {
		setErrorMessage("cannot read resource URI from launch configuration");
		return false;
	}
	if (uriStr.trim().isEmpty()) {
		setErrorMessage("launch configuration must specify a " + getResourceLabel().toLowerCase());
		return false;
	}
	final URI resourceUri = URI.createURI(uriStr, true);

	final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	final IResource resource = root.findMember(resourceUri.toPlatformString(true));
	if (resource == null) {
		setErrorMessage("unable to locate resource in workspace: " + resourceUri.toPlatformString(true));
		return false;
	}

	if (!checkResourceIsInAvailableProject(resourceUri)) {
		return false;
	}
	if (!checkResourceIsOfAcceptedType(resource)) {
		return false;
	}
	if (!checkSubclassSpecificConstraints(launchConfig, resource, resourceUri)) {
		return false;
	}

	return true;
}
 
Example 7
Source File: WorkspaceClasspathUriResolverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testClasspathUriForFileInWorkspaceWithFragment() throws Exception {
	_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
	_project = _javaProject.getProject();
	PluginUtil.copyFileToWorkspace(TestsActivator.getInstance(), "/testfiles/" + MODEL_FILE, _project, "src/"
			+ MODEL_FILE);
	URI classpathUri = URI.createURI("classpath:/" + MODEL_FILE + "#/");
	String expectedUri = "platform:/resource/" + TEST_PROJECT_NAME + "/src/" + MODEL_FILE + "#/";
	URI normalizedUri = _resolver.resolve(_project, classpathUri);
	assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
 
Example 8
Source File: UriExtensionsTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_withEmptyAuthority() throws Exception {
	final URI uriWithoutAuthority = URI.createURI("file:/path/to/resource/");
	assertNull(uriWithoutAuthority.authority());
	final URI uriWithEmptyAuthority = uriExtensions.withEmptyAuthority(uriWithoutAuthority);
	assertNotSame(uriWithoutAuthority, uriWithEmptyAuthority);
	assertEquals("Returned URI is expected to have an empty instead of null authority", "",
			uriWithEmptyAuthority.authority());
	final URI uriWithAuthority = URI.createURI("https://xtext.org/path/to/resource/");
	assertNotNull(uriWithAuthority.authority());
	assertEquals("xtext.org", uriWithAuthority.authority());
	assertSame(uriWithAuthority, uriExtensions.withEmptyAuthority(uriWithAuthority));
}
 
Example 9
Source File: DefaultResourceDescription2Test.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testClasspathURIIsNormalized() {
	XtextResourceSet xtextResourceSet = new XtextResourceSet();
	xtextResourceSet.setClasspathURIContext(this);
	URI classpathURI = URI.createURI("classpath:/org/eclipse/xtext/XtextGrammarTestLanguage.ecore");
	Resource resource = xtextResourceSet.getResource(classpathURI, true);
	IResourceDescription ecoreResourceDescription = createResourceDescription(resource);
	assertNotSame(classpathURI, ecoreResourceDescription.getURI());
	assertEquals(xtextResourceSet.getURIConverter().normalize(classpathURI), ecoreResourceDescription.getURI());
}
 
Example 10
Source File: IdeTestLanguageClient.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
	URI uriRaw = URI.createURI(diagnostics.getUri());
	if (N4Scheme.isN4Scheme(uriRaw)) {
		return;
	}
	if (!uriRaw.isFile()) {
		throw new IllegalArgumentException("not a file URI: " + uriRaw);
	}

	FileURI uri = new FileURI(uriRaw);

	issues.removeAll(uri);
	errors.removeAll(uri);
	warnings.removeAll(uri);

	List<Diagnostic> issueList = diagnostics.getDiagnostics();
	if (issueList.isEmpty()) {
		return;
	}

	for (Diagnostic diag : issueList) {
		String issueString = getIssueString(diag);
		issues.put(uri, diag);

		switch (diag.getSeverity()) {
		case Error:
			errors.put(uri, issueString);
			break;
		case Warning:
			warnings.put(uri, issueString);
			break;
		default:
			// ignore
			break;
		}
	}
}
 
Example 11
Source File: ImportUriGlobalScopeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public URI resolve(String uriAsString) throws IllegalArgumentException {
	URI uri = URI.createURI(uriAsString);
	if (uriResolver != null) {
		try {
			return uriResolver.resolve(uriContext, uri);
		} catch(ClasspathUriResolutionException e) {
			return uri;
		}
	}
	return uri;
}
 
Example 12
Source File: LoadedByClasspathFromMavenStructureTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public URI getReferencedURI() {
	return URI.createURI("platform:/resource/org.eclipse.xtext.test/src/org/eclipse/xtext/resource/mydsl.ecore");
}
 
Example 13
Source File: BundleClasspathUriResolverTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testClasspathUriForFileInPlugin() {
	URI classpathUri = URI.createURI("classpath:/org/eclipse/xtext/ui/tests/util/simple.ecore");
	URI normalizedUri = _resolver.resolve(TestsActivator.getInstance(), classpathUri);
	assertResourceLoadable(classpathUri, normalizedUri, null);
}
 
Example 14
Source File: AbsoluteURI.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public AbsoluteURI(String absoluteURI) {
	this(URI.createURI(absoluteURI));
}
 
Example 15
Source File: FilesInSourceMavenAndModelDifferentProjectsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public URI getPackagedResourceURI() {
	return URI.createURI("platform:/resource/projectName/org/package/First.ecore");
}
 
Example 16
Source File: FilesInModelAndSourceDifferentProjectsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public URI getPackagedResourceURI() {
	return URI.createURI("platform:/resource/projectName/model/First.ecore");
}
 
Example 17
Source File: AbstractXtextTests.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.8
 */
protected URI getTestModelURI() {
	return URI.createURI("mytestmodel."+getCurrentFileExtension());
}
 
Example 18
Source File: UriUtilTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testPrefixRequiresSameScheme() {
	URI prefix = URI.createURI("platform:/foo/");
	URI uri = URI.createURI("file:/foo/bar");
	assertFalse(UriUtil.isPrefixOf(prefix, uri));
}
 
Example 19
Source File: UIUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public static URI getRepositoryBaseURI(IProject project) {
    return URI.createURI(project.getLocationURI().toString());
}
 
Example 20
Source File: LoadedByClasspathBothFromMavenStructureTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public URI getReferencedURI() {
	return URI
			.createURI("platform:/resource/org.eclipse.xtext.test/src/main/org/eclipse/xtext/resource/mydsl.ecore");
}