1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 268604, hyperlinks for overloaded operators

This commit is contained in:
Mike Kucera 2009-03-17 15:19:58 +00:00
parent 0abd280a88
commit 2a023a46e0
2 changed files with 22 additions and 8 deletions

View file

@ -50,11 +50,13 @@ public class HyperlinkTest extends TestCase {
" void set(int x, int y); \n" +
" int getX(); \n" +
" int getY(); \n" +
" Point operator+(Point); \n" +
" private: \n" +
" int x, y; \n" +
"}; \n" +
"int main() { \n" +
"int test(Point p) { \n" +
" char* str = \"STRING LITERAL\"; \n" +
" p + p;" +
"} \n";
@ -172,6 +174,9 @@ public class HyperlinkTest extends TestCase {
assertHyperlink(CPP_CODE.indexOf("set(") + 1, CPP_CODE.indexOf("set("), "set".length());
assertHyperlink(CPP_CODE.indexOf("getX()") + 1, CPP_CODE.indexOf("getX()"), "getX".length());
assertHyperlink(CPP_CODE.indexOf("getY()") + 1, CPP_CODE.indexOf("getY()"), "getY".length());
// hyperlinks for overloaded operators
assertHyperlink(CPP_CODE.indexOf("+ p"), CPP_CODE.indexOf("+ p"), 1);
}
@ -180,6 +185,9 @@ public class HyperlinkTest extends TestCase {
// 'class' is not a keyword in C, it should be hyperlinked
assertHyperlink(C_CODE_1.indexOf("class") + 1, C_CODE_1.indexOf("class"), "class".length());
// no hyperlinks for numeric literals
assertNotHyperlink(C_CODE_1.indexOf("99") + 1);
}

View file

@ -91,10 +91,16 @@ public class CElementHyperlinkDetector extends AbstractHyperlinkDetector {
}
}
else {
// search for include statement
final IASTNode cand= nodeSelector.findEnclosingNode(offset, length);
if (cand instanceof IASTPreprocessorIncludeStatement) {
linkLocation= cand.getFileLocation();
final IASTNode implicit = nodeSelector.findEnclosingImplicitName(offset, length);
if(implicit != null) {
linkLocation = implicit.getFileLocation();
}
else {
// search for include statement
final IASTNode cand= nodeSelector.findEnclosingNode(offset, length);
if (cand instanceof IASTPreprocessorIncludeStatement) {
linkLocation= cand.getFileLocation();
}
}
}
if (linkLocation != null) {
@ -106,13 +112,13 @@ public class CElementHyperlinkDetector extends AbstractHyperlinkDetector {
IRegion wordRegion= CWordFinder.findWord(document, offset);
if (wordRegion != null) {
try {
String word= document.get(wordRegion.getOffset(), wordRegion.getLength());
if (!isLanguageKeyword(lang, word)) {
String word = document.get(wordRegion.getOffset(), wordRegion.getLength());
if(word.length() > 0 && !Character.isDigit(word.charAt(0)) && !isLanguageKeyword(lang, word)) {
result[0]= new CElementHyperlink(
new Region(wordRegion.getOffset(), wordRegion.getLength()), openAction);
}
} catch (BadLocationException exc) {
// ingore
// ignore
}
}
}