【发布时间】:2013-02-21 00:38:46
【问题描述】:
在Java中,是否可以为Java源代码示例生成相应的大括号,给定源代码作为字符串,以及大括号的开头?
public class FindFunctionStartAndEnd{
public static Object findCorrespondingCurlyBrace(String sourceCode, string startingPosition){
//return the string position that corresponds to the matching curly brace
//the input string should be the source code of a Java class
//if sourceCode is not valid Java code, return false
}
}
【问题讨论】:
-
许多 Java IDE(如 Eclipse)在光标位于其中一个大括号前面时突出显示相应的大括号。我很好奇大多数 IDE 将如何实现此功能。
-
@OliCharlesworth 哪个解析器可用于此目的,“他们”是谁?
-
为了正确匹配花括号,我需要找到一种方法来处理字符串文字中的花括号,例如:public static void printStuff(){ System.out。 println("这个方法可能很难解析。}")}
-
这是一个更复杂的问题:stackoverflow.com/q/5497210/422353
-
@AndersonGreen 为什么不看看 Eclipse 的源代码? (虽然我相信代码不会很容易阅读。)
标签: java metaprogramming syntax-highlighting