|
From: <caw...@us...> - 2007-07-02 17:26:06
|
Revision: 2708
http://svn.sourceforge.net/rubyeclipse/?rev=2708&view=rev
Author: cawilliams
Date: 2007-07-02 10:25:57 -0700 (Mon, 02 Jul 2007)
Log Message:
-----------
avoid some exceptions
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java 2007-07-01 16:05:37 UTC (rev 2707)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java 2007-07-02 17:25:57 UTC (rev 2708)
@@ -93,6 +93,7 @@
RubyPlugin.log(e);
continue;
}
+ if (position == null) continue;
int startPosition= position.getStartOffset();
if (startPosition < 0) continue;
int length= position.getEndOffset() - position.getStartOffset();
@@ -217,6 +218,7 @@
for (Node node : fUsages) {
try {
ISourcePosition occurrence = getPositionOfName(node);
+ if (occurrence == null) continue;
Position position = new Position(occurrence.getStartOffset(), occurrence.getEndOffset() - occurrence.getStartOffset());
positions.add(position);
} catch (RuntimeException re) {
@@ -674,13 +676,21 @@
name = ASTUtil.getNameReflectively(node);
} else if (node instanceof ClassNode) {
name = getClassNodeName((ClassNode) node);
- String classDeclString = source.substring(pos.getStartOffset(), pos.getEndOffset());
- int begin = pos.getStartOffset() + classDeclString.indexOf(name);
+ int end = pos.getEndOffset();
+ if (source.length() < end) end = source.length();
+ String classDeclString = source.substring(pos.getStartOffset(), end);
+ int nameEnd = classDeclString.indexOf(name);
+ if (nameEnd == -1) return null;
+ int begin = pos.getStartOffset() + nameEnd;
return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), begin, begin + name.length());
} else if (node instanceof ModuleNode) {
name = getModuleNodeName((ModuleNode) node);
- String moduleDeclString = source.substring(pos.getStartOffset(), pos.getEndOffset());
- int begin = moduleDeclString.indexOf(name);
+ int end = pos.getEndOffset();
+ if (source.length() < end) end = source.length();
+ String classDeclString = source.substring(pos.getStartOffset(), end);
+ int nameEnd = classDeclString.indexOf(name);
+ if (nameEnd == -1) return null;
+ int begin = pos.getStartOffset() + nameEnd;
return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), begin, begin + name.length());
} else if (node instanceof SymbolNode) {
// XXX: This is a hack to get around improper offsets in my JRuby
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|