From 3bf6639e4b5348cc436c1fcb45529417972f304f Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 14 Jan 2011 02:42:04 +0000 Subject: [PATCH] Bug 333050 - Hyperlinks don't work inside macros --- .../org/eclipse/cdt/ui/tests/text/HyperlinkTest.java | 8 ++++---- .../internal/ui/editor/CElementHyperlinkDetector.java | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/HyperlinkTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/HyperlinkTest.java index 32eaf4cddaa..de95ef4015a 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/HyperlinkTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/HyperlinkTest.java @@ -160,8 +160,8 @@ public class HyperlinkTest extends TestCase { assertNotHyperlink(CPP_CODE.indexOf("#define") + 1); assertHyperlink(CPP_CODE.indexOf("SOMEMACRO"), CPP_CODE.indexOf("SOMEMACRO"), "SOMEMACRO".length()); // see bug 259015 -// assertNotHyperlink(CPP_CODE.indexOf("macro_token1") + 1); -// assertNotHyperlink(CPP_CODE.indexOf("macro_token2") + 1); + assertHyperlink(CPP_CODE.indexOf("macro_token1"), CPP_CODE.indexOf("macro_token1"), "macro_token1".length()); + assertHyperlink(CPP_CODE.indexOf("macro_token2"), CPP_CODE.indexOf("macro_token2"), "macro_token2".length()); // no hyperlinks for comments assertNotHyperlink(CPP_CODE.indexOf("//") + 1); @@ -214,8 +214,8 @@ public class HyperlinkTest extends TestCase { assertNotHyperlink(CPP_CODE.indexOf("#define") + 1); assertHyperlink(CPP_CODE.indexOf("SOMEMACRO"), CPP_CODE.indexOf("SOMEMACRO"), "SOMEMACRO".length()); // see bug 259015 -// assertNotHyperlink(CPP_CODE.indexOf("macro_token1") + 1); -// assertNotHyperlink(CPP_CODE.indexOf("macro_token2") + 1); + assertHyperlink(CPP_CODE.indexOf("macro_token1"), CPP_CODE.indexOf("macro_token1"), "macro_token1".length()); + assertHyperlink(CPP_CODE.indexOf("macro_token2"), CPP_CODE.indexOf("macro_token2"), "macro_token2".length()); // no hyperlinks for comments assertNotHyperlink(CPP_CODE.indexOf("//") + 1); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java index c7fdc82727c..ea4d0efbd6f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java @@ -96,15 +96,20 @@ public class CElementHyperlinkDetector extends AbstractHyperlinkDetector { } } } - if (linkLocation != null) { - hyperlinkRegion[0] = new Region(linkLocation.getNodeOffset(), linkLocation.getNodeLength()); + if (linkLocation == null) { + // Consider a fallback way of finding the hyperlink + // (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=333050). + return Status.CANCEL_STATUS; } + + hyperlinkRegion[0] = new Region(linkLocation.getNodeOffset(), linkLocation.getNodeLength()); return Status.OK_STATUS; } }); if (status == Status.CANCEL_STATUS) { - // AST is not available yet, try to compute the hyperlink without it. + // AST was not available yet or didn't help us to find the hyperlink, try to compute + // the hyperlink without it. try { // Check partition type. String partitionType= TextUtilities.getContentType(document, ICPartitions.C_PARTITIONING, region.getOffset(), false);