Source Code Cross Referenced for JavaUnitTests.java in  » Parser » Rats-Parser-Generators » xtc » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Parser » Rats Parser Generators » xtc.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * xtc - The eXTensible Compiler
0003:         * Copyright (C) 2005-2007 IBM Corp.
0004:         *
0005:         * This program is free software; you can redistribute it and/or
0006:         * modify it under the terms of the GNU General Public License
0007:         * version 2 as published by the Free Software Foundation.
0008:         *
0009:         * This program is distributed in the hope that it will be useful,
0010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012:         * GNU General Public License for more details.
0013:         *
0014:         * You should have received a copy of the GNU General Public License
0015:         * along with this program; if not, write to the Free Software
0016:         * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
0017:         * USA.
0018:         */
0019:        package xtc.lang;
0020:
0021:        import java.io.CharArrayWriter;
0022:        import java.io.File;
0023:        import java.io.FileWriter;
0024:        import java.io.IOException;
0025:        import java.io.OutputStream;
0026:        import java.io.StringReader;
0027:        import java.io.StringWriter;
0028:        import java.io.Writer;
0029:        import java.lang.reflect.Method;
0030:        import java.math.BigInteger;
0031:        import java.util.ArrayList;
0032:        import java.util.List;
0033:        import java.util.Set;
0034:
0035:        import junit.framework.Test;
0036:        import junit.framework.TestCase;
0037:        import junit.framework.TestSuite;
0038:        import xtc.Constants;
0039:        import xtc.parser.ParseException;
0040:        import xtc.parser.Result;
0041:        import xtc.tree.GNode;
0042:        import xtc.tree.Node;
0043:        import xtc.tree.Printer;
0044:        import xtc.type.AliasT;
0045:        import xtc.type.AnnotatedT;
0046:        import xtc.type.ClassT;
0047:        import xtc.type.InterfaceT;
0048:        import xtc.type.PackageT;
0049:        import xtc.type.Type;
0050:        import xtc.util.Runtime;
0051:        import xtc.util.SymbolTable;
0052:
0053:        /**
0054:         * JUnit tests for Java-related classes in package xtc.lang.
0055:         * 
0056:         * This class is a good place to quickly try a method on some simple
0057:         * inputs. The test cases also document how to use certain API and
0058:         * what it does.
0059:         * 
0060:         * To run from the console, set your CLASSPATH to include
0061:         * $JAVA_DEV_ROOT/classes and junit.jar, then run
0062:         * 
0063:         *   java -ea junit.textui.TestRunner xtc.lang.JavaUnitTests
0064:         *
0065:         * Or, to run from within eclipse, Run -> Run ... -> JUnit -> New, and
0066:         * specify xtc.lang.JavaUnitTests.
0067:         * 
0068:         * @author Martin Hirzel
0069:         * @version $Revision: 1.36 $
0070:         */
0071:        public final class JavaUnitTests extends TestCase {
0072:            public static abstract class IgnorableTest extends TestCase {
0073:                private final boolean _ignore;
0074:                private final StackTraceElement _location;
0075:
0076:                public IgnorableTest(final boolean ignore) {
0077:                    _ignore = ignore;
0078:                    _location = ignore ? null
0079:                            : new Throwable().getStackTrace()[2];
0080:                }
0081:
0082:                public final void runTest() throws Throwable {
0083:                    if (_ignore && IGNORE_MEANS_SKIP)
0084:                        return;
0085:                    try {
0086:                        runTestIgnorable();
0087:                    } catch (final Throwable t) {
0088:                        if (_ignore)
0089:                            return;
0090:                        final StackTraceElement[] oldTrace = t.getStackTrace();
0091:                        final StackTraceElement[] newTrace = new StackTraceElement[1 + oldTrace.length];
0092:                        newTrace[0] = _location;
0093:                        System.arraycopy(oldTrace, 0, newTrace, 1,
0094:                                oldTrace.length);
0095:                        t.setStackTrace(newTrace);
0096:                        throw t;
0097:                    }
0098:                }
0099:
0100:                public abstract void runTestIgnorable() throws Throwable;
0101:            }
0102:
0103:            static class JavaAnalyzerTestConstant extends IgnorableTest {
0104:                private final Object _expected;
0105:                private final String _input;
0106:
0107:                JavaAnalyzerTestConstant(final boolean ignore,
0108:                        final String input, final Object expected) {
0109:                    super (ignore);
0110:                    _expected = expected;
0111:                    _input = input;
0112:                }
0113:
0114:                public void runTestIgnorable() throws Throwable {
0115:                    final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(),
0116:                            new SymbolTable());
0117:                    enterPackageFile(ana._table, "", "<input>");
0118:                    javaAnalyzerTestConstant(_input, _expected, ana);
0119:                }
0120:            }
0121:
0122:            static class JavaAnalyzerTestError extends IgnorableTest {
0123:                private final String _expected;
0124:                private final String _input;
0125:                private final String _production;
0126:                private final List<TempFile> _tempFiles;
0127:
0128:                JavaAnalyzerTestError(final boolean ignore,
0129:                        final String production, final String input,
0130:                        final String expected) {
0131:                    //      this(ignore, production, input, expected, new ArrayList<TempFile>());
0132:                    super (ignore);
0133:                    _production = production;
0134:                    _input = input;
0135:                    _expected = expected;
0136:                    _tempFiles = new ArrayList<TempFile>();
0137:                }
0138:
0139:                JavaAnalyzerTestError(final boolean ignore,
0140:                        final String production, final String input,
0141:                        final String expected, final List<TempFile> tempFiles) {
0142:                    super (ignore);
0143:                    _production = production;
0144:                    _input = input;
0145:                    _expected = expected;
0146:                    _tempFiles = tempFiles;
0147:                }
0148:
0149:                public void runTestIgnorable() throws Throwable {
0150:                    try {
0151:                        TempFile.create(_tempFiles, TEMP_DIR);
0152:                        javaAnalyzerTestError(_production, _input, _expected);
0153:                    } finally {
0154:                        TempFile.delete(_tempFiles, TEMP_DIR);
0155:                    }
0156:                }
0157:            }
0158:
0159:            static class JavaExternalAnalyzerTest extends IgnorableTest {
0160:                private final String _expected;
0161:                private final String _input;
0162:                private final String _production;
0163:                private final boolean _withType;
0164:
0165:                JavaExternalAnalyzerTest(final boolean ignore,
0166:                        final String production, final boolean withType,
0167:                        final String input, final String expected) {
0168:                    super (ignore);
0169:                    _expected = expected;
0170:                    _input = input;
0171:                    _production = production;
0172:                    _withType = withType;
0173:                }
0174:
0175:                JavaExternalAnalyzerTest(final boolean ignore,
0176:                        final String production, final String input) {
0177:                    this (ignore, production, false, input, input);
0178:                }
0179:
0180:                public void runTestIgnorable() throws Throwable {
0181:                    final JavaExternalAnalyzer ana = newJavaExternalAnalyzer();
0182:                    enterPackageFile(ana._table, "", "<input>");
0183:                    if (_withType) {
0184:                        final ClassT t = new ClassT("Z", JavaEntities
0185:                                .tObjectAlias(ana._table),
0186:                                new ArrayList<Type>(), new ArrayList<Type>(),
0187:                                new ArrayList<Type>());
0188:                        ana._table.current().define("tag(Z)", t);
0189:                        ana._table.enter("Z");
0190:                    }
0191:                    final GNode ast = JavaEntities.javaStringToAst(_production,
0192:                            _input, true);
0193:                    final Object dispatched = ana.dispatch(ast);
0194:                    final String result = JavaEntities.typeDeclString(
0195:                            ana._table, dispatched);
0196:                    assertEquals(contractSpace(_expected),
0197:                            contractSpace(result));
0198:                }
0199:            }
0200:
0201:            static class JavaParserTest extends IgnorableTest {
0202:                private final String _expected;
0203:                private final String _input;
0204:                private final String _production;
0205:
0206:                JavaParserTest(final boolean ignore, final String production,
0207:                        final String input) {
0208:                    super (ignore);
0209:                    _expected = _input = input;
0210:                    _production = production;
0211:                }
0212:
0213:                JavaParserTest(final boolean ignore, final String production,
0214:                        final String input, final String expected) {
0215:                    super (ignore);
0216:                    _expected = expected;
0217:                    _input = input;
0218:                    _production = production;
0219:                }
0220:
0221:                public void runTestIgnorable() throws Exception {
0222:                    javaParserTestRoundTrip(_production, _input, _expected,
0223:                            false);
0224:                    javaParserTestRoundTrip(_production, _input, _expected,
0225:                            true);
0226:                }
0227:            }
0228:
0229:            static class TempFile {
0230:                static List<TempFile> cons(final String contents1,
0231:                        final String path1, final List<TempFile> list) {
0232:                    assertFalse(path1.contains("."));
0233:                    final List<TempFile> result = null == list ? new ArrayList<TempFile>()
0234:                            : list;
0235:                    result.add(new TempFile(contents1, path1 + ".java"));
0236:                    return result;
0237:                }
0238:
0239:                static List<TempFile> cons(final String contents1,
0240:                        final String path11, final String path12,
0241:                        final List<TempFile> list) {
0242:                    return cons(contents1, path11 + File.separator + path12,
0243:                            list);
0244:                }
0245:
0246:                static List<TempFile> cons(final String contents1,
0247:                        final String path11, final String path12,
0248:                        final String path13, final List<TempFile> list) {
0249:                    return cons(contents1, path11 + File.separator + path12
0250:                            + File.separator + path13, list);
0251:                }
0252:
0253:                static void create(final List<TempFile> tempFiles,
0254:                        final File tempDir) throws IOException {
0255:                    for (final TempFile tf : tempFiles)
0256:                        createTempFile(tempDir, tf._path, tf._contents);
0257:                }
0258:
0259:                static void delete(final List<TempFile> tempFiles,
0260:                        final File tempDir) {
0261:                    for (final TempFile tf : tempFiles)
0262:                        new File(tempDir, tf._path).delete();
0263:                }
0264:
0265:                private final String _contents;
0266:                private final String _path;
0267:
0268:                TempFile(final String contents, final String path) {
0269:                    _contents = contents;
0270:                    _path = path;
0271:                }
0272:            }
0273:
0274:            public static class WriterOutputStream extends OutputStream {
0275:                final Writer _writer;
0276:
0277:                public WriterOutputStream(final Writer writer) {
0278:                    _writer = writer;
0279:                }
0280:
0281:                public final void write(final int b) throws IOException {
0282:                    _writer.write(b);
0283:                }
0284:            }
0285:
0286:            public static final boolean IGNORE_MEANS_SKIP = true;
0287:
0288:            public static final File TEMP_DIR = new File("/tmp");
0289:
0290:            public static String cAstToString(final Node ast) {
0291:                final CharArrayWriter writer = new CharArrayWriter();
0292:                final CPrinter printer = new CPrinter(new Printer(writer));
0293:                printer.dispatch(ast);
0294:                return writer.toString();
0295:            }
0296:
0297:            public static String contractSpace(final String string) {
0298:                final StringBuffer result = new StringBuffer();
0299:                char prevChar = '-';
0300:                boolean sawSpace = false;
0301:                for (int i = 0, n = string.length(); i < n; i++) {
0302:                    final char currChar = string.charAt(i);
0303:                    if (Character.isWhitespace(currChar)) {
0304:                        sawSpace = true;
0305:                    } else {
0306:                        if (sawSpace) {
0307:                            if (Character.isJavaIdentifierPart(prevChar)
0308:                                    && Character.isJavaIdentifierPart(currChar))
0309:                                result.append(' ');
0310:                            sawSpace = false;
0311:                        }
0312:                        result.append(currChar);
0313:                        prevChar = currChar;
0314:                    }
0315:                }
0316:                return result.toString();
0317:            }
0318:
0319:            private static void cParserRoundTrip(final String production,
0320:                    final String string) throws Exception {
0321:                final GNode ast = cStringToAst(production, string, null);
0322:                final String result = cAstToString(ast);
0323:                assertEquals(contractSpace(string), contractSpace(result));
0324:            }
0325:
0326:            static File createTempFile(final File tempDir, final String path,
0327:                    final String contents) throws IOException {
0328:                final File result = new File(tempDir, path);
0329:                result.getParentFile().mkdirs();
0330:                if (result.exists())
0331:                    result.delete();
0332:                assertTrue(result.createNewFile());
0333:                final Writer writer = new FileWriter(result);
0334:                writer.write(contents);
0335:                writer.flush();
0336:                writer.close();
0337:                return result;
0338:            }
0339:
0340:            public static GNode cStringToAst(final String production,
0341:                    final String string, final Set<String> typedefs)
0342:                    throws Exception {
0343:                final Class[] paramTypes = { Integer.TYPE };
0344:                final Method method = CParser.class.getDeclaredMethod( //
0345:                        "p" + production, paramTypes);
0346:                method.setAccessible(true);
0347:                final CParser parser = new CParser(new StringReader(string),
0348:                        "<input>", string.length());
0349:                parser.yyState.start();
0350:                if (null != typedefs) {
0351:                    parser.yyState.start();
0352:                    for (final String type : typedefs)
0353:                        parser.yyState.bind(type, true);
0354:                    parser.yyState.commit();
0355:                }
0356:                final Object[] paramValues = { new Integer(0) };
0357:                final Result parseResult = (Result) method.invoke(parser,
0358:                        paramValues);
0359:                return (GNode) parser.value(parseResult);
0360:            }
0361:
0362:            public static void dumpSymbolTable(final SymbolTable table) {
0363:                final Printer p = new Printer(System.out);
0364:                table.root().dump(p);
0365:                p.flush();
0366:            }
0367:
0368:            public static void enterPackageFile(final SymbolTable table,
0369:                    final String packageName, final String fileName) {
0370:                JavaEntities.canonicalNameToPackage(table, packageName);
0371:                table.enter(JavaEntities.packageNameToScopeName(packageName));
0372:                table.enter(JavaEntities.fileNameToScopeName(fileName));
0373:            }
0374:
0375:            static void javaAnalyzerTestConstant(final String expression,
0376:                    final Object expected, final JavaAnalyzer ana)
0377:                    throws Exception {
0378:                final GNode ast = JavaEntities.javaStringToAst("Expression",
0379:                        expression, true);
0380:                final Type type = ana.dispatchRValue(ast);
0381:                assertEquals(expected, type.getConstant().getValue());
0382:            }
0383:
0384:            static void javaAnalyzerTestError(final String production,
0385:                    final String input, final String expected) throws Exception {
0386:                final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(),
0387:                        new SymbolTable());
0388:                if (!"CompilationUnit".equals(production))
0389:                    enterPackageFile(ana._table, "", "<input>");
0390:                javaAnalyzerTestError(production, input, expected, ana);
0391:            }
0392:
0393:            private static void javaAnalyzerTestError(final String production,
0394:                    final String input, final String expected,
0395:                    final JavaAnalyzer ana) throws Exception {
0396:                final StringWriter stringWriter = new StringWriter();
0397:                ana._runtime.setErrConsole(new Printer(stringWriter));
0398:                GNode ast = null;
0399:                try {
0400:                    ast = JavaEntities.javaStringToAst(production, input, true);
0401:                } catch (final ParseException e) {
0402:                    ana._runtime.errConsole().pln(e.toString());
0403:                }
0404:                if (null != ast)
0405:                    ana.dispatch(ast);
0406:                String output = stringWriter.toString();
0407:                output = stripPrefix(output, "error:");
0408:                output = stripPrefix(output, "Exception:");
0409:                output = stripSuffix(output, "\n");
0410:                output = output.trim();
0411:                assertEquals(expected, output);
0412:            }
0413:
0414:            private static void javaAnalyzerTestUseDef(final JavaAnalyzer ana,
0415:                    final String use, final String def) throws Exception {
0416:                final Type u, d;
0417:                {
0418:                    final GNode ast = JavaEntities.javaStringToAst(
0419:                            "Expression", use, true);
0420:                    ana.dispatch(ast);
0421:                    if (ast.hasName("CallExpression")) {
0422:                        u = (Type) ast.getGeneric(3)
0423:                                .getProperty(Constants.TYPE);
0424:                    } else {
0425:                        final Type cu = (Type) ast.getProperty(Constants.TYPE);
0426:                        u = JavaEntities.isConstantT(cu) ? ((AnnotatedT) cu)
0427:                                .getType() : cu;
0428:                    }
0429:                }
0430:                // must parse use before def, since def gets analyzed on demand
0431:                {
0432:                    final int bracket = def.indexOf('[');
0433:                    final String baseName = -1 == bracket ? def : def
0434:                            .substring(0, bracket);
0435:                    final int nDimensions = -1 == bracket ? 0
0436:                            : (def.length() - bracket) / 2;
0437:                    final Type baseType = (Type) ana._table.lookup(baseName);
0438:                    if (null != baseType)
0439:                        d = JavaEntities.typeWithDimensions(baseType,
0440:                                nDimensions);
0441:                    else
0442:                        d = null;
0443:                }
0444:                //    System.out.println("def(" + def + ")=d(" + d + "),use(" + use + ")=u(" + u + ")");
0445:                if (null == d) {
0446:                    System.out.println("can't find \"" + def + "\" in ");
0447:                    dumpSymbolTable(ana._table);
0448:                    System.out.println("u("
0449:                            + JavaEntities.typeDeclString(ana._table, u) + ")");
0450:                }
0451:                assertNotNull(d);
0452:                assertEquals(d, u);
0453:            }
0454:
0455:            static void javaParserTestRoundTrip(
0456:                    // 
0457:                    final String production, final String input,
0458:                    final String expected, final boolean simple //
0459:            ) throws Exception {
0460:                final String unescaped = JavaEntities.unicodeUnescape(input);
0461:                final GNode ast = JavaEntities.javaStringToAst(production,
0462:                        unescaped, simple);
0463:                final String result = JavaEntities.javaAstToString(ast);
0464:                assertEquals(contractSpace(JavaEntities
0465:                        .unicodeUnescape(expected)), contractSpace(result));
0466:            }
0467:
0468:            private static TestSuite makeSuiteJavaAnalyzerConstant() {
0469:                //final boolean ignore = true; //T D 38 failing unit tests
0470:                final TestSuite s = new TestSuite();
0471:                //  s.addTest(new JavaAnalyzerTestConstant(false, "", ));
0472:                s.addTest(new JavaAnalyzerTestConstant(false, "!true",
0473:                        BigInteger.ZERO));
0474:                s.addTest(new JavaAnalyzerTestConstant(false, "'\\100'",
0475:                        new Character('@')));
0476:                s.addTest(new JavaAnalyzerTestConstant(false, "'\\n'",
0477:                        new Character('\n')));
0478:                s.addTest(new JavaAnalyzerTestConstant(false, "'\\u0040'",
0479:                        new Character('@')));
0480:                s.addTest(new JavaAnalyzerTestConstant(false, "'a'!='b'",
0481:                        BigInteger.ONE));
0482:                s.addTest(new JavaAnalyzerTestConstant(false, "'a'=='b'",
0483:                        BigInteger.ZERO));
0484:                s.addTest(new JavaAnalyzerTestConstant(false, "'a'==97L",
0485:                        BigInteger.ONE));
0486:                s.addTest(new JavaAnalyzerTestConstant(false, "'b'",
0487:                        new Character('b')));
0488:                s.addTest(new JavaAnalyzerTestConstant(false,
0489:                        "(String)\"abc\"", "abc"));
0490:                s.addTest(new JavaAnalyzerTestConstant(false, "(boolean)true",
0491:                        BigInteger.ONE));
0492:                s.addTest(new JavaAnalyzerTestConstant(false, "(byte)'Y'",
0493:                        new Byte((byte) 'Y')));
0494:                s.addTest(new JavaAnalyzerTestConstant(false, "(byte)72==72.0",
0495:                        BigInteger.ONE));
0496:                s.addTest(new JavaAnalyzerTestConstant(false,
0497:                        "(double)'\u789a'", new Double(30874.0)));
0498:                s.addTest(new JavaAnalyzerTestConstant(false, "(float)12",
0499:                        new Float(12)));
0500:                s.addTest(new JavaAnalyzerTestConstant(false, "(int)'\\u789a'",
0501:                        new Integer(0x789a)));
0502:                s.addTest(new JavaAnalyzerTestConstant(false, "(int)'\\uffff'",
0503:                        new Integer(0xffff)));
0504:                s.addTest(new JavaAnalyzerTestConstant(false, "(long)12.34e5",
0505:                        new Long((long) 12.34e5)));
0506:                s.addTest(new JavaAnalyzerTestConstant(false, "+12.34e5",
0507:                        new Double(12.34e5)));
0508:                s.addTest(new JavaAnalyzerTestConstant(false, "-12345",
0509:                        new Integer(-12345)));
0510:                s.addTest(new JavaAnalyzerTestConstant(false, ".12",
0511:                        new Double(.12)));
0512:                s.addTest(new JavaAnalyzerTestConstant(false, "0123",
0513:                        new Integer(0123)));
0514:                s.addTest(new JavaAnalyzerTestConstant(false, "0==1?'T':'F'",
0515:                        new Character('F')));
0516:                s
0517:                        .addTest(new JavaAnalyzerTestConstant(false, "0l",
0518:                                new Long(0)));
0519:                s.addTest(new JavaAnalyzerTestConstant(false, "0x00f & 0x0ff",
0520:                        new Integer(0x00f)));
0521:                s.addTest(new JavaAnalyzerTestConstant(false, "0x00f ^ 0x0ff",
0522:                        new Integer(0x0f0)));
0523:                s.addTest(new JavaAnalyzerTestConstant(false, "0x00f | 0x0ff",
0524:                        new Integer(0x0ff)));
0525:                s.addTest(new JavaAnalyzerTestConstant(false,
0526:                        "0x0123456789abcdefL", new Long(0x0123456789abcdefL)));
0527:                s.addTest(new JavaAnalyzerTestConstant(false, "0xCafeBabe",
0528:                        new Integer(0xCafeBabe)));
0529:                s.addTest(new JavaAnalyzerTestConstant(false, "0xff==255",
0530:                        BigInteger.ONE));
0531:                s.addTest(new JavaAnalyzerTestConstant(false,
0532:                        "1+2+\" fiddlers\"", "3 fiddlers"));
0533:                s.addTest(new JavaAnalyzerTestConstant(false, "1-2",
0534:                        new Integer(-1)));
0535:                s.addTest(new JavaAnalyzerTestConstant(false, "1-2-3",
0536:                        new Integer(-4)));
0537:                s.addTest(new JavaAnalyzerTestConstant(false, "1.2/2",
0538:                        new Double(0.6)));
0539:                s.addTest(new JavaAnalyzerTestConstant(false, "12 + 34",
0540:                        new Integer(46)));
0541:                s.addTest(new JavaAnalyzerTestConstant(false, "12 + \"cd\"",
0542:                        "12cd"));
0543:                s.addTest(new JavaAnalyzerTestConstant(false, "12*3",
0544:                        new Integer(36)));
0545:                s.addTest(new JavaAnalyzerTestConstant(false, "123",
0546:                        new Integer(123)));
0547:                s.addTest(new JavaAnalyzerTestConstant(false, "2<2",
0548:                        BigInteger.ZERO));
0549:                s.addTest(new JavaAnalyzerTestConstant(false, "2<<4",
0550:                        new Integer(32)));
0551:                s.addTest(new JavaAnalyzerTestConstant(false, "2<<4L",
0552:                        new Integer(32)));
0553:                s.addTest(new JavaAnalyzerTestConstant(false, "2<=2",
0554:                        BigInteger.ONE));
0555:                s.addTest(new JavaAnalyzerTestConstant(false, "2==2.0",
0556:                        BigInteger.ONE));
0557:                s.addTest(new JavaAnalyzerTestConstant(false, "2L<'2'",
0558:                        BigInteger.ONE));
0559:                s.addTest(new JavaAnalyzerTestConstant(false, "2L<<4",
0560:                        new Long(32)));
0561:                s.addTest(new JavaAnalyzerTestConstant(false, "6.022137e+23D",
0562:                        new Double(6.022137e+23D)));
0563:                s.addTest(new JavaAnalyzerTestConstant(false, "6.022137e+23f",
0564:                        new Float(6.022137e+23f)));
0565:                s.addTest(new JavaAnalyzerTestConstant(false, "97L-'a'",
0566:                        new Long(0)));
0567:                s.addTest(new JavaAnalyzerTestConstant(false, "\"\\40\\100\"",
0568:                        "\40\100"));
0569:                s.addTest(new JavaAnalyzerTestConstant(false, "\"a\\\"b\\nc\"",
0570:                        "a\"b\nc"));
0571:                s.addTest(new JavaAnalyzerTestConstant(false, "\"ab\"==\"ab\"",
0572:                        BigInteger.ONE));
0573:                s.addTest(new JavaAnalyzerTestConstant(false,
0574:                        "\"ab\" + \"cd\"", "abcd"));
0575:                s.addTest(new JavaAnalyzerTestConstant(false,
0576:                        "\"fiddlers \"+1+2", "fiddlers 12"));
0577:                s.addTest(new JavaAnalyzerTestConstant(false, "\"hello\"",
0578:                        "hello"));
0579:                s.addTest(new JavaAnalyzerTestConstant(false, "false",
0580:                        BigInteger.ZERO));
0581:                s.addTest(new JavaAnalyzerTestConstant(false, "false|true",
0582:                        BigInteger.ONE));
0583:                s.addTest(new JavaAnalyzerTestConstant(false, "true && false",
0584:                        BigInteger.ZERO));
0585:                s.addTest(new JavaAnalyzerTestConstant(false, "true ^ false",
0586:                        BigInteger.ONE));
0587:                s.addTest(new JavaAnalyzerTestConstant(false, "true || false",
0588:                        BigInteger.ONE));
0589:                s.addTest(new JavaAnalyzerTestConstant(false, "true",
0590:                        BigInteger.ONE));
0591:                s.addTest(new JavaAnalyzerTestConstant(false, "true&true",
0592:                        BigInteger.ONE));
0593:                s.addTest(new JavaAnalyzerTestConstant(false, "true?'T':'F'",
0594:                        new Character('T')));
0595:                s.addTest(new JavaAnalyzerTestConstant(false, "true^false",
0596:                        BigInteger.ONE));
0597:                return s;
0598:            }
0599:
0600:            private static TestSuite makeSuiteJavaAnalyzerError() {
0601:                final boolean ignore = true;
0602:                final TestSuite s = new TestSuite();
0603:                //  s.addTest(new JavaAnalyzerTestError(false, "", "", ""));
0604:                // ---------------------------------------------------------------
0605:                //TD 18 (15.9) anonymous classes
0606:                s
0607:                        .addTest(new JavaAnalyzerTestError(
0608:                                ignore,
0609:                                "CompilationUnit",
0610:                                "final class B extends p.A implements p.A.B{void f(){new B(){};}}",
0611:                                "",
0612:                                TempFile
0613:                                        .cons(
0614:                                                "package p;public class A{public interface B{}}",
0615:                                                "p", "A", null)));
0616:                s
0617:                        .addTest(new JavaAnalyzerTestError(
0618:                                ignore,
0619:                                "CompilationUnit",
0620:                                "import p2.B;class C extends p1.A{void f(){new B(){};}}",
0621:                                "",
0622:                                TempFile
0623:                                        .cons(
0624:                                                "package p1;public class A{public interface B{}}",
0625:                                                "p1",
0626:                                                "A",
0627:                                                TempFile
0628:                                                        .cons(
0629:                                                                "package p2;public final class B{}",
0630:                                                                "p2", "B", null))));
0631:                s
0632:                        .addTest(new JavaAnalyzerTestError(
0633:                                ignore,
0634:                                "Declaration",
0635:                                "class A{static class B{interface C{}}void f(){class C{}new B(){class D implements C{}};}}",
0636:                                ""));
0637:                s
0638:                        .addTest(new JavaAnalyzerTestError(
0639:                                ignore,
0640:                                "Declaration",
0641:                                "class A{static void f(){class B{B(Object o){}void g(){Class c=Boolean.class;}}new B(new Object(){Class c=Byte.class;});}}",
0642:                                ""));
0643:                s
0644:                        .addTest(new JavaAnalyzerTestError(
0645:                                ignore,
0646:                                "Declaration",
0647:                                "class A{static void f(){class B{static final int i=1;}new Object(){class B{static final int i=2;}void g(int j){switch(j){case 0:case 1:case B.i:}}};}}",
0648:                                ""));
0649:                s
0650:                        .addTest(new JavaAnalyzerTestError(
0651:                                ignore,
0652:                                "Declaration",
0653:                                "class C{Object f(){abstract class D{}return new D(){};}}",
0654:                                ""));
0655:                s
0656:                        .addTest(new JavaAnalyzerTestError(
0657:                                ignore,
0658:                                "Declaration",
0659:                                "class C{static Object f(){abstract class D{}return new D(){};}}",
0660:                                ""));
0661:                s.addTest(new JavaAnalyzerTestError(ignore, "Expression",
0662:                        "new Cloneable(){}", ""));
0663:                s.addTest(new JavaAnalyzerTestError(ignore, "Statement",
0664:                        "test: new Object(){void f(){int i;test:i=1;}};", ""));
0665:                // ---------------------------------------------------------------
0666:                //TD 08 (8.8.5.1) explicit constructor invocations
0667:                s
0668:                        .addTest(new JavaAnalyzerTestError(
0669:                                ignore,
0670:                                "CompilationUnit",
0671:                                "class A{int _a;A(int a){this._a=a;}}class B extends A{int _b;B(int a){this(a,0);}B(int a,int b){super(a);_b=b;}}",
0672:                                ""));
0673:                s
0674:                        .addTest(new JavaAnalyzerTestError(
0675:                                ignore,
0676:                                "CompilationUnit",
0677:                                "class C{C(String s){}private C(Integer i){}}class D extends C{D(){super(null);}}",
0678:                                ""));
0679:                s
0680:                        .addTest(new JavaAnalyzerTestError(
0681:                                false,
0682:                                "CompilationUnit",
0683:                                "class C{C(int i){}}class D extends C{D(int i){super(i);}}",
0684:                                ""));
0685:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
0686:                        "class C{}class D extends C{D(){super();}}", ""));
0687:                s
0688:                        .addTest(new JavaAnalyzerTestError(
0689:                                ignore,
0690:                                "CompilationUnit",
0691:                                "class C{static class D{class E{}}static class F extends D.E{F(){(new D()).super();}}}",
0692:                                ""));
0693:                s
0694:                        .addTest(new JavaAnalyzerTestError(
0695:                                ignore,
0696:                                "Declaration",
0697:                                "class C{A a=new A();static class A{private A(){}A(String s){}A(int i){this(null);}}}",
0698:                                ""));
0699:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0700:                        "class C{int _i;C(int i){_i=i;}C(){this(0);}}", ""));
0701:                // ---------------------------------------------------------------
0702:                //TD 10 (14.20) unreachable statements
0703:                s
0704:                        .addTest(new JavaAnalyzerTestError(ignore,
0705:                                "Declaration",
0706:                                "class C{void f(){return; int i;}}",
0707:                                "unreachable code"));
0708:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0709:                        "class C{void f(){{return;};}}", "unreachable code"));
0710:                s.addTest(new JavaAnalyzerTestError(ignore, "Statement",
0711:                        "for(;false;);", "unreachable code"));
0712:                // ---------------------------------------------------------------
0713:                //TD enclosing instances
0714:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0715:                        "class A{class B{}} class C{ A.B b=new A().new B();}",
0716:                        ""));
0717:                s
0718:                        .addTest(new JavaAnalyzerTestError(
0719:                                ignore,
0720:                                "Declaration",
0721:                                "class A{class B{private B(){}}static class C extends B{}}",
0722:                                "no enclosing instance"));
0723:                s
0724:                        .addTest(new JavaAnalyzerTestError(
0725:                                ignore,
0726:                                "Declaration",
0727:                                "class A{class B{private B(){}}static{class C extends B{}}}",
0728:                                "no enclosing instance"));
0729:                // ---------------------------------------------------------------
0730:                //TD qualified this and super
0731:                s
0732:                        .addTest(new JavaAnalyzerTestError(
0733:                                ignore,
0734:                                "CompilationUnit",
0735:                                "class C{int i;}class D extends C{Object o=int.super.i;}",
0736:                                "super doesn't work on primitive types"));
0737:                s
0738:                        .addTest(new JavaAnalyzerTestError(
0739:                                ignore,
0740:                                "CompilationUnit",
0741:                                "class C{int i;}class D extends C{Object o=int[].super.i;}",
0742:                                "super doesn't work on array types"));
0743:                s
0744:                        .addTest(new JavaAnalyzerTestError(
0745:                                ignore,
0746:                                "CompilationUnit",
0747:                                "class C{int i;}class D extends C{Object o=null.super.i;}",
0748:                                "super doesn't work on null"));
0749:                s
0750:                        .addTest(new JavaAnalyzerTestError(
0751:                                ignore,
0752:                                "Declaration",
0753:                                "class A{public static int v=0;class I{I(int i){}}static class D extends I{D(A a, int i){a.super(v=++i);}}public static void main(String[]args){try{new D(null,5);}catch(NullPointerException e){if(v==0)System.out.print(\"OK\");else System.out.print(\"bad\");return;}System.out.print(\"bad\");}}",
0754:                                ""));
0755:                // ---------------------------------------------------------------
0756:                //TD static use of non-static
0757:                s
0758:                        .addTest(new JavaAnalyzerTestError(
0759:                                ignore,
0760:                                "Declaration",
0761:                                "class A{int i;static class B extends A{private int i;}static class C extends B{int j=i;}}",
0762:                                "static reference to non-static field"));
0763:                s
0764:                        .addTest(new JavaAnalyzerTestError(
0765:                                ignore,
0766:                                "Declaration",
0767:                                "class A{private int f(){return 1;}static class B extends A{int i=f();}}",
0768:                                "static use of non-static method"));
0769:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0770:                        "class C{int i=1; static class D{int j=i;}}",
0771:                        "static use of non-static field"));
0772:                s
0773:                        .addTest(new JavaAnalyzerTestError(
0774:                                ignore,
0775:                                "Declaration",
0776:                                "class C{private int i;static class D extends C{int j=i;}}",
0777:                                "static reference to non-static field"));
0778:                // ---------------------------------------------------------------
0779:                //TD use-def analysis
0780:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0781:                        "class A{final int i;}", "uninitialized blank final"));
0782:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0783:                        "class A{static final int i;}",
0784:                        "uninitialized blank final"));
0785:                s
0786:                        .addTest(new JavaAnalyzerTestError(ignore,
0787:                                "Declaration",
0788:                                "class C{final int x; class D{{x=1;}}}",
0789:                                "a blank final field of a lexically enclosing class can not be assigned"));
0790:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0791:                        "class C{final int x; {x=1;}}", ""));
0792:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0793:                        "class C{int f(){}}", "missing return"));
0794:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0795:                        "class C{int i=(i=1)+i;}", "use before def"));
0796:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0797:                        "class C{int i=i;}", "use of uninitialized variable"));
0798:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0799:                        "class C{int i=j;int j=1;}", "use before def"));
0800:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0801:                        "class C{int j=i=1;final int i;}", ""));
0802:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0803:                        "class C{static{int i=j;}static int j=1;}",
0804:                        "use before def"));
0805:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
0806:                        "interface A{int i;}", "uninitialized field"));
0807:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0808:                        "class B{final static int i;static{i=1;}}", "",
0809:                        TempFile.cons("interface A{int i=B.i;}", "A", null)));
0810:                // ---------------------------------------------------------------
0811:                //TD visibility and scopes
0812:                s
0813:                        .addTest(new JavaAnalyzerTestError(
0814:                                ignore,
0815:                                "CompilationUnit",
0816:                                "class A{int b=C.d.length;}class C{static D[]d;private static class D{}}",
0817:                                "unknown or ambiguous name"));
0818:                s
0819:                        .addTest(new JavaAnalyzerTestError(
0820:                                ignore,
0821:                                "CompilationUnit",
0822:                                "class B extends p.A implements p.A.B{void f(){new B();}}",
0823:                                "the inherited type shadows the current enclosing type",
0824:                                TempFile
0825:                                        .cons(
0826:                                                "package p;public class A{public interface B{}}",
0827:                                                "p", "A", null)));
0828:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0829:                        "class B extends p.A{Object i;int j=((p.A)this).i;}",
0830:                        "unknown or ambiguous name", TempFile.cons(
0831:                                "package p;public class A{protected int i;}",
0832:                                "p", "A", null)));
0833:                s
0834:                        .addTest(new JavaAnalyzerTestError(
0835:                                ignore,
0836:                                "CompilationUnit",
0837:                                "class BB extends p.AA{interface B{void m()throws E2;}static abstract class C extends A implements B{}static abstract class D extends C{{m();try{((C)this).m();}catch(E2 e){}}}}",
0838:                                "",
0839:                                TempFile
0840:                                        .cons(
0841:                                                "package p;public class AA{public static class E1 extends Exception{}public static class E2 extends Exception{}public static abstract class A{protected abstract void m()throws E1;}",
0842:                                                "p", "A", null)));
0843:                s
0844:                        .addTest(new JavaAnalyzerTestError(
0845:                                ignore,
0846:                                "CompilationUnit",
0847:                                "class B{int j=p.A.i++;}",
0848:                                "not accessible",
0849:                                TempFile
0850:                                        .cons(
0851:                                                "package p;public class A{protected static int i;}",
0852:                                                "p", "A", null)));
0853:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0854:                        "class C{private C(){}}class D extends C{}",
0855:                        "super constructor not visible"));
0856:                s
0857:                        .addTest(new JavaAnalyzerTestError(
0858:                                ignore,
0859:                                "CompilationUnit",
0860:                                "interface B{int i=2;}class C extends p1.A implements B{}class D extends C{static int j=new D().i;}",
0861:                                "ambiguous name i",
0862:                                TempFile
0863:                                        .cons(
0864:                                                "package p1;public class A{protected int i=1;}",
0865:                                                "p1", "A", null)));
0866:                s
0867:                        .addTest(new JavaAnalyzerTestError(
0868:                                ignore,
0869:                                "CompilationUnit",
0870:                                "interface B{void m(String s,Object o);}abstract class C extends p.A implements B{}abstract class D extends C{void f(){super.m(\"\",\"\");}}",
0871:                                "ambiguous",
0872:                                TempFile
0873:                                        .cons(
0874:                                                "package p;public class A{protected void m(Object o,String s);}",
0875:                                                "p", "A", null)));
0876:                s
0877:                        .addTest(new JavaAnalyzerTestError(
0878:                                ignore,
0879:                                "CompilationUnit",
0880:                                "interface B{void m(String s,Object o);}abstract class C extends p.A implements B{}abstract class D extends C{void f(D d){d.m(\"\",\"\");}}",
0881:                                "ambiguous",
0882:                                TempFile
0883:                                        .cons(
0884:                                                "package p;public class A{protected void m(Object o,String s){}}",
0885:                                                "p", "A", null)));
0886:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0887:                        "package A;import A.B.C;class B{private class C{}}",
0888:                        "not visible"));
0889:                s
0890:                        .addTest(new JavaAnalyzerTestError(
0891:                                ignore,
0892:                                "CompilationUnit",
0893:                                "package p2;public abstract class B extends p1.A{protected in m(){return 1;}}",
0894:                                "",
0895:                                TempFile
0896:                                        .cons(
0897:                                                "package p1;public abstract class A{abstract int m();}abstract class C extends p2.B{int i=m();}",
0898:                                                "p1", "A", null)));
0899:                s
0900:                        .addTest(new JavaAnalyzerTestError(
0901:                                ignore,
0902:                                "Declaration",
0903:                                "class C{private int i;class D extends C{int j=this.i;}}",
0904:                                "unknown or ambiguous name"));
0905:                // ---------------------------------------------------------------
0906:                // TD duplicate package members
0907:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0908:                        "class A{}class B{}", "duplicate package members",
0909:                        TempFile.cons("class A{}", "A", null)));
0910:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0911:                        "package a;class b{}", "duplicate package members",
0912:                        TempFile.cons("package a.b;class C{}", "a", "b", "C",
0913:                                null)));
0914:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0915:                        "package p;class A{}class B{}",
0916:                        "duplicate package members", TempFile.cons(
0917:                                "package p;class A{}", "p", "A", null)));
0918:                // ---------------------------------------------------------------
0919:                // TD default constructors
0920:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0921:                        "class C{C()throws Exception{}}class D extends C{}",
0922:                        "unhandled exception in default constructor"));
0923:                s
0924:                        .addTest(new JavaAnalyzerTestError(ignore,
0925:                                "CompilationUnit",
0926:                                "class C{private C(){}}class D extends C{}",
0927:                                "can not access super constructor from default constructor"));
0928:                // ---------------------------------------------------------------
0929:                // TD other failed unit tests with multiple compilation units
0930:                s
0931:                        .addTest(new JavaAnalyzerTestError(
0932:                                ignore,
0933:                                "CompilationUnit",
0934:                                "class D{int i=p.C.i;}",
0935:                                "",
0936:                                TempFile
0937:                                        .cons(
0938:                                                "package p;class A{int i;}interface B{int i=1;}public class C extends A implements B{}",
0939:                                                "C", null)));
0940:                s
0941:                        .addTest(new JavaAnalyzerTestError(
0942:                                ignore,
0943:                                "CompilationUnit",
0944:                                "class D{void m(p.C t){try{t.m();}catch(Exception e){}}}",
0945:                                "",
0946:                                TempFile
0947:                                        .cons(
0948:                                                "package p;abstract class A}abstract void m();}interface B{void m()throws Exception;}public abstract class C extends A implements B{}",
0949:                                                "p", "C", null)));
0950:                s
0951:                        .addTest(new JavaAnalyzerTestError(
0952:                                ignore,
0953:                                "CompilationUnit",
0954:                                "import p.A.C.*;class B extends D{}",
0955:                                "",
0956:                                TempFile
0957:                                        .cons(
0958:                                                "package p;public class A{public int C;public int C(){return 0;}public static class C{public static class D{}}}",
0959:                                                "p", "A", null)));
0960:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0961:                        "import p1.*;import p2.*;class B extends A{}", "",
0962:                        TempFile.cons("package p1;class A{}", "p1", "A",
0963:                                TempFile.cons("package p2;public class A{}",
0964:                                        "p2", "A", null))));
0965:                s
0966:                        .addTest(new JavaAnalyzerTestError(
0967:                                ignore,
0968:                                "CompilationUnit",
0969:                                "interface B{int m();}abstract class C extends p1.A implements B{}",
0970:                                "",
0971:                                TempFile
0972:                                        .cons(
0973:                                                "package p1;public abstract class A{abstract void m();}",
0974:                                                "p1", "A", null)));
0975:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
0976:                        "package p;import p.A.*;class B implements I{}", "",
0977:                        TempFile.cons("package p;class A{interface I{}}", "p",
0978:                                "A", null)));
0979:                // ---------------------------------------------------------------
0980:                // TD other failed unit tests with a single compilation unit
0981:                s
0982:                        .addTest(new JavaAnalyzerTestError(
0983:                                ignore,
0984:                                "CompilationUnit",
0985:                                "class A{class B{}}interface C{class B{}}class D extends A implements C{static Object o=new D.B();}",
0986:                                "ambiguous type"));
0987:                s
0988:                        .addTest(new JavaAnalyzerTestError(
0989:                                ignore,
0990:                                "CompilationUnit",
0991:                                "class A{class C{}}interface B{class C{}}class D extends A implements B{D.C t;}",
0992:                                "ambiguous type"));
0993:                s
0994:                        .addTest(new JavaAnalyzerTestError(
0995:                                ignore,
0996:                                "CompilationUnit",
0997:                                "class A{public void m(){}}interface B{void m();}class C extends A implements B{{m();}}",
0998:                                ""));
0999:                s
1000:                        .addTest(new JavaAnalyzerTestError(
1001:                                ignore,
1002:                                "CompilationUnit",
1003:                                "class A{static void f(int i){}}class B extends A{static void f(long l){}{f(0);}}",
1004:                                ""));
1005:                s
1006:                        .addTest(new JavaAnalyzerTestError(
1007:                                ignore,
1008:                                "CompilationUnit",
1009:                                "class A{void f(String s){}}abstract class B extends A{void f(Object o){}{f(\"\");}}",
1010:                                ""));
1011:                s
1012:                        .addTest(new JavaAnalyzerTestError(
1013:                                ignore,
1014:                                "CompilationUnit",
1015:                                "class E1 extends Exception{}class E2 extends Exception{}class E3 extends Exception{}abstract class A{public abstract void m()throws E1,E2;}interface B{void m()throws E2,E3;}abstract class C extends A implements B{{try{m();}catch(E1 e1){}catch(E2 e2){}}}",
1016:                                "jacks says it should fail, but it's no problem in eclipse"));
1017:                s
1018:                        .addTest(new JavaAnalyzerTestError(
1019:                                ignore,
1020:                                "CompilationUnit",
1021:                                "class E1 extends Exception{}class E2 extends Exception{}class E3 extends Exception{}abstract class A{public abstract void m()throws E1,E2;}interface B{void m()throws E2,E3;}abstract class C extends A implements B{{try{m();}catch(E2 e2){}}}",
1022:                                ""));
1023:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
1024:                        "import A.*;class A{class B{}}", "unresolved import"));
1025:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
1026:                        "import foo.inexistsentclass;class A{}",
1027:                        "unknown import"));
1028:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
1029:                        "import nonExistentPackage.*;class A{}",
1030:                        "package doesn't exist"));
1031:                s
1032:                        .addTest(new JavaAnalyzerTestError(
1033:                                ignore,
1034:                                "CompilationUnit",
1035:                                "interface A{Object clone()throws java.io.IOException;}abstract class B implements A{}",
1036:                                "incompatible exceptions"));
1037:                s
1038:                        .addTest(new JavaAnalyzerTestError(
1039:                                ignore,
1040:                                "CompilationUnit",
1041:                                "interface A{String toString();}class B implements A{}",
1042:                                ""));
1043:                s
1044:                        .addTest(new JavaAnalyzerTestError(
1045:                                ignore,
1046:                                "CompilationUnit",
1047:                                "interface A{int clone();}abstract class B implements A{}",
1048:                                "conflicting return types"));
1049:                s
1050:                        .addTest(new JavaAnalyzerTestError(
1051:                                ignore,
1052:                                "CompilationUnit",
1053:                                "interface A{int i=1;}class B{int i=2;}class C extends B implements A{static int j=new C().i;}",
1054:                                "ambiguous"));
1055:                s
1056:                        .addTest(new JavaAnalyzerTestError(
1057:                                ignore,
1058:                                "CompilationUnit",
1059:                                "interface A{void f(String s);}abstract class B implements A{void f(Object o){}{f(\"\");}}",
1060:                                "")); //More than one maximally specific method is ambiguous, and illegal. By JLS2 Clarifications (where?), declaring type is no longer considered, so A.f(String) is more specific than B.foo(Object).
1061:                s
1062:                        .addTest(new JavaAnalyzerTestError(
1063:                                ignore,
1064:                                "CompilationUnit",
1065:                                "interface I{int f();}class C{void f(){}}abstract class D extends C implements I{}",
1066:                                "conflicting methods"));
1067:                s
1068:                        .addTest(new JavaAnalyzerTestError(
1069:                                ignore,
1070:                                "CompilationUnit",
1071:                                "interface I{void f();}class C{static void f(){}}abstract class D extends C implements I{}",
1072:                                "conflicting methods"));
1073:                s.addTest(new JavaAnalyzerTestError(ignore, "CompilationUnit",
1074:                        "package A;import A.B;class B{}", ""));
1075:                s
1076:                        .addTest(new JavaAnalyzerTestError(
1077:                                ignore,
1078:                                "Declaration",
1079:                                "class A{class B{int i;}class C extends B{class D{{i++;}}}}",
1080:                                ""));
1081:                s
1082:                        .addTest(new JavaAnalyzerTestError(
1083:                                ignore,
1084:                                "Declaration",
1085:                                "class A{int i;class B{Object i;}class C extends B{void f(){i=null;}}}",
1086:                                ""));
1087:                s
1088:                        .addTest(new JavaAnalyzerTestError(
1089:                                ignore,
1090:                                "Declaration",
1091:                                "class A{interface B{class C{}}class D{class C{}}class E extends D implements B{C c;}}",
1092:                                "ambiguous"));
1093:                s
1094:                        .addTest(new JavaAnalyzerTestError(
1095:                                ignore,
1096:                                "Declaration",
1097:                                "class A{interface B{void f();}class C{public void f(){}}class D extends C implements B{{f();}}}",
1098:                                ""));
1099:                s
1100:                        .addTest(new JavaAnalyzerTestError(
1101:                                ignore,
1102:                                "Declaration",
1103:                                "class A{interface B{void f()throws Exception;}class C{public void f(){}}class D extends C implements B{}}",
1104:                                ""));
1105:                s
1106:                        .addTest(new JavaAnalyzerTestError(
1107:                                ignore,
1108:                                "Declaration",
1109:                                "class A{private static void f(){}static class B{B(){f();}}}",
1110:                                ""));
1111:                s
1112:                        .addTest(new JavaAnalyzerTestError(
1113:                                ignore,
1114:                                "Declaration",
1115:                                "class A{static class B{static B t,u;}static class C extends B{static class t{static int u;}}void f(){C.t.u=null;}}",
1116:                                ""));
1117:                s
1118:                        .addTest(new JavaAnalyzerTestError(
1119:                                ignore,
1120:                                "Declaration",
1121:                                "class A{static class B{static int i;}A t;int i=t.B.i;}",
1122:                                "not a field"));
1123:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
1124:                        "class A{static void f(){}static class B{B(){f();}}}",
1125:                        ""));
1126:                s
1127:                        .addTest(new JavaAnalyzerTestError(
1128:                                ignore,
1129:                                "Declaration",
1130:                                "class C{Cloneable[][]s=(Cloneable[][])(Object)(Integer[])(Cloneable)(int[])null;}",
1131:                                ""));
1132:                s
1133:                        .addTest(new JavaAnalyzerTestError(
1134:                                ignore,
1135:                                "Declaration",
1136:                                "class C{int f()throws ClassNotFoundException{return 1;}int i=f();C()throws ClassNotFoundException{}}",
1137:                                ""));
1138:                s
1139:                        .addTest(new JavaAnalyzerTestError(
1140:                                ignore,
1141:                                "Declaration",
1142:                                "class C{int f()throws ClassNotFoundException{return 1;}{f();}C()throws ClassNotFoundException{}}",
1143:                                ""));
1144:                s
1145:                        .addTest(new JavaAnalyzerTestError(
1146:                                ignore,
1147:                                "Declaration",
1148:                                "class C{int i=1;{try{i++;throw new Exception();}catch(Exception i){}}}",
1149:                                ""));
1150:                s
1151:                        .addTest(new JavaAnalyzerTestError(
1152:                                ignore,
1153:                                "Declaration",
1154:                                "class C{interface I1{void f();}interface I2{int f();}interface I3 extends I1,I2{}}",
1155:                                "return type mismatch"));
1156:                s
1157:                        .addTest(new JavaAnalyzerTestError(
1158:                                ignore,
1159:                                "Declaration",
1160:                                "class C{interface I{}void f(I i){i.getClass();i.toString();i.equals(null);i.hashCode();try{i.wait();i.wait(1);i.wait(1,0);i.notifyAll();i.notify();}catch(Throwable t){}}}",
1161:                                ""));
1162:                s
1163:                        .addTest(new JavaAnalyzerTestError(
1164:                                ignore,
1165:                                "Declaration",
1166:                                "class C{static class A{static class B{static int i=1;}}int j=new A().B.i;}",
1167:                                "B cannot be resolved"));
1168:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
1169:                        "class C{static final String[] a={\"b\",\"c\"};}",
1170:                        "initializer must be compile-time constant"));
1171:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
1172:                        "class C{void f(){int x=2;class D{int j=x;}}}",
1173:                        "non-local use of non-final local"));
1174:                s
1175:                        .addTest(new JavaAnalyzerTestError(
1176:                                ignore,
1177:                                "Declaration",
1178:                                "class C{void f(){try{throw new Exception();}finally{return;}}}",
1179:                                ""));
1180:                s
1181:                        .addTest(new JavaAnalyzerTestError(
1182:                                ignore,
1183:                                "Declaration",
1184:                                "class C{void f(byte b)throws Exception{}void f(char c)throws Exception{}void f(int i){}void g(byte b){f(true?b:'0');f(false?b:'0');f(true?'0':b);f(false?'0':b);}}",
1185:                                ""));
1186:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
1187:                        "class C{void f(int x){class D{int j=x;}}}",
1188:                        "non-local use of non-final local"));
1189:                s
1190:                        .addTest(new JavaAnalyzerTestError(
1191:                                ignore,
1192:                                "Declaration",
1193:                                "class C{{if(true)throw new ClassNotFoundException();}C()throws ClassNotFoundException{}}",
1194:                                ""));
1195:                s
1196:                        .addTest(new JavaAnalyzerTestError(
1197:                                ignore,
1198:                                "Declaration",
1199:                                "class C{{if(true)throw new ClassNotFoundException();}C()throws Throwable{}}",
1200:                                ""));
1201:                s
1202:                        .addTest(new JavaAnalyzerTestError(ignore,
1203:                                "Declaration",
1204:                                "class C{{int i;for(int i;;);}}",
1205:                                "duplicate variable"));
1206:                s
1207:                        .addTest(new JavaAnalyzerTestError(
1208:                                ignore,
1209:                                "Declaration",
1210:                                "class D{static class A{interface B{}}static class B extends A{{new B();}}}",
1211:                                "cannot instantiate interface"));
1212:                s
1213:                        .addTest(new JavaAnalyzerTestError(
1214:                                ignore,
1215:                                "Declaration",
1216:                                "class E{class A{int i;}interface B{Object i=null;}class C extends A implements B{}class D extends C{int j=super.i;}}",
1217:                                "ambiguous"));
1218:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
1219:                        "interface B{Class getClass();}",
1220:                        "cannot override final method"));
1221:                s
1222:                        .addTest(new JavaAnalyzerTestError(ignore,
1223:                                "Declaration",
1224:                                "interface I{public int toString();}",
1225:                                "JLS 9.2: interface implicitly declares all methods of java.lang.Object"));
1226:                s.addTest(new JavaAnalyzerTestError(ignore, "Statement",
1227:                        "switch(123){case 0:class C{}break;case 1:new C();}",
1228:                        "unknown class"));
1229:                // ---------------------------------------------------------------
1230:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1231:                        ";", ""));
1232:                s
1233:                        .addTest(new JavaAnalyzerTestError(
1234:                                false,
1235:                                "CompilationUnit",
1236:                                "abstract class B extends p1.A{protected int m(){return 1;}}",
1237:                                "",
1238:                                TempFile
1239:                                        .cons(
1240:                                                "package p1;public abstract class A{abstract void m();}",
1241:                                                "p1", "A", null)));
1242:                s
1243:                        .addTest(new JavaAnalyzerTestError(
1244:                                false,
1245:                                "CompilationUnit",
1246:                                "abstract class D extends p.C{{m();}}",
1247:                                "",
1248:                                TempFile
1249:                                        .cons(
1250:                                                "package p;interface B{void m();}public abstract class C implements B{}",
1251:                                                "p", "C", null)));
1252:                s
1253:                        .addTest(new JavaAnalyzerTestError(
1254:                                false,
1255:                                "CompilationUnit",
1256:                                "abstract class D extends p.C{{try{m();}catch(Exception e){}}}",
1257:                                "",
1258:                                TempFile
1259:                                        .cons(
1260:                                                "package p;abstract class A{abstract void m();}interface B{void m()throws Exception;}public abstract class C extends A implements B{}",
1261:                                                "p", "C", null)));
1262:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1263:                        "class A extends B{}", "", TempFile.cons("class B{}",
1264:                                "B", null)));
1265:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1266:                        "class A extends p.B{}", "", TempFile.cons(
1267:                                "package p;public class B{}", "p", "B", null)));
1268:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1269:                        "class A implements B{}",
1270:                        "unknown class or interface B"));
1271:                s
1272:                        .addTest(new JavaAnalyzerTestError(
1273:                                false,
1274:                                "CompilationUnit",
1275:                                "class A{Object b=B.B_CONST;Object c=C.C_CONST;}",
1276:                                "",
1277:                                TempFile
1278:                                        .cons(
1279:                                                "class B{static final Object B_CONST=B.class;}class C extends B{static final Object C_CONST=C.class;}",
1280:                                                "B", null)));
1281:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1282:                        "class A{class B{}}class C extends A{B b=null;}", ""));
1283:                s
1284:                        .addTest(new JavaAnalyzerTestError(
1285:                                false,
1286:                                "CompilationUnit",
1287:                                "class A{class B{}}class C extends A{class D extends B{}}",
1288:                                ""));
1289:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1290:                        "class A{private class B{}}class C extends A{A.B t;}",
1291:                        "unknown type A.B"));
1292:                s
1293:                        .addTest(new JavaAnalyzerTestError(
1294:                                false,
1295:                                "CompilationUnit",
1296:                                "class A{private int x;}class B extends A{void f(){x=0;}}",
1297:                                "unknown or ambiguous name"));
1298:                s
1299:                        .addTest(new JavaAnalyzerTestError(
1300:                                false,
1301:                                "CompilationUnit",
1302:                                "class A{private void f(){}}class B extends A{B(){super();}}",
1303:                                ""));
1304:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1305:                        "class A{private void f(){}}class B extends A{{f();}}",
1306:                        "no such method"));
1307:                s
1308:                        .addTest(new JavaAnalyzerTestError(
1309:                                false,
1310:                                "CompilationUnit",
1311:                                "class A{protected class B{};}class C{Class d=A.B.class;}",
1312:                                ""));
1313:                s
1314:                        .addTest(new JavaAnalyzerTestError(
1315:                                false,
1316:                                "CompilationUnit",
1317:                                "class A{public A(String s){}private A(Integer i){}}class B{Object o=new A(null);}",
1318:                                ""));
1319:                s
1320:                        .addTest(new JavaAnalyzerTestError(
1321:                                false,
1322:                                "CompilationUnit",
1323:                                "class A{public A(String x, String y){}private A(String x,char[] y){}}class B{Object o=new A(\"hi\", null);}",
1324:                                ""));
1325:                s
1326:                        .addTest(new JavaAnalyzerTestError(
1327:                                false,
1328:                                "CompilationUnit",
1329:                                "class A{public int f(String s){return 0;}private int f(Integer i){return 0;}}class B extends A{int i=new A().f(null);}",
1330:                                ""));
1331:                s
1332:                        .addTest(new JavaAnalyzerTestError(
1333:                                false,
1334:                                "CompilationUnit",
1335:                                "class A{static class B{void f(){g();}void g(){}}}",
1336:                                ""));
1337:                s
1338:                        .addTest(new JavaAnalyzerTestError(
1339:                                false,
1340:                                "CompilationUnit",
1341:                                "class A{static final String s=\"a\";}class B{void f(){class C extends A{void f(){s.toString();s.valueOf(1);}}}}",
1342:                                ""));
1343:                s
1344:                        .addTest(new JavaAnalyzerTestError(
1345:                                false,
1346:                                "CompilationUnit",
1347:                                "class A{static void f(){}static class B{static void g(){f();}}}",
1348:                                ""));
1349:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1350:                        "class A{static{String b=\"x\";b=\"y\";}}", ""));
1351:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1352:                        "class A{void f()throws IOException{}}",
1353:                        "unknown class or interface IOException"));
1354:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1355:                        "class A{void f()throws Throwable{finalize();}}", ""));
1356:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1357:                        "class A{void f(){Object o=new B();}}", "", TempFile
1358:                                .cons("class B{void f(){Object o=new A();}}",
1359:                                        "B", null)));
1360:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1361:                        "class A{void f(){new B();}private static class B{}}",
1362:                        ""));
1363:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1364:                        "class A{void f(String s){s.getClass();}}", ""));
1365:                s
1366:                        .addTest(new JavaAnalyzerTestError(
1367:                                false,
1368:                                "CompilationUnit",
1369:                                "class A{void f(p.C x){x.m();}}",
1370:                                "",
1371:                                TempFile
1372:                                        .cons(
1373:                                                "package p;interface B{void m();}public abstract class C implements B{}",
1374:                                                "p", "C", null)));
1375:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1376:                        "class A{{\"\".getClass();}}", ""));
1377:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1378:                        "class A{}", ""));
1379:                s
1380:                        .addTest(new JavaAnalyzerTestError(false,
1381:                                "CompilationUnit", "class B extends A{}", "",
1382:                                TempFile.cons(
1383:                                        "class A{C c;}class C extends B{}",
1384:                                        "A", null)));
1385:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1386:                        "class B extends A{}", "", TempFile.cons("class A{}",
1387:                                "A", null)));
1388:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1389:                        "class B extends A{}", "", TempFile.cons(
1390:                                "class \\u0041{}", "A", null)));
1391:                s
1392:                        .addTest(new JavaAnalyzerTestError(
1393:                                false,
1394:                                "CompilationUnit",
1395:                                "class B extends p.A{abstract class D extends C1{public void m(){}}}",
1396:                                "",
1397:                                TempFile
1398:                                        .cons(
1399:                                                "package p;public class A{abstract class C{abstract void m();}interface I{void m();}protected abstract class C1 extends C implements I{}}",
1400:                                                "p", "A", null)));
1401:                s
1402:                        .addTest(new JavaAnalyzerTestError(
1403:                                false,
1404:                                "CompilationUnit",
1405:                                "class B extends p.A{class D extends C{}}",
1406:                                "",
1407:                                TempFile
1408:                                        .cons(
1409:                                                "package p;public class A{protected class C{}}",
1410:                                                "p", "A", null)));
1411:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1412:                        "class B extends p.A{class D extends C{}}", "",
1413:                        TempFile.cons(
1414:                                "package p;public class A{public class C{}}",
1415:                                "p", "A", null)));
1416:                s
1417:                        .addTest(new JavaAnalyzerTestError(
1418:                                false,
1419:                                "CompilationUnit",
1420:                                "class B extends p.A{class D implements C{}}",
1421:                                "",
1422:                                TempFile
1423:                                        .cons(
1424:                                                "package p;public class A{protected interface C{}}",
1425:                                                "p", "A", null)));
1426:                s
1427:                        .addTest(new JavaAnalyzerTestError(
1428:                                false,
1429:                                "CompilationUnit",
1430:                                "class B extends p.A{interface D extends C{}}",
1431:                                "",
1432:                                TempFile
1433:                                        .cons(
1434:                                                "package p;public class A{protected interface C{}}",
1435:                                                "p", "A", null)));
1436:                s
1437:                        .addTest(new JavaAnalyzerTestError(
1438:                                false,
1439:                                "CompilationUnit",
1440:                                "class B extends p.A{void m()throws Exception{}}",
1441:                                "",
1442:                                TempFile
1443:                                        .cons(
1444:                                                "package p;public class A{static int m(){return 1;}}",
1445:                                                "p", "A", null)));
1446:                s
1447:                        .addTest(new JavaAnalyzerTestError(
1448:                                false,
1449:                                "CompilationUnit",
1450:                                "class B extends p.A{void m(){}}",
1451:                                "must be abstract",
1452:                                TempFile
1453:                                        .cons(
1454:                                                "package p;public abstract class A{abstract void m();}",
1455:                                                "p", "A", null)));
1456:                s
1457:                        .addTest(new JavaAnalyzerTestError(
1458:                                false,
1459:                                "CompilationUnit",
1460:                                "class B extends p1.A{abstract class D extends C implements I{public void m()throws Exception{}}}",
1461:                                "",
1462:                                TempFile
1463:                                        .cons(
1464:                                                "package p1;public class A{public abstract class C{abstract void m();}public interface I{void m()throws Exception;}}",
1465:                                                "p1", "A", null)));
1466:                s
1467:                        .addTest(new JavaAnalyzerTestError(
1468:                                false,
1469:                                "CompilationUnit",
1470:                                "class B extends p1.A{abstract class D extends C implements I{public void m(){}}class E extends D{}}",
1471:                                "must be abstract",
1472:                                TempFile
1473:                                        .cons(
1474:                                                "package p1;public class A{public abstract class C{abstract void m();}public interface I{void m();}}",
1475:                                                "p1", "A", null)));
1476:                s
1477:                        .addTest(new JavaAnalyzerTestError(
1478:                                false,
1479:                                "CompilationUnit",
1480:                                "class B extends p1.A{class D extends C implements I{public void m(){}}}",
1481:                                "must be abstract",
1482:                                TempFile
1483:                                        .cons(
1484:                                                "package p1;public class A{public abstract class C{abstract void m();}public interface I{void m();}}",
1485:                                                "p1", "A", null)));
1486:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1487:                        "class B{Class c=p.A.class;}", "", TempFile.cons(
1488:                                "package p;class A{}", "p", "A", null)));
1489:                s
1490:                        .addTest(new JavaAnalyzerTestError(
1491:                                false,
1492:                                "CompilationUnit",
1493:                                "class C extends p2.B{class D implements p1.A{}}",
1494:                                "",
1495:                                TempFile
1496:                                        .cons(
1497:                                                "package p1;public class A{}",
1498:                                                "p1",
1499:                                                "A",
1500:                                                TempFile
1501:                                                        .cons(
1502:                                                                "package p2;public class B{public static class p1{public interface A{}}}",
1503:                                                                "p2", "B", null))));
1504:                s
1505:                        .addTest(new JavaAnalyzerTestError(
1506:                                false,
1507:                                "CompilationUnit",
1508:                                "class C extends p2.B{void f(){p1.A++;}}",
1509:                                "",
1510:                                TempFile
1511:                                        .cons(
1512:                                                "package p1;public class A{}",
1513:                                                "p1",
1514:                                                "A",
1515:                                                TempFile
1516:                                                        .cons(
1517:                                                                "package p2;public class B{public static class p1{public static int A;}}",
1518:                                                                "p2", "B", null))));
1519:                s
1520:                        .addTest(new JavaAnalyzerTestError(
1521:                                false,
1522:                                "CompilationUnit",
1523:                                "class C{C(){}C(int x){}}class D extends C{C c=new D(3);}",
1524:                                "could not find constructor"));
1525:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1526:                        "class C{C(){}}class D{C c=new C();}", ""));
1527:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1528:                        "class C{D d;}", "unknown type D"));
1529:                s
1530:                        .addTest(new JavaAnalyzerTestError(
1531:                                false,
1532:                                "CompilationUnit",
1533:                                "class C{Integer i;}class D extends C{Object o=super.i;}",
1534:                                ""));
1535:                s
1536:                        .addTest(new JavaAnalyzerTestError(
1537:                                false,
1538:                                "CompilationUnit",
1539:                                "class C{String i;}class D extends C{int i;{i=2;}}",
1540:                                ""));
1541:                s
1542:                        .addTest(new JavaAnalyzerTestError(
1543:                                false,
1544:                                "CompilationUnit",
1545:                                "class C{final void f(){}}class D extends C{void f(){}}",
1546:                                "cannot override final method"));
1547:                s
1548:                        .addTest(new JavaAnalyzerTestError(
1549:                                false,
1550:                                "CompilationUnit",
1551:                                "class C{int i;}class D extends C{Object o=1.super.i;}",
1552:                                "symbol characters expected"));
1553:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1554:                        "class C{int i;}class D extends C{Object o=super.i;}",
1555:                        "initializer type mismatch"));
1556:                s
1557:                        .addTest(new JavaAnalyzerTestError(
1558:                                false,
1559:                                "CompilationUnit",
1560:                                "class C{int i;}class D extends C{String i;{D d=null;int j=((C)d).i;}}",
1561:                                ""));
1562:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1563:                        "class C{private C(){}}class D{C c=new C();}",
1564:                        "could not find constructor"));
1565:                s
1566:                        .addTest(new JavaAnalyzerTestError(
1567:                                false,
1568:                                "CompilationUnit",
1569:                                "class C{private int i;}class D extends C{Object o=super.i;}",
1570:                                "unknown or ambiguous name"));
1571:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1572:                        "class C{private int i;}class D extends C{{i=2;}}",
1573:                        "unknown or ambiguous name"));
1574:                s
1575:                        .addTest(new JavaAnalyzerTestError(
1576:                                false,
1577:                                "CompilationUnit",
1578:                                "class C{private static class D{}}class E extends C.D{}",
1579:                                "unknown class or interface C.D"));
1580:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1581:                        "class C{private static void f(){}}class D{{C.f();}}",
1582:                        "no such method"));
1583:                s
1584:                        .addTest(new JavaAnalyzerTestError(
1585:                                false,
1586:                                "CompilationUnit",
1587:                                "class C{private void f(){}}class D extends C{int f(){return -1;}}",
1588:                                ""));
1589:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1590:                        "class C{protected C(){}}class D extends C{}", ""));
1591:                s
1592:                        .addTest(new JavaAnalyzerTestError(
1593:                                false,
1594:                                "CompilationUnit",
1595:                                "class C{public int x;}class D extends C{void f(){x=2;}}",
1596:                                ""));
1597:                s
1598:                        .addTest(new JavaAnalyzerTestError(
1599:                                false,
1600:                                "CompilationUnit",
1601:                                "class C{static class D{}}class E extends C{}class F extends E.D{}",
1602:                                ""));
1603:                s
1604:                        .addTest(new JavaAnalyzerTestError(
1605:                                false,
1606:                                "CompilationUnit",
1607:                                "class C{static void f(){}}class D extends C{void f(){}}",
1608:                                "instance method cannot override static method"));
1609:                s
1610:                        .addTest(new JavaAnalyzerTestError(
1611:                                false,
1612:                                "CompilationUnit",
1613:                                "class C{void f()throws Exception{}}class D extends C{void f()throws NullPointerException{}}",
1614:                                ""));
1615:                s
1616:                        .addTest(new JavaAnalyzerTestError(
1617:                                false,
1618:                                "CompilationUnit",
1619:                                "class C{void f()throws Exception{}}class D extends C{void f()throws Throwable{}}",
1620:                                "incompatible throws clause in overriding method"));
1621:                s
1622:                        .addTest(new JavaAnalyzerTestError(
1623:                                false,
1624:                                "CompilationUnit",
1625:                                "class C{void f(){}}class D extends C{int f(){return -1;}}",
1626:                                "incompatible return type"));
1627:                s
1628:                        .addTest(new JavaAnalyzerTestError(
1629:                                false,
1630:                                "CompilationUnit",
1631:                                "class C{void f(){}}class D extends C{private void f(){}}",
1632:                                "cannot reduce visibility"));
1633:                s
1634:                        .addTest(new JavaAnalyzerTestError(
1635:                                false,
1636:                                "CompilationUnit",
1637:                                "class C{void f(){}}class D extends C{static void f(){}}",
1638:                                "static method cannot hide instance method"));
1639:                s
1640:                        .addTest(new JavaAnalyzerTestError(
1641:                                false,
1642:                                "CompilationUnit",
1643:                                "class D extends p.C{int j=i;}",
1644:                                "",
1645:                                TempFile
1646:                                        .cons(
1647:                                                "package p;class A{int i;}interface B{int i=1;}public class C extends A implements B{}",
1648:                                                "p", "C", null)));
1649:                s
1650:                        .addTest(new JavaAnalyzerTestError(
1651:                                false,
1652:                                "CompilationUnit",
1653:                                "class D extends p.C{void m(int i){switch(i){case 1:case C.i:}}}",
1654:                                "",
1655:                                TempFile
1656:                                        .cons(
1657:                                                "package p;class A{class C{public static final int i=1;}}interface B{class C{public static final int i=2;}}public class C extends A implements B{}",
1658:                                                "p", "C", null)));
1659:                s
1660:                        .addTest(new JavaAnalyzerTestError(
1661:                                false,
1662:                                "CompilationUnit",
1663:                                "class D extends p.E{int x=C.i;}",
1664:                                "",
1665:                                TempFile
1666:                                        .cons(
1667:                                                "package p;class A{class C{public static final int i=1;}}interface B{class C{public static final int i=2;}}public class E extends A implements B{}",
1668:                                                "p", "E", null)));
1669:                s
1670:                        .addTest(new JavaAnalyzerTestError(
1671:                                false,
1672:                                "CompilationUnit",
1673:                                "import java.lang.*;import java.lang.Object;import java.lang.Integer;class A extends Object{Integer i;}",
1674:                                ""));
1675:                s
1676:                        .addTest(new JavaAnalyzerTestError(
1677:                                false,
1678:                                "CompilationUnit",
1679:                                "import java.util.Vector;import Vector.Mosquito;class A{public static void main(String[]a){System.out.println(new Vector().getClass());System.out.println(new Mosquito().getClass());}}",
1680:                                "",
1681:                                TempFile
1682:                                        .cons(
1683:                                                "package Vector;public class Mosquito{}",
1684:                                                "Vector", "Mosquito", null)));
1685:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1686:                        "import p.*;class A extends B{}", "", TempFile.cons(
1687:                                "package p;public class B{}", "p", "B", null)));
1688:                s
1689:                        .addTest(new JavaAnalyzerTestError(
1690:                                false,
1691:                                "CompilationUnit",
1692:                                "import p.A.C;class B extends C{}",
1693:                                "",
1694:                                TempFile
1695:                                        .cons(
1696:                                                "package p;public class A{public int C;public int C(){return 0;}public static class C{}}",
1697:                                                "p", "A", null)));
1698:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1699:                        "import p.A;class B implements A{}", "", TempFile.cons(
1700:                                "package p;public interface A{}", "p", "A",
1701:                                TempFile.cons("class A{}", "A", null))));
1702:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1703:                        "import p.A;import p.A;class B extends A{}", "",
1704:                        TempFile.cons("package p;public class A{}", "p", "A",
1705:                                null)));
1706:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1707:                        "import p.B;class A extends B{}", "", TempFile.cons(
1708:                                "package p;public class B{}", "p", "B", null)));
1709:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1710:                        "import p1.*;import p2.*;class B extends A{}", "",
1711:                        TempFile.cons("package p1;public class A{}", "p1", "A",
1712:                                TempFile.cons("package p2;public class A{}",
1713:                                        "p2", "A", null))));
1714:                s
1715:                        .addTest(new JavaAnalyzerTestError(
1716:                                false,
1717:                                "CompilationUnit",
1718:                                "interface A{int x=2;}interface B{int x=3;}class C implements A,B{int y=x;}",
1719:                                "unknown or ambiguous name"));
1720:                s
1721:                        .addTest(new JavaAnalyzerTestError(
1722:                                false,
1723:                                "CompilationUnit",
1724:                                "interface A{int x=2;}interface B{int x=3;}class C implements A,B{}",
1725:                                ""));
1726:                s
1727:                        .addTest(new JavaAnalyzerTestError(
1728:                                false,
1729:                                "CompilationUnit",
1730:                                "interface A{interface B{}}interface C extends A{interface D extends B{}}",
1731:                                ""));
1732:                s
1733:                        .addTest(new JavaAnalyzerTestError(
1734:                                false,
1735:                                "CompilationUnit",
1736:                                "interface A{void f();}abstract class B implements A{}",
1737:                                ""));
1738:                s
1739:                        .addTest(new JavaAnalyzerTestError(
1740:                                false,
1741:                                "CompilationUnit",
1742:                                "interface A{void f();}interface B{void f();}class C implements A,B{public void f(){}}",
1743:                                ""));
1744:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1745:                        "interface B{Class BUG=Inner.class;class Inner{}}", "",
1746:                        TempFile.cons("class A{Class c=B.BUG;}", "A", null)));
1747:                s
1748:                        .addTest(new JavaAnalyzerTestError(
1749:                                false,
1750:                                "CompilationUnit",
1751:                                "interface B{void m();}abstract class C extends p1.A implements B{}",
1752:                                "",
1753:                                TempFile
1754:                                        .cons(
1755:                                                "package p1;public abstract class A{abstract void m();}",
1756:                                                "p1", "A", null)));
1757:                s
1758:                        .addTest(new JavaAnalyzerTestError(
1759:                                false,
1760:                                "CompilationUnit",
1761:                                "interface I{int V=1;}interface J extends I{}class C implements I,J{int i=V;}",
1762:                                ""));
1763:                s
1764:                        .addTest(new JavaAnalyzerTestError(
1765:                                false,
1766:                                "CompilationUnit",
1767:                                "interface I{int V=1;}interface J{int V=2;}class C implements I,J{int i=V;}",
1768:                                "unknown or ambiguous name"));
1769:                s
1770:                        .addTest(new JavaAnalyzerTestError(
1771:                                false,
1772:                                "CompilationUnit",
1773:                                "package A;import A.B.*;class B{static class C{}}",
1774:                                ""));
1775:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1776:                        "package A;import A.B.C;public class A extends C{}",
1777:                        "", TempFile.cons("package A.B;public class C{}", "A",
1778:                                "B", "C", null)));
1779:                s
1780:                        .addTest(new JavaAnalyzerTestError(
1781:                                false,
1782:                                "CompilationUnit",
1783:                                "package bazoa;class Gabriel{static int n=org.rpgpoet.Music.wizards.length;}",
1784:                                "",
1785:                                TempFile
1786:                                        .cons(
1787:                                                "package org.rpgpoet;import java.util.Random;public interface Music{Random[]wizards=new Random[4];}",
1788:                                                "org", "rpgpoet", "Music", null)));
1789:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1790:                        "package java.lang;class Object extends Object{}",
1791:                        "Object can not have an extends clause"));
1792:                s
1793:                        .addTest(new JavaAnalyzerTestError(
1794:                                false,
1795:                                "CompilationUnit",
1796:                                "package java.lang;interface I{}class Object implements I{}",
1797:                                "Object can not have an implements clause"));
1798:                s
1799:                        .addTest(new JavaAnalyzerTestError(
1800:                                false,
1801:                                "CompilationUnit",
1802:                                "package p1;public abstract class C extends p2.B{void m(){}}",
1803:                                "",
1804:                                TempFile
1805:                                        .cons(
1806:                                                "package p1;public abstract class A{abstract void m();}",
1807:                                                "p1",
1808:                                                "A",
1809:                                                TempFile
1810:                                                        .cons(
1811:                                                                "package p2;public abstract class B extends p1.A{}",
1812:                                                                "p2", "B", null))));
1813:                s
1814:                        .addTest(new JavaAnalyzerTestError(
1815:                                false,
1816:                                "CompilationUnit",
1817:                                "package p2;import p1.*;interface I{class B{}}class C extends A implements I{static Object o=new C.B();}",
1818:                                "",
1819:                                TempFile
1820:                                        .cons(
1821:                                                "package p1;public class A{static class B{}}",
1822:                                                "p1", "A", null)));
1823:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1824:                        "package p2;import p1.A;class B extends A{}", "",
1825:                        TempFile.cons("package p1;public class A{}", "p1", "A",
1826:                                TempFile.cons("package p2;interface A{}", "p2",
1827:                                        "A", null))));
1828:                s
1829:                        .addTest(new JavaAnalyzerTestError(
1830:                                false,
1831:                                "CompilationUnit",
1832:                                "package p2;public abstract class B extends p1.A{}",
1833:                                "",
1834:                                TempFile
1835:                                        .cons(
1836:                                                "package p1;public abstract class A{abstract void m();}class C extends p2.B{void m(){}}",
1837:                                                "p1", "A", null)));
1838:                s
1839:                        .addTest(new JavaAnalyzerTestError(
1840:                                false,
1841:                                "CompilationUnit",
1842:                                "package p2;public class B extends p1.A{private class p1{}}",
1843:                                "",
1844:                                TempFile
1845:                                        .cons(
1846:                                                "package p1;public class A{public class p1{}}class C extends p2.B{p1.C p;}",
1847:                                                "p1", "A", null)));
1848:                s
1849:                        .addTest(new JavaAnalyzerTestError(
1850:                                false,
1851:                                "CompilationUnit",
1852:                                "package p2;public class B extends p1.A{protected static int m(){return 1;}}",
1853:                                "",
1854:                                TempFile
1855:                                        .cons(
1856:                                                "package p1;public class A{int m(){return 1;}}class C extends p2.B{int i=m();}",
1857:                                                "p1", "A", null)));
1858:                s
1859:                        .addTest(new JavaAnalyzerTestError(
1860:                                false,
1861:                                "CompilationUnit",
1862:                                "package p2;public class B extends p1.A{public abstract class D extends C implements I{public void m()throws Exception{}}}",
1863:                                "",
1864:                                TempFile
1865:                                        .cons(
1866:                                                "package p1;public class A{public abstract class C{abstract void m();}public interface I{void m()throws Exception;}}",
1867:                                                "p1", "A", null)));
1868:                s
1869:                        .addTest(new JavaAnalyzerTestError(
1870:                                false,
1871:                                "CompilationUnit",
1872:                                "package p2;public class B extends p1.A{}",
1873:                                "",
1874:                                TempFile
1875:                                        .cons(
1876:                                                "package p1;public class A{class p1{}}class C extends p2.B{p1.C p;}",
1877:                                                "p1", "A", null)));
1878:                s
1879:                        .addTest(new JavaAnalyzerTestError(
1880:                                false,
1881:                                "CompilationUnit",
1882:                                "package p3;import p2.*;import p1.A;class B extends A{}",
1883:                                "", TempFile.cons(
1884:                                        "package p1;public class A{}", "p1",
1885:                                        "A", TempFile.cons(
1886:                                                "package p2;interface A{}",
1887:                                                "p2", "A", null))));
1888:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1889:                        "package p;import p.A.C;class B implements C{}", "",
1890:                        TempFile.cons("package p;class A{interface C{}}", "p",
1891:                                "A", null)));
1892:                s
1893:                        .addTest(new JavaAnalyzerTestError(
1894:                                false,
1895:                                "CompilationUnit",
1896:                                "package p;public class B{public static A[]array;public static class A{}}",
1897:                                "", TempFile.cons(
1898:                                        "class A{int i=p.B.array.length;}",
1899:                                        "A", null)));
1900:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1901:                        "package p;public class B{}", "", TempFile.cons(
1902:                                "class A{p.B x;}", "A", null)));
1903:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1904:                        "package p;public class B{}", "", TempFile.cons(
1905:                                "class A{p.B[]ref;}", "A", null)));
1906:                s
1907:                        .addTest(new JavaAnalyzerTestError(
1908:                                false,
1909:                                "CompilationUnit",
1910:                                "package p;public class C{public static A[]a;public static class A{}}",
1911:                                "",
1912:                                TempFile
1913:                                        .cons(
1914:                                                "class B{Object o=p.C.array.toString();}",
1915:                                                "B", null)));
1916:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1917:                        "package q;class A extends p.B{}", "", TempFile.cons(
1918:                                "package p;public class B{void f(){}}", "p",
1919:                                "B", null)));
1920:                s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit",
1921:                        "package q;class A extends p.B{}", "", TempFile.cons(
1922:                                "package p;public class B{}", "p", "B", null)));
1923:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1924:                        "abstract class C{abstract private void f(){}}",
1925:                        "conflicting modifiers"));
1926:                s
1927:                        .addTest(new JavaAnalyzerTestError(
1928:                                false,
1929:                                "Declaration",
1930:                                "abstract class C{abstract void f();abstract int f();}",
1931:                                "duplicate method"));
1932:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1933:                        "abstract class C{public abstract String toString();}",
1934:                        ""));
1935:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1936:                        "class A extends B{}", "unknown class or interface B"));
1937:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1938:                        "class A{String[] s=new String[]{};}", ""));
1939:                s
1940:                        .addTest(new JavaAnalyzerTestError(
1941:                                false,
1942:                                "Declaration",
1943:                                "class A{boolean b=new String[]{}instanceof String[];}",
1944:                                ""));
1945:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1946:                        "class A{byte b='\\u0080';}",
1947:                        "initializer type mismatch"));
1948:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1949:                        "class A{byte b=(byte)1;char c=b;}",
1950:                        "initializer type mismatch"));
1951:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1952:                        "class A{byte b=(short)128;}",
1953:                        "initializer type mismatch"));
1954:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1955:                        "class A{byte b=1L;}", "initializer type mismatch"));
1956:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1957:                        "class A{byte n1=1;byte n2=+n1;}",
1958:                        "initializer type mismatch"));
1959:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1960:                        "class A{byte n1=1;byte n2=-n1;}",
1961:                        "initializer type mismatch"));
1962:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1963:                        "class A{byte n1=1;byte n2=~n1;}",
1964:                        "initializer type mismatch"));
1965:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1966:                        "class A{char b='\\u000d';}",
1967:                        "single character must not be line terminator"));
1968:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1969:                        "class A{char b='\\u0027';}",
1970:                        "character constant expected"));
1971:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1972:                        "class A{char b='\\u005c';}",
1973:                        "symbol characters expected"));
1974:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1975:                        "class A{char c='1';byte b=c;}",
1976:                        "initializer type mismatch"));
1977:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1978:                        "class A{char c=(byte)-1;}",
1979:                        "initializer type mismatch"));
1980:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1981:                        "class A{class B{interface C{}}}",
1982:                        "illegal context for static member"));
1983:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1984:                        "class A{class B{static class C{}}}",
1985:                        "illegal context for static member"));
1986:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1987:                        "class A{class B{static void c(){}}}",
1988:                        "illegal context for static member"));
1989:                s
1990:                        .addTest(new JavaAnalyzerTestError(
1991:                                false,
1992:                                "Declaration",
1993:                                "class A{class B{}static class C extends A{private class B{}}static class D extends C{D.B b;}}",
1994:                                "unknown type D.B"));
1995:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1996:                        "class A{double d=-1e-326;}", "literal out of range"));
1997:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
1998:                        "class A{final int i=1;}", ""));
1999:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2000:                        "class A{float f=(float)1/1.0;}",
2001:                        "initializer type mismatch"));
2002:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2003:                        "class A{int A;Class a=A.class;}", ""));
2004:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2005:                        "class A{int A;{A.class.toString();}}", ""));
2006:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2007:                        "class A{int f(){return x;}}",
2008:                        "unknown or ambiguous name"));
2009:                s
2010:                        .addTest(new JavaAnalyzerTestError(
2011:                                false,
2012:                                "Declaration",
2013:                                "class A{int f(long i){return 0;}long f(int i){return 0;}int i=f(0);}",
2014:                                "initializer type mismatch"));
2015:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2016:                        "class A{int i=-100;}", ""));
2017:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2018:                        "class A{int i=-2147483648;}", ""));
2019:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2020:                        "class A{int i=1*2L;}", "initializer type mismatch"));
2021:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2022:                        "class A{int i=1,i2=(-i)++;}",
2023:                        "operand of ++ must be variable"));
2024:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2025:                        "class A{int i=1,i2=(-i)--;}",
2026:                        "operand of -- must be variable"));
2027:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2028:                        "class A{int i=1,i2=++(-i);}",
2029:                        "operand of ++ must be variable"));
2030:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2031:                        "class A{int i=1,i2=--(-i);}",
2032:                        "operand of -- must be variable"));
2033:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2034:                        "class A{int i=123;}", ""));
2035:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2036:                        "class A{int i=1L;}", "initializer type mismatch"));
2037:                s
2038:                        .addTest(new JavaAnalyzerTestError(
2039:                                false,
2040:                                "Declaration",
2041:                                "class A{interface B{int i=1;}interface C extends B{}interface D extends B{}class E implements C,D{int j=i;}}",
2042:                                ""));
2043:                s
2044:                        .addTest(new JavaAnalyzerTestError(false,
2045:                                "Declaration", "class A{long l=0-2147483648;}",
2046:                                "literal out of range"));
2047:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2048:                        "class A{long l=0-9223372036854775808L;}",
2049:                        "literal out of range"));
2050:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2051:                        "class A{long l=1.0D;}", "initializer type mismatch"));
2052:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2053:                        "class A{long l=1L%0L;}", ""));
2054:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2055:                        "class A{long l=1L/0L;}", ""));
2056:                s
2057:                        .addTest(new JavaAnalyzerTestError(
2058:                                false,
2059:                                "Declaration",
2060:                                "class A{private class B{}class C{C(){new B();}}}",
2061:                                ""));
2062:                s
2063:                        .addTest(new JavaAnalyzerTestError(
2064:                                false,
2065:                                "Declaration",
2066:                                "class A{private class B{}static class C extends A{{new B();}}}",
2067:                                ""));
2068:                s
2069:                        .addTest(new JavaAnalyzerTestError(
2070:                                false,
2071:                                "Declaration",
2072:                                "class A{private int f(){return 1;}class B extends A{int i=this.f();}}",
2073:                                "no such method"));
2074:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2075:                        "class A{static int a=3;}", ""));
2076:                s
2077:                        .addTest(new JavaAnalyzerTestError(
2078:                                false,
2079:                                "Declaration",
2080:                                "class A{void f(){(\"1\"+2).toString();(\"1\"+2).valueOf(1);}}",
2081:                                ""));
2082:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2083:                        "class A{void f(){class B{}class B{}}}",
2084:                        "conflicting classes"));
2085:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2086:                        "class A{void f(){interface B{}}}",
2087:                        "interface cannot be local"));
2088:                s
2089:                        .addTest(new JavaAnalyzerTestError(
2090:                                false,
2091:                                "Declaration",
2092:                                "class A{void f(){try{Object.class.forName(\"java.lang.Object\");}catch(Exception e){}}}",
2093:                                ""));
2094:                s
2095:                        .addTest(new JavaAnalyzerTestError(false,
2096:                                "Declaration", "class A{void f(){x=2;}}",
2097:                                "unknown or ambiguous name"));
2098:                s
2099:                        .addTest(new JavaAnalyzerTestError(
2100:                                false,
2101:                                "Declaration",
2102:                                "class A{void f(String[]a){int i=a.length;Class c=a.getClass();String s=a.toString();}}",
2103:                                ""));
2104:                s
2105:                        .addTest(new JavaAnalyzerTestError(
2106:                                false,
2107:                                "Declaration",
2108:                                "class A{void f(int i){switch(i){case 0:case((\"\\u0080\"==\"\"+'\\u0080')?1:0):case((\"\\u0080,\\u0080\"=='\\u0080'+\",\"+'\\u0080')?3:0):}}}",
2109:                                ""));
2110:                s
2111:                        .addTest(new JavaAnalyzerTestError(
2112:                                false,
2113:                                "Declaration",
2114:                                "class A{void f(int[]a){int i=a.length;Class c=a.getClass();String s=a.toString();}}",
2115:                                ""));
2116:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2117:                        "class A{{A.class.toString();}}", ""));
2118:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2119:                        "class A{{\"\".toString();}}", ""));
2120:                s
2121:                        .addTest(new JavaAnalyzerTestError(
2122:                                false,
2123:                                "Declaration",
2124:                                "class A{{if(new String[]{}instanceof String[]);}}",
2125:                                ""));
2126:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2127:                        "class C extends ClassLoader{}", ""));
2128:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2129:                        "class C extends C{}", "circular class"));
2130:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2131:                        "class C extends String{}",
2132:                        "can't subclass final class"));
2133:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2134:                        "class C implements Cloneable, Cloneable{}",
2135:                        "duplicate superinterfaces"));
2136:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2137:                        "class C implements Runnable{abstract void run();}",
2138:                        "must be abstract"));
2139:                s
2140:                        .addTest(new JavaAnalyzerTestError(
2141:                                false,
2142:                                "Declaration",
2143:                                "class C implements Runnable{public void run(){}}",
2144:                                ""));
2145:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2146:                        "class C implements Runnable{}", "must be abstract"));
2147:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2148:                        "class C { // \n } oops", "input not fully consumed"));
2149:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2150:                        "class C { int i; C c; int j = c.i; }", ""));
2151:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2152:                        "class C { int i; int j = C.i; }",
2153:                        "static access to non-static field"));
2154:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2155:                        "class C { int i; int j = new C().i; }", ""));
2156:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2157:                        "class C { static int i; int j = C.i; }", ""));
2158:                s
2159:                        .addTest(new JavaAnalyzerTestError(
2160:                                false,
2161:                                "Declaration",
2162:                                "class C{A a=new A();static class A{private A(){}A(String s){}}{new A(null);}}",
2163:                                ""));
2164:                s
2165:                        .addTest(new JavaAnalyzerTestError(
2166:                                false,
2167:                                "Declaration",
2168:                                "class C{C() throws Exception{}C(int i)throws Exception{}{throw new java.io.IOException();}}",
2169:                                ""));
2170:                s
2171:                        .addTest(new JavaAnalyzerTestError(
2172:                                false,
2173:                                "Declaration",
2174:                                "class C{C() throws Exception{}C(int i){}{throw new Exception();}}",
2175:                                "uncaught exception"));
2176:                s
2177:                        .addTest(new JavaAnalyzerTestError(
2178:                                false,
2179:                                "Declaration",
2180:                                "class C{C() throws Exception{}{throw new Exception();}}",
2181:                                ""));
2182:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2183:                        "class C{C(){return null;}}",
2184:                        "'return' with a value, in method returning void"));
2185:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2186:                        "class C{C(){}C(){}}", "duplicate method"));
2187:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2188:                        "class C{Class c=Object[].class;}", ""));
2189:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2190:                        "class C{Class c=Runnable[][][][].class;}", ""));
2191:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2192:                        "class C{Class c=UnknownType.class;}",
2193:                        "unknown class or interface UnknownType"));
2194:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2195:                        "class C{Object f(){class D{}return new D();}}", ""));
2196:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2197:                        "class C{Object f(){return new Object();}}", ""));
2198:                s
2199:                        .addTest(new JavaAnalyzerTestError(
2200:                                false,
2201:                                "Declaration",
2202:                                "class C{Object x=new java.util.AbstractCollection();}",
2203:                                "cannot instantiate abstract type"));
2204:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2205:                        "class C{Object[]a={new Object()};}", ""));
2206:                s
2207:                        .addTest(new JavaAnalyzerTestError(
2208:                                false,
2209:                                "Declaration",
2210:                                "class C{String s1=(String)\"\";String s2=(String)null;String s3=(String)s1;String s4=(String)s2;String s5=(String)(\"1\"+\"2\");String s6=\"1\".concat(\"2\");}",
2211:                                ""));
2212:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2213:                        "class C{String s=new Object();}",
2214:                        "initializer type mismatch"));
2215:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2216:                        "class C{String toString(){return null;}}",
2217:                        "cannot reduce visibility"));
2218:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2219:                        "class C{abstract void f();}", "must be abstract"));
2220:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2221:                        "class C{boolean b=\"null\"==null;}", ""));
2222:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2223:                        "class C{boolean b=null==\"1\";}", ""));
2224:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2225:                        "class C{class D{static final int i=0;}}", ""));
2226:                s
2227:                        .addTest(new JavaAnalyzerTestError(false,
2228:                                "Declaration",
2229:                                "class C{class D{static int i=0;}}",
2230:                                "static variables of inner classes must be compile-time constants"));
2231:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2232:                        "class C{class D{static{}}}",
2233:                        "inner classes may not declare static initializers"));
2234:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2235:                        "class C{d(){}}", "missing return type"));
2236:                s
2237:                        .addTest(new JavaAnalyzerTestError(
2238:                                false,
2239:                                "Declaration",
2240:                                "class C{final Object[]a={new Object(),new Object()};void swap(){Object t=a[0];a[0]=a[1];a[1]=t;}}",
2241:                                ""));
2242:                s
2243:                        .addTest(new JavaAnalyzerTestError(
2244:                                false,
2245:                                "Declaration",
2246:                                "class C{final StringBuffer s=new StringBuffer();void append(){s.append(\"nuggy\");}}",
2247:                                ""));
2248:                s
2249:                        .addTest(new JavaAnalyzerTestError(
2250:                                false,
2251:                                "Declaration",
2252:                                "class C{final int i=1;{switch (123){case 0:case (i==1)?1:0:}}}",
2253:                                ""));
2254:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2255:                        "class C{final volatile int i=0;}",
2256:                        "conflicting modifiers final and volatile"));
2257:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2258:                        "class C{int f(){return 0;}}", ""));
2259:                s
2260:                        .addTest(new JavaAnalyzerTestError(false,
2261:                                "Declaration", "class C{int f(){return 3.1;}}",
2262:                                "return type mismatch"));
2263:                s
2264:                        .addTest(new JavaAnalyzerTestError(false,
2265:                                "Declaration", "class C{int f(){return;}}",
2266:                                "'return' with no value, in method returning non-void"));
2267:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2268:                        "class C{int foo;Class c=foo.class;}",
2269:                        "unknown class or interface foo"));
2270:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2271:                        "class C{int i;static int f(){return i;}}",
2272:                        "static use of instance field"));
2273:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2274:                        "class C{int i;void f(int i){}}", ""));
2275:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2276:                        "class C{int i=0;static int j=i;}",
2277:                        "static use of instance field"));
2278:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2279:                        "class C{int i=1/0;}", ""));
2280:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2281:                        "class C{int i=1;byte b=i;}",
2282:                        "initializer type mismatch"));
2283:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2284:                        "class C{int i=i=2;}", ""));
2285:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2286:                        "class C{int x;int x;}",
2287:                        "duplicate field declaration x"));
2288:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2289:                        "class C{int x=2;void f(){class D{int j=x;}}}", ""));
2290:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2291:                        "class C{int[] a = {123L};}",
2292:                        "array initializer type mismatch"));
2293:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2294:                        "class C{int[] a = {123};}", ""));
2295:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2296:                        "class C{int[][]ia={{1,2},null};}", ""));
2297:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2298:                        "class C{int[]a={new Object()};}",
2299:                        "array initializer type mismatch"));
2300:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2301:                        "class C{int[]f(){return g();}int g()[]{return f();}}",
2302:                        ""));
2303:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2304:                        "class C{int[]ia={{1,2},null};}",
2305:                        "array initializer type mismatch"));
2306:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2307:                        "class C{native strictfp void f();}",
2308:                        "conflicting modifiers"));
2309:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2310:                        "class C{private class D{}class E extends C{E.D d;}}",
2311:                        "unknown type E.D"));
2312:                s
2313:                        .addTest(new JavaAnalyzerTestError(
2314:                                false,
2315:                                "Declaration",
2316:                                "class C{public static int f(){return 5;}interface I{int CONSTANT=f();}}",
2317:                                ""));
2318:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2319:                        "class C{short s='\u8000';}",
2320:                        "initializer type mismatch"));
2321:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2322:                        "class C{short s=(short)1;char c=s;}",
2323:                        "initializer type mismatch"));
2324:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2325:                        "class C{static C f(){return this;}}",
2326:                        "static use of this"));
2327:                s
2328:                        .addTest(new JavaAnalyzerTestError(
2329:                                false,
2330:                                "Declaration",
2331:                                "class C{static String s=\"1\";void f(int j){switch(j){case 0:case((C.s==\"1\")?1:0):}}}",
2332:                                "case expression must be constant"));
2333:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2334:                        "class C{static class D{interface I{}}}", ""));
2335:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2336:                        "class C{static class D{static{}}}", ""));
2337:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2338:                        "class C{static final String a=\"b\";}", ""));
2339:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2340:                        "class C{static int c=super.hashCode();}",
2341:                        "static use of super"));
2342:                s
2343:                        .addTest(new JavaAnalyzerTestError(
2344:                                false,
2345:                                "Declaration",
2346:                                "class C{static int f()throws Exception{return 0;}int i=C.f();}",
2347:                                "uncaught exception"));
2348:                s
2349:                        .addTest(new JavaAnalyzerTestError(
2350:                                false,
2351:                                "Declaration",
2352:                                "class C{static int f()throws Exception{return 0;}static int i=C.f();}",
2353:                                "uncaught exception"));
2354:                s
2355:                        .addTest(new JavaAnalyzerTestError(
2356:                                false,
2357:                                "Declaration",
2358:                                "class C{static int m() throws Exception {return 1;}static int i=m();}",
2359:                                "uncaught exception"));
2360:                s
2361:                        .addTest(new JavaAnalyzerTestError(
2362:                                false,
2363:                                "Declaration",
2364:                                "class C{static void f(){class D{{new D();}}new D();{new D();}}}",
2365:                                ""));
2366:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2367:                        "class C{static{throw new Exception();}}",
2368:                        "uncaught exception"));
2369:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2370:                        "class C{void f();}", "missing method body"));
2371:                s
2372:                        .addTest(new JavaAnalyzerTestError(
2373:                                false,
2374:                                "Declaration",
2375:                                "class C{void f()throws ClassNotFoundException{throw new Exception();}}",
2376:                                "uncaught exception"));
2377:                s
2378:                        .addTest(new JavaAnalyzerTestError(
2379:                                false,
2380:                                "Declaration",
2381:                                "class C{void f()throws Exception{throw new Exception();}}",
2382:                                ""));
2383:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2384:                        "class C{void f(){12--;}}",
2385:                        "operand of -- must be variable"));
2386:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2387:                        "class C{void f(){Comparable x;Comparable: x=\"c\";}}",
2388:                        ""));
2389:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2390:                        "class C{void f(){String i;i++;}}",
2391:                        "operand of ++ must be number"));
2392:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2393:                        "class C{void f(){String s=new Integer();}}",
2394:                        "could not find constructor"));
2395:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2396:                        "class C{void f(){boolean b;b--;}}",
2397:                        "operand of -- must be number"));
2398:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2399:                        "class C{void f(){final int i;i++;}}",
2400:                        "operand of ++ must not be final"));
2401:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2402:                        "class C{void f(){final int x=2;class D{int j=x;}}}",
2403:                        ""));
2404:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2405:                        "class C{void f(){for (int i=0;i<10;++i) continue;}}",
2406:                        ""));
2407:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2408:                        "class C{void f(){int i;i++++;}}",
2409:                        "operand of ++ must be variable"));
2410:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2411:                        "class C{void f(){int i;i++;}}", ""));
2412:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2413:                        "class C{void f(){int i;j++;}}",
2414:                        "operand of ++ must be variable"));
2415:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2416:                        "class C{void f(){int i;}}", ""));
2417:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2418:                        "class C{void f(){int true;}}", "illegal identifier"));
2419:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2420:                        "class C{void f(){return 0;}}",
2421:                        "'return' with a value, in method returning void"));
2422:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2423:                        "class C{void f(){return;}}", ""));
2424:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2425:                        "class C{void f(){throw null;}}", ""));
2426:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2427:                        "class C{void f(){x:y:{for(;;)break x;}}}", ""));
2428:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2429:                        "class C{void f(){x:y:{for(;;)continue x;}}}",
2430:                        "x is not a loop label"));
2431:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2432:                        "class C{void f(){x:{ for (;;) break x;}}}", ""));
2433:                s
2434:                        .addTest(new JavaAnalyzerTestError(
2435:                                false,
2436:                                "Declaration",
2437:                                "class C{void f(){x:{ for (int i=0;i<10;++i) continue x;}}}",
2438:                                "x is not a loop label"));
2439:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2440:                        "class C{void f(){}void f(){}}", "duplicate method"));
2441:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2442:                        "class C{void f(byte b){switch(b){case 0x1ff:}}}",
2443:                        "invalid case clause"));
2444:                s
2445:                        .addTest(new JavaAnalyzerTestError(
2446:                                false,
2447:                                "Declaration",
2448:                                "class C{void f(char c)throws Exception{}void f(int i){}void g(){f(true?'0':-1);f(false?'0':-1);f(true?-1:'0');f(false?-1:'0');}}",
2449:                                ""));
2450:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2451:                        "class C{void f(char c){switch(c){case 123:}}}", ""));
2452:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2453:                        "class C{void f(final int i){i=1;}}",
2454:                        "left operand of assignment is final"));
2455:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2456:                        "class C{void f(final int x){class D{int j=x;}}}", ""));
2457:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2458:                        "class C{void f(int i){for(int i=2;;);}}",
2459:                        "duplicate variable declaration i"));
2460:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2461:                        "class C{void f(int i){for(int j=2,k=3;;);}}", ""));
2462:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2463:                        "class C{void f(int i){int i;}}",
2464:                        "duplicate variable declaration i"));
2465:                s
2466:                        .addTest(new JavaAnalyzerTestError(
2467:                                false,
2468:                                "Declaration",
2469:                                "class C{void f(int i){switch(i){case 0:case(('\\u0061'=='a')?1:0):}}}",
2470:                                ""));
2471:                s
2472:                        .addTest(new JavaAnalyzerTestError(
2473:                                false,
2474:                                "Declaration",
2475:                                "class C{void f(int i){switch(i){case 0:case(('\\uABcD'=='\\uabCd')?1:0):}}}",
2476:                                ""));
2477:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2478:                        "class C{void f(int i){switch(i){}}}", ""));
2479:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2480:                        "class C{void f(int i){{int i;}}}",
2481:                        "duplicate variable declaration i"));
2482:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2483:                        "class C{void f(int i){for(int i=2;;);}}",
2484:                        "duplicate variable declaration i"));
2485:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2486:                        "class C{void f(int i,int i);}",
2487:                        "duplicate parameter declaration i"));
2488:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2489:                        "class C{void f(int[]a){int b;b=a.length;}}", ""));
2490:                s
2491:                        .addTest(new JavaAnalyzerTestError(false,
2492:                                "Declaration", "class C{void m(){break;}}",
2493:                                "break without label can only be used in loop or switch"));
2494:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2495:                        "class C{void m(){continue;}}",
2496:                        "continue cannot be used outside of a loop"));
2497:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2498:                        "class C{void m(){i:{i:{}}}}", "duplicate label i"));
2499:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2500:                        "class C{void m(){i:{}}}", ""));
2501:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2502:                        "class C{{int i=1;switch(123){case i++:;}}}",
2503:                        "case expression must be constant"));
2504:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2505:                        "class C{{new C();}}", ""));
2506:                s
2507:                        .addTest(new JavaAnalyzerTestError(
2508:                                false,
2509:                                "Declaration",
2510:                                "class C{{try{throw new ClassNotFoundException();}catch(Exception e){}}}",
2511:                                ""));
2512:                s
2513:                        .addTest(new JavaAnalyzerTestError(
2514:                                false,
2515:                                "Declaration",
2516:                                "class C{{try{throw new Exception();}catch(ClassNotFoundException e){}}}",
2517:                                "uncaught exception"));
2518:                s
2519:                        .addTest(new JavaAnalyzerTestError(
2520:                                false,
2521:                                "Declaration",
2522:                                "class C{{try{throw new Exception();}catch(Exception e){}}}",
2523:                                ""));
2524:                s
2525:                        .addTest(new JavaAnalyzerTestError(
2526:                                false,
2527:                                "Declaration",
2528:                                "class C{{try{try{throw new Exception();}catch(ClassNotFoundException e){}}catch(ClassNotFoundException e){}}}",
2529:                                "uncaught exception"));
2530:                s
2531:                        .addTest(new JavaAnalyzerTestError(
2532:                                false,
2533:                                "Declaration",
2534:                                "class C{{try{try{throw new Exception();}catch(ClassNotFoundException e){}}catch(Exception e){}}}",
2535:                                ""));
2536:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2537:                        "class C{{try{}catch(Exception e){}}}", ""));
2538:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2539:                        "class C{{try{}catch(String e){}}}",
2540:                        "illegal type for exception parameter"));
2541:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2542:                        "class C{{try{}catch(int e){}}}",
2543:                        "illegal type for exception parameter"));
2544:                s
2545:                        .addTest(new JavaAnalyzerTestError(
2546:                                false,
2547:                                "Declaration",
2548:                                "class H { static void i() { } static H k() { } }",
2549:                                ""));
2550:                s
2551:                        .addTest(new JavaAnalyzerTestError(
2552:                                false,
2553:                                "Declaration",
2554:                                "class TestString { char[] value; int offset, count; int indexOf(TestString str, int fromIndex) { char[] v1 = value, v2 = str.value; int max = offset + (count - str.count); int start = offset + ((fromIndex < 0) ? 0 : fromIndex); i: for (int i = start; i <= max; i++) { int n = str.count, j = i, k = str.offset; while (n-- != 0) { if (v1[j++] != v2[k++]) continue i; } return i - offset; } return -1; } }",
2555:                                ""));
2556:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2557:                        "final abstract class C {}",
2558:                        "can not be both abstract and final"));
2559:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2560:                        "interface A{;}", ""));
2561:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2562:                        "interface A{A a=null;int i=1;int j=a.i;}", ""));
2563:                s.addTest(new JavaAnalyzerTestError(false, "Declaration",
2564:                        "public class C{void f(){Object[]o=null;}}", ""));
2565:                s
2566:                        .addTest(new JavaAnalyzerTestError(false,
2567:                                "Declaration", "public public class C{}",
2568:                                "duplicate modifier public"));
2569:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2570:                        "'\\u000a'",
2571:                        "single character must not be line terminator"));
2572:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2573:                        "'\\u001a'", ""));
2574:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2575:                        "'\\u03a9'", ""));
2576:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2577:                        "'\\uFFFF'", ""));
2578:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2579:                        "'\\uuuuuuuuuuabcd'", ""));
2580:                s
2581:                        .addTest(new JavaAnalyzerTestError(false, "Expression",
2582:                                "'\n'",
2583:                                "single character must not be line terminator"));
2584:                s
2585:                        .addTest(new JavaAnalyzerTestError(false, "Expression",
2586:                                "'\r'",
2587:                                "single character must not be line terminator"));
2588:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2589:                        "(Object).class", "input not fully consumed"));
2590:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2591:                        "-100", ""));
2592:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2593:                        "-1e-326", "literal out of range"));
2594:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2595:                        "-1e310", "literal out of range"));
2596:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2597:                        "-2147483648", ""));
2598:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2599:                        "-Float.NaN", ""));
2600:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2601:                        "02000000000000000000000L", "literal out of range"));
2602:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2603:                        "040000000000", "literal out of range"));
2604:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2605:                        "0x123456789", "literal out of range"));
2606:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2607:                        "0x123456789abcdef01L", "literal out of range"));
2608:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2609:                        "0xCafeBabe", ""));
2610:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2611:                        "1.class", "input not fully consumed"));
2612:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2613:                        "1// This is a comment\n", ""));
2614:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2615:                        "123 instanceof String", "reference type expected"));
2616:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2617:                        "12345678901", "literal out of range"));
2618:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2619:                        "12345678901234567890L", "literal out of range"));
2620:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2621:                        "1234?1:0", "condition must be boolean"));
2622:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2623:                        "1\\u002f\\u002f This is a comment\\u000a", ""));
2624:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2625:                        "1e-47f", "literal out of range"));
2626:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2627:                        "1e39f", "literal out of range"));
2628:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2629:                        "2147483648", "literal out of range"));
2630:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2631:                        "9223372036854775808L", "literal out of range"));
2632:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2633:                        "Object.noSuchMethod()", "no such method"));
2634:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2635:                        "String.class", ""));
2636:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2637:                        "System.gc()", ""));
2638:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2639:                        "System.out instanceof String", "not castable"));
2640:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2641:                        "System.out.println()", ""));
2642:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2643:                        "\"\".class", "input not fully consumed"));
2644:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2645:                        "\"\\u001a\"", ""));
2646:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2647:                        "\"\\u005c\\u005a\"", "symbol characters expected"));
2648:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2649:                        "\"\\u03a9\"", ""));
2650:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2651:                        "\"\\uFFFF\"", ""));
2652:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2653:                        "\"\n\"", "string must not contain line terminator"));
2654:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2655:                        "\"\r\"", "string must not contain line terminator"));
2656:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2657:                        "\"hello\" instanceof Object", ""));
2658:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2659:                        "\"hello\" instanceof String", ""));
2660:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2661:                        "\"hi\" instanceof int", "reference type expected"));
2662:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2663:                        "false?-1:'0'", ""));
2664:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2665:                        "int.class", ""));
2666:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2667:                        "int[][].class", ""));
2668:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2669:                        "java.io.PrintStream.println()",
2670:                        "static call to non-static method"));
2671:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2672:                        "new Object()", ""));
2673:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2674:                        "new String().class", "input not fully consumed"));
2675:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2676:                        "new String(123)", "could not find constructor"));
2677:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2678:                        "new String[]{}instanceof String[]", ""));
2679:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2680:                        "new int['3']", ""));
2681:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2682:                        "new int[0]", ""));
2683:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2684:                        "new int[3.0]", "dimension must be integer"));
2685:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2686:                        "new int[3L]", "dimension must be integer"));
2687:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2688:                        "new int[3]", ""));
2689:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2690:                        "new int[3][3]", ""));
2691:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2692:                        "new int[3][]", ""));
2693:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2694:                        "new int[null]", "dimension must be integer"));
2695:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2696:                        "null instanceof int[]", ""));
2697:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2698:                        "null.class", "input not fully consumed"));
2699:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2700:                        "null==\"\"", ""));
2701:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2702:                        "this.class", "input not fully consumed"));
2703:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2704:                        "true?'0':-1", ""));
2705:                s.addTest(new JavaAnalyzerTestError(false, "Expression",
2706:                        "true?1:0", ""));
2707:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2708:                        "i:for(;;){break i;}", ""));
2709:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2710:                        "switch('a'){}", ""));
2711:                s
2712:                        .addTest(new JavaAnalyzerTestError(
2713:                                false,
2714:                                "Statement",
2715:                                "switch(12){case 0:case(((double)'\u789a'==30874.0)?1:0):}",
2716:                                ""));
2717:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2718:                        "switch(12){case 1:case 1:}", "duplicate case clause"));
2719:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2720:                        "switch(12){case 1:case 2:}", ""));
2721:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2722:                        "switch(12){default:default:}",
2723:                        "duplicate default clause"));
2724:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2725:                        "switch(12){}", ""));
2726:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2727:                        "switch(12.3){}",
2728:                        "switch expression must be char, byte, short, or int"));
2729:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2730:                        "switch(123){case 0.0D:}", "invalid case clause"));
2731:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2732:                        "switch(123){case 0:class C{}break;}", ""));
2733:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2734:                        "switch(123){case 0:class C{}break;}", ""));
2735:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2736:                        "switch(123){case true:}", "invalid case clause"));
2737:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2738:                        "synchronized(12.5) {}",
2739:                        "invalid type for synchronized statement"));
2740:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2741:                        "synchronized(null) {}",
2742:                        "invalid type for synchronized statement"));
2743:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2744:                        "throw new ClassNotFoundException();",
2745:                        "uncaught exception"));
2746:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2747:                        "throw new Error();", ""));
2748:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2749:                        "throw new Exception();", "uncaught exception"));
2750:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2751:                        "throw new NullPointerException();", ""));
2752:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2753:                        "throw new RuntimeException();", ""));
2754:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2755:                        "while(1);", "condition must be boolean"));
2756:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2757:                        "while(true);", ""));
2758:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2759:                        "while(true){break;}", ""));
2760:                s
2761:                        .addTest(new JavaAnalyzerTestError(
2762:                                false,
2763:                                "Statement",
2764:                                "{class C{final int i=1;}class D extends C{{switch (123){case 0:case (i==1)?1:0:}}}}",
2765:                                ""));
2766:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2767:                        "{class C{int i=1; class D{int j=i;}}}", ""));
2768:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2769:                        "{class C{}}", ""));
2770:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2771:                        "{i:while(true){continue i;}}", ""));
2772:                s.addTest(new JavaAnalyzerTestError(false, "Statement",
2773:                        "{i:{continue j;}}", "the label j is missing"));
2774:                return s;
2775:            }
2776:
2777:            private static TestSuite makeSuiteJavaExternalAnalyzer() {
2778:                //    final boolean ignore = true; //T D 38 failing unit tests
2779:                final TestSuite s = new TestSuite();
2780:                //  s.addTest(new JavaExternalAnalyzerTestType(false, "Declaration", "", "", true));
2781:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2782:                        false, "class A extends B implements D,C{}",
2783:                        "class A extends B implements D,C{A()->void;}"));
2784:                s
2785:                        .addTest(new JavaExternalAnalyzerTest(false,
2786:                                "Declaration", false,
2787:                                "class A{class C{}class B{}}",
2788:                                "class A{A()->void;class A.B{B()->void;};class A.C{C()->void;};}"));
2789:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2790:                        false, "class A{int b;}",
2791:                        "class A{field(int,b);A()->void;}"));
2792:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2793:                        false, "class A{void b();C[]d;}",
2794:                        "class A{field(C[],d);A()->void;b()->void;}"));
2795:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2796:                        false, "class A{}", "class A{A()->void;}"));
2797:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2798:                        false, "interface A extends B,D,C{}",
2799:                        "abstract interface A extends B,D,C{}"));
2800:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2801:                        false, "public final class A{}",
2802:                        "public final class A{public A()->void;}"));
2803:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2804:                        true, "A b,c;", "field(A,b);field(A,c);"));
2805:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2806:                        true, "A b;", "field(A,b);"));
2807:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2808:                        true, "A b=1;", "field(A,b);"));
2809:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2810:                        true, "A[]b;", "field(A[],b);"));
2811:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2812:                        true, "A[]b[];", "field(A[][],b);"));
2813:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2814:                        true, "a.b.C[]d,e[];",
2815:                        "field(a.b.C[],d); field(a.b.C[][],e);"));
2816:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2817:                        true, "char a;", "field(char,a);"));
2818:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2819:                        true, "int a();", "a()->int"));
2820:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2821:                        true, "int b(){}", "b()->int"));
2822:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2823:                        true, "int b(C d);", "b(param(C,d))->int"));
2824:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2825:                        true, "int b(C d,E[]f,G[][]h);",
2826:                        "b(param(C,d),param(E[],f),param(G[][],h))->int"));
2827:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2828:                        true, "public static final String s;",
2829:                        "public static final field(String,s);"));
2830:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2831:                        true, "public strictfp float b();",
2832:                        "public strictfp b()->float"));
2833:                s.addTest(new JavaExternalAnalyzerTest(false, "Declaration",
2834:                        true, "void a();", "a()->void"));
2835:                s.addTest(new JavaExternalAnalyzerTest(false, "Type", "A"));
2836:                s.addTest(new JavaExternalAnalyzerTest(false, "Type", "A[]"));
2837:                s.addTest(new JavaExternalAnalyzerTest(false, "Type", "A[][]"));
2838:                s.addTest(new JavaExternalAnalyzerTest(false, "Type", "a.B"));
2839:                s.addTest(new JavaExternalAnalyzerTest(false, "Type",
2840:                        "a.b.C[][]"));
2841:                s.addTest(new JavaExternalAnalyzerTest(false, "Type", "byte"));
2842:                s
2843:                        .addTest(new JavaExternalAnalyzerTest(false, "Type",
2844:                                "char[]"));
2845:                return s;
2846:            }
2847:
2848:            private static TestSuite makeSuiteJavaParser() {
2849:                final boolean ignore = true; //TD 38 parser-related bugs
2850:                final TestSuite s = new TestSuite();
2851:                //s.addTest(new JavaParserTest("", false, "", ""));
2852:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
2853:                        "class C{int i;C t;void f(){t.(i)=1;}}",
2854:                        "invalid syntax"));
2855:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
2856:                        "class C{static void f(){int i;(i=1);}}",
2857:                        "invalid expression statement"));
2858:                s.addTest(new JavaAnalyzerTestError(ignore, "Declaration",
2859:                        "class C{void f(){}void g(){(f());}}",
2860:                        "invalid expression statement"));
2861:                s.addTest(new JavaParserTest(ignore, "Expression",
2862:                        "class C{int i = new int[]{1}[0];}"));
2863:                s.addTest(new JavaParserTest(false, "Expression", "(a+b)*c"));
2864:                s.addTest(new JavaParserTest(false, "Expression", "a&b==c&&d"));
2865:                s.addTest(new JavaParserTest(false, "Expression", "a+1"));
2866:                s.addTest(new JavaParserTest(false, "Expression", "a+b*c"));
2867:                s.addTest(new JavaParserTest(false, "Expression", "a-(b-c)"));
2868:                s.addTest(new JavaParserTest(false, "Expression", "a-b-c"));
2869:                s.addTest(new JavaParserTest(false, "Expression", "a.f(0)"));
2870:                s
2871:                        .addTest(new JavaParserTest(false, "Expression",
2872:                                "a.f(a,b,c)"));
2873:                s.addTest(new JavaParserTest(false, "Expression", "f()"));
2874:                s.addTest(new JavaParserTest(false, "Expression", "f().g()"));
2875:                s.addTest(new JavaParserTest(false, "Expression", "f(0)"));
2876:                s
2877:                        .addTest(new JavaParserTest(false, "Statement",
2878:                                "switch (i) { case 'a': case 2: break; case 0x1: { } default: }"));
2879:                s.addTest(new JavaParserTest(false, "Expression", "(A)b"));
2880:                s.addTest(new JavaParserTest(false, "Expression", "(A[][])b"));
2881:                s.addTest(new JavaParserTest(false, "Expression", "(char[])a"));
2882:                s.addTest(new JavaParserTest(false, "Expression", "(int)'a'"));
2883:                s.addTest(new JavaParserTest(false, "Expression", "(int)a"));
2884:                s.addTest(new JavaParserTest(false, "Expression",
2885:                        "Integer[].class"));
2886:                s.addTest(new JavaParserTest(false, "Expression", "int.class"));
2887:                s
2888:                        .addTest(new JavaParserTest(false, "Expression",
2889:                                "int[].class"));
2890:                s
2891:                        .addTest(new JavaParserTest(false, "Expression",
2892:                                "void.class"));
2893:                s.addTest(new JavaParserTest(false, "CompilationUnit",
2894:                        "class A{class B{}} class C{ A.B b=new A().new B();}"));
2895:                s
2896:                        .addTest(new JavaParserTest(
2897:                                false,
2898:                                "CompilationUnit",
2899:                                "class Main { public static void main(String[] args) { System.class.println(\"Hello world!\"); } }"));
2900:                s.addTest(new JavaParserTest(false, "Expression",
2901:                        "(a==++b.c(1)[d.e()][2].f&g)-h"));
2902:                s.addTest(new JavaParserTest(false, "Declaration", "A a=0;"));
2903:                s.addTest(new JavaParserTest(false, "Declaration", "A b,c;"));
2904:                s.addTest(new JavaParserTest(false, "Declaration", "A b;"));
2905:                s.addTest(new JavaParserTest(false, "Declaration",
2906:                        "A b[],c,d[][];"));
2907:                s.addTest(new JavaParserTest(false, "Declaration", "A[]b;"));
2908:                s.addTest(new JavaParserTest(false, "Declaration", "A[]b[];"));
2909:                s.addTest(new JavaParserTest(false, "Declaration", "int a;"));
2910:                s.addTest(new JavaParserTest(false, "Declaration",
2911:                        "public A b;"));
2912:                s.addTest(new JavaParserTest(false, "Declaration",
2913:                        "public final A b;"));
2914:                s
2915:                        .addTest(new JavaParserTest(false, "Statement",
2916:                                "for(0,1;;);"));
2917:                s.addTest(new JavaParserTest(false, "Statement", "for(;;);"));
2918:                s.addTest(new JavaParserTest(false, "Statement",
2919:                        "for(A b=c,d=e;;);"));
2920:                s.addTest(new JavaParserTest(false, "Statement",
2921:                        "for(A[]b[];;);"));
2922:                s.addTest(new JavaParserTest(false, "Statement",
2923:                        "for(int a=0,b=c;a<b;a++)d*=2;"));
2924:                s.addTest(new JavaParserTest(false, "Statement",
2925:                        "for(int a=0;;);"));
2926:                s.addTest(new JavaParserTest(false, "FormalParameter", "A b"));
2927:                s.addTest(new JavaParserTest(false, "FormalParameter",
2928:                        "a[][] b"));
2929:                s.addTest(new JavaParserTest(false, "FormalParameter",
2930:                        "final int i"));
2931:                s.addTest(new JavaParserTest(false, "Statement", "if(a)b;"));
2932:                s.addTest(new JavaParserTest(false, "Statement",
2933:                        "if(a)b;else c;"));
2934:                s.addTest(new JavaParserTest(false, "Declaration", "A b();"));
2935:                s
2936:                        .addTest(new JavaParserTest(false, "Declaration",
2937:                                "A b(C d);"));
2938:                s.addTest(new JavaParserTest(false, "Declaration",
2939:                        "A b(C d,E[]f){}"));
2940:                s.addTest(new JavaParserTest(false, "Declaration",
2941:                        "X A()throws B{}"));
2942:                s.addTest(new JavaParserTest(false, "Declaration", "X A(){}"));
2943:                s.addTest(new JavaParserTest(false, "Declaration",
2944:                        "char a()throws B,C;"));
2945:                s.addTest(new JavaParserTest(false, "Declaration",
2946:                        "public final int[]a(){}"));
2947:                s
2948:                        .addTest(new JavaParserTest(false, "Declaration",
2949:                                "void a();"));
2950:                s.addTest(new JavaParserTest(false, "Expression", "a.new B()"));
2951:                s.addTest(new JavaParserTest(false, "Expression",
2952:                        "a.new B().new C()"));
2953:                s.addTest(new JavaParserTest(false, "Expression",
2954:                        "a.new B(c,d)"));
2955:                s.addTest(new JavaParserTest(false, "Expression", "new A()"));
2956:                s.addTest(new JavaParserTest(false, "Expression", "new A(){}"));
2957:                s.addTest(new JavaParserTest(false, "Expression", "new A[2]"));
2958:                s
2959:                        .addTest(new JavaParserTest(false, "Expression",
2960:                                "new A[2][]"));
2961:                s.addTest(new JavaParserTest(false, "Expression",
2962:                        "new A[][]{{b,c},{d,e}}"));
2963:                s.addTest(new JavaParserTest(false, "Expression",
2964:                        "new A[]{b,c}"));
2965:                s.addTest(new JavaParserTest(false, "Expression", "a.b"));
2966:                s.addTest(new JavaParserTest(false, "Expression", "a.b.c"));
2967:                s.addTest(new JavaParserTest(false, "Expression", "a.class"));
2968:                s.addTest(new JavaParserTest(false, "Expression", "a.class.b"));
2969:                s
2970:                        .addTest(new JavaParserTest(false, "Expression",
2971:                                "a.class.b.c"));
2972:                s.addTest(new JavaParserTest(false, "Expression", "a[0]"));
2973:                s.addTest(new JavaParserTest(false, "Expression", "a[0][1]"));
2974:                s
2975:                        .addTest(new JavaParserTest(false, "Expression",
2976:                                "a[b][c][d]"));
2977:                s.addTest(new JavaParserTest(false, "Statement",
2978:                        "switch(123){case 0:}"));
2979:                s.addTest(new JavaParserTest(false, "Statement",
2980:                        "try{}catch(A b){}"));
2981:                s.addTest(new JavaParserTest(false, "Statement",
2982:                        "try{}catch(A b){}catch(C d){}finally{}"));
2983:                s.addTest(new JavaParserTest(false, "Statement",
2984:                        "try{}catch(A b){}finally{}"));
2985:                s.addTest(new JavaParserTest(false, "Statement",
2986:                        "try{}finally{}"));
2987:                s.addTest(new JavaParserTest(false, "Expression", "!a++"));
2988:                s.addTest(new JavaParserTest(false, "Expression", "++a"));
2989:                s
2990:                        .addTest(new JavaParserTest(false, "Expression",
2991:                                "+-!~--a++--"));
2992:                s.addTest(new JavaParserTest(false, "Expression", "-a"));
2993:                s.addTest(new JavaParserTest(false, "Expression", "a++"));
2994:                s.addTest(new JavaParserTest(false, "Expression", "a--"));
2995:                s.addTest(new JavaParserTest(false, "Declaration",
2996:                        "class C{int[] a = {,};}", "class C{int[] a = {};}"));
2997:                s.addTest(new JavaParserTest(false, "Declaration",
2998:                        "class C{int[] a = {1,};}", "class C{int[] a = {1};}"));
2999:                s.addTest(new JavaParserTest(false, "Expression",
3000:                        "'\\u005c\\u0030'"));
3001:                s.addTest(new JavaParserTest(false, "CompilationUnit",
3002:                        "class c{ { this(); super(); } }"));
3003:                s.addTest(new JavaParserTest(false, "Expression", "super()"));
3004:                s.addTest(new JavaParserTest(false, "Expression", "this()"));
3005:                s.addTest(new JavaParserTest(false, "Expression",
3006:                        "this(1, 2, null)"));
3007:                s.addTest(new JavaParserTest(false, "Expression", "z.super()"));
3008:                s.addTest(new JavaParserTest(false, "CompilationUnit",
3009:                        "class A{}//", "class A{}"));
3010:                s.addTest(new JavaParserTest(false, "Statement", "\\u0062:;"));
3011:                s.addTest(new JavaParserTest(false, "Expression", "B"));
3012:                s.addTest(new JavaParserTest(false, "Expression", "\\u0062"));
3013:                s.addTest(new JavaParserTest(false, "Expression", "\u0062"));
3014:                return s;
3015:            }
3016:
3017:            static JavaExternalAnalyzer newJavaExternalAnalyzer() {
3018:                return new JavaExternalAnalyzer(new Runtime(),
3019:                        new SymbolTable());
3020:            }
3021:
3022:            public static Runtime newRuntime() {
3023:                final Runtime runtime = new Runtime();
3024:                runtime.dir("in", Runtime.INPUT_DIRECTORY, true, "").setValue(
3025:                        Runtime.INPUT_DIRECTORY, TEMP_DIR); //.initDefaultValues();
3026:                return runtime;
3027:            }
3028:
3029:            public static String stripPrefix(final String s, final String prefix) {
3030:                final int pos = s.indexOf(prefix);
3031:                return -1 == pos ? s : s.substring(prefix.length() + pos);
3032:            }
3033:
3034:            public static String stripSuffix(final String s, final String suffix) {
3035:                final int pos = s.indexOf(suffix);
3036:                return -1 == pos ? s : s.substring(0, pos);
3037:            }
3038:
3039:            public static Test suite() {
3040:                final TestSuite s = new TestSuite();
3041:                if (false) { //TD 00 quick test-bed
3042:                //      s.addTest(new JavaAnalyzerTestError(false, "CompilationUnit", "class A{Character.Subset s;}", ""));
3043:                } else {
3044:                    s.addTest(makeSuiteJavaParser());
3045:                    s.addTest(makeSuiteJavaExternalAnalyzer());
3046:                    s.addTest(makeSuiteJavaAnalyzerError());
3047:                    s.addTest(makeSuiteJavaAnalyzerConstant());
3048:                    s.addTestSuite(xtc.lang.JavaUnitTests.class);
3049:                }
3050:                return s;
3051:            }
3052:
3053:            /**
3054:             * To enable assertions in eclipse, go to Run -> Run... -> Arguments, and in
3055:             * the box labeled VM arguments, enter -enableassertions.
3056:             */
3057:            public final void testAssertEnabled() {
3058:                boolean caught = false;
3059:                try {
3060:                    assert false;
3061:                } catch (final AssertionError e) {
3062:                    caught = true;
3063:                }
3064:                assertTrue(caught);
3065:            }
3066:
3067:            public final void testCParser_pTranslationUnit() throws Exception {
3068:                final String[] strings = {
3069:                        "int main(int argc, char** argv) { printf(\"Hello world!\\n\"); }",
3070:                        "int x;" };
3071:                for (int i = 0, n = strings.length; i < n; i++)
3072:                    cParserRoundTrip("TranslationUnit", strings[i]);
3073:            }
3074:
3075:            public final void testJavaAnalyzer_visitAssignmentExpression()
3076:                    throws Exception {
3077:                final String fileABF = "package a.b;" + // .package(a.b).file(<input>)
3078:                        "class F {           " + // .F
3079:                        "  public int i1;    " + //
3080:                        "  void g(char c1) { " + // .method(g)(char c1)
3081:                        "    int[] a1;       " + //
3082:                        "    final int[] a2; " + //
3083:                        "    int[][] a3;     " + //
3084:                        "    boolean b1;     " + //
3085:                        "    char c2;        " + //
3086:                        "    float f1;       " + //
3087:                        "    int i2, i3;     " + //
3088:                        "    final int i4;   " + //
3089:                        "    String s1;      " + //
3090:                        "  }                 " + //
3091:                        "}                   ";
3092:                final GNode ast = JavaEntities.javaStringToAst(
3093:                        "CompilationUnit", fileABF, true);
3094:                final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(),
3095:                        new SymbolTable());
3096:                ana.dispatch(ast);
3097:                JavaEntities.enterScopeByQualifiedName(ana._table,
3098:                        ".package(a.b).file(<input>).F.method(g)(char c1)");
3099:                javaAnalyzerTestError("Expression", "i2=40", "", ana);
3100:                javaAnalyzerTestError("Expression", "40=i2",
3101:                        "left operand of assignment not l-value", ana);
3102:                javaAnalyzerTestError("Expression", "i2=true",
3103:                        "illegal assignment", ana);
3104:                javaAnalyzerTestError("Expression", "i2=i3", "", ana);
3105:                javaAnalyzerTestError("Expression", "i2=i4", "", ana);
3106:                javaAnalyzerTestError("Expression", "i4=40",
3107:                        "left operand of assignment is final", ana);
3108:                javaAnalyzerTestError("Expression", "i2=f1",
3109:                        "illegal assignment", ana);
3110:                javaAnalyzerTestError("Expression", "i2=b1",
3111:                        "illegal assignment", ana);
3112:                javaAnalyzerTestError("Expression", "i2=s1",
3113:                        "illegal assignment", ana);
3114:                javaAnalyzerTestError("Expression", "i2='x'", "", ana);
3115:                javaAnalyzerTestError("Expression", "i2=c1", "", ana);
3116:                javaAnalyzerTestError("Expression", "i2=c2", "", ana);
3117:                javaAnalyzerTestError("Expression", "c1='x'", "", ana);
3118:                javaAnalyzerTestError("Expression", "c1=i2",
3119:                        "illegal assignment", ana);
3120:                javaAnalyzerTestError("Expression", "i1=40", "", ana);
3121:                javaAnalyzerTestError("Expression", "i1=i2", "", ana);
3122:                javaAnalyzerTestError("Expression", "i1=c1", "", ana);
3123:                javaAnalyzerTestError("Expression", "i1=i4", "", ana);
3124:                javaAnalyzerTestError("Expression", "i1=b1",
3125:                        "illegal assignment", ana);
3126:                javaAnalyzerTestError("Expression", "a1[3]=40", "", ana);
3127:                javaAnalyzerTestError("Expression", "a1[3]=true",
3128:                        "illegal assignment", ana);
3129:                javaAnalyzerTestError("Expression", "i2=a1[3]", "", ana);
3130:                javaAnalyzerTestError("Expression", "a1=a2", "", ana);
3131:                javaAnalyzerTestError("Expression", "a2=a1",
3132:                        "left operand of assignment is final", ana);
3133:                javaAnalyzerTestError("Expression", "a2[1]='a'", "", ana);
3134:                javaAnalyzerTestError("Expression", "a3[2]=a2", "", ana);
3135:                javaAnalyzerTestError("Expression", "a3[2][1]=2", "", ana);
3136:                javaAnalyzerTestError("Expression", "s1=99",
3137:                        "illegal assignment", ana);
3138:                javaAnalyzerTestError("Expression", "i1+=99", "", ana);
3139:                javaAnalyzerTestError("Expression", "s1+=99", "", ana);
3140:                javaAnalyzerTestError("Expression", "i1-=99", "", ana);
3141:                javaAnalyzerTestError("Expression", "s1-=99",
3142:                        "illegal assignment", ana);
3143:                javaAnalyzerTestError("Expression", "b1^=true", "", ana);
3144:                javaAnalyzerTestError("Expression", "i1|=0xff", "", ana);
3145:                javaAnalyzerTestError("Expression", "b1&=i1",
3146:                        "illegal assignment", ana);
3147:                javaAnalyzerTestError("Expression", "i1^=true",
3148:                        "illegal assignment", ana);
3149:            }
3150:
3151:            public final void testJavaAnalyzer_visitCallExpression()
3152:                    throws Exception {
3153:                final String fileABF = "package a.b;" + // .package(a.b).file(<input>)
3154:                        "class F {              " + // .F
3155:                        "  static void i() {    " + //
3156:                        "    G g;               " + //
3157:                        "    H h;               " + //
3158:                        "  }                    " + // .method(i)()
3159:                        "  static void j(G z) {}" + //
3160:                        "  static void j(H z) {}" + //
3161:                        "}                      " + //
3162:                        "class G extends F    { " + //
3163:                        "}                      " + //
3164:                        "class H extends F    { " + //
3165:                        "  static void i() { }  " + //
3166:                        "  static H k() { }     " + //
3167:                        "}                      " + //
3168:                        "";
3169:                final GNode ast = JavaEntities.javaStringToAst(
3170:                        "CompilationUnit", fileABF, true);
3171:                final SymbolTable tab = new SymbolTable();
3172:                final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(), tab);
3173:                ana.dispatch(ast);
3174:                JavaEntities.enterScopeByQualifiedName(tab,
3175:                        ".package(a.b).file(<input>).F.method(i)()");
3176:                javaAnalyzerTestUseDef(ana, "i()",
3177:                        ".package(a.b).file(<input>).F.method(i)()");
3178:                javaAnalyzerTestUseDef(ana, "j(g)",
3179:                        ".package(a.b).file(<input>).F.method(j)(G z)");
3180:                javaAnalyzerTestUseDef(ana, "j(h)",
3181:                        ".package(a.b).file(<input>).F.method(j)(H z)");
3182:                javaAnalyzerTestUseDef(ana, "F.j(g)",
3183:                        ".package(a.b).file(<input>).F.method(j)(G z)");
3184:                javaAnalyzerTestUseDef(ana, "g.i()",
3185:                        ".package(a.b).file(<input>).F.method(i)()");
3186:                javaAnalyzerTestUseDef(ana, "h.i()",
3187:                        ".package(a.b).file(<input>).H.method(i)()");
3188:                javaAnalyzerTestUseDef(ana, "H.k().i()",
3189:                        ".package(a.b).file(<input>).H.method(i)()");
3190:                javaAnalyzerTestUseDef(ana, "hashCode()",
3191:                        ".package(java.lang).file().Object.method(hashCode)()");
3192:            }
3193:
3194:            public final strictfp void testJavaAnalyzer_visitConstantExpression()
3195:                    throws Exception {
3196:                // gosling_et_al_2000 15.28, 3.10
3197:                final String fileABF = "package a.b;" + // .package(a.b).file(<input>)
3198:                        "class F {                          " + // .F
3199:                        "  final static int x=123;          " + //
3200:                        "  void g() {                       " + // .method(g)()
3201:                        "    final int y=456;               " + //
3202:                        "    final String z=2+\" fiddlers\";" + //
3203:                        "  }                                " + //
3204:                        "}                                  ";
3205:                final GNode ast = JavaEntities.javaStringToAst(
3206:                        "CompilationUnit", fileABF, true);
3207:                final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(),
3208:                        new SymbolTable());
3209:                ana.dispatch(ast);
3210:                JavaEntities.enterScopeByQualifiedName(ana._table,
3211:                        ".package(a.b).file(<input>).F.method(g)()");
3212:                javaAnalyzerTestConstant("x", new Integer(123), ana);
3213:                javaAnalyzerTestConstant("y", new Integer(456), ana);
3214:                javaAnalyzerTestConstant("a.b.F.x", new Integer(123), ana);
3215:                javaAnalyzerTestConstant("1+z", "12 fiddlers", ana);
3216:            }
3217:
3218:            public final void testJavaAnalyzer_visitExpression()
3219:                    throws Exception {
3220:                final String fileABF = "package a.b;" + // .package(a.b).file(<input>)
3221:                        "class F {         " + // .F
3222:                        "  void g() {      " + // .method(g)()
3223:                        "    boolean b1;   " + //
3224:                        "    int i1, i2;   " + //
3225:                        "    double d1;    " + //
3226:                        "  }               " + //
3227:                        "}                 ";
3228:                final GNode ast = JavaEntities.javaStringToAst(
3229:                        "CompilationUnit", fileABF, true);
3230:                final SymbolTable tab = new SymbolTable();
3231:                final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(), tab);
3232:                ana.dispatch(ast);
3233:                JavaEntities.enterScopeByQualifiedName(tab,
3234:                        ".package(a.b).file(<input>).F.method(g)()");
3235:                javaAnalyzerTestUseDef(ana, "i1",
3236:                        ".package(a.b).file(<input>).F.method(g)().i1");
3237:                javaAnalyzerTestUseDef(ana, "i1+i2", "int");
3238:                javaAnalyzerTestUseDef(ana, "\"a\"+i2",
3239:                        ".package(java.lang).file().tag(String)");
3240:                javaAnalyzerTestUseDef(ana, "i1<i2", "boolean");
3241:                javaAnalyzerTestUseDef(ana, "false", "boolean");
3242:                javaAnalyzerTestUseDef(ana, "i1+d1", "double");
3243:                javaAnalyzerTestUseDef(ana, "i1++", "int");
3244:                javaAnalyzerTestUseDef(ana, "d1--", "double");
3245:                javaAnalyzerTestUseDef(ana, "(byte)d1", "byte");
3246:                javaAnalyzerTestUseDef(ana, "b1 ? i1 : d1", "double");
3247:                javaAnalyzerTestUseDef(ana, "this instanceof F", "boolean");
3248:                javaAnalyzerTestUseDef(ana, "new F()",
3249:                        ".package(a.b).file(<input>).tag(F)");
3250:                javaAnalyzerTestUseDef(ana, "d1++", "d1");
3251:                javaAnalyzerTestUseDef(ana, "this",
3252:                        ".package(a.b).file(<input>).tag(F)");
3253:                javaAnalyzerTestUseDef(ana, "super",
3254:                        ".package(java.lang).file().tag(Object)");
3255:                javaAnalyzerTestUseDef(ana, "F.this",
3256:                        ".package(a.b).file(<input>).tag(F)");
3257:                javaAnalyzerTestUseDef(ana, "a.b.F.this",
3258:                        ".package(a.b).file(<input>).tag(F)");
3259:                javaAnalyzerTestUseDef(ana, "F.super",
3260:                        ".package(java.lang).file().tag(Object)");
3261:                javaAnalyzerTestUseDef(ana, "a.b.F.super",
3262:                        ".package(java.lang).file().tag(Object)");
3263:                javaAnalyzerTestUseDef(ana, "this instanceof Object", "boolean");
3264:            }
3265:
3266:            public final void testJavaAnalyzer_visitPrimaryIdentifier()
3267:                    throws Exception {
3268:                final File fileABQ = createTempFile(TEMP_DIR, "a/b/Q.java",
3269:                        "package a.b;class Q{}");
3270:                final File fileNOP = createTempFile(TEMP_DIR, "n/o/P.java",
3271:                        "package n.o;class P{}");
3272:                final File fileRST = createTempFile(TEMP_DIR, "r/s/T.java",
3273:                        "package r.s;class T{}");
3274:                final String fileABF = "package a.b;" + // .package(a.b).file(<input>)
3275:                        "import n.o.P;       " + //
3276:                        "import r.s.*;       " + //
3277:                        "class F {           " + // .F
3278:                        "  int h, i, j;      " + //
3279:                        "  void g(int h) {   " + // .method(g)(int h)
3280:                        "    int i, j;       " + //
3281:                        "    class L { }     " + //
3282:                        "    { int j; }      " + // .block(0)
3283:                        "    for (int q=0;;);" + //.forStatement(1)
3284:                        "  }                 " + //
3285:                        "  int k;            " + //
3286:                        "  final int l=2;    " + //
3287:                        "}                   " + //
3288:                        "class M { }         ";
3289:                final GNode ast = JavaEntities.javaStringToAst(
3290:                        "CompilationUnit", fileABF, true);
3291:                final SymbolTable tab = new SymbolTable();
3292:                final Runtime runtime = new Runtime();
3293:                runtime.dir("in", Runtime.INPUT_DIRECTORY, true, "").setValue(
3294:                        Runtime.INPUT_DIRECTORY, TEMP_DIR);
3295:                final JavaAnalyzer ana = new JavaAnalyzer(runtime, tab);
3296:                ana.dispatch(ast);
3297:                JavaEntities
3298:                        .enterScopeByQualifiedName(tab,
3299:                                ".package(a.b).file(<input>).F.method(g)(int h).block(0)");
3300:                javaAnalyzerTestUseDef(ana, "h",
3301:                        ".package(a.b).file(<input>).F.method(g)(int h).h");
3302:                javaAnalyzerTestUseDef(ana, "i",
3303:                        ".package(a.b).file(<input>).F.method(g)(int h).i");
3304:                javaAnalyzerTestUseDef(ana, "j",
3305:                        ".package(a.b).file(<input>).F.method(g)(int h).block(0).j");
3306:                javaAnalyzerTestUseDef(ana, "k",
3307:                        ".package(a.b).file(<input>).F.k");
3308:                javaAnalyzerTestUseDef(ana, "L",
3309:                        ".package(a.b).file(<input>).F.method(g)(int h).tag(L)");
3310:                javaAnalyzerTestUseDef(ana, "F",
3311:                        ".package(a.b).file(<input>).tag(F)");
3312:                javaAnalyzerTestUseDef(ana, "M",
3313:                        ".package(a.b).file(<input>).tag(M)");
3314:                javaAnalyzerTestUseDef(ana, "P", ".package(n.o)."
3315:                        + JavaEntities.fileNameToScopeName(fileNOP
3316:                                .getAbsolutePath()) + ".tag(P)");
3317:                javaAnalyzerTestUseDef(ana, "Q", ".package(a.b)."
3318:                        + JavaEntities.fileNameToScopeName(fileABQ
3319:                                .getAbsolutePath()) + ".tag(Q)");
3320:                javaAnalyzerTestUseDef(ana, "T", ".package(r.s)."
3321:                        + JavaEntities.fileNameToScopeName(fileRST
3322:                                .getAbsolutePath()) + ".tag(T)");
3323:                javaAnalyzerTestUseDef(ana, "Object",
3324:                        ".package(java.lang).file().tag(Object)");
3325:                javaAnalyzerTestUseDef(ana, "Runnable",
3326:                        ".package(java.lang).file().tag(Runnable)");
3327:                javaAnalyzerTestUseDef(ana, "l",
3328:                        ".package(a.b).file(<input>).F.l");
3329:                JavaEntities
3330:                        .enterScopeByQualifiedName(tab,
3331:                                ".package(a.b).file(<input>).F.method(g)(int h).forStatement(1)");
3332:                javaAnalyzerTestUseDef(ana, "q",
3333:                        ".package(a.b).file(<input>).F.method(g)(int h).forStatement(1).q");
3334:            }
3335:
3336:            public final void testJavaAnalyzer_visitSelectionExpression()
3337:                    throws Exception {
3338:                final String fileABF = "package a.b;" + // .package(a.b).file(<input>)
3339:                        "class F {          " + // .F
3340:                        "  static int g;    " + //
3341:                        "  void h() {       " + // .method(h)()
3342:                        "    F i;           " + //
3343:                        "    J l;           " + //
3344:                        "  }                " + //
3345:                        "}                  " + //
3346:                        "class J extends F {" + //
3347:                        "  static int k;    " + //
3348:                        "  J m;             " + //
3349:                        "}                  " + //
3350:                        "";
3351:                final GNode ast = JavaEntities.javaStringToAst(
3352:                        "CompilationUnit", fileABF, true);
3353:                final SymbolTable tab = new SymbolTable();
3354:                final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(), tab);
3355:                ana.dispatch(ast);
3356:                JavaEntities.enterScopeByQualifiedName(tab,
3357:                        ".package(a.b).file(<input>).F.method(h)()");
3358:                javaAnalyzerTestUseDef(ana, "i.g",
3359:                        ".package(a.b).file(<input>).F.g");
3360:                javaAnalyzerTestUseDef(ana, "F.g",
3361:                        ".package(a.b).file(<input>).F.g");
3362:                javaAnalyzerTestUseDef(ana, "l.k",
3363:                        ".package(a.b).file(<input>).J.k");
3364:                javaAnalyzerTestUseDef(ana, "l.g",
3365:                        ".package(a.b).file(<input>).F.g");
3366:                javaAnalyzerTestUseDef(ana, "l.g",
3367:                        ".package(a.b).file(<input>).F.g");
3368:                javaAnalyzerTestUseDef(ana, "l.m",
3369:                        ".package(a.b).file(<input>).J.m");
3370:                javaAnalyzerTestUseDef(ana, "l.m.g",
3371:                        ".package(a.b).file(<input>).F.g");
3372:                javaAnalyzerTestUseDef(ana, "l.m.m",
3373:                        ".package(a.b).file(<input>).J.m");
3374:                javaAnalyzerTestUseDef(ana, "l.m.m.g",
3375:                        ".package(a.b).file(<input>).F.g");
3376:                javaAnalyzerTestUseDef(ana, "a.b", ".package(a).tag(b)");
3377:                javaAnalyzerTestUseDef(ana, "a.b.F",
3378:                        ".package(a.b).file(<input>).tag(F)");
3379:                javaAnalyzerTestUseDef(ana, "a.b.F.g",
3380:                        ".package(a.b).file(<input>).F.g");
3381:                javaAnalyzerTestUseDef(ana, "a.b.J.g",
3382:                        ".package(a.b).file(<input>).F.g");
3383:                javaAnalyzerTestUseDef(ana, "System.out",
3384:                        ".package(java.lang).file().System.out");
3385:                javaAnalyzerTestUseDef(ana, "Character.Subset",
3386:                        ".package(java.lang).file().Character.tag(Subset)");
3387:            }
3388:
3389:            public final void testJavaAnalyzer_visitSubscriptExpression()
3390:                    throws Exception {
3391:                final String fileABF = "package a.b;" + // .package(a.b).file(<input>)
3392:                        "class C {          " + // .C
3393:                        "  void d() {       " + // .method(d)()
3394:                        "    int[] e;       " + //
3395:                        "    int[][] f;     " + //
3396:                        "    float[][][] g; " + //
3397:                        "    final int[] h; " + //
3398:                        "    C[] i;         " + //
3399:                        "    String[] j;    " + //
3400:                        "  }                " + //
3401:                        "}                  " + //
3402:                        "";
3403:                final GNode ast = JavaEntities.javaStringToAst(
3404:                        "CompilationUnit", fileABF, true);
3405:                final SymbolTable tab = new SymbolTable();
3406:                final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(), tab);
3407:                ana.dispatch(ast);
3408:                JavaEntities.enterScopeByQualifiedName(tab,
3409:                        ".package(a.b).file(<input>).C.method(d)()");
3410:                javaAnalyzerTestUseDef(ana, "e[0]", "int");
3411:                javaAnalyzerTestUseDef(ana, "f[0][0]", "int");
3412:                javaAnalyzerTestUseDef(ana, "f[0]", "int[]");
3413:                javaAnalyzerTestUseDef(ana, "g[100]", "float[][]");
3414:                javaAnalyzerTestUseDef(ana, "h[100]", "int");
3415:                javaAnalyzerTestUseDef(ana, "i[2]",
3416:                        ".package(a.b).file(<input>).tag(C)");
3417:                javaAnalyzerTestUseDef(ana, "j[12]",
3418:                        ".package(java.lang).file().tag(String)");
3419:            }
3420:
3421:            public final void testJavaEntities_nestingClassification()
3422:                    throws Exception {
3423:                assertTrue(JavaEntities.isScopeTopLevel(".package(a.b).file()"));
3424:                assertTrue(JavaEntities
3425:                        .isScopeTopLevel(".package(a.b).file(<input>)"));
3426:                assertFalse(JavaEntities.isScopeTopLevel(".package(a.b)"));
3427:                assertFalse(JavaEntities
3428:                        .isScopeTopLevel(".package(a.b).file().x"));
3429:                assertFalse(JavaEntities
3430:                        .isScopeTopLevel(".package(a.b).file(<input>).y"));
3431:                assertFalse(JavaEntities
3432:                        .isScopeTopLevel(".package(a.b).file().c.d.e"));
3433:                assertFalse(JavaEntities.isScopeNested(".package(a.b)"));
3434:                assertFalse(JavaEntities.isScopeNested(".package(a.b).file()"));
3435:                assertTrue(JavaEntities.isScopeNested(".package(a.b).file().a"));
3436:                assertTrue(JavaEntities
3437:                        .isScopeNested(".package(a.b).file().a.b"));
3438:                assertFalse(JavaEntities
3439:                        .isScopeNested(".package(a.b).file(Foo)"));
3440:                assertTrue(JavaEntities
3441:                        .isScopeLocal(".package(a.b).file(Foo).A.method(f())"));
3442:                assertFalse(JavaEntities
3443:                        .isScopeLocal(".package(a.b).file(Foo).A.F"));
3444:                assertTrue(JavaEntities
3445:                        .isScopeForMember(".package(a.b).file(Foo).A.F"));
3446:                assertFalse(JavaEntities
3447:                        .isScopeForMember(".package(a.b).file(Foo).A.method(f())"));
3448:                final String fileABF = "package a.b;" + // .package(a.b).file(<input>)
3449:                        "class C {          " + // .package(a.b).file(<input>).C
3450:                        "  class D {}       " + // .package(a.b).file(<input>).C.D
3451:                        "  static class E {}" + // .package(a.b).file(<input>).C.E
3452:                        "  void f() {       " + // .package(a.b).file(<input>).C.method(f)()
3453:                        "    class G {      " + // .package(a.b).file(<input>).C.method(f)().G
3454:                        "      class H {}   " + // .package(a.b).file(<input>).C.method(f)().G.H
3455:                        "    }              " + //
3456:                        "  }                " + //
3457:                        "  interface I {}   " + // .package(a.b).file(<input>).C.I
3458:                        "}                  " + //
3459:                        "";
3460:                final GNode ast = JavaEntities.javaStringToAst(
3461:                        "CompilationUnit", fileABF, true);
3462:                final SymbolTable tab = new SymbolTable();
3463:                final JavaAnalyzer ana = new JavaAnalyzer(newRuntime(), tab);
3464:                ana.dispatch(ast);
3465:                JavaEntities.enterScopeByQualifiedName(tab,
3466:                        ".package(a.b).file(<input>)");
3467:                final ClassT c = (ClassT) tab
3468:                        .lookup(".package(a.b).file(<input>).tag(C)");
3469:                assertTrue(JavaEntities.isTypeTopLevel(c));
3470:                final ClassT d = (ClassT) tab
3471:                        .lookup(".package(a.b).file(<input>).C.tag(D)");
3472:                assertTrue(JavaEntities.isTypeMember(d));
3473:                assertFalse(JavaEntities.isTypeLocal(d));
3474:                assertTrue(JavaEntities.isTypeInner(d));
3475:                final ClassT e = (ClassT) tab
3476:                        .lookup(".package(a.b).file(<input>).C.tag(E)");
3477:                assertTrue(JavaEntities.isTypeMember(e));
3478:                assertFalse(JavaEntities.isTypeInner(e));
3479:                final ClassT g = (ClassT) tab
3480:                        .lookup(".package(a.b).file(<input>).C.method(f)().tag(G)");
3481:                assertTrue(JavaEntities.isTypeLocal(g));
3482:                assertTrue(JavaEntities.isTypeInner(g));
3483:                assertTrue(JavaEntities.isTypeNested(g));
3484:                assertTrue(JavaEntities.isTypeNamed(g));
3485:                assertFalse(JavaEntities.isTypeMember(g));
3486:                final ClassT h = (ClassT) tab
3487:                        .lookup(".package(a.b).file(<input>).C.method(f)().G.tag(H)");
3488:                assertTrue(JavaEntities.isTypeMember(h));
3489:                assertTrue(JavaEntities.isTypeInner(h));
3490:                final InterfaceT i = (InterfaceT) tab
3491:                        .lookup(".package(a.b).file(<input>).C.tag(I)");
3492:                assertTrue(JavaEntities.isTypeMember(i));
3493:                assertTrue(JavaEntities.isTypeNested(i));
3494:                assertFalse(JavaEntities.isTypeInner(i));
3495:            }
3496:
3497:            public final void testJavaExternalAnalyzer_visitCompilationUnit()
3498:                    throws Exception {
3499:                final JavaExternalAnalyzer ana = newJavaExternalAnalyzer();
3500:                ana.dispatch(JavaEntities.javaStringToAst("CompilationUnit",
3501:                        "package a.b;class C{class D{E f;}}", true));
3502:                final SymbolTable table = ana._table;
3503:                final PackageT ab = (PackageT) table
3504:                        .lookup(".package(a).tag(b)");
3505:                assertEquals("a.b", ab.getName());
3506:                final ClassT abc = (ClassT) table
3507:                        .lookup(".package(a.b).file(<input>).tag(C)");
3508:                JavaEntities.enterScopeByQualifiedName(table,
3509:                        ".package(a.b).file(<input>)");
3510:                assertEquals(
3511:                        contractSpace("class a.b.C{C()->void; class a.b.C.D{field(E,f); D()->void;};}"),
3512:                        contractSpace(JavaEntities.typeDeclString(ana._table,
3513:                                abc)));
3514:                final ClassT abcd = (ClassT) table
3515:                        .lookup(".package(a.b).file(<input>).C.tag(D)");
3516:                assertEquals(
3517:                        contractSpace("class a.b.C.D{field(E,f);D()->void;}"),
3518:                        contractSpace(JavaEntities.typeDeclString(ana._table,
3519:                                abcd)));
3520:            }
3521:
3522:            public final void testJavaExternalAnalyzer_visitImportDeclaration()
3523:                    throws Exception {
3524:                final JavaExternalAnalyzer ana = newJavaExternalAnalyzer();
3525:                ana
3526:                        .dispatch(JavaEntities
3527:                                .javaStringToAst(
3528:                                        "CompilationUnit",
3529:                                        "package a.b;import c.*;import d.e;import f.g.*;",
3530:                                        true));
3531:                final SymbolTable table = ana._table;
3532:                final List imports = (List) table
3533:                        .lookup(".package(a.b).file(<input>).imports(*)");
3534:                assertEquals(imports.size(), 2);
3535:                assertEquals(((PackageT) imports.get(0)).getName(), "c");
3536:                assertEquals(((PackageT) imports.get(1)).getName(), "f.g");
3537:                final AliasT de = (AliasT) table
3538:                        .lookup(".package(a.b).file(<input>).tag(e)");
3539:                assertEquals(de.getName(), "d.e");
3540:            }
3541:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.