Skip to content

Commit cb78349

Browse files
committed
Fixed regex to search for methods
1 parent c8015e4 commit cb78349

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

plugins/sources/src/org/graalvm/visualvm/sources/java/JavaMethod.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,16 @@ private static JavaMethod findMethod(String methodName, String modelName, String
185185

186186
// Search for method declaration
187187
if (endMatcher.find(offset)) {
188-
if (offset == endMatcher.start()) {
189-
offset = endMatcher.end() - 1;
190-
if (offset > bodyEnd) return null;
191-
192-
if (withoutBody && ';' == source.charAt(offset)) return new JavaMethod(methodName, methodSignature, source, nameStart, -1, -1); // NOI18N
188+
offset = endMatcher.end() - 1;
189+
if (offset > bodyEnd) return null;
193190

194-
// Search for method body
195-
int[] bodyOffsets = JavaSourceUtils.getBlockBounds(source, offset, '{', '}'); // NOI18N
196-
if (bodyOffsets[0] == -1 || bodyOffsets[1] == -1 || bodyOffsets[1] > bodyEnd) return null;
191+
if (withoutBody && ';' == source.charAt(offset)) return new JavaMethod(methodName, methodSignature, source, nameStart, -1, -1); // NOI18N
197192

198-
return new JavaMethod(modelName, methodSignature, source, nameStart, bodyOffsets[0], bodyOffsets[1]); // NOI18N
199-
}
193+
// Search for method body
194+
int[] bodyOffsets = JavaSourceUtils.getBlockBounds(source, offset, '{', '}'); // NOI18N
195+
if (bodyOffsets[0] == -1 || bodyOffsets[1] == -1 || bodyOffsets[1] > bodyEnd) return null;
196+
197+
return new JavaMethod(modelName, methodSignature, source, nameStart, bodyOffsets[0], bodyOffsets[1]); // NOI18N
200198
}
201199
}
202200

plugins/sources/src/org/graalvm/visualvm/sources/java/JavaSourceUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ final class JavaSourceUtils {
6161
static final String INSTANCE_INITIALIZER_REGEX = "[\\{\\};]\\s*\\{"; // NOI18N
6262

6363
static final String DEFINED_METHOD_WITHBODY_START_REGEX = "(?<" + REGEX_GROUP_PREFIX + ">[\\s\\>])" + REGEX_PARAMETER_0 + "\\s*\\("; // NOI18N
64-
static final String DEFINED_METHOD_WITHBODY_END_REGEX = "\\s*(" + THROWS_REGEX + ")??\\s*\\{"; // NOI18N
64+
static final String DEFINED_METHOD_WITHBODY_END_REGEX = "\\G\\s*(" + THROWS_REGEX + ")??\\s*\\{"; // NOI18N
6565
/* TODO: review */ static final String DEFINED_METHOD_WITHOUTBODY_START_REGEX = "(?<" + REGEX_GROUP_PREFIX + ">\\Wnative[\\s\\S&&[^;]&&[^\\(]]*?[\\s\\>])" + REGEX_PARAMETER_0 + "\\s*\\("; // NOI18N
66-
static final String DEFINED_METHOD_WITHOUTBODY_END_REGEX = "\\s*(" + THROWS_REGEX + ")??\\s*;"; // NOI18N
66+
static final String DEFINED_METHOD_WITHOUTBODY_END_REGEX = "\\G\\s*(" + THROWS_REGEX + ")??\\s*;"; // NOI18N
6767

6868

6969
private JavaSourceUtils() {}

0 commit comments

Comments
 (0)