Search in sources :

Example 6 with ILocationInEclipseResource

use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.

the class DerivedResourceMarkerCopier method copyProblemMarker.

private void copyProblemMarker(IFile javaFile, IEclipseTrace traceToSource, Set<IMarker> problemsInJava, IFile srcFile) throws CoreException {
    String sourceMarkerType = null;
    for (IMarker marker : problemsInJava) {
        String message = (String) marker.getAttribute(IMarker.MESSAGE);
        if (message == null) {
            continue;
        }
        Integer charStart = marker.getAttribute(IMarker.CHAR_START, 0);
        Integer charEnd = marker.getAttribute(IMarker.CHAR_END, 0);
        int severity = MarkerUtilities.getSeverity(marker);
        ILocationInEclipseResource associatedLocation = traceToSource.getBestAssociatedLocation(new TextRegion(charStart, charEnd - charStart));
        if (associatedLocation != null) {
            if (sourceMarkerType == null) {
                sourceMarkerType = determinateMarkerTypeByURI(associatedLocation.getSrcRelativeResourceURI());
            }
            if (!srcFile.equals(findIFile(associatedLocation, srcFile.getWorkspace()))) {
                LOG.error("File in associated location is not the same as main source file.");
            }
            IMarker xtendMarker = srcFile.createMarker(sourceMarkerType);
            xtendMarker.setAttribute(IMarker.MESSAGE, "Java problem: " + message);
            xtendMarker.setAttribute(IMarker.SEVERITY, severity);
            ITextRegionWithLineInformation region = associatedLocation.getTextRegion();
            xtendMarker.setAttribute(IMarker.LINE_NUMBER, region.getLineNumber());
            xtendMarker.setAttribute(IMarker.CHAR_START, region.getOffset());
            xtendMarker.setAttribute(IMarker.CHAR_END, region.getOffset() + region.getLength());
            xtendMarker.setAttribute(COPIED_FROM_FILE, javaFile.getFullPath().toString());
        }
    }
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) IMarker(org.eclipse.core.resources.IMarker)

Example 7 with ILocationInEclipseResource

use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.

the class JavaBreakPointProvider method getJavaLineNumber.

private int getJavaLineNumber(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
    ILocationInEclipseResource javaLocation = getJavaLocation(breakpoint);
    if (javaLocation == null)
        return -1;
    IStorage storage = javaLocation.getPlatformResource();
    if (storage == null) {
        ITextRegionWithLineInformation textRegion = javaLocation.getTextRegion();
        if (textRegion == null)
            return -1;
        return textRegion.getEndLineNumber();
    } else {
        AbstractEclipseTrace sourceTrace = (AbstractEclipseTrace) traceForStorageProvider.getTraceToSource(storage);
        if (sourceTrace == null)
            return -1;
        AbstractTraceRegion rootTraceRegion = sourceTrace.getRootTraceRegion();
        if (rootTraceRegion == null)
            return -1;
        List<LineMapping> lineMappings = lineMappingProvider.getLineMapping(rootTraceRegion);
        if (lineMappings == null) {
            return -1;
        }
        for (LineMapping lineMapping : lineMappings) {
            if (lineMapping.sourceStartLine == breakpoint.getLineNumber()) {
                return lineMapping.targetEndLine + 1;
            }
        }
        return -1;
    }
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) IStorage(org.eclipse.core.resources.IStorage) AbstractEclipseTrace(org.eclipse.xtext.ui.generator.trace.AbstractEclipseTrace) LineMapping(org.eclipse.xtext.generator.trace.LineMappingProvider.LineMapping)

Example 8 with ILocationInEclipseResource

use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.

the class JavaBreakPointProvider method getHandleId.

private String getHandleId(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
    IClassFile classFile = getClassFile(breakpoint);
    if (classFile != null)
        return classFile.getType().getHandleIdentifier();
    ILocationInEclipseResource javaLocation = getJavaLocation(breakpoint);
    if (javaLocation == null)
        return null;
    IStorage javaResource = javaLocation.getPlatformResource();
    if (!(javaResource instanceof IFile))
        return null;
    ICompilationUnit compilationUnit = (ICompilationUnit) JavaCore.create((IFile) javaResource);
    IJavaElement element = compilationUnit.getElementAt(javaLocation.getTextRegion().getOffset());
    return element == null ? null : element.getHandleIdentifier();
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) IClassFile(org.eclipse.jdt.core.IClassFile) IFile(org.eclipse.core.resources.IFile) IStorage(org.eclipse.core.resources.IStorage)

Aggregations

ILocationInEclipseResource (org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource)8 IStorage (org.eclipse.core.resources.IStorage)4 IFile (org.eclipse.core.resources.IFile)3 IEclipseTrace (org.eclipse.xtext.ui.generator.trace.IEclipseTrace)3 TextRegion (org.eclipse.xtext.util.TextRegion)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CoreException (org.eclipse.core.runtime.CoreException)2 IClassFile (org.eclipse.jdt.core.IClassFile)2 ITextRegionWithLineInformation (org.eclipse.xtext.util.ITextRegionWithLineInformation)2 Function (com.google.common.base.Function)1 WrappedRuntimeException (org.eclipse.core.internal.utils.WrappedRuntimeException)1 IMarker (org.eclipse.core.resources.IMarker)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 URI (org.eclipse.emf.common.util.URI)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IClassFileEditorInput (org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput)1