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

The following examples show how to use org.eclipse.emf.common.util.URI#path() . 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: ProjectStateHolder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private SourceChangeKind getSourceChangeKind(HashedFileContent hfc, PersistedState persistedState) {
	URI sourceUri = hfc.getUri();
	long loadedHash = hfc.getHash();

	HashedFileContent newHash = doHash(sourceUri);
	if (newHash == null) {
		return SourceChangeKind.DELETED;
	}

	if (loadedHash != newHash.getHash()) {
		return SourceChangeKind.CHANGED;
	}

	XSource2GeneratedMapping sourceFileMappings = persistedState.indexState.getFileMappings();
	List<URI> allPrevGenerated = sourceFileMappings.getGenerated(sourceUri);
	for (URI prevGenerated : allPrevGenerated) {
		File prevGeneratedFile = new File(prevGenerated.path());
		if (!prevGeneratedFile.isFile()) {
			return SourceChangeKind.CHANGED;
		}
	}
	return SourceChangeKind.UNCHANGED;
}
 
Example 2
Source File: EObjectUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Return the fie location of a given object in a text resource as the path to the file and the line number.
 * <p>
 * This is very similar to {@link #getLocationString(EObject)} but it will not include the {@link Object#toString()} representation of the object.
 *
 * @param object
 *          any EObject
 * @return a string representation of the location of this object in its file, never {@code null}
 */
public static String getFileLocation(final EObject object) {
  if (object == null || object.eResource() == null) {
    return ""; //$NON-NLS-1$
  }

  URI uri = object.eResource().getURI();
  // CHECKSTYLE:CHECK-OFF MagicNumber
  String path = uri.isPlatform() ? '/' + String.join("/", uri.segmentsList().subList(3, uri.segmentCount())) : uri.path(); //$NON-NLS-1$
  // CHECKSTYLE:CHECK-ON MagicNumber
  StringBuilder result = new StringBuilder(path);
  final ICompositeNode node = NodeModelUtils.getNode(object);
  if (node != null) {
    result.append(':').append(node.getStartLine());
  }

  return result.toString();
}
 
Example 3
Source File: TesterFrontEnd.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a default name for a new test configuration with the given runnerId and moduleToTest.
 */
private String computeConfigurationName(String testerId, URI moduleToTest) {
	String modulePath = moduleToTest.path();
	modulePath = stripStart(modulePath, "/", "resource/", "plugin/");
	final String moduleName = modulePath.replace('/', '-');
	final String runnerName = testerRegistry.getDescriptor(testerId).getName();
	return moduleName + " (" + runnerName + ")";
}
 
Example 4
Source File: RunnerHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a default name for a new run configuration with the given runnerId and moduleToRun.
 */
public String computeConfigurationName(String runnerId, URI moduleToRun) {
	String modulePath = moduleToRun.path();
	modulePath = stripStart(modulePath, "/", "resource/", "plugin/");
	// strip '@' character from project scopes
	if (modulePath.startsWith(ProjectDescriptionUtils.NPM_SCOPE_PREFIX)) {
		modulePath = modulePath.substring(1);
	}
	final String moduleName = modulePath.replace('/', '-').replace(':', '-');
	final String runnerName = runnerRegistry.getDescriptor(runnerId).getName();
	return moduleName + " (" + runnerName + ")";
}
 
Example 5
Source File: ProjectStateHolder.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private HashedFileContent doHash(URI uri) {
	try {
		File srcFile = new File(uri.path());
		if (!srcFile.isFile()) {
			return null;
		}
		HashedFileContent generatedTargetContent = new HashedFileContent(uri, srcFile);
		return generatedTargetContent;
	} catch (IOException e) {
		return null;
	}
}
 
Example 6
Source File: AbstractJvmTypeProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public IMirror createMirror(URI resourceURI) {
	if (resourceURI.hasFragment())
		throw new IllegalArgumentException("Cannot create mirror for uri '" + resourceURI.toString() + "'");
	String name = resourceURI.path();
	if (URIHelperConstants.PRIMITIVES.equals(name))
		return new PrimitiveMirror(primitiveTypeFactory);
	if (!name.startsWith(URIHelperConstants.OBJECTS))
		throw new IllegalArgumentException("Invalid resource uri '" + resourceURI.toString() + "'");
	name = name.substring(URIHelperConstants.OBJECTS.length());
	return createMirrorForFQN(name);
}
 
Example 7
Source File: BundleClasspathUriResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private URI findResourceInBundle(Bundle bundle, URI classpathUri)
        throws MalformedURLException, IOException {
    Path fullPath = new Path(classpathUri.path());
    if (bundle != null) {
        String projectRelativePath = "/" + fullPath;
        URL resourceUrl = bundle.getResource(projectRelativePath);
        if (resourceUrl != null) {
        	URL resolvedUrl = FileLocator.resolve(resourceUrl);
            URI normalizedURI = URI.createURI(
                    resolvedUrl.toString(), true);
            return normalizedURI;
        }
    }
    return classpathUri;
}
 
Example 8
Source File: JdtValidationJobScheduler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected boolean isDirty(URI uri) {
	if (uri == null)
		return false;
	if (URIHelperConstants.PROTOCOL.equals(uri.scheme())) {
		String path = uri.path();
		if (URIHelperConstants.PRIMITIVES.equals(path))
			return false;
		String topLevelTypeName = path.substring(URIHelperConstants.OBJECTS.length());
		ICompilationUnit[] workingCopies = JavaCore.getWorkingCopies(null);
		for(ICompilationUnit cu: workingCopies) {
			try {
				if (cu.hasUnsavedChanges()) {
					IType primaryType = cu.findPrimaryType();
					if (primaryType != null) {
						if (topLevelTypeName.equals(primaryType.getFullyQualifiedName())) {
							return true;
						}
					}
				}
			} catch (JavaModelException e) {
				// ignore
			}
		}
	}
	return super.isDirty(uri);
}
 
Example 9
Source File: ClassloaderClasspathUriResolver.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public URI findResourceOnClasspath(ClassLoader classLoader, URI classpathUri) throws URISyntaxException {
    String pathAsString = classpathUri.path();
    if (classpathUri.hasAbsolutePath()) {
        pathAsString = pathAsString.substring(1);
    }
    URL resource = classLoader.getResource(pathAsString);
    if (resource==null)
    	throw new FileNotFoundOnClasspathException("Couldn't find resource on classpath. URI was '"+classpathUri+"'");
    URI fileUri = URI.createURI(resource.toString(),true);
    return fileUri.appendFragment(classpathUri.fragment());
}
 
Example 10
Source File: DefaultFileSystemAccessFactory.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void checkWriteAccess(ISCTFileSystemAccess access, String outputConfiguration, String folderName) {
	URI uri = access.getURI("", outputConfiguration);
	if (uri.isFile()) {
		File file = new File(uri.path());
		if (!file.exists()) return;
		if (!file.canWrite()) {
			logger.log(String.format("Can not generate files to read-only folder '%s'. ", folderName));
		}

	}
}
 
Example 11
Source File: AbstractPortableURIsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertPortableURI(URI uri) {
	if (uri.isRelative()) {
		String path = uri.path();
		assertFalse(uri.toString() + " is not portable", path.startsWith(".."));
	}
}
 
Example 12
Source File: AbstractPortableURIsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertPortableURI(URI uri) {
	if (uri.isRelative()) {
		String path = uri.path();
		assertFalse(uri.toString() + " is not portable", path.startsWith(".."));
	}
}
 
Example 13
Source File: AbstractPortableURIsTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertPortableURI(URI uri) {
	if (uri.isRelative()) {
		String path = uri.path();
		assertFalse(uri.toString() + " is not portable", path.startsWith(".."));
	}
}
 
Example 14
Source File: URIsInEcoreFilesXtendTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertPortableURI(URI uri) {
	if (uri.isRelative()) {
		String path = uri.path();
		assertFalse(uri.toString() + " is not portable", path.startsWith(".."));
	}
}
 
Example 15
Source File: AbstractPortableURIsTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertPortableURI(URI uri) {
	if (uri.isRelative()) {
		String path = uri.path();
		assertFalse(uri.toString() + " is not portable", path.startsWith(".."));
	}
}