How to use java-parser - 7 common examples

To help you get started, we’ve selected a few java-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github swisspush / apikana / test / specs / path-v3-generator.spec.js View on Github external
function assertResult( result ){
            const compileUnit = JavaParser.parse( result , {});
            const clazz = compileUnit.types[0];
            const fooSegment = clazz.bodyDeclarations.filter( e => e.name.identifier==="foo" )[0];
            expect( fooSegment ).toBeTruthy();
            const based = fooSegment.bodyDeclarations.filter( e => e.name && e.name.identifier==="BASED" )[0];
            expect( based ).toBeTruthy();
            // Check if BASED class has expected content.
            const barSegment = based.bodyDeclarations.filter( e => e.name.identifier==="bar" )[0];
            expect( barSegment ).toBeTruthy();
            done();
        }
    });
github swisspush / apikana / test / specs / path-v3-generator.spec.js View on Github external
function assertResult( result ){
            const compileUnit = JavaParser.parse( result , {});
            const values = collectAllValuesOfCollectionConstants( compileUnit );
            expect( values.length ).toBe( 18 );
            for( let i=0 ; i<values.length ; ++i ){
                const value = values[i];
                expect( value ).toEqual( 'RESOURCE + "/"' );
            }
            done();
        }
        function collectAllValuesOfCollectionConstants( node ){
github swisspush / apikana / test / specs / path-v3-generator.spec.js View on Github external
function assertResult( result ){
            const compilationUnit = JavaParser.parse( result , {} );
            const clazz = compilationUnit.types[0];
            const foo = clazz.bodyDeclarations.filter( e => e.name && e.name.identifier==="foo" )[0];
            expect( foo ).toBeTruthy();
            const bar = clazz.bodyDeclarations.filter( e => e.name && e.name.identifier==="bar" )[0];
            expect( bar ).toBeTruthy();
            done();
        }
    });
github swisspush / apikana / test / specs / path-v3-generator.spec.js View on Github external
function assertResult( result ){
            const compilationUnit = JavaParser.parse( result , {});
            const resources = [];
            createJavaParserNodeIterator( compilationUnit ).forEach(function( node ){
                if( node.node==="TypeDeclaration" && node.name.identifier !== "EoarheAoiuno" && node.name.identifier !== "BASED" ){
                    resources.push( node );
                }
            });
            const whitelist = [
                "_abstract", "_assert", "_boolean", "_break", "_byte", "_case",
                "_catch", "_char", "_class", "_const", "_continue", "_default",
                "_double", "_do", "_else", "_enum", "_extends", "_false",
                "_final", "_finally", "_float", "_for", "_goto", "_if",
                "_implements", "_import", "_instanceof", "_int", "_interface", "_long",
                "_native", "_new", "_null", "_package", "_private", "_protected",
                "_public", "_return", "_short", "_static", "_strictfp", "_super",
                "_switch", "_synchronized", "_this", "_throw", "_throws", "_transient",
                "_true", "_try", "_void", "_volatile", "_while",
github DaGhostman / vscode-tree-view / src / providers / java.ts View on Github external
public refresh(document: vscode.TextDocument): void {
        this.config = vscode.workspace.getConfiguration("treeview.java");
        this.tree = {} as token.ITokenTree;
        const raw = require("java-parser").parse(document.getText());
        const lines = document.getText().split("\n");
        if (raw.package) {
            const nsParts: string[] = [];
            let ns = raw.package.name;
            while (ns.qualifier !== undefined) {
                nsParts.push(ns.name.identifier);
                ns = ns.qualifier;
            }

            nsParts.push(ns.identifier);
            this.tree.namespace = nsParts.reverse().join(".");
        }
        if (raw.imports.length !== 0) {
            this.tree.imports = [];

            let importName = null;
github felipemanga / FemtoIDE / plugins / buildjava.js View on Github external
postRun( res ){
                    res.unit.file = res.filePath || "???";
                    let cst;
                    try{
                        cst = javaParser( res.src );
                    }catch(ex){

                        if(analyze)
                            return;
                        
                        let name = res.name || (res.unit && res.unit.name + "") || "???";
                        if( name.startsWith(DATA.projectPath) ){
                            name = name.substr(DATA.projectPath.length+1);
                        }

                        console.log(ex.message, ex.stack);
                        
                        throw( name + ": " + (ex.message || ex) );
                    }
                    res.unit.process(cst);
                }
github jhipster / prettier-java / packages / prettier-plugin-java / src / parser.js View on Github external
function parse(text) {
  const ast = javaParser.parse(text);
  return ast;
}

java-parser

Java Parser in JavaScript

Apache-2.0
Latest version published 6 days ago

Package Health Score

80 / 100
Full package analysis

Popular java-parser functions