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

The following examples show how to use org.eclipse.xtext.generator.trace.ITrace. 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: ClassFileBasedOpenerContributor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean collectSourceFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) {
	if (!(editor instanceof XtextEditor) && editor.getEditorInput() != null) {
		try {
			IClassFile classFile = Adapters.adapt(editor, IClassFile.class);
			if (classFile == null) {
				return false;
			}
			ITrace trace = traceForTypeRootProvider.getTraceToSource(classFile);
			if (trace == null) {
				return false;
			}
			for (ILocationInResource location : trace.getAllAssociatedLocations()) {
				String name = location.getAbsoluteResourceURI().getURI().lastSegment();
				IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(name);
				acceptor.accept(createEditorOpener(editor.getEditorInput(), editorDescriptor.getId()));
				return true;
			}
		} catch (PartInitException e) {
			LOG.error(e.getMessage(), e);
		}
	}
	return false;
}
 
Example #2
Source File: XtendTraceTests.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNoEmptyTraces() throws Exception {
	testHelper.createFile("test/Foo.java", 
			"package test;\n"
			+ "public class Foo {\n"
			+ "	public void foo(Object it) {}\n"
			+ "	public void _foo(Object it) {}\n"
			+ "}");
	IFile sourceFile = testHelper.createFile("test/Zar", 
			"package test\n"
			+ "class Bar extends Foo {\n"
			+ "	def dispatch foo(String it) {print(it)}\n"
			+ "}");
	waitForBuild();
	ITrace trace = traceInformation.getTraceToTarget(sourceFile);
	assertNotNull(trace);
	trace.getBestAssociatedLocation(new TextRegion(65, 0));
}
 
Example #3
Source File: CompilerTraceTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertTrace(final String javaCodeWithMarker, String xbaseCodeWithMarker) throws Exception {
	xbaseCodeWithMarker = " " + xbaseCodeWithMarker + " ";
	Matcher xbaseMatcher = p.matcher(xbaseCodeWithMarker);
	assertTrue(xbaseMatcher.matches());
	String xbaseGroup1 = xbaseMatcher.group(1);
	String xbaseGroup2 = xbaseMatcher.group(2);
	String xbaseGroup3 = xbaseMatcher.group(3);
	String actualCode = xbaseGroup1 + xbaseGroup2 + xbaseGroup3; 
	XExpression model = expression(actualCode,true);
	TreeAppendable appendable = new TreeAppendable(new ImportManager(true), converter, locationProvider, jvmModelAssociations, model, "  ", "\n");
	XbaseCompiler compiler = get(XbaseCompiler.class);
	LightweightTypeReference returnType = typeResolver.resolveTypes(model).getReturnType(model);
	if (returnType == null) {
		throw new IllegalStateException();
	}
	compiler.compile(model, appendable, returnType);
	String compiledJavaCode = appendable.getContent();
	Matcher javaMatcher = p.matcher(javaCodeWithMarker);
	assertTrue(javaMatcher.matches());
	String javaGroup1 = javaMatcher.group(1);
	String javaGroup2 = javaMatcher.group(2);
	String javaGroup3 = javaMatcher.group(3);
	String actualExpectation = javaGroup1 + javaGroup2 + javaGroup3;
	assertEquals(actualExpectation, compiledJavaCode);
	ITrace trace = new SimpleTrace(appendable.getTraceRegion());
	ILocationInResource location = trace.getBestAssociatedLocation(new TextRegion(javaGroup1.length(), javaGroup2.length()));
	if (location == null) {
		throw new IllegalStateException("location may not be null");
	}
	assertEquals(new TextRegion(xbaseGroup1.length(), xbaseGroup2.length()), location.getTextRegion());
}
 
Example #4
Source File: JvmOutlineNodeElementOpener.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void openEObject(EObject state) {
	try {
		if (state instanceof JvmIdentifiableElement && state.eResource() instanceof TypeResource) {
			IJavaElement javaElement = javaElementFinder.findElementFor((JvmIdentifiableElement) state);
			if (javaElement instanceof IMember) {
				IResource resource = javaElement.getResource();
				if (resource instanceof IStorage) {
					ITrace traceToSource = traceInformation.getTraceToSource((IStorage) resource);
					if (traceToSource != null) {
						ISourceRange sourceRange = ((IMember) javaElement).getSourceRange();
						ILocationInResource sourceInformation = traceToSource.getBestAssociatedLocation(new TextRegion(sourceRange.getOffset(), sourceRange.getLength()));
						if (sourceInformation != null) {
							globalURIEditorOpener.open(sourceInformation.getAbsoluteResourceURI().getURI(), javaElement, true);
							return;
						}
					}
				}
				globalURIEditorOpener.open(null, javaElement, true);
				return;
			}
		}
	} catch (Exception exc) {
		LOG.error("Error opening java editor", exc);
	}
	super.openEObject(state);
}
 
Example #5
Source File: XbaseResourceForEditorInputFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected URI getClassFileSourceURI(IClassFile classFile) {
	ITrace traceToSource = typeForTypeRootProvider.getTraceToSource(classFile);
	if (traceToSource != null) {
		for (ILocationInResource loc : traceToSource.getAllAssociatedLocations())
			return loc.getAbsoluteResourceURI().getURI();
	}
	return null;
}
 
Example #6
Source File: XbaseEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ILocationInResource getLocationInResource(ITrace traceToSource) {
	if (traceToSource == null) {
		return null;
	}
	for (ILocationInResource locationInResource : traceToSource.getAllAssociatedLocations()) {
		return locationInResource;
	}
	return null;
}
 
Example #7
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 #8
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 #9
Source File: XbaseEditor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected ITrace getTraceStorage() {
	if (typeRoot == null) {
		return null;
	}
	return traceInformation.getTraceToSource(typeRoot);
}
 
Example #10
Source File: DebugSourceInstallingCompilationParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected AbstractTraceRegion findRootTraceRegion(ITrace traceToSource) {
	if (!(traceToSource instanceof AbstractEclipseTrace))
		return null;
	return ((AbstractEclipseTrace) traceToSource).getRootTraceRegion();
}