├── .gitignore ├── .travis.yml ├── Gruntfile.js ├── README.md ├── lib ├── javaparser7.js └── javaparser7.min.js ├── npm ├── .gitignore ├── README.md ├── cmd.js └── package.json ├── package.json ├── src └── Java.1.7.pegjs ├── test ├── Attic │ ├── Eclipse-ASTFlattenerTests.js │ ├── JavaParser-JavaConceptsTests.js │ ├── Lucene-StandardTokenizerTests.js │ └── Snowball-StemmerTests.js ├── CompilationUnitTests │ ├── AnnotationTests │ │ └── TypeTests.js │ ├── ClassTests │ │ ├── BodyBlocksTests.js │ │ ├── BodyMembersTests.js │ │ ├── ClassExtendsImplementsTests.js │ │ ├── ClassModifiersTests.js │ │ └── EmptyClassTests.js │ ├── EnumTests │ │ └── EnumTests.js │ ├── ExpressionsTests.js │ ├── FormalParamsTests.js │ ├── InterfaceTests │ │ ├── BodyTests.js │ │ └── EmptyTests.js │ ├── NoTypesTests.js │ ├── PackageAnnotationsTests.js │ ├── PackageImportsTests.js │ ├── StatementsTests.js │ └── VariableDeclarationsTests.js ├── coverage.html ├── jls7.pdf └── qunit │ ├── blanket │ ├── blanket.js │ └── lcov_reporter.js │ ├── multiline │ ├── browser.js │ └── license │ ├── qunit.css │ └── qunit.js └── tools └── EclipseAST ├── .gitignore ├── ASTDumper.java ├── App.java ├── IASTPrinter.java ├── ICommentsExtractor.java ├── Indenter.java ├── JSONStyleASTPrinter.java ├── UglyMathCommentsExtractor.java ├── lib ├── commons-cli-1.3.1.jar ├── commons-lang3-3.4.jar ├── org.eclipse.core.contenttype_3.5.0.v20150421-2214.jar ├── org.eclipse.core.jobs_3.7.0.v20150330-2103.jar ├── org.eclipse.core.resources_3.10.0.v20150423-0755.jar ├── org.eclipse.core.runtime_3.11.0.v20150405-1723.jar ├── org.eclipse.equinox.common_3.7.0.v20150402-1709.jar ├── org.eclipse.equinox.preferences_3.5.300.v20150408-1437.jar ├── org.eclipse.jdt.core_3.11.0.v20150602-1242.jar ├── org.eclipse.osgi_3.10.100.v20150529-1857.jar └── org.eclipse.text_3.5.400.v20150505-1044.jar └── run.sh /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | bower_components/ 3 | .coverage-results/ 4 | .coveralls.yml -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # whitelist 2 | branches: 3 | only: 4 | - master 5 | 6 | language: node_js 7 | node_js: 8 | - "stable" 9 | 10 | script: 11 | - travis_wait 30 grunt travis --verbose 12 | 13 | after_success: grunt coveralls -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | // Travis CI task. 2 | 3 | module.exports = function(grunt) { 4 | 5 | grunt.initConfig({ 6 | 7 | qunit: { 8 | all : { 9 | options: { 10 | timeout: 500000, 11 | urls: [ 12 | "./test/coverage.html?coverage=true" 13 | ] 14 | } 15 | } 16 | }, 17 | 18 | coveralls: { 19 | options: { 20 | force: true 21 | }, 22 | all: { 23 | src: './.coverage-results/core.lcov', 24 | } 25 | } 26 | }); 27 | 28 | grunt.event.on('qunit.report', function(data) { 29 | // visualize results local: genhtml .coverage-results/core.lcov 30 | grunt.file.write('./.coverage-results/core.lcov', data); 31 | }); 32 | 33 | // Load plugin 34 | grunt.loadNpmTasks('grunt-contrib-qunit'); 35 | grunt.loadNpmTasks('grunt-coveralls'); 36 | 37 | // Task to run tests 38 | grunt.registerTask('travis', ['qunit']); 39 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaScript Java Parser [![Build Status](https://travis-ci.org/mazko/jsjavaparser.svg?branch=master)](https://travis-ci.org/mazko/jsjavaparser) [![Coverage Status](https://coveralls.io/repos/mazko/jsjavaparser/badge.svg?branch=master&service=github)](https://coveralls.io/github/mazko/jsjavaparser?branch=master) [![npm version](https://badge.fury.io/js/java-parser.svg)](http://badge.fury.io/js/java-parser) 2 | 3 | - [Online Demo](http://mazko.github.io/jsjavaparser) 4 | 5 | - [ESJava Transpiler](http://mazko.github.io/ESJava) 6 | 7 | - [Eclipse](http://help.eclipse.org/juno/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/AST.html) Like AST 8 | 9 | - [PEG.js](http://pegjs.org/) Grammar 10 | 11 | - [Java Tool](tools/EclipseAST/run.sh) with JSON AST output for test purposes 12 | 13 | - BUILD: ```bash -c 'cd npm && npm i && npm run build'``` 14 | -------------------------------------------------------------------------------- /npm/.gitignore: -------------------------------------------------------------------------------- 1 | java-parser-*.tgz 2 | javaparser7.js -------------------------------------------------------------------------------- /npm/README.md: -------------------------------------------------------------------------------- 1 | [Demo](http://mazko.github.io/jsjavaparser/) 2 | 3 | ### Example Command Line: 4 | 5 | ~$ npm i -g java-parser 6 | 7 | ~$ echo ' 8 | class HelloWorld { 9 | final int UNIVERSE = 42; 10 | } 11 | ' > HelloWorld.java 12 | 13 | ~$ java-parser HelloWorld.java 14 | { 15 | "node": "CompilationUnit", 16 | "types": [ 17 | { 18 | "node": "TypeDeclaration", 19 | "name": { 20 | "identifier": "HelloWorld", 21 | "node": "SimpleName" 22 | }, 23 | "superInterfaceTypes": [], 24 | "superclassType": null, 25 | "bodyDeclarations": [ 26 | { 27 | "node": "FieldDeclaration", 28 | "fragments": [ 29 | { 30 | "node": "VariableDeclarationFragment", 31 | "name": { 32 | "identifier": "UNIVERSE", 33 | "node": "SimpleName" 34 | }, 35 | "extraDimensions": 0, 36 | "initializer": { 37 | "node": "NumberLiteral", 38 | "token": "42" 39 | } 40 | } 41 | ], 42 | "type": { 43 | "node": "PrimitiveType", 44 | "primitiveTypeCode": "int" 45 | }, 46 | "modifiers": [ 47 | { 48 | "node": "Modifier", 49 | "keyword": "final" 50 | } 51 | ] 52 | } 53 | ], 54 | "typeParameters": [], 55 | "interface": false, 56 | "modifiers": [] 57 | } 58 | ], 59 | "package": null, 60 | "imports": [] 61 | } 62 | 63 | ### Example Program: 64 | 65 | ~$ npm i java-parser 66 | 67 | ~$ echo ' 68 | var japa = require("java-parser"); 69 | console.log(japa.parse("package hello;")); 70 | ' | node 71 | { node: 'CompilationUnit', 72 | types: [], 73 | package: 74 | { node: 'PackageDeclaration', 75 | name: { identifier: 'hello', node: 'SimpleName' }, 76 | annotations: [] }, 77 | imports: [] } -------------------------------------------------------------------------------- /npm/cmd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | "use strict"; 4 | 5 | (function() { 6 | var japa, echo, file, fs, i, len, ref, src; 7 | 8 | fs = require('fs'); 9 | japa = require('java-parser'); 10 | 11 | echo = function(msg) { 12 | return process.stdout.write(JSON.stringify(msg, null, 2) + '\n'); 13 | }; 14 | 15 | if (process.argv.length > 2) { 16 | ref = process.argv.slice(2); 17 | for (i = 0, len = ref.length; i < len; i++) { 18 | file = ref[i]; 19 | src = fs.readFileSync(file, 'utf8'); 20 | try { 21 | echo(japa.parse(src)); 22 | } catch (err) { 23 | process.stderr.write( 24 | err.name === 'SyntaxError' 25 | ? "Location: " + JSON.stringify(err.location, null, 4) + "\n" + err 26 | : err.name + ': ' + err.message 27 | ); 28 | } 29 | } 30 | } else { 31 | echo("Usage: java-parser file..."); 32 | } 33 | 34 | }).call(this); -------------------------------------------------------------------------------- /npm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "java-parser", 3 | "version": "0.0.2", 4 | "description": "Java1.7 parser", 5 | "scripts": { 6 | "prepublish": "cp ../lib/javaparser7.js .", 7 | "build": "node_modules/pegjs/bin/pegjs < ../src/Java.1.7.pegjs | node_modules/umd/bin/cli.js JavaParser -c > ../lib/javaparser7.js", 8 | "build-min": "npm build && node_modules/uglify-js/bin/uglifyjs ../lib/javaparser7.js -o ../lib/javaparser7.min.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/mazko/jsjavaparser.git" 13 | }, 14 | "keywords": [ 15 | "java", 16 | "parser" 17 | ], 18 | "author": "Oleg Mazko", 19 | "license": "BSD-2-Clause", 20 | "bugs": { 21 | "url": "https://github.com/mazko/jsjavaparser/issues" 22 | }, 23 | "main": "javaparser7.js", 24 | "bin": { 25 | "java-parser": "./cmd.js" 26 | }, 27 | "devDependencies": { 28 | "pegjs": "^0.10.0", 29 | "uglify-js": "^2.7.3", 30 | "umd": "^3.0.1" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "grunt": "~0.4.5", 4 | "grunt-cli": "~0.1", 5 | "grunt-contrib-qunit": "~0.7.0", 6 | "grunt-coveralls": "^1.0.0" 7 | }, 8 | "name": "jsjavaparser", 9 | "version": "0.1.0" 10 | } 11 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/AnnotationTests/TypeTests.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | test("marker annotation type", function(assert) { 4 | var src = multiline(function(){/* 5 | @interface Preliminary {} 6 | */}); 7 | assert.deepEqual( 8 | JavaParser.parse(src) 9 | , 10 | { 11 | node: "CompilationUnit", 12 | package: null, 13 | imports: [ 14 | 15 | ], 16 | types: [ 17 | { 18 | node: "AnnotationTypeDeclaration", 19 | modifiers: [ 20 | 21 | ], 22 | name: { 23 | node: "SimpleName", 24 | identifier: "Preliminary" 25 | }, 26 | bodyDeclarations: [ 27 | 28 | ] 29 | } 30 | ] 31 | } 32 | ); 33 | }); 34 | 35 | test("marker annotation type ws semi", function(assert) { 36 | var src = multiline(function(){/* 37 | @interface Preliminary {;} 38 | */}); 39 | assert.deepEqual( 40 | JavaParser.parse(src) 41 | , 42 | { 43 | node: "CompilationUnit", 44 | package: null, 45 | imports: [ 46 | 47 | ], 48 | types: [ 49 | { 50 | node: "AnnotationTypeDeclaration", 51 | modifiers: [ 52 | 53 | ], 54 | name: { 55 | node: "SimpleName", 56 | identifier: "Preliminary" 57 | }, 58 | bodyDeclarations: [ 59 | 60 | ] 61 | } 62 | ] 63 | } 64 | ); 65 | }); 66 | 67 | test("marker annotation type ws interface", function(assert) { 68 | var src = multiline(function(){/* 69 | @interface Preliminary { private interface ITest {}} 70 | */}); 71 | assert.deepEqual( 72 | JavaParser.parse(src) 73 | , 74 | { 75 | node: "CompilationUnit", 76 | package: null, 77 | imports: [ 78 | 79 | ], 80 | types: [ 81 | { 82 | node: "AnnotationTypeDeclaration", 83 | modifiers: [ 84 | 85 | ], 86 | name: { 87 | node: "SimpleName", 88 | identifier: "Preliminary" 89 | }, 90 | bodyDeclarations: [ 91 | { 92 | node: "TypeDeclaration", 93 | modifiers: [ 94 | { 95 | node: "Modifier", 96 | keyword: "private" 97 | } 98 | ], 99 | interface: true, 100 | name: { 101 | node: "SimpleName", 102 | identifier: "ITest" 103 | }, 104 | typeParameters: [ 105 | 106 | ], 107 | superclassType: null, 108 | superInterfaceTypes: [ 109 | 110 | ], 111 | bodyDeclarations: [ 112 | 113 | ] 114 | } 115 | ] 116 | } 117 | ] 118 | } 119 | ); 120 | }); 121 | 122 | test("marker annotation type ws enum", function(assert) { 123 | var src = multiline(function(){/* 124 | @interface Preliminary { private enum TestEnum {A,B}} 125 | */}); 126 | assert.deepEqual( 127 | JavaParser.parse(src) 128 | , 129 | { 130 | node: "CompilationUnit", 131 | package: null, 132 | imports: [ 133 | 134 | ], 135 | types: [ 136 | { 137 | node: "AnnotationTypeDeclaration", 138 | modifiers: [ 139 | 140 | ], 141 | name: { 142 | node: "SimpleName", 143 | identifier: "Preliminary" 144 | }, 145 | bodyDeclarations: [ 146 | { 147 | node: "EnumDeclaration", 148 | modifiers: [ 149 | { 150 | node: "Modifier", 151 | keyword: "private" 152 | } 153 | ], 154 | name: { 155 | node: "SimpleName", 156 | identifier: "TestEnum" 157 | }, 158 | superInterfaceTypes: [ 159 | 160 | ], 161 | enumConstants: [ 162 | { 163 | node: "EnumConstantDeclaration", 164 | modifiers: [ 165 | 166 | ], 167 | name: { 168 | node: "SimpleName", 169 | identifier: "A" 170 | }, 171 | arguments: [ 172 | 173 | ], 174 | anonymousClassDeclaration: null 175 | }, 176 | { 177 | node: "EnumConstantDeclaration", 178 | modifiers: [ 179 | 180 | ], 181 | name: { 182 | node: "SimpleName", 183 | identifier: "B" 184 | }, 185 | arguments: [ 186 | 187 | ], 188 | anonymousClassDeclaration: null 189 | } 190 | ], 191 | bodyDeclarations: [ 192 | 193 | ] 194 | } 195 | ] 196 | } 197 | ] 198 | } 199 | ); 200 | }); 201 | 202 | test("marker annotation type ws enum", function(assert) { 203 | var src = multiline(function(){/* 204 | @interface Preliminary { private class TestClass { final int i = 42; }} 205 | */}); 206 | assert.deepEqual( 207 | JavaParser.parse(src) 208 | , 209 | { 210 | node: "CompilationUnit", 211 | package: null, 212 | imports: [ 213 | 214 | ], 215 | types: [ 216 | { 217 | node: "AnnotationTypeDeclaration", 218 | modifiers: [ 219 | 220 | ], 221 | name: { 222 | node: "SimpleName", 223 | identifier: "Preliminary" 224 | }, 225 | bodyDeclarations: [ 226 | { 227 | node: "TypeDeclaration", 228 | modifiers: [ 229 | { 230 | node: "Modifier", 231 | keyword: "private" 232 | } 233 | ], 234 | interface: false, 235 | name: { 236 | node: "SimpleName", 237 | identifier: "TestClass" 238 | }, 239 | typeParameters: [ 240 | 241 | ], 242 | superclassType: null, 243 | superInterfaceTypes: [ 244 | 245 | ], 246 | bodyDeclarations: [ 247 | { 248 | node: "FieldDeclaration", 249 | modifiers: [ 250 | { 251 | node: "Modifier", 252 | keyword: "final" 253 | } 254 | ], 255 | type: { 256 | node: "PrimitiveType", 257 | primitiveTypeCode: "int" 258 | }, 259 | fragments: [ 260 | { 261 | node: "VariableDeclarationFragment", 262 | name: { 263 | node: "SimpleName", 264 | identifier: "i" 265 | }, 266 | extraDimensions: 0, 267 | initializer: { 268 | node: "NumberLiteral", 269 | token: "42" 270 | } 271 | } 272 | ] 273 | } 274 | ] 275 | } 276 | ] 277 | } 278 | ] 279 | } 280 | ); 281 | }); 282 | 283 | test("annotation type with several elements", function(assert) { 284 | var src = multiline(function(){/* 285 | @interface RequestForEnhancement { 286 | int id(); 287 | // Unique ID number associated with RFE 288 | String synopsis(); // Synopsis of RFE 289 | String engineer(); // Name of engineer who implemented RFE 290 | String date(); 291 | double pi = 3.14; 292 | // Date RFE was implemented 293 | } 294 | */}); 295 | assert.deepEqual( 296 | JavaParser.parse(src) 297 | , 298 | { 299 | node: "CompilationUnit", 300 | package: null, 301 | imports: [ 302 | 303 | ], 304 | types: [ 305 | { 306 | node: "AnnotationTypeDeclaration", 307 | modifiers: [ 308 | 309 | ], 310 | name: { 311 | node: "SimpleName", 312 | identifier: "RequestForEnhancement" 313 | }, 314 | bodyDeclarations: [ 315 | { 316 | node: "AnnotationTypeMemberDeclaration", 317 | modifiers: [ 318 | 319 | ], 320 | type: { 321 | node: "PrimitiveType", 322 | primitiveTypeCode: "int" 323 | }, 324 | name: { 325 | node: "SimpleName", 326 | identifier: "id" 327 | }, 328 | default: null 329 | }, 330 | { 331 | node: "AnnotationTypeMemberDeclaration", 332 | modifiers: [ 333 | 334 | ], 335 | type: { 336 | node: "SimpleType", 337 | name: { 338 | node: "SimpleName", 339 | identifier: "String" 340 | } 341 | }, 342 | name: { 343 | node: "SimpleName", 344 | identifier: "synopsis" 345 | }, 346 | default: null 347 | }, 348 | { 349 | node: "AnnotationTypeMemberDeclaration", 350 | modifiers: [ 351 | 352 | ], 353 | type: { 354 | node: "SimpleType", 355 | name: { 356 | node: "SimpleName", 357 | identifier: "String" 358 | } 359 | }, 360 | name: { 361 | node: "SimpleName", 362 | identifier: "engineer" 363 | }, 364 | default: null 365 | }, 366 | { 367 | node: "AnnotationTypeMemberDeclaration", 368 | modifiers: [ 369 | 370 | ], 371 | type: { 372 | node: "SimpleType", 373 | name: { 374 | node: "SimpleName", 375 | identifier: "String" 376 | } 377 | }, 378 | name: { 379 | node: "SimpleName", 380 | identifier: "date" 381 | }, 382 | default: null 383 | }, 384 | { 385 | node: "FieldDeclaration", 386 | modifiers: [ 387 | 388 | ], 389 | type: { 390 | node: "PrimitiveType", 391 | primitiveTypeCode: "double" 392 | }, 393 | fragments: [ 394 | { 395 | node: "VariableDeclarationFragment", 396 | name: { 397 | node: "SimpleName", 398 | identifier: "pi" 399 | }, 400 | extraDimensions: 0, 401 | initializer: { 402 | node: "NumberLiteral", 403 | token: "3.14" 404 | } 405 | } 406 | ] 407 | } 408 | ] 409 | } 410 | ] 411 | } 412 | ); 413 | }); 414 | 415 | test("annotation type with default ws modifier", function(assert) { 416 | var src = multiline(function(){/* 417 | public @interface RequestForEnhancement { 418 | @interface ClassPreamble { 419 | String author(); 420 | String date(); 421 | int currentRevision() default 1; 422 | String lastModified() default "N/A"; 423 | String lastModifiedBy() default "N/A"; 424 | // Note use of array 425 | String[] reviewers(); 426 | } 427 | } 428 | */}); 429 | assert.deepEqual( 430 | JavaParser.parse(src) 431 | , 432 | { 433 | node: "CompilationUnit", 434 | package: null, 435 | imports: [ 436 | 437 | ], 438 | types: [ 439 | { 440 | node: "AnnotationTypeDeclaration", 441 | modifiers: [ 442 | { 443 | node: "Modifier", 444 | keyword: "public" 445 | } 446 | ], 447 | name: { 448 | node: "SimpleName", 449 | identifier: "RequestForEnhancement" 450 | }, 451 | bodyDeclarations: [ 452 | { 453 | node: "AnnotationTypeDeclaration", 454 | modifiers: [ 455 | 456 | ], 457 | name: { 458 | node: "SimpleName", 459 | identifier: "ClassPreamble" 460 | }, 461 | bodyDeclarations: [ 462 | { 463 | node: "AnnotationTypeMemberDeclaration", 464 | modifiers: [ 465 | 466 | ], 467 | type: { 468 | node: "SimpleType", 469 | name: { 470 | node: "SimpleName", 471 | identifier: "String" 472 | } 473 | }, 474 | name: { 475 | node: "SimpleName", 476 | identifier: "author" 477 | }, 478 | default: null 479 | }, 480 | { 481 | node: "AnnotationTypeMemberDeclaration", 482 | modifiers: [ 483 | 484 | ], 485 | type: { 486 | node: "SimpleType", 487 | name: { 488 | node: "SimpleName", 489 | identifier: "String" 490 | } 491 | }, 492 | name: { 493 | node: "SimpleName", 494 | identifier: "date" 495 | }, 496 | default: null 497 | }, 498 | { 499 | node: "AnnotationTypeMemberDeclaration", 500 | modifiers: [ 501 | 502 | ], 503 | type: { 504 | node: "PrimitiveType", 505 | primitiveTypeCode: "int" 506 | }, 507 | name: { 508 | node: "SimpleName", 509 | identifier: "currentRevision" 510 | }, 511 | default: { 512 | node: "NumberLiteral", 513 | token: "1" 514 | } 515 | }, 516 | { 517 | node: "AnnotationTypeMemberDeclaration", 518 | modifiers: [ 519 | 520 | ], 521 | type: { 522 | node: "SimpleType", 523 | name: { 524 | node: "SimpleName", 525 | identifier: "String" 526 | } 527 | }, 528 | name: { 529 | node: "SimpleName", 530 | identifier: "lastModified" 531 | }, 532 | default: { 533 | node: "StringLiteral", 534 | escapedValue: "\"N/A\"" 535 | } 536 | }, 537 | { 538 | node: "AnnotationTypeMemberDeclaration", 539 | modifiers: [ 540 | 541 | ], 542 | type: { 543 | node: "SimpleType", 544 | name: { 545 | node: "SimpleName", 546 | identifier: "String" 547 | } 548 | }, 549 | name: { 550 | node: "SimpleName", 551 | identifier: "lastModifiedBy" 552 | }, 553 | default: { 554 | node: "StringLiteral", 555 | escapedValue: "\"N/A\"" 556 | } 557 | }, 558 | { 559 | node: "AnnotationTypeMemberDeclaration", 560 | modifiers: [ 561 | 562 | ], 563 | type: { 564 | node: "ArrayType", 565 | componentType: { 566 | node: "SimpleType", 567 | name: { 568 | node: "SimpleName", 569 | identifier: "String" 570 | } 571 | } 572 | }, 573 | name: { 574 | node: "SimpleName", 575 | identifier: "reviewers" 576 | }, 577 | default: null 578 | } 579 | ] 580 | } 581 | ] 582 | } 583 | ] 584 | } 585 | ); 586 | }); 587 | 588 | test("annotation type list", function(assert) { 589 | var src = multiline(function(){/* 590 | @interface Ping { Pong value(); } 591 | @interface Pong { Ping value(); } 592 | */}); 593 | assert.deepEqual( 594 | JavaParser.parse(src) 595 | , 596 | { 597 | node: "CompilationUnit", 598 | package: null, 599 | imports: [ 600 | 601 | ], 602 | types: [ 603 | { 604 | node: "AnnotationTypeDeclaration", 605 | modifiers: [ 606 | 607 | ], 608 | name: { 609 | node: "SimpleName", 610 | identifier: "Ping" 611 | }, 612 | bodyDeclarations: [ 613 | { 614 | node: "AnnotationTypeMemberDeclaration", 615 | modifiers: [ 616 | 617 | ], 618 | type: { 619 | node: "SimpleType", 620 | name: { 621 | node: "SimpleName", 622 | identifier: "Pong" 623 | } 624 | }, 625 | name: { 626 | node: "SimpleName", 627 | identifier: "value" 628 | }, 629 | default: null 630 | } 631 | ] 632 | }, 633 | { 634 | node: "AnnotationTypeDeclaration", 635 | modifiers: [ 636 | 637 | ], 638 | name: { 639 | node: "SimpleName", 640 | identifier: "Pong" 641 | }, 642 | bodyDeclarations: [ 643 | { 644 | node: "AnnotationTypeMemberDeclaration", 645 | modifiers: [ 646 | 647 | ], 648 | type: { 649 | node: "SimpleType", 650 | name: { 651 | node: "SimpleName", 652 | identifier: "Ping" 653 | } 654 | }, 655 | name: { 656 | node: "SimpleName", 657 | identifier: "value" 658 | }, 659 | default: null 660 | } 661 | ] 662 | } 663 | ] 664 | } 665 | ); 666 | }); 667 | 668 | test("annotation type generic enum", function(assert) { 669 | var src = multiline(function(){/* 670 | interface Formatter {} 671 | 672 | @interface PrettyPrinter { 673 | Class value(); 674 | } 675 | 676 | @interface Quality { 677 | enum Level { BAD, INDIFFERENT, GOOD } 678 | Level value(); 679 | } 680 | */}); 681 | assert.deepEqual( 682 | JavaParser.parse(src) 683 | , 684 | { 685 | node: "CompilationUnit", 686 | package: null, 687 | imports: [ 688 | 689 | ], 690 | types: [ 691 | { 692 | node: "TypeDeclaration", 693 | modifiers: [ 694 | 695 | ], 696 | interface: true, 697 | name: { 698 | node: "SimpleName", 699 | identifier: "Formatter" 700 | }, 701 | typeParameters: [ 702 | 703 | ], 704 | superclassType: null, 705 | superInterfaceTypes: [ 706 | 707 | ], 708 | bodyDeclarations: [ 709 | 710 | ] 711 | }, 712 | { 713 | node: "AnnotationTypeDeclaration", 714 | modifiers: [ 715 | 716 | ], 717 | name: { 718 | node: "SimpleName", 719 | identifier: "PrettyPrinter" 720 | }, 721 | bodyDeclarations: [ 722 | { 723 | node: "AnnotationTypeMemberDeclaration", 724 | modifiers: [ 725 | 726 | ], 727 | type: { 728 | node: "ParameterizedType", 729 | type: { 730 | node: "SimpleType", 731 | name: { 732 | node: "SimpleName", 733 | identifier: "Class" 734 | } 735 | }, 736 | typeArguments: [ 737 | { 738 | node: "WildcardType", 739 | bound: { 740 | node: "SimpleType", 741 | name: { 742 | node: "SimpleName", 743 | identifier: "Formatter" 744 | } 745 | }, 746 | upperBound: true 747 | } 748 | ] 749 | }, 750 | name: { 751 | node: "SimpleName", 752 | identifier: "value" 753 | }, 754 | default: null 755 | } 756 | ] 757 | }, 758 | { 759 | node: "AnnotationTypeDeclaration", 760 | modifiers: [ 761 | 762 | ], 763 | name: { 764 | node: "SimpleName", 765 | identifier: "Quality" 766 | }, 767 | bodyDeclarations: [ 768 | { 769 | node: "EnumDeclaration", 770 | modifiers: [ 771 | 772 | ], 773 | name: { 774 | node: "SimpleName", 775 | identifier: "Level" 776 | }, 777 | superInterfaceTypes: [ 778 | 779 | ], 780 | enumConstants: [ 781 | { 782 | node: "EnumConstantDeclaration", 783 | modifiers: [ 784 | 785 | ], 786 | name: { 787 | node: "SimpleName", 788 | identifier: "BAD" 789 | }, 790 | arguments: [ 791 | 792 | ], 793 | anonymousClassDeclaration: null 794 | }, 795 | { 796 | node: "EnumConstantDeclaration", 797 | modifiers: [ 798 | 799 | ], 800 | name: { 801 | node: "SimpleName", 802 | identifier: "INDIFFERENT" 803 | }, 804 | arguments: [ 805 | 806 | ], 807 | anonymousClassDeclaration: null 808 | }, 809 | { 810 | node: "EnumConstantDeclaration", 811 | modifiers: [ 812 | 813 | ], 814 | name: { 815 | node: "SimpleName", 816 | identifier: "GOOD" 817 | }, 818 | arguments: [ 819 | 820 | ], 821 | anonymousClassDeclaration: null 822 | } 823 | ], 824 | bodyDeclarations: [ 825 | 826 | ] 827 | }, 828 | { 829 | node: "AnnotationTypeMemberDeclaration", 830 | modifiers: [ 831 | 832 | ], 833 | type: { 834 | node: "SimpleType", 835 | name: { 836 | node: "SimpleName", 837 | identifier: "Level" 838 | } 839 | }, 840 | name: { 841 | node: "SimpleName", 842 | identifier: "value" 843 | }, 844 | default: null 845 | } 846 | ] 847 | } 848 | ] 849 | } 850 | ); 851 | }); 852 | 853 | test("Complex Annotation Type Declaration", function(assert) { 854 | var src = multiline(function(){/* 855 | @Target(ElementType.METHOD) 856 | public @interface ReallyComplexAnnotation { 857 | public SimpleAnnotation value() default @SimpleAnnotation(a="..."); 858 | } 859 | */}); 860 | assert.deepEqual( 861 | JavaParser.parse(src) 862 | , 863 | { 864 | node: "CompilationUnit", 865 | package: null, 866 | imports: [ 867 | 868 | ], 869 | types: [ 870 | { 871 | node: "AnnotationTypeDeclaration", 872 | modifiers: [ 873 | { 874 | node: "SingleMemberAnnotation", 875 | typeName: { 876 | node: "SimpleName", 877 | identifier: "Target" 878 | }, 879 | value: { 880 | node: "QualifiedName", 881 | qualifier: { 882 | node: "SimpleName", 883 | identifier: "ElementType" 884 | }, 885 | name: { 886 | node: "SimpleName", 887 | identifier: "METHOD" 888 | } 889 | } 890 | }, 891 | { 892 | node: "Modifier", 893 | keyword: "public" 894 | } 895 | ], 896 | name: { 897 | node: "SimpleName", 898 | identifier: "ReallyComplexAnnotation" 899 | }, 900 | bodyDeclarations: [ 901 | { 902 | node: "AnnotationTypeMemberDeclaration", 903 | modifiers: [ 904 | { 905 | node: "Modifier", 906 | keyword: "public" 907 | } 908 | ], 909 | type: { 910 | node: "SimpleType", 911 | name: { 912 | node: "SimpleName", 913 | identifier: "SimpleAnnotation" 914 | } 915 | }, 916 | name: { 917 | node: "SimpleName", 918 | identifier: "value" 919 | }, 920 | default: { 921 | node: "NormalAnnotation", 922 | typeName: { 923 | node: "SimpleName", 924 | identifier: "SimpleAnnotation" 925 | }, 926 | values: [ 927 | { 928 | node: "MemberValuePair", 929 | name: { 930 | node: "SimpleName", 931 | identifier: "a" 932 | }, 933 | value: { 934 | node: "StringLiteral", 935 | escapedValue: "\"...\"" 936 | } 937 | } 938 | ] 939 | } 940 | } 941 | ] 942 | } 943 | ] 944 | } 945 | ); 946 | }); 947 | 948 | test("nested Annotation Type Declaration", function(assert) { 949 | var src = multiline(function(){/* 950 | @Target(ElementType.METHOD) 951 | public @interface ReallyComplexAnnotation { 952 | protected @interface InnerAnnotation { 953 | public SimpleAnnotation value() default @SimpleAnnotation(a="..."); 954 | } 955 | } 956 | */}); 957 | assert.deepEqual( 958 | JavaParser.parse(src) 959 | , 960 | { 961 | node: "CompilationUnit", 962 | package: null, 963 | imports: [ 964 | 965 | ], 966 | types: [ 967 | { 968 | node: "AnnotationTypeDeclaration", 969 | modifiers: [ 970 | { 971 | node: "SingleMemberAnnotation", 972 | typeName: { 973 | node: "SimpleName", 974 | identifier: "Target" 975 | }, 976 | value: { 977 | node: "QualifiedName", 978 | qualifier: { 979 | node: "SimpleName", 980 | identifier: "ElementType" 981 | }, 982 | name: { 983 | node: "SimpleName", 984 | identifier: "METHOD" 985 | } 986 | } 987 | }, 988 | { 989 | node: "Modifier", 990 | keyword: "public" 991 | } 992 | ], 993 | name: { 994 | node: "SimpleName", 995 | identifier: "ReallyComplexAnnotation" 996 | }, 997 | bodyDeclarations: [ 998 | { 999 | node: "AnnotationTypeDeclaration", 1000 | modifiers: [ 1001 | { 1002 | node: "Modifier", 1003 | keyword: "protected" 1004 | } 1005 | ], 1006 | name: { 1007 | node: "SimpleName", 1008 | identifier: "InnerAnnotation" 1009 | }, 1010 | bodyDeclarations: [ 1011 | { 1012 | node: "AnnotationTypeMemberDeclaration", 1013 | modifiers: [ 1014 | { 1015 | node: "Modifier", 1016 | keyword: "public" 1017 | } 1018 | ], 1019 | type: { 1020 | node: "SimpleType", 1021 | name: { 1022 | node: "SimpleName", 1023 | identifier: "SimpleAnnotation" 1024 | } 1025 | }, 1026 | name: { 1027 | node: "SimpleName", 1028 | identifier: "value" 1029 | }, 1030 | default: { 1031 | node: "NormalAnnotation", 1032 | typeName: { 1033 | node: "SimpleName", 1034 | identifier: "SimpleAnnotation" 1035 | }, 1036 | values: [ 1037 | { 1038 | node: "MemberValuePair", 1039 | name: { 1040 | node: "SimpleName", 1041 | identifier: "a" 1042 | }, 1043 | value: { 1044 | node: "StringLiteral", 1045 | escapedValue: "\"...\"" 1046 | } 1047 | } 1048 | ] 1049 | } 1050 | } 1051 | ] 1052 | } 1053 | ] 1054 | } 1055 | ] 1056 | } 1057 | ); 1058 | }); 1059 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/ClassTests/BodyBlocksTests.js: -------------------------------------------------------------------------------- 1 | 2 | test("class body ws semi", function(assert) { 3 | var src = "class Hello {;}"; 4 | assert.deepEqual( 5 | JavaParser.parse(src) 6 | , 7 | { 8 | node: "CompilationUnit", 9 | package: null, 10 | imports: [ 11 | 12 | ], 13 | types: [ 14 | { 15 | node: "TypeDeclaration", 16 | modifiers: [ 17 | 18 | ], 19 | interface: false, 20 | name: { 21 | node: "SimpleName", 22 | identifier: "Hello" 23 | }, 24 | typeParameters: [ 25 | 26 | ], 27 | superclassType: null, 28 | superInterfaceTypes: [ 29 | 30 | ], 31 | bodyDeclarations: [ 32 | 33 | ] 34 | } 35 | ] 36 | } 37 | ); 38 | }); 39 | 40 | test("class inner static empty block", function(assert) { 41 | var src = multiline(function(){/* 42 | class Z { 43 | static { } 44 | } 45 | */}); 46 | assert.deepEqual( 47 | JavaParser.parse(src) 48 | , 49 | { 50 | node: "CompilationUnit", 51 | package: null, 52 | imports: [ 53 | 54 | ], 55 | types: [ 56 | { 57 | node: "TypeDeclaration", 58 | modifiers: [ 59 | 60 | ], 61 | interface: false, 62 | name: { 63 | node: "SimpleName", 64 | identifier: "Z" 65 | }, 66 | typeParameters: [ 67 | 68 | ], 69 | superclassType: null, 70 | superInterfaceTypes: [ 71 | 72 | ], 73 | bodyDeclarations: [ 74 | { 75 | node: "Initializer", 76 | modifiers: [ 77 | { 78 | node: "Modifier", 79 | keyword: "static" 80 | } 81 | ], 82 | body: { 83 | node: "Block", 84 | statements: [ 85 | 86 | ] 87 | } 88 | } 89 | ] 90 | } 91 | ] 92 | } 93 | ); 94 | }); 95 | 96 | test("class inner static block ws semi", function(assert) { 97 | var src = multiline(function(){/* 98 | class Z { 99 | static { ; } 100 | } 101 | */}); 102 | assert.deepEqual( 103 | JavaParser.parse(src) 104 | , 105 | { 106 | node: "CompilationUnit", 107 | package: null, 108 | imports: [ 109 | 110 | ], 111 | types: [ 112 | { 113 | node: "TypeDeclaration", 114 | modifiers: [ 115 | 116 | ], 117 | interface: false, 118 | name: { 119 | node: "SimpleName", 120 | identifier: "Z" 121 | }, 122 | typeParameters: [ 123 | 124 | ], 125 | superclassType: null, 126 | superInterfaceTypes: [ 127 | 128 | ], 129 | bodyDeclarations: [ 130 | { 131 | node: "Initializer", 132 | modifiers: [ 133 | { 134 | node: "Modifier", 135 | keyword: "static" 136 | } 137 | ], 138 | body: { 139 | node: "Block", 140 | statements: [ 141 | { 142 | node: "EmptyStatement" 143 | } 144 | ] 145 | } 146 | } 147 | ] 148 | } 149 | ] 150 | } 151 | ); 152 | }); 153 | 154 | test("class inner empty block", function(assert) { 155 | var src = multiline(function(){/* 156 | class Z { 157 | { } 158 | } 159 | */}); 160 | assert.deepEqual( 161 | JavaParser.parse(src) 162 | , 163 | { 164 | node: "CompilationUnit", 165 | package: null, 166 | imports: [ 167 | 168 | ], 169 | types: [ 170 | { 171 | node: "TypeDeclaration", 172 | modifiers: [ 173 | 174 | ], 175 | interface: false, 176 | name: { 177 | node: "SimpleName", 178 | identifier: "Z" 179 | }, 180 | typeParameters: [ 181 | 182 | ], 183 | superclassType: null, 184 | superInterfaceTypes: [ 185 | 186 | ], 187 | bodyDeclarations: [ 188 | { 189 | node: "Initializer", 190 | modifiers: [ 191 | 192 | ], 193 | body: { 194 | node: "Block", 195 | statements: [ 196 | 197 | ] 198 | } 199 | } 200 | ] 201 | } 202 | ] 203 | } 204 | ); 205 | }); 206 | 207 | test("class inner block ws semi", function(assert) { 208 | var src = multiline(function(){/* 209 | class Z { 210 | { ;} 211 | } 212 | */}); 213 | assert.deepEqual( 214 | JavaParser.parse(src) 215 | , 216 | { 217 | node: "CompilationUnit", 218 | package: null, 219 | imports: [ 220 | 221 | ], 222 | types: [ 223 | { 224 | node: "TypeDeclaration", 225 | modifiers: [ 226 | 227 | ], 228 | interface: false, 229 | name: { 230 | node: "SimpleName", 231 | identifier: "Z" 232 | }, 233 | typeParameters: [ 234 | 235 | ], 236 | superclassType: null, 237 | superInterfaceTypes: [ 238 | 239 | ], 240 | bodyDeclarations: [ 241 | { 242 | node: "Initializer", 243 | modifiers: [ 244 | 245 | ], 246 | body: { 247 | node: "Block", 248 | statements: [ 249 | { 250 | node: "EmptyStatement" 251 | } 252 | ] 253 | } 254 | } 255 | ] 256 | } 257 | ] 258 | } 259 | ); 260 | }); 261 | 262 | 263 | test("class inner static block ws code", function(assert) { 264 | var src = multiline(function(){/* 265 | class UA { 266 | static { i = j + 2; } 267 | static int i, j; 268 | static { j = 4; } 269 | } 270 | */}); 271 | assert.deepEqual( 272 | JavaParser.parse(src) 273 | , 274 | { 275 | node: "CompilationUnit", 276 | package: null, 277 | imports: [], 278 | types: [ 279 | { 280 | node: "TypeDeclaration", 281 | modifiers: [], 282 | interface: false, 283 | name: { 284 | node: "SimpleName", 285 | identifier: "UA" 286 | }, 287 | typeParameters: [], 288 | superclassType: null, 289 | superInterfaceTypes: [], 290 | bodyDeclarations: [ 291 | { 292 | node: "Initializer", 293 | modifiers: [ 294 | { 295 | node: "Modifier", 296 | keyword: "static" 297 | } 298 | ], 299 | body: { 300 | node: "Block", 301 | statements: [ 302 | { 303 | node: "ExpressionStatement", 304 | expression: { 305 | node: "Assignment", 306 | leftHandSide: { 307 | node: "SimpleName", 308 | identifier: "i" 309 | }, 310 | operator: "=", 311 | rightHandSide: { 312 | node: "InfixExpression", 313 | leftOperand: { 314 | node: "SimpleName", 315 | identifier: "j" 316 | }, 317 | operator: "+", 318 | rightOperand: { 319 | node: "NumberLiteral", 320 | token: "2" 321 | }, 322 | } 323 | } 324 | } 325 | ] 326 | } 327 | }, 328 | { 329 | node: "FieldDeclaration", 330 | modifiers: [ 331 | { 332 | node: "Modifier", 333 | keyword: "static" 334 | } 335 | ], 336 | type: { 337 | node: "PrimitiveType", 338 | primitiveTypeCode: "int" 339 | }, 340 | fragments: [ 341 | { 342 | node: "VariableDeclarationFragment", 343 | name: { 344 | node: "SimpleName", 345 | identifier: "i" 346 | }, 347 | extraDimensions: 0, 348 | initializer: null 349 | }, 350 | { 351 | node: "VariableDeclarationFragment", 352 | name: { 353 | node: "SimpleName", 354 | identifier: "j" 355 | }, 356 | extraDimensions: 0, 357 | initializer: null 358 | } 359 | ] 360 | }, 361 | { 362 | node: "Initializer", 363 | modifiers: [ 364 | { 365 | node: "Modifier", 366 | keyword: "static" 367 | } 368 | ], 369 | body: { 370 | node: "Block", 371 | statements: [ 372 | { 373 | node: "ExpressionStatement", 374 | expression: { 375 | node: "Assignment", 376 | leftHandSide: { 377 | node: "SimpleName", 378 | identifier: "j" 379 | }, 380 | operator: "=", 381 | rightHandSide: { 382 | node: "NumberLiteral", 383 | token: "4" 384 | } 385 | } 386 | } 387 | ] 388 | } 389 | } 390 | ] 391 | } 392 | ] 393 | } 394 | ); 395 | }); 396 | 397 | test("class inner static block ws inner block ws code", function(assert) { 398 | var src = multiline(function(){/* 399 | class UA { 400 | static { i = j - 1 -2 -3 - 4 -5 + 6 + 7 + 8 * 5 * 7 * 42; } 401 | } 402 | */}); 403 | assert.deepEqual( 404 | JavaParser.parse(src) 405 | , 406 | { 407 | node: "CompilationUnit", 408 | package: null, 409 | imports: [], 410 | types: [ 411 | { 412 | node: "TypeDeclaration", 413 | modifiers: [], 414 | interface: false, 415 | name: { 416 | node: "SimpleName", 417 | identifier: "UA" 418 | }, 419 | typeParameters: [], 420 | superclassType: null, 421 | superInterfaceTypes: [], 422 | bodyDeclarations: [ 423 | { 424 | node: "Initializer", 425 | modifiers: [ 426 | { 427 | node: "Modifier", 428 | keyword: "static" 429 | } 430 | ], 431 | body: { 432 | node: "Block", 433 | statements: [ 434 | { 435 | node: "ExpressionStatement", 436 | expression: { 437 | node: "Assignment", 438 | leftHandSide: { 439 | node: "SimpleName", 440 | identifier: "i" 441 | }, 442 | operator: "=", 443 | rightHandSide: { 444 | node: "InfixExpression", 445 | leftOperand: { 446 | node: "InfixExpression", 447 | leftOperand: { 448 | node: "InfixExpression", 449 | leftOperand: { 450 | node: "InfixExpression", 451 | leftOperand: { 452 | node: "InfixExpression", 453 | leftOperand: { 454 | node: "InfixExpression", 455 | leftOperand: { 456 | node: "InfixExpression", 457 | leftOperand: { 458 | node: "InfixExpression", 459 | leftOperand: { 460 | node: "SimpleName", 461 | identifier: "j" 462 | }, 463 | operator: "-", 464 | rightOperand: { 465 | node: "NumberLiteral", 466 | token: "1" 467 | }, 468 | }, 469 | operator: "-", 470 | rightOperand: { 471 | node: "NumberLiteral", 472 | token: "2" 473 | }, 474 | }, 475 | operator: "-", 476 | rightOperand: { 477 | node: "NumberLiteral", 478 | token: "3" 479 | }, 480 | }, 481 | operator: "-", 482 | rightOperand: { 483 | node: "NumberLiteral", 484 | token: "4" 485 | }, 486 | }, 487 | operator: "-", 488 | rightOperand: { 489 | node: "NumberLiteral", 490 | token: "5" 491 | }, 492 | }, 493 | operator: "+", 494 | rightOperand: { 495 | node: "NumberLiteral", 496 | token: "6" 497 | }, 498 | }, 499 | operator: "+", 500 | rightOperand: { 501 | node: "NumberLiteral", 502 | token: "7" 503 | }, 504 | }, 505 | operator: "+", 506 | rightOperand: { 507 | node: "InfixExpression", 508 | leftOperand: { 509 | node: "InfixExpression", 510 | leftOperand: { 511 | node: "InfixExpression", 512 | leftOperand: { 513 | node: "NumberLiteral", 514 | token: "8" 515 | }, 516 | operator: "*", 517 | rightOperand: { 518 | node: "NumberLiteral", 519 | token: "5" 520 | }, 521 | }, 522 | operator: "*", 523 | rightOperand: { 524 | node: "NumberLiteral", 525 | token: "7" 526 | }, 527 | }, 528 | operator: "*", 529 | rightOperand: { 530 | node: "NumberLiteral", 531 | token: "42" 532 | }, 533 | }, 534 | } 535 | } 536 | } 537 | ] 538 | } 539 | } 540 | ] 541 | } 542 | ] 543 | } 544 | ); 545 | }); 546 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/ClassTests/ClassExtendsImplementsTests.js: -------------------------------------------------------------------------------- 1 | 2 | test("extends", function(assert) { 3 | var src = "class Hello extends World {}"; 4 | assert.deepEqual( 5 | JavaParser.parse(src) 6 | , 7 | { 8 | node: "CompilationUnit", 9 | package: null, 10 | imports: [ 11 | 12 | ], 13 | types: [ 14 | { 15 | node: "TypeDeclaration", 16 | modifiers: [ 17 | 18 | ], 19 | interface: false, 20 | name: { 21 | node: "SimpleName", 22 | identifier: "Hello" 23 | }, 24 | typeParameters: [ 25 | 26 | ], 27 | superclassType: { 28 | node: "SimpleType", 29 | name: { 30 | node: "SimpleName", 31 | identifier: "World" 32 | } 33 | }, 34 | superInterfaceTypes: [ 35 | 36 | ], 37 | bodyDeclarations: [ 38 | 39 | ] 40 | } 41 | ] 42 | } 43 | ); 44 | }); 45 | 46 | test("extends ws qualified generic", function(assert) { 47 | var src = "class Hello extends Foo.Bar {}"; 48 | assert.deepEqual( 49 | JavaParser.parse(src) 50 | , 51 | { 52 | node: "CompilationUnit", 53 | package: null, 54 | imports: [ 55 | 56 | ], 57 | types: [ 58 | { 59 | node: "TypeDeclaration", 60 | modifiers: [ 61 | 62 | ], 63 | interface: false, 64 | name: { 65 | node: "SimpleName", 66 | identifier: "Hello" 67 | }, 68 | typeParameters: [ 69 | 70 | ], 71 | superclassType: { 72 | node: "ParameterizedType", 73 | type: { 74 | node: "SimpleType", 75 | name: { 76 | node: "QualifiedName", 77 | qualifier: { 78 | node: "SimpleName", 79 | identifier: "Foo" 80 | }, 81 | name: { 82 | node: "SimpleName", 83 | identifier: "Bar" 84 | } 85 | } 86 | }, 87 | typeArguments: [ 88 | { 89 | node: "SimpleType", 90 | name: { 91 | node: "SimpleName", 92 | identifier: "T" 93 | } 94 | } 95 | ] 96 | }, 97 | superInterfaceTypes: [ 98 | 99 | ], 100 | bodyDeclarations: [ 101 | 102 | ] 103 | } 104 | ] 105 | } 106 | ); 107 | }); 108 | 109 | test("extends ws dots ws spaces ws generic", function(assert) { 110 | var src = "class Hello extends Foo < ? extends T.A> . Bar {}"; 111 | assert.deepEqual( 112 | JavaParser.parse(src) 113 | , 114 | { 115 | node: "CompilationUnit", 116 | package: null, 117 | imports: [ 118 | 119 | ], 120 | types: [ 121 | { 122 | node: "TypeDeclaration", 123 | modifiers: [ 124 | 125 | ], 126 | interface: false, 127 | name: { 128 | node: "SimpleName", 129 | identifier: "Hello" 130 | }, 131 | typeParameters: [ 132 | { 133 | node: "TypeParameter", 134 | name: { 135 | node: "SimpleName", 136 | identifier: "C" 137 | }, 138 | typeBounds: [ 139 | 140 | ] 141 | } 142 | ], 143 | superclassType: { 144 | node: "QualifiedType", 145 | qualifier: { 146 | node: "ParameterizedType", 147 | type: { 148 | node: "SimpleType", 149 | name: { 150 | node: "SimpleName", 151 | identifier: "Foo" 152 | } 153 | }, 154 | typeArguments: [ 155 | { 156 | node: "WildcardType", 157 | bound: { 158 | node: "ParameterizedType", 159 | type: { 160 | node: "SimpleType", 161 | name: { 162 | node: "QualifiedName", 163 | qualifier: { 164 | node: "SimpleName", 165 | identifier: "T" 166 | }, 167 | name: { 168 | node: "SimpleName", 169 | identifier: "A" 170 | } 171 | } 172 | }, 173 | typeArguments: [ 174 | { 175 | node: "SimpleType", 176 | name: { 177 | node: "SimpleName", 178 | identifier: "C" 179 | } 180 | } 181 | ] 182 | }, 183 | upperBound: true 184 | } 185 | ] 186 | }, 187 | name: { 188 | node: "SimpleName", 189 | identifier: "Bar" 190 | } 191 | }, 192 | superInterfaceTypes: [ 193 | 194 | ], 195 | bodyDeclarations: [ 196 | 197 | ] 198 | } 199 | ] 200 | } 201 | ); 202 | }); 203 | 204 | test("implements single", function(assert) { 205 | var src = "class Hello implements IList {}"; 206 | assert.deepEqual( 207 | JavaParser.parse(src) 208 | , 209 | { 210 | node: "CompilationUnit", 211 | package: null, 212 | imports: [ 213 | 214 | ], 215 | types: [ 216 | { 217 | node: "TypeDeclaration", 218 | modifiers: [ 219 | 220 | ], 221 | interface: false, 222 | name: { 223 | node: "SimpleName", 224 | identifier: "Hello" 225 | }, 226 | typeParameters: [ 227 | 228 | ], 229 | superclassType: null, 230 | superInterfaceTypes: [ 231 | { 232 | node: "SimpleType", 233 | name: { 234 | node: "SimpleName", 235 | identifier: "IList" 236 | } 237 | } 238 | ], 239 | bodyDeclarations: [ 240 | 241 | ] 242 | } 243 | ] 244 | } 245 | ); 246 | }); 247 | 248 | test("implements multiple ws qualified", function(assert) { 249 | var src = "class Hello implements IList, org.git.IHub {}"; 250 | assert.deepEqual( 251 | JavaParser.parse(src) 252 | , 253 | { 254 | node: "CompilationUnit", 255 | package: null, 256 | imports: [ 257 | 258 | ], 259 | types: [ 260 | { 261 | node: "TypeDeclaration", 262 | modifiers: [ 263 | 264 | ], 265 | interface: false, 266 | name: { 267 | node: "SimpleName", 268 | identifier: "Hello" 269 | }, 270 | typeParameters: [ 271 | 272 | ], 273 | superclassType: null, 274 | superInterfaceTypes: [ 275 | { 276 | node: "SimpleType", 277 | name: { 278 | node: "SimpleName", 279 | identifier: "IList" 280 | } 281 | }, 282 | { 283 | node: "SimpleType", 284 | name: { 285 | node: "QualifiedName", 286 | qualifier: { 287 | node: "QualifiedName", 288 | qualifier: { 289 | node: "SimpleName", 290 | identifier: "org" 291 | }, 292 | name: { 293 | node: "SimpleName", 294 | identifier: "git" 295 | } 296 | }, 297 | name: { 298 | node: "SimpleName", 299 | identifier: "IHub" 300 | } 301 | } 302 | } 303 | ], 304 | bodyDeclarations: [ 305 | 306 | ] 307 | } 308 | ] 309 | } 310 | ); 311 | }); 312 | 313 | test("implements multiple ws qualified ws generic", function(assert) { 314 | var src = "class Hello< A, B> implements IList< C > , org.git. IHub > {}"; 315 | assert.deepEqual( 316 | JavaParser.parse(src) 317 | , 318 | { 319 | node: "CompilationUnit", 320 | package: null, 321 | imports: [ 322 | 323 | ], 324 | types: [ 325 | { 326 | node: "TypeDeclaration", 327 | modifiers: [ 328 | 329 | ], 330 | interface: false, 331 | name: { 332 | node: "SimpleName", 333 | identifier: "Hello" 334 | }, 335 | typeParameters: [ 336 | { 337 | node: "TypeParameter", 338 | name: { 339 | node: "SimpleName", 340 | identifier: "A" 341 | }, 342 | typeBounds: [ 343 | 344 | ] 345 | }, 346 | { 347 | node: "TypeParameter", 348 | name: { 349 | node: "SimpleName", 350 | identifier: "B" 351 | }, 352 | typeBounds: [ 353 | 354 | ] 355 | } 356 | ], 357 | superclassType: null, 358 | superInterfaceTypes: [ 359 | { 360 | node: "ParameterizedType", 361 | type: { 362 | node: "SimpleType", 363 | name: { 364 | node: "SimpleName", 365 | identifier: "IList" 366 | } 367 | }, 368 | typeArguments: [ 369 | { 370 | node: "SimpleType", 371 | name: { 372 | node: "SimpleName", 373 | identifier: "C" 374 | } 375 | } 376 | ] 377 | }, 378 | { 379 | node: "ParameterizedType", 380 | type: { 381 | node: "SimpleType", 382 | name: { 383 | node: "QualifiedName", 384 | qualifier: { 385 | node: "QualifiedName", 386 | qualifier: { 387 | node: "SimpleName", 388 | identifier: "org" 389 | }, 390 | name: { 391 | node: "SimpleName", 392 | identifier: "git" 393 | } 394 | }, 395 | name: { 396 | node: "SimpleName", 397 | identifier: "IHub" 398 | } 399 | } 400 | }, 401 | typeArguments: [ 402 | { 403 | node: "SimpleType", 404 | name: { 405 | node: "SimpleName", 406 | identifier: "A" 407 | } 408 | }, 409 | { 410 | node: "ParameterizedType", 411 | type: { 412 | node: "SimpleType", 413 | name: { 414 | node: "QualifiedName", 415 | qualifier: { 416 | node: "SimpleName", 417 | identifier: "B" 418 | }, 419 | name: { 420 | node: "SimpleName", 421 | identifier: "C" 422 | } 423 | } 424 | }, 425 | typeArguments: [ 426 | { 427 | node: "SimpleType", 428 | name: { 429 | node: "SimpleName", 430 | identifier: "C" 431 | } 432 | } 433 | ] 434 | } 435 | ] 436 | } 437 | ], 438 | bodyDeclarations: [ 439 | 440 | ] 441 | } 442 | ] 443 | } 444 | ); 445 | }); 446 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/ClassTests/ClassModifiersTests.js: -------------------------------------------------------------------------------- 1 | 2 | test("default class modifier", function(assert) { 3 | var src = "class Hello {}"; 4 | assert.deepEqual( 5 | JavaParser.parse(src) 6 | , 7 | { 8 | node: "CompilationUnit", 9 | package: null, 10 | imports: [ 11 | 12 | ], 13 | types: [ 14 | { 15 | node: "TypeDeclaration", 16 | modifiers: [ 17 | 18 | ], 19 | interface: false, 20 | name: { 21 | node: "SimpleName", 22 | identifier: "Hello" 23 | }, 24 | typeParameters: [ 25 | 26 | ], 27 | superclassType: null, 28 | superInterfaceTypes: [ 29 | 30 | ], 31 | bodyDeclarations: [ 32 | 33 | ] 34 | } 35 | ] 36 | } 37 | ); 38 | }); 39 | 40 | test("single class modifier", function(assert) { 41 | var src = "final class Hello {}"; 42 | assert.deepEqual( 43 | JavaParser.parse(src) 44 | , 45 | { 46 | node: "CompilationUnit", 47 | package: null, 48 | imports: [ 49 | 50 | ], 51 | types: [ 52 | { 53 | node: "TypeDeclaration", 54 | modifiers: [ 55 | { 56 | node: "Modifier", 57 | keyword: "final" 58 | } 59 | ], 60 | interface: false, 61 | name: { 62 | node: "SimpleName", 63 | identifier: "Hello" 64 | }, 65 | typeParameters: [ 66 | 67 | ], 68 | superclassType: null, 69 | superInterfaceTypes: [ 70 | 71 | ], 72 | bodyDeclarations: [ 73 | 74 | ] 75 | } 76 | ] 77 | } 78 | ); 79 | }); 80 | 81 | test("multi class modifier", function(assert) { 82 | var src = "final private class Hello {}"; 83 | assert.deepEqual( 84 | JavaParser.parse(src) 85 | , 86 | { 87 | node: "CompilationUnit", 88 | package: null, 89 | imports: [ 90 | 91 | ], 92 | types: [ 93 | { 94 | node: "TypeDeclaration", 95 | modifiers: [ 96 | { 97 | node: "Modifier", 98 | keyword: "final" 99 | }, 100 | { 101 | node: "Modifier", 102 | keyword: "private" 103 | } 104 | ], 105 | interface: false, 106 | name: { 107 | node: "SimpleName", 108 | identifier: "Hello" 109 | }, 110 | typeParameters: [ 111 | 112 | ], 113 | superclassType: null, 114 | superInterfaceTypes: [ 115 | 116 | ], 117 | bodyDeclarations: [ 118 | 119 | ] 120 | } 121 | ] 122 | } 123 | ); 124 | }); 125 | 126 | test("default class modifier ws annotation", function(assert) { 127 | var src = multiline(function(){/* 128 | @Author(@Name(first = "Joe", last = "Hacker")) 129 | class Hello {} 130 | */}); 131 | assert.deepEqual( 132 | JavaParser.parse(src) 133 | , 134 | { 135 | node: "CompilationUnit", 136 | package: null, 137 | imports: [ 138 | 139 | ], 140 | types: [ 141 | { 142 | node: "TypeDeclaration", 143 | modifiers: [ 144 | { 145 | node: "SingleMemberAnnotation", 146 | typeName: { 147 | node: "SimpleName", 148 | identifier: "Author" 149 | }, 150 | value: { 151 | node: "NormalAnnotation", 152 | typeName: { 153 | node: "SimpleName", 154 | identifier: "Name" 155 | }, 156 | values: [ 157 | { 158 | node: "MemberValuePair", 159 | name: { 160 | node: "SimpleName", 161 | identifier: "first" 162 | }, 163 | value: { 164 | node: "StringLiteral", 165 | escapedValue: "\"Joe\"" 166 | } 167 | }, 168 | { 169 | node: "MemberValuePair", 170 | name: { 171 | node: "SimpleName", 172 | identifier: "last" 173 | }, 174 | value: { 175 | node: "StringLiteral", 176 | escapedValue: "\"Hacker\"" 177 | } 178 | } 179 | ] 180 | } 181 | } 182 | ], 183 | interface: false, 184 | name: { 185 | node: "SimpleName", 186 | identifier: "Hello" 187 | }, 188 | typeParameters: [ 189 | 190 | ], 191 | superclassType: null, 192 | superInterfaceTypes: [ 193 | 194 | ], 195 | bodyDeclarations: [ 196 | 197 | ] 198 | } 199 | ] 200 | } 201 | ); 202 | }); 203 | 204 | test("multi class modifier ws annotation", function(assert) { 205 | var src = multiline(function(){/* 206 | @Author(@Name(first = "Joe", last = "Hacker")) 207 | private static class Hello {} 208 | */}); 209 | assert.deepEqual( 210 | JavaParser.parse(src) 211 | , 212 | { 213 | node: "CompilationUnit", 214 | package: null, 215 | imports: [ 216 | 217 | ], 218 | types: [ 219 | { 220 | node: "TypeDeclaration", 221 | modifiers: [ 222 | { 223 | node: "SingleMemberAnnotation", 224 | typeName: { 225 | node: "SimpleName", 226 | identifier: "Author" 227 | }, 228 | value: { 229 | node: "NormalAnnotation", 230 | typeName: { 231 | node: "SimpleName", 232 | identifier: "Name" 233 | }, 234 | values: [ 235 | { 236 | node: "MemberValuePair", 237 | name: { 238 | node: "SimpleName", 239 | identifier: "first" 240 | }, 241 | value: { 242 | node: "StringLiteral", 243 | escapedValue: "\"Joe\"" 244 | } 245 | }, 246 | { 247 | node: "MemberValuePair", 248 | name: { 249 | node: "SimpleName", 250 | identifier: "last" 251 | }, 252 | value: { 253 | node: "StringLiteral", 254 | escapedValue: "\"Hacker\"" 255 | } 256 | } 257 | ] 258 | } 259 | }, 260 | { 261 | node: "Modifier", 262 | keyword: "private" 263 | }, 264 | { 265 | node: "Modifier", 266 | keyword: "static" 267 | } 268 | ], 269 | interface: false, 270 | name: { 271 | node: "SimpleName", 272 | identifier: "Hello" 273 | }, 274 | typeParameters: [ 275 | 276 | ], 277 | superclassType: null, 278 | superInterfaceTypes: [ 279 | 280 | ], 281 | bodyDeclarations: [ 282 | 283 | ] 284 | } 285 | ] 286 | } 287 | ); 288 | }); 289 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/EnumTests/EnumTests.js: -------------------------------------------------------------------------------- 1 | 2 | test("empty enum", function(assert) { 3 | var src = "enum Test {}"; 4 | assert.deepEqual( 5 | JavaParser.parse(src) 6 | , 7 | { 8 | node: "CompilationUnit", 9 | package: null, 10 | imports: [ 11 | 12 | ], 13 | types: [ 14 | { 15 | node: "EnumDeclaration", 16 | modifiers: [ 17 | 18 | ], 19 | name: { 20 | node: "SimpleName", 21 | identifier: "Test" 22 | }, 23 | superInterfaceTypes: [ 24 | 25 | ], 26 | enumConstants: [ 27 | 28 | ], 29 | bodyDeclarations: [ 30 | 31 | ] 32 | } 33 | ] 34 | } 35 | ); 36 | }); 37 | 38 | test("empty enum implements", function(assert) { 39 | var src = "enum Color implements ITest {}"; 40 | assert.deepEqual( 41 | JavaParser.parse(src) 42 | , 43 | { 44 | node: "CompilationUnit", 45 | package: null, 46 | imports: [ 47 | 48 | ], 49 | types: [ 50 | { 51 | node: "EnumDeclaration", 52 | modifiers: [ 53 | 54 | ], 55 | name: { 56 | node: "SimpleName", 57 | identifier: "Color" 58 | }, 59 | superInterfaceTypes: [ 60 | { 61 | node: "ParameterizedType", 62 | type: { 63 | node: "SimpleType", 64 | name: { 65 | node: "SimpleName", 66 | identifier: "ITest" 67 | } 68 | }, 69 | typeArguments: [ 70 | { 71 | node: "SimpleType", 72 | name: { 73 | node: "SimpleName", 74 | identifier: "A" 75 | } 76 | } 77 | ] 78 | } 79 | ], 80 | enumConstants: [ 81 | 82 | ], 83 | bodyDeclarations: [ 84 | 85 | ] 86 | } 87 | ] 88 | } 89 | ); 90 | }); 91 | 92 | test("empty enum ws body ws modifiers", function(assert) { 93 | var src = "public final enum Season { WINTER, SPRING, SUMMER, FALL }"; 94 | assert.deepEqual( 95 | JavaParser.parse(src) 96 | , 97 | { 98 | node: "CompilationUnit", 99 | package: null, 100 | imports: [ 101 | 102 | ], 103 | types: [ 104 | { 105 | node: "EnumDeclaration", 106 | modifiers: [ 107 | { 108 | node: "Modifier", 109 | keyword: "public" 110 | }, 111 | { 112 | node: "Modifier", 113 | keyword: "final" 114 | } 115 | ], 116 | name: { 117 | node: "SimpleName", 118 | identifier: "Season" 119 | }, 120 | superInterfaceTypes: [ 121 | 122 | ], 123 | enumConstants: [ 124 | { 125 | node: "EnumConstantDeclaration", 126 | modifiers: [ 127 | 128 | ], 129 | name: { 130 | node: "SimpleName", 131 | identifier: "WINTER" 132 | }, 133 | arguments: [ 134 | 135 | ], 136 | anonymousClassDeclaration: null 137 | }, 138 | { 139 | node: "EnumConstantDeclaration", 140 | modifiers: [ 141 | 142 | ], 143 | name: { 144 | node: "SimpleName", 145 | identifier: "SPRING" 146 | }, 147 | arguments: [ 148 | 149 | ], 150 | anonymousClassDeclaration: null 151 | }, 152 | { 153 | node: "EnumConstantDeclaration", 154 | modifiers: [ 155 | 156 | ], 157 | name: { 158 | node: "SimpleName", 159 | identifier: "SUMMER" 160 | }, 161 | arguments: [ 162 | 163 | ], 164 | anonymousClassDeclaration: null 165 | }, 166 | { 167 | node: "EnumConstantDeclaration", 168 | modifiers: [ 169 | 170 | ], 171 | name: { 172 | node: "SimpleName", 173 | identifier: "FALL" 174 | }, 175 | arguments: [ 176 | 177 | ], 178 | anonymousClassDeclaration: null 179 | } 180 | ], 181 | bodyDeclarations: [ 182 | 183 | ] 184 | } 185 | ] 186 | } 187 | ); 188 | }); 189 | 190 | test("empty enum ws body ws members", function(assert) { 191 | var src = multiline(function(){/* 192 | enum Color { 193 | RED, GREEN, BLUE; 194 | private int value; 195 | static Object obj[][]; 196 | static Object[] test; 197 | Object[][] testdims[]; 198 | } 199 | */}); 200 | assert.deepEqual( 201 | JavaParser.parse(src) 202 | , 203 | { 204 | node: "CompilationUnit", 205 | package: null, 206 | imports: [ 207 | 208 | ], 209 | types: [ 210 | { 211 | node: "EnumDeclaration", 212 | modifiers: [ 213 | 214 | ], 215 | name: { 216 | node: "SimpleName", 217 | identifier: "Color" 218 | }, 219 | superInterfaceTypes: [ 220 | 221 | ], 222 | enumConstants: [ 223 | { 224 | node: "EnumConstantDeclaration", 225 | modifiers: [ 226 | 227 | ], 228 | name: { 229 | node: "SimpleName", 230 | identifier: "RED" 231 | }, 232 | arguments: [ 233 | 234 | ], 235 | anonymousClassDeclaration: null 236 | }, 237 | { 238 | node: "EnumConstantDeclaration", 239 | modifiers: [ 240 | 241 | ], 242 | name: { 243 | node: "SimpleName", 244 | identifier: "GREEN" 245 | }, 246 | arguments: [ 247 | 248 | ], 249 | anonymousClassDeclaration: null 250 | }, 251 | { 252 | node: "EnumConstantDeclaration", 253 | modifiers: [ 254 | 255 | ], 256 | name: { 257 | node: "SimpleName", 258 | identifier: "BLUE" 259 | }, 260 | arguments: [ 261 | 262 | ], 263 | anonymousClassDeclaration: null 264 | } 265 | ], 266 | bodyDeclarations: [ 267 | { 268 | node: "FieldDeclaration", 269 | modifiers: [ 270 | { 271 | node: "Modifier", 272 | keyword: "private" 273 | } 274 | ], 275 | type: { 276 | node: "PrimitiveType", 277 | primitiveTypeCode: "int" 278 | }, 279 | fragments: [ 280 | { 281 | node: "VariableDeclarationFragment", 282 | name: { 283 | node: "SimpleName", 284 | identifier: "value" 285 | }, 286 | extraDimensions: 0, 287 | initializer: null 288 | } 289 | ] 290 | }, 291 | { 292 | node: "FieldDeclaration", 293 | modifiers: [ 294 | { 295 | node: "Modifier", 296 | keyword: "static" 297 | } 298 | ], 299 | type: { 300 | node: "SimpleType", 301 | name: { 302 | node: "SimpleName", 303 | identifier: "Object" 304 | } 305 | }, 306 | fragments: [ 307 | { 308 | node: "VariableDeclarationFragment", 309 | name: { 310 | node: "SimpleName", 311 | identifier: "obj" 312 | }, 313 | extraDimensions: 2, 314 | initializer: null 315 | } 316 | ] 317 | }, 318 | { 319 | node: "FieldDeclaration", 320 | modifiers: [ 321 | { 322 | node: "Modifier", 323 | keyword: "static" 324 | } 325 | ], 326 | type: { 327 | node: "ArrayType", 328 | componentType: { 329 | node: "SimpleType", 330 | name: { 331 | node: "SimpleName", 332 | identifier: "Object" 333 | } 334 | } 335 | }, 336 | fragments: [ 337 | { 338 | node: "VariableDeclarationFragment", 339 | name: { 340 | node: "SimpleName", 341 | identifier: "test" 342 | }, 343 | extraDimensions: 0, 344 | initializer: null 345 | } 346 | ] 347 | }, 348 | { 349 | node: "FieldDeclaration", 350 | modifiers: [ 351 | 352 | ], 353 | type: { 354 | node: "ArrayType", 355 | componentType: { 356 | node: "ArrayType", 357 | componentType: { 358 | node: "SimpleType", 359 | name: { 360 | node: "SimpleName", 361 | identifier: "Object" 362 | } 363 | } 364 | } 365 | }, 366 | fragments: [ 367 | { 368 | node: "VariableDeclarationFragment", 369 | name: { 370 | node: "SimpleName", 371 | identifier: "testdims" 372 | }, 373 | extraDimensions: 1, 374 | initializer: null 375 | } 376 | ] 377 | } 378 | ] 379 | } 380 | ] 381 | } 382 | ); 383 | }); 384 | 385 | test("Enum Constants ws Class Bodies", function(assert) { 386 | var src = multiline(function(){/* 387 | enum Operation { 388 | PLUS { public double a;}, 389 | MINUS {int b;}, 390 | TIMES {Object c;}, 391 | DIVIDED_BY{;}; 392 | } 393 | */}); 394 | assert.deepEqual( 395 | JavaParser.parse(src) 396 | , 397 | { 398 | node: "CompilationUnit", 399 | package: null, 400 | imports: [ 401 | 402 | ], 403 | types: [ 404 | { 405 | node: "EnumDeclaration", 406 | modifiers: [ 407 | 408 | ], 409 | name: { 410 | node: "SimpleName", 411 | identifier: "Operation" 412 | }, 413 | superInterfaceTypes: [ 414 | 415 | ], 416 | enumConstants: [ 417 | { 418 | node: "EnumConstantDeclaration", 419 | modifiers: [ 420 | 421 | ], 422 | name: { 423 | node: "SimpleName", 424 | identifier: "PLUS" 425 | }, 426 | arguments: [ 427 | 428 | ], 429 | anonymousClassDeclaration: { 430 | node: "AnonymousClassDeclaration", 431 | bodyDeclarations: [ 432 | { 433 | node: "FieldDeclaration", 434 | modifiers: [ 435 | { 436 | node: "Modifier", 437 | keyword: "public" 438 | } 439 | ], 440 | type: { 441 | node: "PrimitiveType", 442 | primitiveTypeCode: "double" 443 | }, 444 | fragments: [ 445 | { 446 | node: "VariableDeclarationFragment", 447 | name: { 448 | node: "SimpleName", 449 | identifier: "a" 450 | }, 451 | extraDimensions: 0, 452 | initializer: null 453 | } 454 | ] 455 | } 456 | ] 457 | } 458 | }, 459 | { 460 | node: "EnumConstantDeclaration", 461 | modifiers: [ 462 | 463 | ], 464 | name: { 465 | node: "SimpleName", 466 | identifier: "MINUS" 467 | }, 468 | arguments: [ 469 | 470 | ], 471 | anonymousClassDeclaration: { 472 | node: "AnonymousClassDeclaration", 473 | bodyDeclarations: [ 474 | { 475 | node: "FieldDeclaration", 476 | modifiers: [ 477 | 478 | ], 479 | type: { 480 | node: "PrimitiveType", 481 | primitiveTypeCode: "int" 482 | }, 483 | fragments: [ 484 | { 485 | node: "VariableDeclarationFragment", 486 | name: { 487 | node: "SimpleName", 488 | identifier: "b" 489 | }, 490 | extraDimensions: 0, 491 | initializer: null 492 | } 493 | ] 494 | } 495 | ] 496 | } 497 | }, 498 | { 499 | node: "EnumConstantDeclaration", 500 | modifiers: [ 501 | 502 | ], 503 | name: { 504 | node: "SimpleName", 505 | identifier: "TIMES" 506 | }, 507 | arguments: [ 508 | 509 | ], 510 | anonymousClassDeclaration: { 511 | node: "AnonymousClassDeclaration", 512 | bodyDeclarations: [ 513 | { 514 | node: "FieldDeclaration", 515 | modifiers: [ 516 | 517 | ], 518 | type: { 519 | node: "SimpleType", 520 | name: { 521 | node: "SimpleName", 522 | identifier: "Object" 523 | } 524 | }, 525 | fragments: [ 526 | { 527 | node: "VariableDeclarationFragment", 528 | name: { 529 | node: "SimpleName", 530 | identifier: "c" 531 | }, 532 | extraDimensions: 0, 533 | initializer: null 534 | } 535 | ] 536 | } 537 | ] 538 | } 539 | }, 540 | { 541 | node: "EnumConstantDeclaration", 542 | modifiers: [ 543 | 544 | ], 545 | name: { 546 | node: "SimpleName", 547 | identifier: "DIVIDED_BY" 548 | }, 549 | arguments: [ 550 | 551 | ], 552 | anonymousClassDeclaration: { 553 | node: "AnonymousClassDeclaration", 554 | bodyDeclarations: [ 555 | 556 | ] 557 | } 558 | } 559 | ], 560 | bodyDeclarations: [ 561 | 562 | ] 563 | } 564 | ] 565 | } 566 | ); 567 | }); 568 | 569 | test("Enum Constants ws arguments", function(assert) { 570 | var src = multiline(function(){/* 571 | enum Coin { 572 | T,PENNY(1L), NICKEL(), DIME(0x10,-42), QUARTER(0b11), 573 | R(0222), R1(true), R5(false), R3(null), R4(3.14), T('a'), 574 | T1("hello\u1984"), T34(-0x1.8p1); 575 | } 576 | */}); 577 | assert.deepEqual( 578 | JavaParser.parse(src) 579 | , 580 | { 581 | node: "CompilationUnit", 582 | package: null, 583 | imports: [], 584 | types: [ 585 | { 586 | node: "EnumDeclaration", 587 | modifiers: [], 588 | name: { 589 | node: "SimpleName", 590 | identifier: "Coin" 591 | }, 592 | superInterfaceTypes: [], 593 | enumConstants: [ 594 | { 595 | node: "EnumConstantDeclaration", 596 | modifiers: [], 597 | name: { 598 | node: "SimpleName", 599 | identifier: "T" 600 | }, 601 | arguments: [], 602 | anonymousClassDeclaration: null 603 | }, 604 | { 605 | node: "EnumConstantDeclaration", 606 | modifiers: [], 607 | name: { 608 | node: "SimpleName", 609 | identifier: "PENNY" 610 | }, 611 | arguments: [ 612 | { 613 | node: "NumberLiteral", 614 | token: "1L" 615 | } 616 | ], 617 | anonymousClassDeclaration: null 618 | }, 619 | { 620 | node: "EnumConstantDeclaration", 621 | modifiers: [], 622 | name: { 623 | node: "SimpleName", 624 | identifier: "NICKEL" 625 | }, 626 | arguments: [], 627 | anonymousClassDeclaration: null 628 | }, 629 | { 630 | node: "EnumConstantDeclaration", 631 | modifiers: [], 632 | name: { 633 | node: "SimpleName", 634 | identifier: "DIME" 635 | }, 636 | arguments: [ 637 | { 638 | node: "NumberLiteral", 639 | token: "0x10" 640 | }, 641 | { 642 | node: "PrefixExpression", 643 | operator: "-", 644 | operand: { 645 | node: "NumberLiteral", 646 | token: "42" 647 | } 648 | } 649 | ], 650 | anonymousClassDeclaration: null 651 | }, 652 | { 653 | node: "EnumConstantDeclaration", 654 | modifiers: [], 655 | name: { 656 | node: "SimpleName", 657 | identifier: "QUARTER" 658 | }, 659 | arguments: [ 660 | { 661 | node: "NumberLiteral", 662 | token: "0b11" 663 | } 664 | ], 665 | anonymousClassDeclaration: null 666 | }, 667 | { 668 | node: "EnumConstantDeclaration", 669 | modifiers: [], 670 | name: { 671 | node: "SimpleName", 672 | identifier: "R" 673 | }, 674 | arguments: [ 675 | { 676 | node: "NumberLiteral", 677 | token: "0222" 678 | } 679 | ], 680 | anonymousClassDeclaration: null 681 | }, 682 | { 683 | node: "EnumConstantDeclaration", 684 | modifiers: [], 685 | name: { 686 | node: "SimpleName", 687 | identifier: "R1" 688 | }, 689 | arguments: [ 690 | { 691 | node: "BooleanLiteral", 692 | booleanValue: true 693 | } 694 | ], 695 | anonymousClassDeclaration: null 696 | }, 697 | { 698 | node: "EnumConstantDeclaration", 699 | modifiers: [], 700 | name: { 701 | node: "SimpleName", 702 | identifier: "R5" 703 | }, 704 | arguments: [ 705 | { 706 | node: "BooleanLiteral", 707 | booleanValue: false 708 | } 709 | ], 710 | anonymousClassDeclaration: null 711 | }, 712 | { 713 | node: "EnumConstantDeclaration", 714 | modifiers: [], 715 | name: { 716 | node: "SimpleName", 717 | identifier: "R3" 718 | }, 719 | arguments: [ 720 | { 721 | node: "NullLiteral" 722 | } 723 | ], 724 | anonymousClassDeclaration: null 725 | }, 726 | { 727 | node: "EnumConstantDeclaration", 728 | modifiers: [], 729 | name: { 730 | node: "SimpleName", 731 | identifier: "R4" 732 | }, 733 | arguments: [ 734 | { 735 | node: "NumberLiteral", 736 | token: "3.14" 737 | } 738 | ], 739 | anonymousClassDeclaration: null 740 | }, 741 | { 742 | node: "EnumConstantDeclaration", 743 | modifiers: [], 744 | name: { 745 | node: "SimpleName", 746 | identifier: "T" 747 | }, 748 | arguments: [ 749 | { 750 | node: "CharacterLiteral", 751 | escapedValue: "'a'" 752 | } 753 | ], 754 | anonymousClassDeclaration: null 755 | }, 756 | { 757 | node: "EnumConstantDeclaration", 758 | modifiers: [], 759 | name: { 760 | node: "SimpleName", 761 | identifier: "T1" 762 | }, 763 | arguments: [ 764 | { 765 | node: "StringLiteral", 766 | escapedValue: "\"hello\\u1984\"" 767 | } 768 | ], 769 | anonymousClassDeclaration: null 770 | }, 771 | { 772 | node: "EnumConstantDeclaration", 773 | modifiers: [], 774 | name: { 775 | node: "SimpleName", 776 | identifier: "T34" 777 | }, 778 | arguments: [ 779 | { 780 | node: "PrefixExpression", 781 | operator: "-", 782 | operand: { 783 | node: "NumberLiteral", 784 | token: "0x1.8p1" 785 | } 786 | } 787 | ], 788 | anonymousClassDeclaration: null 789 | } 790 | ], 791 | bodyDeclarations: [] 792 | } 793 | ] 794 | } 795 | ); 796 | }); 797 | 798 | test("Enum Constants ws annotation ws arguments", function(assert) { 799 | var src = multiline(function(){/* 800 | enum Coin { 801 | @annotation T,PENNY(1L), NICKEL(), DIME(-42), QUARTER(0b11); 802 | } 803 | */}); 804 | assert.deepEqual( 805 | JavaParser.parse(src) 806 | , 807 | { 808 | node: "CompilationUnit", 809 | package: null, 810 | imports: [ 811 | 812 | ], 813 | types: [ 814 | { 815 | node: "EnumDeclaration", 816 | modifiers: [ 817 | 818 | ], 819 | name: { 820 | node: "SimpleName", 821 | identifier: "Coin" 822 | }, 823 | superInterfaceTypes: [ 824 | 825 | ], 826 | enumConstants: [ 827 | { 828 | node: "EnumConstantDeclaration", 829 | modifiers: [ 830 | { 831 | node: "MarkerAnnotation", 832 | typeName: { 833 | node: "SimpleName", 834 | identifier: "annotation" 835 | } 836 | } 837 | ], 838 | name: { 839 | node: "SimpleName", 840 | identifier: "T" 841 | }, 842 | arguments: [ 843 | 844 | ], 845 | anonymousClassDeclaration: null 846 | }, 847 | { 848 | node: "EnumConstantDeclaration", 849 | modifiers: [ 850 | 851 | ], 852 | name: { 853 | node: "SimpleName", 854 | identifier: "PENNY" 855 | }, 856 | arguments: [ 857 | { 858 | node: "NumberLiteral", 859 | token: "1L" 860 | } 861 | ], 862 | anonymousClassDeclaration: null 863 | }, 864 | { 865 | node: "EnumConstantDeclaration", 866 | modifiers: [ 867 | 868 | ], 869 | name: { 870 | node: "SimpleName", 871 | identifier: "NICKEL" 872 | }, 873 | arguments: [ 874 | 875 | ], 876 | anonymousClassDeclaration: null 877 | }, 878 | { 879 | node: "EnumConstantDeclaration", 880 | modifiers: [ 881 | 882 | ], 883 | name: { 884 | node: "SimpleName", 885 | identifier: "DIME" 886 | }, 887 | arguments: [ 888 | { 889 | node: "PrefixExpression", 890 | operator: "-", 891 | operand: { 892 | node: "NumberLiteral", 893 | token: "42" 894 | } 895 | } 896 | ], 897 | anonymousClassDeclaration: null 898 | }, 899 | { 900 | node: "EnumConstantDeclaration", 901 | modifiers: [ 902 | 903 | ], 904 | name: { 905 | node: "SimpleName", 906 | identifier: "QUARTER" 907 | }, 908 | arguments: [ 909 | { 910 | node: "NumberLiteral", 911 | token: "0b11" 912 | } 913 | ], 914 | anonymousClassDeclaration: null 915 | } 916 | ], 917 | bodyDeclarations: [ 918 | 919 | ] 920 | } 921 | ] 922 | } 923 | ); 924 | }); 925 | 926 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/InterfaceTests/EmptyTests.js: -------------------------------------------------------------------------------- 1 | 2 | test("empty interface", function(assert) { 3 | var src = "interface Test {}"; 4 | assert.deepEqual( 5 | JavaParser.parse(src) 6 | , 7 | { 8 | node: "CompilationUnit", 9 | package: null, 10 | imports: [ 11 | 12 | ], 13 | types: [ 14 | { 15 | node: "TypeDeclaration", 16 | modifiers: [ 17 | 18 | ], 19 | interface: true, 20 | name: { 21 | node: "SimpleName", 22 | identifier: "Test" 23 | }, 24 | typeParameters: [ 25 | 26 | ], 27 | superclassType: null, 28 | superInterfaceTypes: [ 29 | 30 | ], 31 | bodyDeclarations: [ 32 | 33 | ] 34 | } 35 | ] 36 | } 37 | ); 38 | }); 39 | 40 | test("empty interface extends single", function(assert) { 41 | var src = "interface Test extends A {}"; 42 | assert.deepEqual( 43 | JavaParser.parse(src) 44 | , 45 | { 46 | node: "CompilationUnit", 47 | package: null, 48 | imports: [ 49 | 50 | ], 51 | types: [ 52 | { 53 | node: "TypeDeclaration", 54 | modifiers: [ 55 | 56 | ], 57 | interface: true, 58 | name: { 59 | node: "SimpleName", 60 | identifier: "Test" 61 | }, 62 | typeParameters: [ 63 | 64 | ], 65 | superclassType: null, 66 | superInterfaceTypes: [ 67 | { 68 | node: "SimpleType", 69 | name: { 70 | node: "SimpleName", 71 | identifier: "A" 72 | } 73 | } 74 | ], 75 | bodyDeclarations: [ 76 | 77 | ] 78 | } 79 | ] 80 | } 81 | ); 82 | }); 83 | 84 | test("empty interface extends multiple", function(assert) { 85 | var src = "interface Test extends A, C.D {}"; 86 | assert.deepEqual( 87 | JavaParser.parse(src) 88 | , 89 | { 90 | node: "CompilationUnit", 91 | package: null, 92 | imports: [ 93 | 94 | ], 95 | types: [ 96 | { 97 | node: "TypeDeclaration", 98 | modifiers: [ 99 | 100 | ], 101 | interface: true, 102 | name: { 103 | node: "SimpleName", 104 | identifier: "Test" 105 | }, 106 | typeParameters: [ 107 | 108 | ], 109 | superclassType: null, 110 | superInterfaceTypes: [ 111 | { 112 | node: "SimpleType", 113 | name: { 114 | node: "SimpleName", 115 | identifier: "A" 116 | } 117 | }, 118 | { 119 | node: "SimpleType", 120 | name: { 121 | node: "QualifiedName", 122 | qualifier: { 123 | node: "SimpleName", 124 | identifier: "C" 125 | }, 126 | name: { 127 | node: "SimpleName", 128 | identifier: "D" 129 | } 130 | } 131 | } 132 | ], 133 | bodyDeclarations: [ 134 | 135 | ] 136 | } 137 | ] 138 | } 139 | ); 140 | }); 141 | 142 | test("empty interface ws generic extends multiple", function(assert) { 143 | var src = "interface Test extends A, C.D {}"; 144 | assert.deepEqual( 145 | JavaParser.parse(src) 146 | , 147 | { 148 | node: "CompilationUnit", 149 | package: null, 150 | imports: [ 151 | 152 | ], 153 | types: [ 154 | { 155 | node: "TypeDeclaration", 156 | modifiers: [ 157 | 158 | ], 159 | interface: true, 160 | name: { 161 | node: "SimpleName", 162 | identifier: "Test" 163 | }, 164 | typeParameters: [ 165 | { 166 | node: "TypeParameter", 167 | name: { 168 | node: "SimpleName", 169 | identifier: "T" 170 | }, 171 | typeBounds: [ 172 | 173 | ] 174 | } 175 | ], 176 | superclassType: null, 177 | superInterfaceTypes: [ 178 | { 179 | node: "SimpleType", 180 | name: { 181 | node: "SimpleName", 182 | identifier: "A" 183 | } 184 | }, 185 | { 186 | node: "ParameterizedType", 187 | type: { 188 | node: "QualifiedType", 189 | qualifier: { 190 | node: "ParameterizedType", 191 | type: { 192 | node: "SimpleType", 193 | name: { 194 | node: "SimpleName", 195 | identifier: "C" 196 | } 197 | }, 198 | typeArguments: [ 199 | { 200 | node: "WildcardType", 201 | bound: { 202 | node: "SimpleType", 203 | name: { 204 | node: "QualifiedName", 205 | qualifier: { 206 | node: "SimpleName", 207 | identifier: "A" 208 | }, 209 | name: { 210 | node: "SimpleName", 211 | identifier: "B" 212 | } 213 | } 214 | }, 215 | upperBound: true 216 | } 217 | ] 218 | }, 219 | name: { 220 | node: "SimpleName", 221 | identifier: "D" 222 | } 223 | }, 224 | typeArguments: [ 225 | { 226 | node: "SimpleType", 227 | name: { 228 | node: "SimpleName", 229 | identifier: "T" 230 | } 231 | } 232 | ] 233 | } 234 | ], 235 | bodyDeclarations: [ 236 | 237 | ] 238 | } 239 | ] 240 | } 241 | ); 242 | }); 243 | 244 | test("empty interface ws modifiers ws annotation", function(assert) { 245 | var src = multiline(function(){/* 246 | @Author(@Name(first = "Joe", last = "Hacker")) 247 | protected interface Test {} 248 | */}); 249 | assert.deepEqual( 250 | JavaParser.parse(src) 251 | , 252 | { 253 | node: "CompilationUnit", 254 | package: null, 255 | imports: [ 256 | 257 | ], 258 | types: [ 259 | { 260 | node: "TypeDeclaration", 261 | modifiers: [ 262 | { 263 | node: "SingleMemberAnnotation", 264 | typeName: { 265 | node: "SimpleName", 266 | identifier: "Author" 267 | }, 268 | value: { 269 | node: "NormalAnnotation", 270 | typeName: { 271 | node: "SimpleName", 272 | identifier: "Name" 273 | }, 274 | values: [ 275 | { 276 | node: "MemberValuePair", 277 | name: { 278 | node: "SimpleName", 279 | identifier: "first" 280 | }, 281 | value: { 282 | node: "StringLiteral", 283 | escapedValue: "\"Joe\"" 284 | } 285 | }, 286 | { 287 | node: "MemberValuePair", 288 | name: { 289 | node: "SimpleName", 290 | identifier: "last" 291 | }, 292 | value: { 293 | node: "StringLiteral", 294 | escapedValue: "\"Hacker\"" 295 | } 296 | } 297 | ] 298 | } 299 | }, 300 | { 301 | node: "Modifier", 302 | keyword: "protected" 303 | } 304 | ], 305 | interface: true, 306 | name: { 307 | node: "SimpleName", 308 | identifier: "Test" 309 | }, 310 | typeParameters: [ 311 | 312 | ], 313 | superclassType: null, 314 | superInterfaceTypes: [ 315 | 316 | ], 317 | bodyDeclarations: [ 318 | 319 | ] 320 | } 321 | ] 322 | } 323 | ); 324 | }); 325 | 326 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/NoTypesTests.js: -------------------------------------------------------------------------------- 1 | 2 | test("package without types", function(assert) { 3 | var src = 'package a;'; 4 | assert.deepEqual( 5 | JavaParser.parse(src) 6 | , 7 | { 8 | node: "CompilationUnit", 9 | package: { 10 | node: "PackageDeclaration", 11 | annotations: [ 12 | 13 | ], 14 | name: { 15 | node: "SimpleName", 16 | identifier: "a" 17 | } 18 | }, 19 | imports: [ 20 | 21 | ], 22 | types: [ 23 | 24 | ] 25 | } 26 | ); 27 | }); 28 | 29 | test("package without types with dots", function(assert) { 30 | var src = 'package a.b.c;'; 31 | assert.deepEqual( 32 | JavaParser.parse(src) 33 | , 34 | { 35 | node: "CompilationUnit", 36 | package: { 37 | node: "PackageDeclaration", 38 | annotations: [ 39 | 40 | ], 41 | name: { 42 | node: "QualifiedName", 43 | qualifier: { 44 | node: "QualifiedName", 45 | qualifier: { 46 | node: "SimpleName", 47 | identifier: "a" 48 | }, 49 | name: { 50 | node: "SimpleName", 51 | identifier: "b" 52 | } 53 | }, 54 | name: { 55 | node: "SimpleName", 56 | identifier: "c" 57 | } 58 | } 59 | }, 60 | imports: [ 61 | 62 | ], 63 | types: [ 64 | 65 | ] 66 | } 67 | ); 68 | }); 69 | 70 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/PackageAnnotationsTests.js: -------------------------------------------------------------------------------- 1 | 2 | test("package ws Marker Annotations", function(assert) { 3 | var src = multiline(function(){/* 4 | @hello 5 | package hello.world; 6 | */}); 7 | assert.deepEqual( 8 | JavaParser.parse(src) 9 | , 10 | { 11 | node: "CompilationUnit", 12 | package: { 13 | node: "PackageDeclaration", 14 | annotations: [ 15 | { 16 | node: "MarkerAnnotation", 17 | typeName: { 18 | node: "SimpleName", 19 | identifier: "hello" 20 | } 21 | } 22 | ], 23 | name: { 24 | node: "QualifiedName", 25 | qualifier: { 26 | node: "SimpleName", 27 | identifier: "hello" 28 | }, 29 | name: { 30 | node: "SimpleName", 31 | identifier: "world" 32 | } 33 | } 34 | }, 35 | imports: [ 36 | 37 | ], 38 | types: [ 39 | 40 | ] 41 | } 42 | ); 43 | }); 44 | 45 | test("package ws Normal Empty Annotations", function(assert) { 46 | var src = multiline(function(){/* 47 | @RequestForEnhancement() 48 | package hello.world; 49 | */}); 50 | assert.deepEqual( 51 | JavaParser.parse(src) 52 | , 53 | { 54 | node: "CompilationUnit", 55 | package: { 56 | node: "PackageDeclaration", 57 | annotations: [ 58 | { 59 | node: "NormalAnnotation", 60 | typeName: { 61 | node: "SimpleName", 62 | identifier: "RequestForEnhancement" 63 | }, 64 | values: [ 65 | 66 | ] 67 | } 68 | ], 69 | name: { 70 | node: "QualifiedName", 71 | qualifier: { 72 | node: "SimpleName", 73 | identifier: "hello" 74 | }, 75 | name: { 76 | node: "SimpleName", 77 | identifier: "world" 78 | } 79 | } 80 | }, 81 | imports: [ 82 | 83 | ], 84 | types: [ 85 | 86 | ] 87 | } 88 | ); 89 | }); 90 | 91 | test("package ws Normal Annotations", function(assert) { 92 | var src = multiline(function(){/* 93 | @RequestForEnhancement( 94 | id = 2868724, 95 | synopsis = "Provide time-travel functionality", 96 | engineer = "Mr. Peabody", 97 | date = "4/1/2004" 98 | ) 99 | package hello.world; 100 | */}); 101 | assert.deepEqual( 102 | JavaParser.parse(src) 103 | , 104 | { 105 | node: "CompilationUnit", 106 | package: { 107 | node: "PackageDeclaration", 108 | annotations: [ 109 | { 110 | node: "NormalAnnotation", 111 | typeName: { 112 | node: "SimpleName", 113 | identifier: "RequestForEnhancement" 114 | }, 115 | values: [ 116 | { 117 | node: "MemberValuePair", 118 | name: { 119 | node: "SimpleName", 120 | identifier: "id" 121 | }, 122 | value: { 123 | node: "NumberLiteral", 124 | token: "2868724" 125 | } 126 | }, 127 | { 128 | node: "MemberValuePair", 129 | name: { 130 | node: "SimpleName", 131 | identifier: "synopsis" 132 | }, 133 | value: { 134 | node: "StringLiteral", 135 | escapedValue: "\"Provide time-travel functionality\"" 136 | } 137 | }, 138 | { 139 | node: "MemberValuePair", 140 | name: { 141 | node: "SimpleName", 142 | identifier: "engineer" 143 | }, 144 | value: { 145 | node: "StringLiteral", 146 | escapedValue: "\"Mr. Peabody\"" 147 | } 148 | }, 149 | { 150 | node: "MemberValuePair", 151 | name: { 152 | node: "SimpleName", 153 | identifier: "date" 154 | }, 155 | value: { 156 | node: "StringLiteral", 157 | escapedValue: "\"4/1/2004\"" 158 | } 159 | } 160 | ] 161 | } 162 | ], 163 | name: { 164 | node: "QualifiedName", 165 | qualifier: { 166 | node: "SimpleName", 167 | identifier: "hello" 168 | }, 169 | name: { 170 | node: "SimpleName", 171 | identifier: "world" 172 | } 173 | } 174 | }, 175 | imports: [ 176 | 177 | ], 178 | types: [ 179 | 180 | ] 181 | } 182 | ); 183 | }); 184 | 185 | test("package ws Single-Element Annotations", function(assert) { 186 | var src = multiline(function(){/* 187 | @Copyright("2002 Yoyodyne Propulsion Systems, Inc.") 188 | package hello; 189 | */}); 190 | assert.deepEqual( 191 | JavaParser.parse(src) 192 | , 193 | { 194 | node: "CompilationUnit", 195 | package: { 196 | node: "PackageDeclaration", 197 | annotations: [ 198 | { 199 | node: "SingleMemberAnnotation", 200 | typeName: { 201 | node: "SimpleName", 202 | identifier: "Copyright" 203 | }, 204 | value: { 205 | node: "StringLiteral", 206 | escapedValue: "\"2002 Yoyodyne Propulsion Systems, Inc.\"" 207 | } 208 | } 209 | ], 210 | name: { 211 | node: "SimpleName", 212 | identifier: "hello" 213 | } 214 | }, 215 | imports: [ 216 | 217 | ], 218 | types: [ 219 | 220 | ] 221 | } 222 | ); 223 | }); 224 | 225 | test("array-valued single-element annotation", function(assert) { 226 | var src = multiline(function(){/* 227 | @Endorsers({"Children", "Unscrupulous dentists"}) 228 | package hello; 229 | */}); 230 | assert.deepEqual( 231 | JavaParser.parse(src) 232 | , 233 | { 234 | node: "CompilationUnit", 235 | package: { 236 | node: "PackageDeclaration", 237 | annotations: [ 238 | { 239 | node: "SingleMemberAnnotation", 240 | typeName: { 241 | node: "SimpleName", 242 | identifier: "Endorsers" 243 | }, 244 | value: { 245 | node: "ArrayInitializer", 246 | expressions: [ 247 | { 248 | node: "StringLiteral", 249 | escapedValue: "\"Children\"" 250 | }, 251 | { 252 | node: "StringLiteral", 253 | escapedValue: "\"Unscrupulous dentists\"" 254 | } 255 | ] 256 | } 257 | } 258 | ], 259 | name: { 260 | node: "SimpleName", 261 | identifier: "hello" 262 | } 263 | }, 264 | imports: [ 265 | 266 | ], 267 | types: [ 268 | 269 | ] 270 | } 271 | ); 272 | }); 273 | 274 | test("array-valued empty annotation", function(assert) { 275 | var src = multiline(function(){/* 276 | @Endorsers({}) 277 | package hello; 278 | */}); 279 | assert.deepEqual( 280 | JavaParser.parse(src) 281 | , 282 | { 283 | node: "CompilationUnit", 284 | package: { 285 | node: "PackageDeclaration", 286 | annotations: [ 287 | { 288 | node: "SingleMemberAnnotation", 289 | typeName: { 290 | node: "SimpleName", 291 | identifier: "Endorsers" 292 | }, 293 | value: { 294 | node: "ArrayInitializer", 295 | expressions: [ 296 | 297 | ] 298 | } 299 | } 300 | ], 301 | name: { 302 | node: "SimpleName", 303 | identifier: "hello" 304 | } 305 | }, 306 | imports: [ 307 | 308 | ], 309 | types: [ 310 | 311 | ] 312 | } 313 | ); 314 | }); 315 | 316 | test("single-element array-valued single-element annotation", function(assert) { 317 | var src = multiline(function(){/* 318 | @Endorsers("Epicurus") 319 | package hello; 320 | */}); 321 | assert.deepEqual( 322 | JavaParser.parse(src) 323 | , 324 | { 325 | node: "CompilationUnit", 326 | package: { 327 | node: "PackageDeclaration", 328 | annotations: [ 329 | { 330 | node: "SingleMemberAnnotation", 331 | typeName: { 332 | node: "SimpleName", 333 | identifier: "Endorsers" 334 | }, 335 | value: { 336 | node: "StringLiteral", 337 | escapedValue: "\"Epicurus\"" 338 | } 339 | } 340 | ], 341 | name: { 342 | node: "SimpleName", 343 | identifier: "hello" 344 | } 345 | }, 346 | imports: [ 347 | 348 | ], 349 | types: [ 350 | 351 | ] 352 | } 353 | ); 354 | }); 355 | 356 | test("single-element annotation that contains a normal annotation", function(assert) { 357 | var src = multiline(function(){/* 358 | @Author(@Name(first = "Joe", last = "Hacker")) 359 | package hello; 360 | */}); 361 | assert.deepEqual( 362 | JavaParser.parse(src) 363 | , 364 | { 365 | node: "CompilationUnit", 366 | package: { 367 | node: "PackageDeclaration", 368 | annotations: [ 369 | { 370 | node: "SingleMemberAnnotation", 371 | typeName: { 372 | node: "SimpleName", 373 | identifier: "Author" 374 | }, 375 | value: { 376 | node: "NormalAnnotation", 377 | typeName: { 378 | node: "SimpleName", 379 | identifier: "Name" 380 | }, 381 | values: [ 382 | { 383 | node: "MemberValuePair", 384 | name: { 385 | node: "SimpleName", 386 | identifier: "first" 387 | }, 388 | value: { 389 | node: "StringLiteral", 390 | escapedValue: "\"Joe\"" 391 | } 392 | }, 393 | { 394 | node: "MemberValuePair", 395 | name: { 396 | node: "SimpleName", 397 | identifier: "last" 398 | }, 399 | value: { 400 | node: "StringLiteral", 401 | escapedValue: "\"Hacker\"" 402 | } 403 | } 404 | ] 405 | } 406 | } 407 | ], 408 | name: { 409 | node: "SimpleName", 410 | identifier: "hello" 411 | } 412 | }, 413 | imports: [ 414 | 415 | ], 416 | types: [ 417 | 418 | ] 419 | } 420 | ); 421 | }); 422 | 423 | -------------------------------------------------------------------------------- /test/CompilationUnitTests/PackageImportsTests.js: -------------------------------------------------------------------------------- 1 | 2 | test("package ws import", function(assert) { 3 | var src = multiline(function(){/* 4 | package hello.world; 5 | 6 | import static hello.*; 7 | import org.hello.world; 8 | */}); 9 | assert.deepEqual( 10 | JavaParser.parse(src) 11 | , 12 | { 13 | node: "CompilationUnit", 14 | package: { 15 | node: "PackageDeclaration", 16 | annotations: [ 17 | 18 | ], 19 | name: { 20 | node: "QualifiedName", 21 | qualifier: { 22 | node: "SimpleName", 23 | identifier: "hello" 24 | }, 25 | name: { 26 | node: "SimpleName", 27 | identifier: "world" 28 | } 29 | } 30 | }, 31 | imports: [ 32 | { 33 | node: "ImportDeclaration", 34 | static: true, 35 | name: { 36 | node: "SimpleName", 37 | identifier: "hello" 38 | }, 39 | onDemand: true 40 | }, 41 | { 42 | node: "ImportDeclaration", 43 | static: false, 44 | name: { 45 | node: "QualifiedName", 46 | qualifier: { 47 | node: "QualifiedName", 48 | qualifier: { 49 | node: "SimpleName", 50 | identifier: "org" 51 | }, 52 | name: { 53 | node: "SimpleName", 54 | identifier: "hello" 55 | } 56 | }, 57 | name: { 58 | node: "SimpleName", 59 | identifier: "world" 60 | } 61 | }, 62 | onDemand: false 63 | } 64 | ], 65 | types: [ 66 | 67 | ] 68 | } 69 | ); 70 | }); 71 | 72 | test("package ws import ws spaces", function(assert) { 73 | var src = multiline(function(){/* 74 | package hello . world; 75 | 76 | import static hello. *; 77 | import org.hello . world; 78 | */}); 79 | assert.deepEqual( 80 | JavaParser.parse(src) 81 | , 82 | { 83 | node: "CompilationUnit", 84 | package: { 85 | node: "PackageDeclaration", 86 | annotations: [ 87 | 88 | ], 89 | name: { 90 | node: "QualifiedName", 91 | qualifier: { 92 | node: "SimpleName", 93 | identifier: "hello" 94 | }, 95 | name: { 96 | node: "SimpleName", 97 | identifier: "world" 98 | } 99 | } 100 | }, 101 | imports: [ 102 | { 103 | node: "ImportDeclaration", 104 | static: true, 105 | name: { 106 | node: "SimpleName", 107 | identifier: "hello" 108 | }, 109 | onDemand: true 110 | }, 111 | { 112 | node: "ImportDeclaration", 113 | static: false, 114 | name: { 115 | node: "QualifiedName", 116 | qualifier: { 117 | node: "QualifiedName", 118 | qualifier: { 119 | node: "SimpleName", 120 | identifier: "org" 121 | }, 122 | name: { 123 | node: "SimpleName", 124 | identifier: "hello" 125 | } 126 | }, 127 | name: { 128 | node: "SimpleName", 129 | identifier: "world" 130 | } 131 | }, 132 | onDemand: false 133 | } 134 | ], 135 | types: [ 136 | 137 | ] 138 | } 139 | ); 140 | }); 141 | 142 | -------------------------------------------------------------------------------- /test/coverage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Java Parser QUnit Tests 6 | 7 | 8 | 9 | 10 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 |
52 | 53 | 54 | -------------------------------------------------------------------------------- /test/jls7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/test/jls7.pdf -------------------------------------------------------------------------------- /test/qunit/blanket/lcov_reporter.js: -------------------------------------------------------------------------------- 1 | //lcov_reporter 2 | (function (){ 3 | //takes the option: toHTML {boolean} 4 | 5 | var body = document.body; 6 | 7 | var appendHtml = function ( filename,data,toHTML) { 8 | 9 | var str=""; 10 | str += 'SF:' + filename + '\n'; 11 | 12 | data.source.forEach(function(line, num) { 13 | // increase the line number, as JS arrays are zero-based 14 | num++; 15 | 16 | if (data[num] !== undefined) { 17 | str += 'DA:' + num + ',' + data[num] + '\n'; 18 | } 19 | }); 20 | 21 | str += 'end_of_record\n'; 22 | if (toHTML){ 23 | var div = document.createElement('div'); 24 | div.className = "blanket_lcov_reporter"; 25 | div.innerText = str; 26 | body.appendChild(div); 27 | }else{ 28 | window._$blanket_LCOV = (window._$blanket_LCOV || '') + str; 29 | } 30 | }; 31 | 32 | blanket.customReporter=function(coverageData,options){ 33 | var toHTML=true; 34 | if (typeof options !== 'undefined' && typeof options.toHTML !== 'undefined'){ 35 | toHTML = options.toHTML; 36 | } 37 | for (var filename in coverageData.files) { 38 | var data = coverageData.files[filename]; 39 | // jssnowball patch 40 | if (typeof options !== 'undefined' && typeof options.strip_file_name !== 'undefined'){ 41 | if (options.strip_file_name) { 42 | filename = filename.replace(/^(file|ftp|https?):\/\//, ''); 43 | } 44 | } 45 | // end 46 | appendHtml(filename,data,toHTML); 47 | } 48 | }; 49 | })(); 50 | -------------------------------------------------------------------------------- /test/qunit/multiline/browser.js: -------------------------------------------------------------------------------- 1 | !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.multiline=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0 ? str.replace(re, '') : str; 17 | }; 18 | 19 | },{}],2:[function(require,module,exports){ 20 | 'use strict'; 21 | var stripIndent = require('strip-indent'); 22 | 23 | // start matching after: comment start block => ! or @preserve => optional whitespace => newline 24 | // stop matching before: last newline => optional whitespace => comment end block 25 | var reCommentContents = /\/\*!?(?:\@preserve)?[ \t]*(?:\r\n|\n)([\s\S]*?)(?:\r\n|\n)[ \t]*\*\//; 26 | 27 | var multiline = module.exports = function (fn) { 28 | if (typeof fn !== 'function') { 29 | throw new TypeError('Expected a function'); 30 | } 31 | 32 | var match = reCommentContents.exec(fn.toString()); 33 | 34 | if (!match) { 35 | throw new TypeError('Multiline comment missing.'); 36 | } 37 | 38 | return match[1]; 39 | }; 40 | 41 | multiline.stripIndent = function (fn) { 42 | return stripIndent(multiline(fn)); 43 | }; 44 | 45 | },{"strip-indent":1}]},{},[2])(2) 46 | }); -------------------------------------------------------------------------------- /test/qunit/multiline/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/qunit/qunit.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * QUnit 1.20.0 3 | * http://qunitjs.com/ 4 | * 5 | * Copyright jQuery Foundation and other contributors 6 | * Released under the MIT license 7 | * http://jquery.org/license 8 | * 9 | * Date: 2015-10-27T17:53Z 10 | */ 11 | 12 | /** Font Family and Sizes */ 13 | 14 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult { 15 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; 16 | } 17 | 18 | #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 19 | #qunit-tests { font-size: smaller; } 20 | 21 | 22 | /** Resets */ 23 | 24 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { 25 | margin: 0; 26 | padding: 0; 27 | } 28 | 29 | 30 | /** Header */ 31 | 32 | #qunit-header { 33 | padding: 0.5em 0 0.5em 1em; 34 | 35 | color: #8699A4; 36 | background-color: #0D3349; 37 | 38 | font-size: 1.5em; 39 | line-height: 1em; 40 | font-weight: 400; 41 | 42 | border-radius: 5px 5px 0 0; 43 | } 44 | 45 | #qunit-header a { 46 | text-decoration: none; 47 | color: #C2CCD1; 48 | } 49 | 50 | #qunit-header a:hover, 51 | #qunit-header a:focus { 52 | color: #FFF; 53 | } 54 | 55 | #qunit-testrunner-toolbar label { 56 | display: inline-block; 57 | padding: 0 0.5em 0 0.1em; 58 | } 59 | 60 | #qunit-banner { 61 | height: 5px; 62 | } 63 | 64 | #qunit-testrunner-toolbar { 65 | padding: 0.5em 1em 0.5em 1em; 66 | color: #5E740B; 67 | background-color: #EEE; 68 | overflow: hidden; 69 | } 70 | 71 | #qunit-filteredTest { 72 | padding: 0.5em 1em 0.5em 1em; 73 | background-color: #F4FF77; 74 | color: #366097; 75 | } 76 | 77 | #qunit-userAgent { 78 | padding: 0.5em 1em 0.5em 1em; 79 | background-color: #2B81AF; 80 | color: #FFF; 81 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; 82 | } 83 | 84 | #qunit-modulefilter-container { 85 | float: right; 86 | padding: 0.2em; 87 | } 88 | 89 | .qunit-url-config { 90 | display: inline-block; 91 | padding: 0.1em; 92 | } 93 | 94 | .qunit-filter { 95 | display: block; 96 | float: right; 97 | margin-left: 1em; 98 | } 99 | 100 | /** Tests: Pass/Fail */ 101 | 102 | #qunit-tests { 103 | list-style-position: inside; 104 | } 105 | 106 | #qunit-tests li { 107 | padding: 0.4em 1em 0.4em 1em; 108 | border-bottom: 1px solid #FFF; 109 | list-style-position: inside; 110 | } 111 | 112 | #qunit-tests > li { 113 | display: none; 114 | } 115 | 116 | #qunit-tests li.running, 117 | #qunit-tests li.pass, 118 | #qunit-tests li.fail, 119 | #qunit-tests li.skipped { 120 | display: list-item; 121 | } 122 | 123 | #qunit-tests.hidepass li.running, 124 | #qunit-tests.hidepass li.pass { 125 | visibility: hidden; 126 | position: absolute; 127 | width: 0; 128 | height: 0; 129 | padding: 0; 130 | border: 0; 131 | margin: 0; 132 | } 133 | 134 | #qunit-tests li strong { 135 | cursor: pointer; 136 | } 137 | 138 | #qunit-tests li.skipped strong { 139 | cursor: default; 140 | } 141 | 142 | #qunit-tests li a { 143 | padding: 0.5em; 144 | color: #C2CCD1; 145 | text-decoration: none; 146 | } 147 | 148 | #qunit-tests li p a { 149 | padding: 0.25em; 150 | color: #6B6464; 151 | } 152 | #qunit-tests li a:hover, 153 | #qunit-tests li a:focus { 154 | color: #000; 155 | } 156 | 157 | #qunit-tests li .runtime { 158 | float: right; 159 | font-size: smaller; 160 | } 161 | 162 | .qunit-assert-list { 163 | margin-top: 0.5em; 164 | padding: 0.5em; 165 | 166 | background-color: #FFF; 167 | 168 | border-radius: 5px; 169 | } 170 | 171 | .qunit-source { 172 | margin: 0.6em 0 0.3em; 173 | } 174 | 175 | .qunit-collapsed { 176 | display: none; 177 | } 178 | 179 | #qunit-tests table { 180 | border-collapse: collapse; 181 | margin-top: 0.2em; 182 | } 183 | 184 | #qunit-tests th { 185 | text-align: right; 186 | vertical-align: top; 187 | padding: 0 0.5em 0 0; 188 | } 189 | 190 | #qunit-tests td { 191 | vertical-align: top; 192 | } 193 | 194 | #qunit-tests pre { 195 | margin: 0; 196 | white-space: pre-wrap; 197 | word-wrap: break-word; 198 | } 199 | 200 | #qunit-tests del { 201 | background-color: #E0F2BE; 202 | color: #374E0C; 203 | text-decoration: none; 204 | } 205 | 206 | #qunit-tests ins { 207 | background-color: #FFCACA; 208 | color: #500; 209 | text-decoration: none; 210 | } 211 | 212 | /*** Test Counts */ 213 | 214 | #qunit-tests b.counts { color: #000; } 215 | #qunit-tests b.passed { color: #5E740B; } 216 | #qunit-tests b.failed { color: #710909; } 217 | 218 | #qunit-tests li li { 219 | padding: 5px; 220 | background-color: #FFF; 221 | border-bottom: none; 222 | list-style-position: inside; 223 | } 224 | 225 | /*** Passing Styles */ 226 | 227 | #qunit-tests li li.pass { 228 | color: #3C510C; 229 | background-color: #FFF; 230 | border-left: 10px solid #C6E746; 231 | } 232 | 233 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } 234 | #qunit-tests .pass .test-name { color: #366097; } 235 | 236 | #qunit-tests .pass .test-actual, 237 | #qunit-tests .pass .test-expected { color: #999; } 238 | 239 | #qunit-banner.qunit-pass { background-color: #C6E746; } 240 | 241 | /*** Failing Styles */ 242 | 243 | #qunit-tests li li.fail { 244 | color: #710909; 245 | background-color: #FFF; 246 | border-left: 10px solid #EE5757; 247 | white-space: pre; 248 | } 249 | 250 | #qunit-tests > li:last-child { 251 | border-radius: 0 0 5px 5px; 252 | } 253 | 254 | #qunit-tests .fail { color: #000; background-color: #EE5757; } 255 | #qunit-tests .fail .test-name, 256 | #qunit-tests .fail .module-name { color: #000; } 257 | 258 | #qunit-tests .fail .test-actual { color: #EE5757; } 259 | #qunit-tests .fail .test-expected { color: #008000; } 260 | 261 | #qunit-banner.qunit-fail { background-color: #EE5757; } 262 | 263 | /*** Skipped tests */ 264 | 265 | #qunit-tests .skipped { 266 | background-color: #EBECE9; 267 | } 268 | 269 | #qunit-tests .qunit-skipped-label { 270 | background-color: #F4FF77; 271 | display: inline-block; 272 | font-style: normal; 273 | color: #366097; 274 | line-height: 1.8em; 275 | padding: 0 0.5em; 276 | margin: -0.4em 0.4em -0.4em 0; 277 | } 278 | 279 | /** Result */ 280 | 281 | #qunit-testresult { 282 | padding: 0.5em 1em 0.5em 1em; 283 | 284 | color: #2B81AF; 285 | background-color: #D2E0E6; 286 | 287 | border-bottom: 1px solid #FFF; 288 | } 289 | #qunit-testresult .module-name { 290 | font-weight: 700; 291 | } 292 | 293 | /** Fixture */ 294 | 295 | #qunit-fixture { 296 | position: absolute; 297 | top: -10000px; 298 | left: -10000px; 299 | width: 1000px; 300 | height: 1000px; 301 | } 302 | -------------------------------------------------------------------------------- /tools/EclipseAST/.gitignore: -------------------------------------------------------------------------------- 1 | *.class -------------------------------------------------------------------------------- /tools/EclipseAST/ASTDumper.java: -------------------------------------------------------------------------------- 1 | 2 | //=========================================================================== 3 | // 4 | // This program use Eclipse JDT to parse java source files 5 | // and dumps resulting AST in JSON representation. 6 | // 7 | //--------------------------------------------------------------------------- 8 | // 9 | // Copyright (C) 2015 10 | // by Oleg Mazko(o.mazko@mail.ru). 11 | // 12 | // The author gives unlimited permission to copy and distribute 13 | // this file, with or without modifications, as long as this notice 14 | // is preserved, and any changes are properly documented. 15 | // 16 | 17 | import java.util.ArrayList; 18 | import java.util.Iterator; 19 | import java.util.List; 20 | 21 | import org.eclipse.jdt.core.dom.ASTNode; 22 | import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; 23 | import org.eclipse.jdt.core.dom.ChildPropertyDescriptor; 24 | import org.eclipse.jdt.core.dom.SimplePropertyDescriptor; 25 | 26 | /** 27 | * Dumps the AST to a supplied "printer". 28 | */ 29 | public class ASTDumper { 30 | 31 | /** 32 | * The printer to send events to. 33 | */ 34 | private final IASTPrinter printer; 35 | 36 | /** 37 | * By default comments detached from AST. This feature helps to dump 38 | * comments too. 39 | */ 40 | private final ICommentsExtractor comments; 41 | 42 | /** 43 | * Constructs an AST dumper with a {@link ASTPrinter} and 44 | * {@link ICommentsExtractor} specified. 45 | * 46 | * @param printer 47 | * the {@link ASTPrinter} to send events to. 48 | * 49 | * @param comments 50 | * the {@link ICommentsExtractor} to extract comments from 51 | * ASTNode. 52 | */ 53 | public ASTDumper(final IASTPrinter printer, final ICommentsExtractor comments) { 54 | this.printer = printer; 55 | this.comments = comments; 56 | } 57 | 58 | /** 59 | * Constructs an AST dumper with a {@link ICommentsExtractor} specified. 60 | * 61 | * @param comments 62 | * the {@link ICommentsExtractor} to extract comments from 63 | * ASTNode. 64 | */ 65 | public ASTDumper(final ICommentsExtractor comments) { 66 | this(new JSONStyleASTPrinter(System.out), comments); 67 | } 68 | 69 | /** 70 | * Default constructor which outputs JSON-style AST trees to stdout. 71 | */ 72 | public ASTDumper() { 73 | this(null); 74 | } 75 | 76 | /** 77 | * Dumps a root node and all it's child nodes as a tree. 78 | * 79 | * @param rootNode 80 | * the node to start at. 81 | */ 82 | public void dump(final ASTNode rootNode) { 83 | printer.startPrint(); 84 | walk(rootNode); 85 | printer.endPrint(); 86 | } 87 | 88 | /** 89 | * Returns the output of the dumper as a string. 90 | */ 91 | @Override 92 | public String toString() { 93 | return printer.toString(); 94 | } 95 | 96 | /** 97 | * Walks the tree of objects from the specified node, sending events to the 98 | * specified printer. 99 | * 100 | * @param node 101 | * the root node. 102 | */ 103 | 104 | private void walk(final ASTNode node) { 105 | walk(node, false); 106 | } 107 | 108 | /** 109 | * Walks through list of comments. 110 | * 111 | * @param comments 112 | * list. 113 | * @param leading 114 | * true if leading, false for trailing. 115 | */ 116 | 117 | private void dumpComments(final ICommentsExtractor.CommentItem[] comments, final boolean leading) { 118 | if (comments != null && comments.length > 0) { 119 | 120 | final String id = leading ? "leadingComments" : "trailingComments"; 121 | printer.startElement(id, true); 122 | 123 | for (ICommentsExtractor.CommentItem comment : comments) { 124 | final String commentId = comment.node.isLineComment() ? "LineComment" 125 | : comment.node.isDocComment() ? "DocComment" : "BlockComment"; 126 | printer.startType(commentId, true); 127 | printer.literal("value", comment.value); 128 | printer.endType(commentId, true); 129 | } 130 | 131 | printer.endElement(id, true); 132 | } 133 | } 134 | 135 | /** 136 | * Walks the tree of objects from the specified node, sending events to the 137 | * specified printer. 138 | * 139 | * @param node 140 | * the root node. 141 | * @param parentIsList 142 | * indicates whether the parent node is a list or not. 143 | */ 144 | private void walk(final ASTNode node, final boolean parentIsList) { 145 | printer.startType(node.getClass().getSimpleName(), parentIsList); 146 | final List properties = node.structuralPropertiesForType(); 147 | 148 | if (comments != null) { 149 | dumpComments(comments.leadingComments(node), true); 150 | dumpComments(comments.trailingComments(node), false); 151 | } 152 | for (Iterator iterator = properties.iterator(); iterator.hasNext();) { 153 | final Object desciptor = iterator.next(); 154 | 155 | if (desciptor instanceof SimplePropertyDescriptor) { 156 | SimplePropertyDescriptor simple = (SimplePropertyDescriptor) desciptor; 157 | Object value = node.getStructuralProperty(simple); 158 | printer.literal(simple.getId(), value); 159 | } else if (desciptor instanceof ChildPropertyDescriptor) { 160 | ChildPropertyDescriptor child = (ChildPropertyDescriptor) desciptor; 161 | ASTNode childNode = (ASTNode) node.getStructuralProperty(child); 162 | if (childNode != null) { 163 | printer.startElement(child.getId(), false); 164 | walk(childNode); 165 | printer.endElement(child.getId(), false); 166 | } else { 167 | printer.literal(child.getId(), null); 168 | } 169 | } else { 170 | ChildListPropertyDescriptor list = (ChildListPropertyDescriptor) desciptor; 171 | List value = new ArrayList<>((List) node.getStructuralProperty(list)); 172 | if (value.size() > 0) { 173 | printer.startElement(list.getId(), true); 174 | walk(value); 175 | printer.endElement(list.getId(), true); 176 | } else { 177 | printer.literal(list.getId(), value); 178 | } 179 | } 180 | } 181 | 182 | printer.endType(node.getClass().getSimpleName(), parentIsList); 183 | } 184 | 185 | /** 186 | * Walks through list of nodes. 187 | * 188 | * @param nodes 189 | * list. 190 | */ 191 | 192 | private void walk(final List nodes) { 193 | for (Iterator iterator = nodes.iterator(); iterator.hasNext();) { 194 | ASTNode node = (ASTNode) iterator.next(); 195 | walk(node, true); 196 | } 197 | } 198 | } -------------------------------------------------------------------------------- /tools/EclipseAST/App.java: -------------------------------------------------------------------------------- 1 | 2 | //=========================================================================== 3 | // 4 | // This program use Eclipse JDT to parse java source files 5 | // and dumps resulting AST in JSON representation. 6 | // 7 | //--------------------------------------------------------------------------- 8 | // 9 | // Copyright (C) 2015 10 | // by Oleg Mazko(o.mazko@mail.ru). 11 | // 12 | // The author gives unlimited permission to copy and distribute 13 | // this file, with or without modifications, as long as this notice 14 | // is preserved, and any changes are properly documented. 15 | // 16 | 17 | import java.io.IOException; 18 | import java.nio.charset.Charset; 19 | import java.nio.charset.StandardCharsets; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.util.ArrayList; 23 | import java.util.Collections; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | import org.apache.commons.cli.CommandLine; 28 | import org.apache.commons.cli.DefaultParser; 29 | import org.apache.commons.cli.HelpFormatter; 30 | import org.apache.commons.cli.Options; 31 | import org.eclipse.jdt.core.JavaCore; 32 | import org.eclipse.jdt.core.compiler.IProblem; 33 | import org.eclipse.jdt.core.dom.AST; 34 | import org.eclipse.jdt.core.dom.ASTParser; 35 | import org.eclipse.jdt.core.dom.ASTVisitor; 36 | import org.eclipse.jdt.core.dom.Comment; 37 | import org.eclipse.jdt.core.dom.CompilationUnit; 38 | import org.eclipse.jdt.core.dom.Expression; 39 | import org.eclipse.jdt.core.dom.InfixExpression; 40 | 41 | public class App { 42 | static String readFile(final String path, final Charset encoding) throws IOException { 43 | final byte[] encoded = Files.readAllBytes(Paths.get(path)); 44 | return new String(encoded, encoding); 45 | } 46 | 47 | public static void main(final String[] args) throws Exception { 48 | final Options options = new Options().addOption("c", "attach comments").addOption("h", "print this message"); 49 | final CommandLine cmd = new DefaultParser().parse(options, args); 50 | if (args.length == 0 || cmd.hasOption("h")) { 51 | new HelpFormatter().printHelp(App.class.getSimpleName() + "[OPTION]... [FILE]...", options); 52 | } else { 53 | for (final String file : cmd.getArgs()) { 54 | ast(file, cmd); 55 | } 56 | } 57 | } 58 | 59 | private static void ast(final String file, final CommandLine cmd) throws IOException { 60 | @SuppressWarnings("deprecation") 61 | final ASTParser parser = ASTParser.newParser(AST.JLS4); // JLS4 (aka 62 | // JLS7) 63 | final String src = readFile(file, StandardCharsets.UTF_8); 64 | parser.setSource(src.toCharArray()); 65 | parser.setKind(ASTParser.K_COMPILATION_UNIT); 66 | final Map options = JavaCore.getOptions(); 67 | JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options); 68 | parser.setCompilerOptions(options); 69 | final CompilationUnit cu = (CompilationUnit) parser.createAST(null); 70 | for (IProblem problem : cu.getProblems()) { 71 | System.err.println(problem); 72 | } 73 | cu.accept(new ASTVisitor() { 74 | // Eclipse AST optimize deeply nested expressions of the form L op R 75 | // op R2 76 | // op R3... where the same operator appears between 77 | // all the operands. This 78 | // function disable such optimization back to tree view. 79 | @Override 80 | public boolean visit(final InfixExpression node) { 81 | if (node.hasExtendedOperands()) { 82 | @SuppressWarnings("unchecked") 83 | List operands = new ArrayList<>(node.extendedOperands()); 84 | Collections.reverse(operands); 85 | operands.add(node.getRightOperand()); 86 | final Expression firstOperand = operands.remove(0); 87 | firstOperand.delete(); // remove node from its parent 88 | node.setRightOperand(firstOperand); 89 | InfixExpression last = node; 90 | for (final Expression expr : operands) { 91 | InfixExpression infixExpression = node.getAST().newInfixExpression(); 92 | infixExpression.setOperator(node.getOperator()); 93 | expr.delete(); 94 | infixExpression.setRightOperand(expr); 95 | final Expression left = last.getLeftOperand(); 96 | last.setLeftOperand(infixExpression); 97 | infixExpression.setLeftOperand(left); 98 | last = infixExpression; 99 | } 100 | } 101 | 102 | return super.visit(node); 103 | } 104 | }); 105 | 106 | if (cmd.hasOption("c")) { 107 | try (final UglyMathCommentsExtractor cex = new UglyMathCommentsExtractor(cu, src)) { 108 | final ASTDumper dumper = new ASTDumper(cex); 109 | dumper.dump(cu); 110 | System.out.flush(); 111 | } 112 | } else { 113 | final ASTDumper dumper = new ASTDumper(); 114 | for (final Object comment : cu.getCommentList()) { 115 | ((Comment) comment).delete(); 116 | } 117 | dumper.dump(cu); 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /tools/EclipseAST/IASTPrinter.java: -------------------------------------------------------------------------------- 1 | //=========================================================================== 2 | // 3 | // This program use Eclipse JDT to parse java source files 4 | // and dumps resulting AST in JSON representation. 5 | // 6 | //--------------------------------------------------------------------------- 7 | // 8 | // Copyright (C) 2015 9 | // by Oleg Mazko(o.mazko@mail.ru). 10 | // 11 | // The author gives unlimited permission to copy and distribute 12 | // this file, with or without modifications, as long as this notice 13 | // is preserved, and any changes are properly documented. 14 | // 15 | 16 | /** 17 | * SAX-style printer for outputting AST nodes. 18 | */ 19 | public interface IASTPrinter { 20 | 21 | /** 22 | * Flags the start of the print job. 23 | */ 24 | public void startPrint(); 25 | 26 | /** 27 | * Flags the end of the print job. 28 | */ 29 | public void endPrint(); 30 | 31 | /** 32 | * Starts an AST element. 33 | * 34 | * @param name 35 | * the name of the AST element. 36 | * @param isList 37 | * indicates whether the element is a list container. 38 | */ 39 | public void startElement(String name, boolean isList); 40 | 41 | /** 42 | * Starts an AST element type. 43 | * 44 | * @param name 45 | * the name of the type. 46 | * @param parentIsList 47 | * indicates whether the parent node is a list or not. 48 | */ 49 | public void startType(String name, boolean parentIsList); 50 | 51 | /** 52 | * Ends the element type. 53 | * 54 | * @param name 55 | * the name of the type. 56 | * @param parentIsList 57 | * indicates whether the parent node is a list or not. 58 | */ 59 | public void endType(String name, boolean parentIsList); 60 | 61 | /** 62 | * Ends an AST element. 63 | * 64 | * @param name 65 | * the name of the AST element. 66 | * @param isList 67 | * indicates whether the item is a list or not. 68 | */ 69 | public void endElement(String name, boolean isList); 70 | 71 | /** 72 | * Some literal value. 73 | * 74 | * @param name 75 | * the name of the literal. 76 | * @param value 77 | * the value to write. 78 | */ 79 | public void literal(String name, Object value); 80 | } 81 | -------------------------------------------------------------------------------- /tools/EclipseAST/ICommentsExtractor.java: -------------------------------------------------------------------------------- 1 | 2 | //=========================================================================== 3 | // 4 | // This program use Eclipse JDT to parse java source files 5 | // and dumps resulting AST in JSON representation. 6 | // 7 | //--------------------------------------------------------------------------- 8 | // 9 | // Copyright (C) 2015 10 | // by Oleg Mazko(o.mazko@mail.ru). 11 | // 12 | // The author gives unlimited permission to copy and distribute 13 | // this file, with or without modifications, as long as this notice 14 | // is preserved, and any changes are properly documented. 15 | // 16 | 17 | import org.eclipse.jdt.core.dom.ASTNode; 18 | import org.eclipse.jdt.core.dom.Comment; 19 | 20 | public interface ICommentsExtractor { 21 | public final class CommentItem { 22 | protected CommentItem(final Comment node, final String value) { 23 | this.node = node; 24 | this.value = value; 25 | } 26 | 27 | public final Comment node; 28 | public final String value; 29 | } 30 | 31 | CommentItem[] leadingComments(final ASTNode node); 32 | 33 | CommentItem[] trailingComments(final ASTNode node); 34 | } 35 | -------------------------------------------------------------------------------- /tools/EclipseAST/Indenter.java: -------------------------------------------------------------------------------- 1 | //=========================================================================== 2 | // 3 | // This program use Eclipse JDT to parse java source files 4 | // and dumps resulting AST in JSON representation. 5 | // 6 | //--------------------------------------------------------------------------- 7 | // 8 | // Copyright (C) 2015 9 | // by Oleg Mazko(o.mazko@mail.ru). 10 | // 11 | // The author gives unlimited permission to copy and distribute 12 | // this file, with or without modifications, as long as this notice 13 | // is preserved, and any changes are properly documented. 14 | // 15 | 16 | /** 17 | * Maintains an indentation string. 18 | */ 19 | public class Indenter { 20 | 21 | private final StringBuffer indent = new StringBuffer(); 22 | 23 | private int indentationSize = 4; 24 | 25 | /** 26 | * Gets the indentation string. 27 | * 28 | * @return a string of blanks which match the indentation level. 29 | */ 30 | protected String getIndentString() { 31 | return indent.toString(); 32 | } 33 | 34 | /** 35 | * Sets the space indentation size (default = 4). 36 | * 37 | * @param indentationSize 38 | * the size of the indentations. 39 | */ 40 | public void setIndentationSize(int indentationSize) { 41 | this.indentationSize = indentationSize; 42 | } 43 | 44 | /** 45 | * Increments the indentation. 46 | */ 47 | protected void indent() { 48 | for (int i = 0; i < indentationSize; i++) { 49 | indent.append(" "); 50 | } 51 | } 52 | 53 | /** 54 | * Decrements the indentation. 55 | */ 56 | protected void unindent() { 57 | indent.setLength(indent.length() - indentationSize); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tools/EclipseAST/JSONStyleASTPrinter.java: -------------------------------------------------------------------------------- 1 | 2 | //=========================================================================== 3 | // 4 | // This program use Eclipse JDT to parse java source files 5 | // and dumps resulting AST in JSON representation. 6 | // 7 | //--------------------------------------------------------------------------- 8 | // 9 | // Copyright (C) 2015 10 | // by Oleg Mazko(o.mazko@mail.ru). 11 | // 12 | // The author gives unlimited permission to copy and distribute 13 | // this file, with or without modifications, as long as this notice 14 | // is preserved, and any changes are properly documented. 15 | // 16 | 17 | import java.io.OutputStream; 18 | import java.io.PrintWriter; 19 | import java.util.ArrayList; 20 | import java.util.Arrays; 21 | import java.util.HashSet; 22 | import java.util.Set; 23 | import java.util.Stack; 24 | 25 | import org.apache.commons.lang3.StringEscapeUtils; 26 | 27 | /** 28 | * Outputs the AST in JSON-style format. 29 | * 30 | * NOTE: This is not intended as legitimate JSON. 31 | */ 32 | public class JSONStyleASTPrinter extends Indenter implements IASTPrinter { 33 | 34 | private final PrintWriter printer; 35 | 36 | private final Stack hasItemsStack = new Stack() { 37 | private static final long serialVersionUID = 1L; 38 | 39 | { 40 | // Make sure there is one item on the stack which represents 41 | // the root node. 42 | push(false); 43 | } 44 | }; 45 | 46 | public JSONStyleASTPrinter(OutputStream destination) { 47 | this.printer = new PrintWriter(destination); 48 | } 49 | 50 | public void startElement(String name, boolean isList) { 51 | if (hasItemsStack.peek() == true) { 52 | printer.println(","); 53 | } else { 54 | hasItemsStack.pop(); 55 | hasItemsStack.push(true); 56 | } 57 | 58 | printer.println(getIndentString() + name + ": " + (isList ? "[" : "{")); 59 | indent(); 60 | hasItemsStack.push(false); 61 | } 62 | 63 | public void endElement(String name, boolean isList) { 64 | unindent(); 65 | printer.print("\n" + getIndentString() + (isList ? "]" : "}")); 66 | hasItemsStack.pop(); 67 | } 68 | 69 | public void startType(String name, boolean parentIsList) { 70 | if (hasItemsStack.peek() == true) { 71 | printer.println(","); 72 | } else { 73 | hasItemsStack.pop(); 74 | hasItemsStack.push(true); 75 | } 76 | 77 | if (parentIsList) { 78 | printer.println(getIndentString() + "{"); 79 | indent(); 80 | } 81 | 82 | printer.print(getIndentString() + "node: \"" + name + "\""); 83 | } 84 | 85 | public void endType(String name, boolean parentIsList) { 86 | if (parentIsList) { 87 | unindent(); 88 | printer.print("\n" + getIndentString() + "}"); 89 | } 90 | } 91 | 92 | private static final Set> JSON_ALLOWED_WRAPPER_TYPES = new HashSet>( 93 | Arrays.asList(Boolean.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, 94 | ArrayList.class)); 95 | 96 | private static boolean isJsonAllowedType(Class clazz) { 97 | return JSON_ALLOWED_WRAPPER_TYPES.contains(clazz); 98 | } 99 | 100 | public void literal(String name, Object value) { 101 | if (hasItemsStack.peek() == true) { 102 | printer.println(","); 103 | } else { 104 | hasItemsStack.pop(); 105 | hasItemsStack.push(true); 106 | } 107 | 108 | printer.print(getIndentString() + name + ": " + (value == null || isJsonAllowedType(value.getClass()) ? value 109 | : "\"" + StringEscapeUtils.escapeJson(value.toString()) + "\"")); 110 | } 111 | 112 | public void startPrint() { 113 | printer.println("{"); 114 | indent(); 115 | } 116 | 117 | public void endPrint() { 118 | printer.println(); 119 | unindent(); 120 | printer.println("}"); 121 | printer.flush(); 122 | printer.close(); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /tools/EclipseAST/UglyMathCommentsExtractor.java: -------------------------------------------------------------------------------- 1 | 2 | //=========================================================================== 3 | // 4 | // This program use Eclipse JDT to parse java source files 5 | // and dumps resulting AST in JSON representation. 6 | // 7 | //--------------------------------------------------------------------------- 8 | // 9 | // Copyright (C) 2015 10 | // by Oleg Mazko(o.mazko@mail.ru). 11 | // 12 | // The author gives unlimited permission to copy and distribute 13 | // this file, with or without modifications, as long as this notice 14 | // is preserved, and any changes are properly documented. 15 | // 16 | 17 | import java.io.Closeable; 18 | import java.io.IOException; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import org.eclipse.jdt.core.dom.ASTNode; 23 | import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; 24 | import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; 25 | import org.eclipse.jdt.core.dom.Comment; 26 | import org.eclipse.jdt.core.dom.CompilationUnit; 27 | import org.eclipse.jdt.core.dom.EnumConstantDeclaration; 28 | import org.eclipse.jdt.core.dom.FieldDeclaration; 29 | import org.eclipse.jdt.core.dom.MethodDeclaration; 30 | import org.eclipse.jdt.core.dom.PackageDeclaration; 31 | 32 | public final class UglyMathCommentsExtractor implements ICommentsExtractor, Closeable { 33 | private final CompilationUnit cu; 34 | private final String src; 35 | private final List comments; 36 | private final boolean[] commentsVisited; 37 | 38 | public UglyMathCommentsExtractor(final CompilationUnit cu, final String src) { 39 | this.cu = cu; 40 | this.src = src; 41 | this.comments = cu.getCommentList(); 42 | /* For type boolean the default value is false */ 43 | commentsVisited = new boolean[this.comments.size()]; 44 | } 45 | 46 | private static int getNodeStartPosition(final ASTNode node) { 47 | if (node instanceof MethodDeclaration) { 48 | MethodDeclaration decl = (MethodDeclaration) node; 49 | return decl.isConstructor() ? decl.getName().getStartPosition() : decl.getReturnType2().getStartPosition(); 50 | } else if (node instanceof FieldDeclaration) { 51 | return ((FieldDeclaration) node).getType().getStartPosition(); 52 | } else if (node instanceof AbstractTypeDeclaration) { 53 | return ((AbstractTypeDeclaration) node).getName().getStartPosition(); 54 | } else if (node instanceof AnnotationTypeMemberDeclaration) { 55 | return ((AnnotationTypeMemberDeclaration) node).getName().getStartPosition(); 56 | } else if (node instanceof EnumConstantDeclaration) { 57 | return ((EnumConstantDeclaration) node).getName().getStartPosition(); 58 | } else if (node instanceof PackageDeclaration) { 59 | return ((PackageDeclaration) node).getName().getStartPosition(); 60 | } 61 | /* TODO: Initializer */ 62 | 63 | return node.getStartPosition(); 64 | } 65 | 66 | private final CommentItem extractCommentItem(final int index) { 67 | if (commentsVisited[index]) { 68 | return null; 69 | } else { 70 | final Comment comment = (Comment) comments.get(index); 71 | if (comment.isDocComment()) { 72 | /* Interpret DocComment as Line or Block */ 73 | comment.delete(); 74 | } 75 | final int start = comment.getStartPosition(); 76 | final int end = start + comment.getLength(); 77 | final String value = this.src.substring(start, end); 78 | return new CommentItem(comment, value); 79 | } 80 | } 81 | 82 | private final int getNodeFirstLeadingCommentIndex(final ASTNode node) { 83 | if (node instanceof PackageDeclaration) { 84 | if (commentsVisited.length > 0) { 85 | final Comment comment = (Comment) comments.get(0); 86 | if (comment.getStartPosition() + comment.getLength() <= ((PackageDeclaration) node).getName() 87 | .getStartPosition()) { 88 | return 0; 89 | } 90 | } 91 | return -1; 92 | } else { 93 | return cu.firstLeadingCommentIndex(node); 94 | } 95 | } 96 | 97 | @Override 98 | public CommentItem[] leadingComments(final ASTNode node) { 99 | final int index = getNodeFirstLeadingCommentIndex(node); 100 | final List items = new ArrayList<>(); 101 | 102 | if (index != -1) { 103 | final int nodeStart = getNodeStartPosition(node); 104 | for (int i = index; i < commentsVisited.length; i++) { 105 | final CommentItem item = extractCommentItem(i); 106 | if (item != null) { 107 | final int commentEnd = item.node.getStartPosition() + item.node.getLength(); 108 | if (commentEnd > nodeStart) { 109 | break; 110 | } 111 | commentsVisited[i] = true; 112 | items.add(item); 113 | } 114 | } 115 | } 116 | return items.toArray(new CommentItem[items.size()]); 117 | } 118 | 119 | @Override 120 | public CommentItem[] trailingComments(final ASTNode node) { 121 | final int index = cu.lastTrailingCommentIndex(node); 122 | final List items = new ArrayList<>(); 123 | 124 | if (index != -1) { 125 | final int nodeEnd = node.getStartPosition() + node.getLength(); 126 | for (int i = index; i >= 0; i--) { 127 | final CommentItem item = extractCommentItem(i); 128 | if (item != null) { 129 | if (item.node.getStartPosition() < nodeEnd) { 130 | break; 131 | } 132 | commentsVisited[i] = true; 133 | items.add(item); 134 | } 135 | } 136 | } 137 | 138 | return items.toArray(new CommentItem[items.size()]); 139 | } 140 | 141 | @Override 142 | public void close() throws IOException { 143 | for (int i = 0; i < commentsVisited.length; i++) { 144 | if (commentsVisited[i] == false) { 145 | System.err.println("Orphan comment is lost:"); 146 | System.err.println(extractCommentItem(i).value); 147 | } 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /tools/EclipseAST/lib/commons-cli-1.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/commons-cli-1.3.1.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/commons-lang3-3.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/commons-lang3-3.4.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.core.contenttype_3.5.0.v20150421-2214.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.core.contenttype_3.5.0.v20150421-2214.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.core.jobs_3.7.0.v20150330-2103.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.core.jobs_3.7.0.v20150330-2103.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.core.resources_3.10.0.v20150423-0755.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.core.resources_3.10.0.v20150423-0755.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.core.runtime_3.11.0.v20150405-1723.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.core.runtime_3.11.0.v20150405-1723.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.equinox.common_3.7.0.v20150402-1709.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.equinox.common_3.7.0.v20150402-1709.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.equinox.preferences_3.5.300.v20150408-1437.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.equinox.preferences_3.5.300.v20150408-1437.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.jdt.core_3.11.0.v20150602-1242.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.jdt.core_3.11.0.v20150602-1242.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.osgi_3.10.100.v20150529-1857.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.osgi_3.10.100.v20150529-1857.jar -------------------------------------------------------------------------------- /tools/EclipseAST/lib/org.eclipse.text_3.5.400.v20150505-1044.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazko/jsjavaparser/c6d399cfc660c014ce091be63f1d41a54f835e87/tools/EclipseAST/lib/org.eclipse.text_3.5.400.v20150505-1044.jar -------------------------------------------------------------------------------- /tools/EclipseAST/run.sh: -------------------------------------------------------------------------------- 1 | # TODO: javadoc, extendedOperands not implemented - removing from JSON output 2 | # Usage: ./run.sh -c '../../Test.java' 3 | javac -Xlint:deprecation -cp 'lib/*' *.java && java -Xss4m -cp .:'lib/*' App "$@" 2>&1 | \ 4 | sed '/^[ \t]*javadoc: null,$/d' | sed '/^[ \t]*extendedOperands: \[\]$/d' | \ 5 | tee /dev/tty | xclip -selection clipboard --------------------------------------------------------------------------------