org.eclipse.xtext.generator.trace.SourceRelativeURI Java Examples

The following examples show how to use org.eclipse.xtext.generator.trace.SourceRelativeURI. 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: DebugSourceInstallingCompilationParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected OutputConfiguration findOutputConfiguration(SourceRelativeURI dslSourceFile, IFile generatedJavaFile) {
	IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(dslSourceFile.getURI());
	if (serviceProvider == null)
		return null;
	EclipseOutputConfigurationProvider cfgProvider = serviceProvider.get(EclipseOutputConfigurationProvider.class);
	IProject project = generatedJavaFile.getProject();
	Set<OutputConfiguration> configurations = cfgProvider.getOutputConfigurations(project);
	if (!configurations.isEmpty()) {
		if (configurations.size() == 1)
			return configurations.iterator().next();
		for (OutputConfiguration out : configurations) {
			for (String source : out.getSourceFolders()) {
				IContainer container = ResourceUtil.getContainer(project, out.getOutputDirectory(source));
				if (container != null && container.getFullPath().isPrefixOf(generatedJavaFile.getFullPath()))
					return out;
			}
		}
	}
	log.error("Could not find output configuration for file " + generatedJavaFile.getFullPath());
	return null;
}
 
Example #2
Source File: AppendableBasedTraceRegion.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String toString() {
	return new AbstractTraceRegionToString() {

		@Override
		protected String getRemoteText(SourceRelativeURI uri) {
			return AppendableBasedTraceRegion.this.getRoot().sourceText;
		}

		@Override
		protected String getLocalText() {
			return AppendableBasedTraceRegion.this.getRoot().generatedText;
		}

		@Override
		protected AbstractTraceRegion getTrace() {
			return AppendableBasedTraceRegion.this;
		}

	}.toString();
}
 
Example #3
Source File: TraceRegionToStringTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void simple() {
  final TraceRegionToStringTester tester = new TraceRegionToStringTester();
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("foo bar");
  _builder.newLine();
  tester.setLocalText(_builder.toString());
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("baz buz");
  _builder_1.newLine();
  tester.setRemote1(_builder_1.toString());
  SourceRelativeURI _uri1 = tester.getUri1();
  TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(4, 2, _uri1);
  TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(1, 2, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location)));
  tester.setTrace(_region);
  StringConcatenation _builder_2 = new StringConcatenation();
  _builder_2.append("-- local1 --- | -- remote1 --");
  _builder_2.newLine();
  _builder_2.append("f[1[oo]1] bar | baz [1[bu]1]z");
  _builder_2.newLine();
  _builder_2.append("-----------------------------");
  _builder_2.newLine();
  _builder_2.append("1: D 1-2 Region -> Location[4,2,remote1]");
  _builder_2.newLine();
  this.operator_tripleEquals(tester, _builder_2);
}
 
Example #4
Source File: JDTAwareEclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Since sourceTraces are relative the URI has to be computed with the currentSource as context
 */
@Override
public void flushSourceTraces(String generatorName) throws CoreException {
	Multimap<SourceRelativeURI, IPath> sourceTraces = getSourceTraces();
	if (sourceTraces != null) {
		Set<SourceRelativeURI> keys = sourceTraces.keySet();
		String source = getCurrentSource();
		IContainer container = Strings.isEmpty(source) ? getProject() : getProject().getFolder(source);
		for (SourceRelativeURI uri : keys) {
			if (uri != null && source != null) {
				Collection<IPath> paths = sourceTraces.get(uri);
				IFile sourceFile = container.getFile(new Path(uri.getURI().path()));
				if (sourceFile.exists()) {
					IPath[] tracePathArray = paths.toArray(new IPath[paths.size()]);
					getTraceMarkers().installMarker(sourceFile, generatorName, tracePathArray);
				}
			}
		}
	}
	resetSourceTraces();
}
 
Example #5
Source File: JarEntryAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected AbsoluteURI resolvePath(IJavaProject javaProject, SourceRelativeURI path) {
	try {
		for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots())
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				IResource resource = root.getResource();
				if (resource instanceof IFolder) {
					IFolder folder = (IFolder) resource;
					String decodedPath = URI.decode(path.toString());
					IResource candidate = folder.findMember(decodedPath);
					if (candidate != null && candidate.exists())
						return new AbsoluteURI(URI.createPlatformResourceURI(resource.getFullPath() + "/" + decodedPath, true));
				}
			}
	} catch (JavaModelException e) {
		log.error("Error resolving path", e);
	}
	return null;
}
 
Example #6
Source File: EclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Can be used to announce that a builder participant is done with this file system access and all potentially
 * recorded trace information should be persisted.
 * 
 * @param generatorName
 *            the name of the generator.
 * @since 2.3
 */
public void flushSourceTraces(String generatorName) throws CoreException {
	Multimap<SourceRelativeURI, IPath> sourceTraces = getSourceTraces();
	if (sourceTraces != null) {
		Set<SourceRelativeURI> keys = sourceTraces.keySet();
		String source = getCurrentSource();
		IContainer container = Strings.isEmpty(source) ? getProject() : getProject().getFolder(source);
		for (SourceRelativeURI uri : keys) {
			if (uri != null) {
				Collection<IPath> paths = sourceTraces.get(uri);
				IFile sourceFile = container.getFile(new Path(uri.getURI().path()));
				if (sourceFile.exists()) {
					IPath[] tracePathArray = paths.toArray(new IPath[paths.size()]);
					getTraceMarkers().installMarker(sourceFile, generatorName, tracePathArray);
				}
			}
		}
	}
	resetSourceTraces();
}
 
Example #7
Source File: DerivedResourceMarkerCopier.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private String determinateMarkerTypeByURI(SourceRelativeURI resourceURI) {
	IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(resourceURI.getURI());
	if (serviceProvider == null)
		return null;
	MarkerTypeProvider typeProvider = serviceProvider.get(MarkerTypeProvider.class);
	Issue.IssueImpl issue = new Issue.IssueImpl();
	issue.setType(CheckType.NORMAL);
	return typeProvider.getMarkerType(issue);
}
 
Example #8
Source File: TraceEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void updateText(EObject obj) {
	DebugTraceRegion region = EcoreUtil2.getContainerOfType(obj, DebugTraceRegion.class);
	if (region == null) {
		text.setText("No " + DebugTraceRegion.class.getSimpleName() + " found for " + obj.eClass().getName());
		return;
	}
	final DebugTraceBasedRegion trace = new DebugTraceBasedRegion(null, region);
	SourceRelativeURI sourceURI = trace.getAssociatedSrcRelativePath();
	if (sourceURI == null) {
		text.setText("Could not find associated URI");
		return;
	}
	Registry registry = IResourceServiceProvider.Registry.INSTANCE;
	IResourceServiceProvider serviceProvider = registry.getResourceServiceProvider(sourceURI.getURI());
	URI traceURI = obj.eResource().getURI();
	IStorage localStorage = getLocalStorage(serviceProvider, traceURI);

	StorageAwareTrace traceProvider = serviceProvider.get(StorageAwareTrace.class);
	traceProvider.setLocalStorage(localStorage);
	traceProvider.setTraceToSource(true);
	traceProvider.setTraceRegionProvider(new ITraceRegionProvider() {
		@Override
		public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
			return trace;
		}
	});
	String newText = traceProvider.toString();
	text.setText(newText);
}
 
Example #9
Source File: TraceRegionToStringTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void twoBounding() {
  final TraceRegionToStringTester tester = new TraceRegionToStringTester();
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("foobar");
  _builder.newLine();
  tester.setLocalText(_builder.toString());
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("bazbuz");
  _builder_1.newLine();
  tester.setRemote1(_builder_1.toString());
  SourceRelativeURI _uri1 = tester.getUri1();
  TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(0, 6, _uri1);
  TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(0, 6, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location)));
  final Procedure1<TraceRegionToStringTester.Region> _function = (TraceRegionToStringTester.Region it) -> {
    TraceRegionToStringTester.Location _location_1 = new TraceRegionToStringTester.Location(0, 3);
    it.addChild(0, 3, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_1)));
    TraceRegionToStringTester.Location _location_2 = new TraceRegionToStringTester.Location(3, 3);
    it.addChild(3, 3, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_2)));
  };
  TraceRegionToStringTester.Region _doubleArrow = ObjectExtensions.<TraceRegionToStringTester.Region>operator_doubleArrow(_region, _function);
  tester.setTrace(_doubleArrow);
  StringConcatenation _builder_2 = new StringConcatenation();
  _builder_2.append("------- local1 ------- | ------ remote1 -------");
  _builder_2.newLine();
  _builder_2.append("[1,2[foo]2][3[bar]3,1] | [1,2[baz]2][3[buz]3,1]");
  _builder_2.newLine();
  _builder_2.append("-----------------------------------------------");
  _builder_2.newLine();
  _builder_2.append("1: D 0-6 Region -> Location[0,6,remote1] {");
  _builder_2.newLine();
  _builder_2.append("2: D 0-3   Region -> Location[0,3]");
  _builder_2.newLine();
  _builder_2.append("3: D 3-3   Region -> Location[3,3]");
  _builder_2.newLine();
  _builder_2.append("1:       }");
  _builder_2.newLine();
  this.operator_tripleEquals(tester, _builder_2);
}
 
Example #10
Source File: AbstractTraceForURIProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected SomeFile asFile(SourceRelativeURI srcRelativeDerivedResource, IProjectConfig project) {
	String[] pathSegments = srcRelativeDerivedResource.getURI().segments();
	Set<? extends ISourceFolder> sourceFolders = project.getSourceFolders();
	for(ISourceFolder folder: sourceFolders) {
		URI srcFolderPath = folder.getPath();
		URI absoluteURI = srcFolderPath.appendSegments(pathSegments);
		SomeFile result = asFile(new AbsoluteURI(absoluteURI), project);
		if (result != null) {
			return result;
		}
	}
	URI fromRoot = project.getPath().appendSegments(pathSegments);
	return asFile(new AbsoluteURI(fromRoot), project);
}
 
Example #11
Source File: AppendableBasedTraceRegion.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private boolean allLocationsMatch(TreeAppendable appendable, SourceRelativeURI path) {
	for(ILocationData locationData: appendable.getLocationData()) {
		if (!path.equals(locationData.getSrcRelativePath())) {
			return false;
		}
	}
	return true;
}
 
Example #12
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isAssociatedWith(AbstractTraceRegion region, AbsoluteURI uri, IProjectConfig project) {
	ITraceURIConverter traceURIConverter = getService(uri, ITraceURIConverter.class);
	if (traceURIConverter == null) {
		traceURIConverter = getService(getLocalURI(), ITraceURIConverter.class);
	}
	SourceRelativeURI convertedUri = traceURIConverter.getURIForTrace(project, uri);
	return convertedUri.equals(region.getAssociatedSrcRelativePath());
}
 
Example #13
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ITrace apply(SourceRelativeURI relativeURI) {
	if (traceToSource) {
		return traceProvider.getTraceToSource(relativeURI, project);
	} else {
		return traceProvider.getTraceToTarget(relativeURI, project);
	}
}
 
Example #14
Source File: TraceRegionToStringTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void twoIdentical() {
  final TraceRegionToStringTester tester = new TraceRegionToStringTester();
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("foo bar");
  _builder.newLine();
  tester.setLocalText(_builder.toString());
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("baz buz");
  _builder_1.newLine();
  tester.setRemote1(_builder_1.toString());
  SourceRelativeURI _uri1 = tester.getUri1();
  TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(1, 5, _uri1);
  TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(0, 7, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location)));
  final Procedure1<TraceRegionToStringTester.Region> _function = (TraceRegionToStringTester.Region it) -> {
    TraceRegionToStringTester.Location _location_1 = new TraceRegionToStringTester.Location(1, 5);
    it.addChild(0, 7, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_1)));
  };
  TraceRegionToStringTester.Region _doubleArrow = ObjectExtensions.<TraceRegionToStringTester.Region>operator_doubleArrow(_region, _function);
  tester.setTrace(_doubleArrow);
  StringConcatenation _builder_2 = new StringConcatenation();
  _builder_2.append("---- local1 ----- | ---- remote1 ----");
  _builder_2.newLine();
  _builder_2.append("[1,2[foo bar]2,1] | b[1,2[az bu]2,1]z");
  _builder_2.newLine();
  _builder_2.append("-------------------------------------");
  _builder_2.newLine();
  _builder_2.append("1: D 0-7 Region -> Location[1,5,remote1] {");
  _builder_2.newLine();
  _builder_2.append("2: D 0-7   Region -> Location[1,5]");
  _builder_2.newLine();
  _builder_2.append("1:       }");
  _builder_2.newLine();
  this.operator_tripleEquals(tester, _builder_2);
}
 
Example #15
Source File: TraceAsSmapInstaller.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getStratumName(final SourceRelativeURI path) {
	IResourceServiceProvider provider = serviceProviderRegistry.getResourceServiceProvider(path.getURI());
	if (provider == null) {
		// it might happen that trace data is in the workspace but the corresponding language is not installed.
		// we use the file extension then.
		String result = path.getURI().fileExtension();
		if (result != null) {
			return result;
		}
		return "unknown";
	}
	final LanguageInfo languageInfo = provider.get(LanguageInfo.class);
	String name = languageInfo.getShortName();
	return name;
}
 
Example #16
Source File: StorageAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected InputStream getContents(SourceRelativeURI uri, IProject project) throws IOException {
	try {
		IStorage storage = findStorage(uri, project);
		if (storage == null)
			return null;
		return storage.getContents();
	} catch(CoreException e) {
		throw new WrappedCoreException(e);
	}
}
 
Example #17
Source File: StorageAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected AbsoluteURI resolvePath(IProject project, SourceRelativeURI path) {
	String decodedPath = URI.decode(path.getURI().toString());
	IResource candidate = project.findMember(decodedPath);
	if (candidate != null && candidate.exists())
		return new AbsoluteURI(URI.createPlatformResourceURI(project.getFullPath() + "/" + decodedPath, true));
	return null;
}
 
Example #18
Source File: StorageAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IStorage findStorage(SourceRelativeURI uri, IProject project) {
	AbsoluteURI resolvePath = resolvePath(uri);
	Iterable<Pair<IStorage, IProject>> allStorages = getStorage2uriMapper().getStorages(resolvePath.getURI());
	for (Pair<IStorage, IProject> storage : allStorages) {
		if (project.equals(storage.getSecond())) {
			return storage.getFirst();
		}
	}
	return null;
}
 
Example #19
Source File: XbaseBreakpointUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public SourceRelativeURI getBreakpointURI(IEditorInput input) {
	IResource resource = Adapters.adapt(input, IResource.class);
	if (resource != null)
		return null;
	if (input instanceof IStorageEditorInput) {
		IStorage storage;
		try {
			storage = ((IStorageEditorInput) input).getStorage();
			if (storage instanceof IResource)
				return null;
			if (storage instanceof IJarEntryResource) {
				IJarEntryResource jarEntryResource = (IJarEntryResource) storage;
				if (!jarEntryResource.getPackageFragmentRoot().isArchive())
					return null;
				Object parent = jarEntryResource.getParent();
				if (parent instanceof IPackageFragment) {
					String path = ((IPackageFragment) parent).getElementName().replace('.', '/');
					return new SourceRelativeURI(path + "/" + storage.getName());
				} else if (parent instanceof IPackageFragmentRoot) {
					return new SourceRelativeURI(storage.getName());
				}
			}
		} catch (CoreException e) {
			logger.error("Error finding breakpoint URI", e);
			return null;
		}
	} else {
		IClassFile classFile = Adapters.adapt(input, IClassFile.class);
		if (classFile != null) {
			ITrace traceToSource = traceForTypeRootProvider.getTraceToSource(classFile);
			if (traceToSource == null)
				return null;
			for (ILocationInResource loc : traceToSource.getAllAssociatedLocations())
				return loc.getSrcRelativeResourceURI();
			return null;
		}
	}
	return null;
}
 
Example #20
Source File: ZipFileAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Reader getContentsAsText(SourceRelativeURI uri, IProject project) {
	InputStream contents = getContents(uri, project);
	if (contents != null)
		return new InputStreamReader(contents, getEncoding());
	return null;
}
 
Example #21
Source File: TraceResourceFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public DebugLocationData createLocation(int offset, int length, int lineNumber, int endLineNumber, SourceRelativeURI path) {
	DebugLocationData result = TraceFactory.eINSTANCE.createDebugLocationData();
	result.setOffset(offset);
	result.setLength(length);
	result.setLineNumber(lineNumber);
	result.setEndLineNumber(endLineNumber);
	result.setPath(path != null ? path.getURI() : null);
	return result;
}
 
Example #22
Source File: TraceRegionToStringTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void twoFrame1() {
  final TraceRegionToStringTester tester = new TraceRegionToStringTester();
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("foo bar");
  _builder.newLine();
  tester.setLocalText(_builder.toString());
  TextRegion _textRegion = new TextRegion(1, 5);
  tester.setLocalFrame(_textRegion);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("baz buz");
  _builder_1.newLine();
  tester.setRemote1(_builder_1.toString());
  SourceRelativeURI _uri1 = tester.getUri1();
  TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(1, 5, _uri1);
  TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(0, 7, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location)));
  final Procedure1<TraceRegionToStringTester.Region> _function = (TraceRegionToStringTester.Region it) -> {
    TraceRegionToStringTester.Location _location_1 = new TraceRegionToStringTester.Location(1, 5);
    it.addChild(2, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_1)));
    TraceRegionToStringTester.Location _location_2 = new TraceRegionToStringTester.Location(1, 5);
    it.addChild(5, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_2)));
  };
  TraceRegionToStringTester.Region _doubleArrow = ObjectExtensions.<TraceRegionToStringTester.Region>operator_doubleArrow(_region, _function);
  tester.setTrace(_doubleArrow);
  StringConcatenation _builder_2 = new StringConcatenation();
  _builder_2.append("---- local1 ----- | ---- remote1 ----");
  _builder_2.newLine();
  _builder_2.append("o[1[o]1] b[2[a]2] | b[1,2[az bu]2,1]z");
  _builder_2.newLine();
  _builder_2.append("-------------------------------------");
  _builder_2.newLine();
  _builder_2.append("1: D 2-1 Region -> Location[1,5]");
  _builder_2.newLine();
  _builder_2.append("2: D 5-1 Region -> Location[1,5]");
  _builder_2.newLine();
  this.operator_tripleEquals(tester, _builder_2);
}
 
Example #23
Source File: LocationInResource.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public LocationInResource(int offset, int length, int lineNumber, int endLineNumber, SourceRelativeURI srcRelativeResourceURI, AbstractTrace trace) {
	super(trace);
	this.offset = offset;
	this.length = length;
	this.lineNumber = lineNumber;
	this.endLineNumber = endLineNumber;
	this.srcRelativeResourceURI = srcRelativeResourceURI;
}
 
Example #24
Source File: DebugTraceBasedRegion.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public SourceRelativeURI getAssociatedSrcRelativePath() {
	SourceRelativeURI path = super.getAssociatedSrcRelativePath();
	if (path != null)
		return path;
	return getAssociatedSrcRelativePath(delegate);
}
 
Example #25
Source File: DebugTraceBasedRegion.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected SourceRelativeURI getAssociatedSrcRelativePath(DebugTraceRegion region) {
	for (DebugLocationData associated : region.getAssociations()) {
		URI uri = associated.getPath();
		if (uri != null)
			return new SourceRelativeURI(uri);
	}
	EObject container = region.eContainer();
	if (container instanceof DebugTraceRegion)
		return getAssociatedSrcRelativePath((DebugTraceRegion) container);
	return null;
}
 
Example #26
Source File: JarEntryAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AbsoluteURI tryResolvePath(IStorage localStorage, SourceRelativeURI path) {
	if (localStorage instanceof IFile) {
		IProject project = ((IFile) localStorage).getProject();
		if (project != null) {
			IJavaProject javaProject = JavaCore.create(project);
			if (javaProject != null && javaProject.exists())
				return resolvePath(javaProject, path);
			return null;
		}
	} else if (localStorage instanceof IJarEntryResource) {
		return resolvePath((IJarEntryResource) localStorage, path);
	}
	return null;
}
 
Example #27
Source File: JarEntryAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected AbsoluteURI resolvePath(IJarEntryResource jarEntry, SourceRelativeURI path) {
	IPackageFragmentRoot packageFragmentRoot = jarEntry.getPackageFragmentRoot();
	try {
		Pair<URI, URI> pair = uriMapperExtensions.getURIMapping(packageFragmentRoot);
		if (pair != null) {
			URI first = pair.getFirst();
			if (first != null)
				return new AbsoluteURI(URI.createURI(first + "/" + path));
		}
	} catch (JavaModelException e) {
		log.error("Error resolving path", e);
	}
	return null;
}
 
Example #28
Source File: FolderAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public InputStream getContents(SourceRelativeURI uri, IProject project) throws IOException {
	File container = new File(folder);
	if (!container.exists())
		return null;
	File file = findFile(container, uri.getURI().toString());
	if (file == null)
		return null;
	return new FileInputStream(file);
}
 
Example #29
Source File: ResourceStorageTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDecodeURI() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package mypack");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public def void foo() {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IFile file = this.helper.createFile("mypack/MyClass Foo.xtend", _builder.toString());
    IResourcesSetupUtil.waitForBuild();
    final ResourceStorageTest.TestableStorageAwareTrace storageAwareTrace = new ResourceStorageTest.TestableStorageAwareTrace();
    this.getInjector().injectMembers(storageAwareTrace);
    storageAwareTrace.setLocalStorage(file);
    URI _createURI = URI.createURI("mypack/MyClass%20Foo.xtend");
    SourceRelativeURI _sourceRelativeURI = new SourceRelativeURI(_createURI);
    AbsoluteURI result = storageAwareTrace.resolvePath(_sourceRelativeURI);
    Assert.assertEquals("platform:/resource/test.project/src/mypack/MyClass%20Foo.xtend", result.toString());
    IProject _project = this.helper.getProject();
    URI _createURI_1 = URI.createURI("src/mypack/MyClass%20Foo.xtend");
    SourceRelativeURI _sourceRelativeURI_1 = new SourceRelativeURI(_createURI_1);
    result = storageAwareTrace.resolvePath(_project, _sourceRelativeURI_1);
    Assert.assertEquals("platform:/resource/test.project/src/mypack/MyClass%20Foo.xtend", result.toString());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #30
Source File: TraceRegionMergerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public TraceRegionMergerTest.AssertBuilder region(final int offset, final int length, final int startLine, final int endLine, final List<String> uris, final Procedure1<? super TraceRegionMergerTest.AssertBuilder> init) {
  TraceRegionMergerTest.AssertBuilder _xblockexpression = null;
  {
    final AbstractTraceRegion head = this.regions.poll();
    Assert.assertEquals(head.toString(), offset, head.getMyOffset());
    Assert.assertEquals(head.toString(), length, head.getMyLength());
    Assert.assertEquals(head.toString(), startLine, head.getMyLineNumber());
    Assert.assertEquals(head.toString(), endLine, head.getMyEndLineNumber());
    final Function1<ILocationData, SourceRelativeURI> _function = (ILocationData it) -> {
      return it.getSrcRelativePath();
    };
    final Set<SourceRelativeURI> associatedLocations = IterableExtensions.<SourceRelativeURI>toSet(ListExtensions.<ILocationData, SourceRelativeURI>map(head.getAssociatedLocations(), _function));
    Assert.assertEquals(head.toString(), ((Object[])Conversions.unwrapArray(uris, Object.class)).length, ((Object[])Conversions.unwrapArray(associatedLocations, Object.class)).length);
    for (final String uri : uris) {
      URI _createURI = URI.createURI(uri);
      SourceRelativeURI _sourceRelativeURI = new SourceRelativeURI(_createURI);
      Assert.assertTrue(("Missing " + uri), associatedLocations.contains(_sourceRelativeURI));
    }
    if ((init == null)) {
      Assert.assertTrue(head.getNestedRegions().isEmpty());
    } else {
      LinkedList<AbstractTraceRegion> _newLinkedList = CollectionLiterals.<AbstractTraceRegion>newLinkedList(((AbstractTraceRegion[])Conversions.unwrapArray(head.getNestedRegions(), AbstractTraceRegion.class)));
      final TraceRegionMergerTest.AssertBuilder child = new TraceRegionMergerTest.AssertBuilder(this.testBuilder, _newLinkedList);
      init.apply(child);
      child.thatsIt();
    }
    _xblockexpression = this;
  }
  return _xblockexpression;
}