I wanted to report to the mailing list shortcomings i've found with
semantic with regards to context, analysis and completion of java code.
Below is annotated java code that shows where the problems/issues occur.
The problems in summary are:
a. semantic-get-local-variables and semantic-get-all-local-variables do
not work outside of method blocks. They should, as field declaration
statements can access previously-declared fields; and static blocks are
executable code, so it should work there too. (see comments 1, 2, 15)
b. semantic-current-nonterminal does not handle classes declared within
methods properly, always returning the outer method, instead of the
inner/anonymous class or it's methods (comments 5, 6, 8, 11, 13, 17)
c. perhaps semantic-current-nonterminal should return something to
indicate a static block (comment 3)
d. semantic-get-local-variables returns variables that haven't been
declared yet (comments 4, 7, 9, 12, 14, 16)
e. variables declared in a for statement are not included in
semantic-get-local-variables (comment 5)
f. semantic-end-of-command does not handle anonymous class declaration
statements properly (comment 10).
Here's the code, which compiles in java 1.4.1:
public class Outer {
public int outer1;
//1. get-all-local-variables will not execute here.
// the error is:
// "No context of type function to advance in".
// It should work, and return "outer1", since
// in this context they
// can be used in statements:
String outer2 = outer1 + "foo";
//semantic-current-nonterminal is correct here: Outer.
static {
//2. get locals fails here too.
//3. semantic-current-nonterminal returns "Outer"
// class - should the static block be considered
// a nonterminal?
String sLocal1;
int sLocal2;
}
void outerMethod(final String omArg) {
final int omLocal1 = 0;
//semantic-current-nonterminal correctly returns
//"outerMethod".
//4. semantic-get-local-variables incorrectly returns
// omLocal2, even though it isn't declared yet.
final String omLocal2 = omArg + omLocal1;
for (int forVar = 0 ; forVar < omLocal1 ; forVar ++ ) {
//5. semantic-get-local-variables incorrectly
// omits "forVar" here.
}
class InnerInMethod {
int inner1;
//6. semantic-current-nonterminal incorrectly returns
// "outerMethod" when it should return "InnerInMethod".
//7. semantic-get-local-variables correctly returns
// omArg, omLocal*, and inner1, but again is
// incorrect in returning inner2 as it is not yet
// declared.
String inner2 = omArg +
omLocal1 + omLocal2 +
inner1;
void innerMethod(final String imArg) {
//8. semantic-current-nonterminal again incorrectly
// returns "outerMethod".
final int imLocal1 = 0;
//9. same problem as 6: get-all-locals correctly
// returns omArg, omLocal*, inner*, imArg, and
// imLocal1, but incorrectly includes imLocal2.
final String imLocal2 = omArg +
omLocal1 + omLocal2 +
inner1 + inner2 +
imArg + imLocal1;
new Object()
//10. here, semantic-end-of-command takes you to
// the end of the anon1 declaration below,
// instead of to the end of this "new Object()"
// statement below.
{
int anon1;
//11. current nonterm still "outerMethod"
//12. local vars includes undeclared "anon2"
String anon2 = omArg +
omLocal1 + omLocal2 +
inner1 + inner2 +
imArg +
imLocal1 + imLocal2 +
anon1;
private void anonMethod(String amArg1) {
int amLocal1 = 0;
//13. same nonterminal problem
//14. undeclared amLocal2 from get-locals
String amLocal2 = omArg +
omLocal1 + omLocal2 +
inner1 + inner2 +
imArg +
imLocal1 + imLocal2 +
anon1 + anon2 +
amLocal1;
}
}.toString(); //end of "new Object()" statement
}
}
}
class InnerInClass {
int innerInClass1;
//15. semantic-get-local-variables fails here.
//semantic-current-nonterminal correct: "InnerInClass".
String innerInClass2 = innerInClass1 + "foo";
void innerICMethod(String icmArg) {
int iicLocal1 = 0;
//semantic-current-nonterminal correct: "innerICMethod"
//16. get locals returns undeclared iicLocal2
String iicLocal2 = innerInClass1 + innerInClass2 +
icmArg + iicLocal1;
new Object() { public void foo() {
//17. semantic-current-nonterminal incorrectly returns
// "innerICMethod"
} };
}
}
}
Thanks,
Stuart
--
Stuart Popejoy <stuart@...>
Pink Sheets LLC
|