Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-02-24 03:55:06 -0500
committerMilos Kleint2011-02-24 03:55:06 -0500
commita6b6ea7bf2b707688b2449c8cbe45b750f3e7b72 (patch)
treec384dd068735aebe6608e5a69ec553695c470e01 /org.eclipse.m2e.editor.xml
parent4eea7ec7c6a8f5d3c14b174c3c2970c3cd881651 (diff)
downloadm2e-core-a6b6ea7bf2b707688b2449c8cbe45b750f3e7b72.tar.gz
m2e-core-a6b6ea7bf2b707688b2449c8cbe45b750f3e7b72.tar.xz
m2e-core-a6b6ea7bf2b707688b2449c8cbe45b750f3e7b72.zip
335407 have a hyperlink to parent definition if the cause of the problem resides in the parent
Diffstat (limited to 'org.eclipse.m2e.editor.xml')
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java117
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java29
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java5
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java36
4 files changed, 149 insertions, 38 deletions
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java
index e4544cc8..26f92bee 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java
@@ -16,6 +16,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import org.apache.maven.model.Build;
@@ -37,9 +39,11 @@ import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -47,9 +51,13 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
@@ -60,10 +68,12 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.core.ui.internal.actions.OpenPomAction;
import org.eclipse.m2e.core.ui.internal.actions.OpenPomAction.MavenPathStorageEditorInput;
import org.eclipse.m2e.editor.xml.internal.Messages;
@@ -102,8 +112,15 @@ public class PomHyperlinkDetector implements IHyperlinkDetector {
}
final List<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
final int offset = region.getOffset();
+
XmlUtils.performOnCurrentElement(document, offset, new NodeOperation<Node>() {
public void process(Node node, IStructuredDocument structured) {
+ if (textViewer instanceof ISourceViewer) {
+ IHyperlink[] links = openExternalMarkerDefinition((ISourceViewer)textViewer, offset);
+ if (links.length > 0) {
+ hyperlinks.addAll(Arrays.asList(links));
+ }
+ }
//check if we have a property expression at cursor
IHyperlink link = openPropertyDefinition(node, textViewer, offset);
if (link != null) {
@@ -243,6 +260,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector {
}
return null;
}
+
static InputLocation findLocationForManagedArtifact(final ManagedArtifactRegion region, MavenProject mavprj) {
@@ -366,6 +384,66 @@ public class PomHyperlinkDetector implements IHyperlinkDetector {
}
+
+ static IHyperlink[] openExternalMarkerDefinition(ISourceViewer sourceViewer, int offset) {
+ List<IHyperlink> toRet = new ArrayList<IHyperlink>();
+ MarkerRegion[] regions = findMarkerRegions(sourceViewer, offset);
+ for (MarkerRegion reg : regions) {
+ if (reg.isDefinedInParent()) {
+ toRet.add(createHyperlink(reg));
+ }
+ }
+ return toRet.toArray(new IHyperlink[0]);
+ }
+
+ static MarkerRegion[] findMarkerRegions(ISourceViewer sourceViewer, int offset) {
+ List<MarkerRegion> toRet = new ArrayList<MarkerRegion>();
+ IAnnotationModel model = sourceViewer.getAnnotationModel();
+ if (model != null) { //eg. in tests
+ @SuppressWarnings("unchecked")
+ Iterator<Annotation> it = model.getAnnotationIterator();
+ while (it.hasNext()) {
+ Annotation ann = it.next();
+ if (ann instanceof MarkerAnnotation) {
+ Position pos = sourceViewer.getAnnotationModel().getPosition(ann);
+ if (pos.includes(offset)) {
+ toRet.add(new MarkerRegion(pos.getOffset(), pos.getLength(), (MarkerAnnotation) ann));
+ }
+ }
+ }
+ }
+ return toRet.toArray(new MarkerRegion[0]);
+ }
+
+ public static IHyperlink createHyperlink(final MarkerRegion mark) {
+ return new IHyperlink() {
+
+ public IRegion getHyperlinkRegion() {
+ return new Region(mark.getOffset(), mark.getLength());
+ }
+
+ public String getTypeLabel() {
+ return "marker-error-defined-in-parent"; //$NON-NLS-1$;
+ }
+
+ public String getHyperlinkText() {
+ return NLS.bind("Open definition in parent for {0}", mark.getAnnotation().getText()); //TODO if there are multiple markers in one spot, how to differenciate better..
+ }
+
+ public void open() {
+ IMarker marker = mark.getAnnotation().getMarker();
+ String loc = marker.getAttribute(IMavenConstants.MARKER_CAUSE_RESOURCE_PATH, null);
+ if (loc != null) {
+ IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(loc));
+ int row = marker.getAttribute(IMavenConstants.MARKER_CAUSE_LINE_NUMBER, 0);
+ int column = marker.getAttribute(IMavenConstants.MARKER_CAUSE_COLUMN_START, 0);
+ String name = marker.getAttribute(IMavenConstants.MARKER_CAUSE_RESOURCE_ID, null);
+ openXmlEditor(fileStore, row, column, name);
+ }
+ }
+ };
+ }
+
private IHyperlink openPropertyDefinition(Node current, ITextViewer viewer, int offset) {
final ExpressionRegion region = findExpressionRegion(current, viewer, offset);
if (region != null) {
@@ -433,6 +511,8 @@ public class PomHyperlinkDetector implements IHyperlinkDetector {
}
};
}
+
+
private IHyperlink openPOMbyID(Node current, final ITextViewer viewer, int offset) {
while (current != null && !( current instanceof Element)) {
@@ -670,6 +750,43 @@ public class PomHyperlinkDetector implements IHyperlinkDetector {
return offset;
}
}
+
+ public static class MarkerRegion implements IRegion {
+
+ private final MarkerAnnotation ann;
+ final int offset;
+ final int length;
+
+ public MarkerRegion(int offset, int length, MarkerAnnotation applicable) {
+ this.offset = offset;
+ this.length = length;
+ this.ann = applicable;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public int getOffset() {
+ return offset;
+ }
+
+ public MarkerAnnotation getAnnotation() {
+ return ann;
+ }
+
+ public boolean isDefinedInParent() {
+ IMarker mark = ann.getMarker();
+ String isElsewhere = mark.getAttribute(IMavenConstants.MARKER_CAUSE_RESOURCE_PATH, null);
+ if (isElsewhere != null) {
+ return true;
+ }
+ return false;
+ }
+
+ }
+
+
}
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java
index 6c7b8442..6c2c839e 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java
@@ -170,7 +170,7 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover
if (ann instanceof MarkerAnnotation) {
Position pos = sourceViewer.getAnnotationModel().getPosition(ann);
if (pos.includes(offset)) {
- toRet.addRegion( new MarkerRegion(pos.getOffset(), pos.getLength(), (MarkerAnnotation)ann));
+ toRet.addRegion( new PomHyperlinkDetector.MarkerRegion(pos.getOffset(), pos.getLength(), (MarkerAnnotation)ann));
}
}
}
@@ -192,33 +192,6 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover
};
}
-
- public static class MarkerRegion implements IRegion {
-
- private final MarkerAnnotation ann;
- final int offset;
- final int length;
-
- public MarkerRegion(int offset, int length, MarkerAnnotation applicable) {
- this.offset = offset;
- this.length = length;
- this.ann = applicable;
- }
-
- public int getLength() {
- return length;
- }
-
- public int getOffset() {
- return offset;
- }
-
- public MarkerAnnotation getAnnotation() {
- return ann;
- }
-
- }
-
public static class CompoundRegion implements IRegion {
private int length = Integer.MIN_VALUE;
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java
index 21627141..32290ea8 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java
@@ -33,8 +33,9 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.texteditor.MarkerAnnotation;
+import org.eclipse.m2e.editor.xml.PomHyperlinkDetector;
+import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.MarkerRegion;
import org.eclipse.m2e.editor.xml.PomTextHover;
-import org.eclipse.m2e.editor.xml.PomTextHover.MarkerRegion;
public final class FormHoverProvider {
@@ -50,7 +51,7 @@ public final class FormHoverProvider {
if (ann instanceof MarkerAnnotation) {
MarkerAnnotation mann = (MarkerAnnotation) ann;
if (markersSet.contains(mann.getMarker()));
- compound.addRegion(new MarkerRegion(0, 0, mann));
+ compound.addRegion(new PomHyperlinkDetector.MarkerRegion(0, 0, mann));
}
}
final MarkerHoverControl mhc = new MarkerHoverControl(parentShell);
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java
index 2bebfe47..9bd24770 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java
@@ -64,12 +64,13 @@ import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
+import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.editor.xml.PomHyperlinkDetector;
import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.ExpressionRegion;
import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.ManagedArtifactRegion;
+import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.MarkerRegion;
import org.eclipse.m2e.editor.xml.PomTextHover;
import org.eclipse.m2e.editor.xml.PomTextHover.CompoundRegion;
-import org.eclipse.m2e.editor.xml.PomTextHover.MarkerRegion;
public class MarkerHoverControl extends AbstractInformationControl implements IInformationControlExtension2, IInformationControlExtension3, IInformationControlExtension5 {
@@ -193,9 +194,10 @@ public class MarkerHoverControl extends AbstractInformationControl implements II
for (IRegion reg : region.getRegions()) {
- if (reg instanceof MarkerRegion) {
- createAnnotationInformation(composite, ((MarkerRegion)reg).getAnnotation());
- IMarker mark = ((MarkerRegion)reg).getAnnotation().getMarker();
+ if (reg instanceof PomHyperlinkDetector.MarkerRegion) {
+ final PomHyperlinkDetector.MarkerRegion markerReg = (PomHyperlinkDetector.MarkerRegion) reg;
+ createAnnotationInformation(composite, markerReg);
+ final IMarker mark = markerReg.getAnnotation().getMarker();
IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(mark);
if (resolutions.length > 0) {
createResolutionsControl(composite, mark, resolutions);
@@ -290,7 +292,7 @@ public class MarkerHoverControl extends AbstractInformationControl implements II
}
}
- private void createAnnotationInformation(Composite parent, final Annotation annotation) {
+ private void createAnnotationInformation(Composite parent, final MarkerRegion annotation) {
Composite composite= new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
GridLayout layout= new GridLayout(2, false);
@@ -308,7 +310,7 @@ public class MarkerHoverControl extends AbstractInformationControl implements II
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.setFont(null);
- markerAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
+ markerAccess.paint(annotation.getAnnotation(), e.gc, canvas, new Rectangle(0, 0, 16, 16));
}
});
@@ -316,9 +318,27 @@ public class MarkerHoverControl extends AbstractInformationControl implements II
StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
text.setLayoutData(data);
- String annotationText = annotation.getText();
- if (annotationText != null)
+ String annotationText = annotation.getAnnotation().getText();
+ if (annotationText != null) {
text.setText(annotationText);
+ }
+ if (annotation.isDefinedInParent()) {
+ new Label(composite, SWT.NONE);
+
+ Link link = new Link(composite, SWT.NONE);
+ GridData data2 = new GridData(SWT.FILL, SWT.FILL, true, true);
+ data2.horizontalIndent = 18;
+ link.setLayoutData(data2);
+ link.setText("<a>Jump to definition in parent POM</a>");
+ link.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ PomHyperlinkDetector.createHyperlink(annotation).open();
+ dispose();
+ }
+ });
+ }
+
}
private void createSeparator(Composite parent) {

Back to the top