diff options
author | Milos Kleint | 2010-12-21 14:46:35 +0000 |
---|---|---|
committer | Milos Kleint | 2010-12-21 14:46:55 +0000 |
commit | afebdc190b069187840b3d19386ea11cbfb94700 (patch) | |
tree | c6964b7107d6495eaefbe285ce4a1bb38f1bdd35 /org.eclipse.m2e.editor.xml/src | |
parent | a26b7d98f5a4563be69e21972e25bf39819242c9 (diff) | |
download | m2e-core-afebdc190b069187840b3d19386ea11cbfb94700.tar.gz m2e-core-afebdc190b069187840b3d19386ea11cbfb94700.tar.xz m2e-core-afebdc190b069187840b3d19386ea11cbfb94700.zip |
refactor the <module> hyperlink to work on top of the Node hierarchy
Diffstat (limited to 'org.eclipse.m2e.editor.xml/src')
-rw-r--r-- | org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java | 56 |
1 files changed, 33 insertions, 23 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 cc0d5dc0..d240fdd6 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 @@ -123,6 +123,11 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { if (link != null) { hyperlinks.add(link); } + //check if <module> text is selected. + link = openModule(node, textViewer, offset); + if (link != null) { + hyperlinks.add(link); + } } }); @@ -141,15 +146,6 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { hyperlinks.add(link); } } - //check if <module> text is selected. - //TODO rewrite to use Nodes - fragment = getFragment(text, offset, "<module>", "</module>"); //$NON-NLS-1$ //$NON-NLS-2$ - if (fragment != null) { - IHyperlink link = openModule(fragment, textViewer); - if (link != null) { - hyperlinks.add(link); - } - } if (hyperlinks.size() > 0) { return hyperlinks.toArray(new IHyperlink[0]); } @@ -387,37 +383,54 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { return null; } - private IHyperlink openModule(Fragment fragment, ITextViewer textViewer) { - final Fragment module = getValue(fragment, "<module>", "</module>"); //$NON-NLS-1$ //$NON-NLS-2$ - + private IHyperlink openModule(Node current, ITextViewer textViewer, int offset) { + while (current != null && !( current instanceof Element)) { + current = current.getParentNode(); + } + if (current == null) { + return null; + } + String pathUp = XmlUtils.pathUp(current, 2); + if (! "modules/module".equals(pathUp)) { //$NON-NLS-1$ + //just in case we are in some random plugin configuration snippet.. + return null; + } + ITextFileBuffer buf = FileBuffers.getTextFileBufferManager().getTextFileBuffer(textViewer.getDocument()); + if (buf == null) { + //for repository based poms.. + return null; + } IFileStore folder = buf.getFileStore().getParent(); - String path = module.text; + String path = XmlUtils.getElementTextValue(current); + final String fPath = path; //construct IPath for the child pom file, handle relative paths.. - while(folder != null && path.startsWith("../")) { //NOI18N //$NON-NLS-1$ + while(folder != null && path.startsWith("../")) { //$NON-NLS-1$ folder = folder.getParent(); - path = path.substring("../".length());//NOI18N //$NON-NLS-1$ + path = path.substring("../".length());//$NON-NLS-1$ } if(folder == null) { return null; } IFileStore modulePom = folder.getChild(path); - if(!modulePom.getName().endsWith("xml")) {//NOI18N //$NON-NLS-1$ - modulePom = modulePom.getChild("pom.xml");//NOI18N //$NON-NLS-1$ + if(!modulePom.getName().endsWith("xml")) { //$NON-NLS-1$ + modulePom = modulePom.getChild("pom.xml");//$NON-NLS-1$ } final IFileStore fileStore = modulePom; if (!fileStore.fetchInfo().exists()) { return null; } + assert current instanceof IndexedRegion; + final IndexedRegion region = (IndexedRegion) current; - IHyperlink pomHyperlink = new IHyperlink() { + return new IHyperlink() { public IRegion getHyperlinkRegion() { - return new Region(module.offset, module.length); + return new Region(region.getStartOffset(), region.getEndOffset() - region.getStartOffset()); } public String getHyperlinkText() { - return NLS.bind(Messages.PomHyperlinkDetector_open_module, module.text); + return NLS.bind(Messages.PomHyperlinkDetector_open_module, fPath); } public String getTypeLabel() { @@ -428,9 +441,6 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { openXmlEditor(fileStore); } }; - - return pomHyperlink; - } private IHyperlink openPOMbyID(Fragment fragment, final ITextViewer viewer) { |