@Test public void testClassWithoutPackage() { try { final JavaFileAnalyzer2 jfa = (JavaFileAnalyzer2) FileAnalyzerFactory.buildFileAnalyzer( new File("./src/test/java/ClassWithoutPackage.java")); final Map<ConstructId, Construct> constructs_from_java = jfa.getConstructs(); final ClassFileAnalyzer cfa = (ClassFileAnalyzer) FileAnalyzerFactory.buildFileAnalyzer( new File("./target/test-classes/ClassWithoutPackage.class")); final Map<ConstructId, Construct> constructs_from_class = cfa.getConstructs(); final JavaClassId cl = JavaId.parseClassQName("ClassWithoutPackage"); final JavaConstructorId co = JavaId.parseConstructorQName("ClassWithoutPackage()"); final JavaMethodId m = JavaId.parseMethodQName("ClassWithoutPackage.foo()"); assertEquals(3, constructs_from_java.size()); assertTrue(constructs_from_java.containsKey(cl)); assertTrue(constructs_from_java.containsKey(co)); assertTrue(constructs_from_java.containsKey(m)); assertEquals(3, constructs_from_class.size()); assertTrue(constructs_from_class.containsKey(cl)); assertTrue(constructs_from_java.containsKey(co)); assertTrue(constructs_from_class.containsKey(m)); } catch (FileAnalysisException e) { e.printStackTrace(); assertTrue(false); } }
@Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs == null) { try { this.constructs = new TreeMap<ConstructId, Construct>(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final InputStream is2 = new BufferedInputStream(new FileInputStream(this.file))) { int cc = -1; while ((cc = is2.read()) >= 0) baos.write(cc); } baos.flush(); this.input = new ANTLRInputStream(new ByteArrayInputStream(baos.toByteArray())); JavaLexer lexer = new JavaLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); JavaParser parser = new JavaParser(tokens); CompilationUnitContext ctx = parser.compilationUnit(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, ctx); } catch (FileNotFoundException e) { throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException( "ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException( "I/O exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (Exception e) { throw new FileAnalysisException( "Exception of type [" + e.getClass().getSimpleName() + "] while analyzing file [" + this.file.toPath().toAbsolutePath() + "]: " + e.getMessage(), e); } } return this.constructs; }
JavaFileAnalyzer2 extends JavaParserBaseListener implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs == null) { try { this.constructs = new TreeMap<ConstructId, Construct>(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final InputStream is2 = new BufferedInputStream(new FileInputStream(this.file))) { int cc = -1; while ((cc = is2.read()) >= 0) baos.write(cc); } baos.flush(); this.input = new ANTLRInputStream(new ByteArrayInputStream(baos.toByteArray())); JavaLexer lexer = new JavaLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); JavaParser parser = new JavaParser(tokens); CompilationUnitContext ctx = parser.compilationUnit(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, ctx); } catch (FileNotFoundException e) { throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException( "ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException( "I/O exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (Exception e) { throw new FileAnalysisException( "Exception of type [" + e.getClass().getSimpleName() + "] while analyzing file [" + this.file.toPath().toAbsolutePath() + "]: " + e.getMessage(), e); } } return this.constructs; } }
JavaFileAnalyzer2 extends JavaParserBaseListener implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs == null) { try { this.constructs = new TreeMap<ConstructId, Construct>(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final InputStream is2 = new BufferedInputStream(new FileInputStream(this.file))) { int cc = -1; while ((cc = is2.read()) >= 0) baos.write(cc); } baos.flush(); this.input = new ANTLRInputStream(new ByteArrayInputStream(baos.toByteArray())); JavaLexer lexer = new JavaLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); JavaParser parser = new JavaParser(tokens); CompilationUnitContext ctx = parser.compilationUnit(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, ctx); } catch (FileNotFoundException e) { throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException( "ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException( "I/O exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (Exception e) { throw new FileAnalysisException( "Exception of type [" + e.getClass().getSimpleName() + "] while analyzing file [" + this.file.toPath().toAbsolutePath() + "]: " + e.getMessage(), e); } } return this.constructs; }  }
JavaFileAnalyzer2 extends JavaParserBaseListener implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs == null) { try { this.constructs = new TreeMap<ConstructId, Construct>(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final InputStream is2 = new BufferedInputStream(new FileInputStream(this.file))) { int cc = -1; while ((cc = is2.read()) >= 0) baos.write(cc); } baos.flush(); this.input = new ANTLRInputStream(new ByteArrayInputStream(baos.toByteArray())); JavaLexer lexer = new JavaLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); JavaParser parser = new JavaParser(tokens); CompilationUnitContext ctx = parser.compilationUnit(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, ctx); } catch (FileNotFoundException e) { throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException( "ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException( "I/O exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (Exception e) { throw new FileAnalysisException( "Exception of type [" + e.getClass().getSimpleName() + "] while analyzing file [" + this.file.toPath().toAbsolutePath() + "]: " + e.getMessage(), e); } } return this.constructs; }  @Override String[] getSupportedFileExtensions(); @Override boolean canAnalyze(File _file); @Override void analyze(final File _file); void setFile(File _file); @Override void enterPackageDeclaration(@NotNull JavaParser.PackageDeclarationContext ctx); @Override void enterEnumDeclaration(@NotNull JavaParser.EnumDeclarationContext ctx); @Override void exitEnumDeclaration(@NotNull JavaParser.EnumDeclarationContext ctx); @Override void enterInterfaceDeclaration(@NotNull JavaParser.InterfaceDeclarationContext ctx); @Override void exitInterfaceDeclaration(@NotNull JavaParser.InterfaceDeclarationContext ctx); @Override void enterClassDeclaration(@NotNull JavaParser.ClassDeclarationContext ctx); @Override void exitClassDeclaration(@NotNull JavaParser.ClassDeclarationContext ctx); @Override void enterClassBody(@NotNull JavaParser.ClassBodyContext ctx); @Override void exitClassBody(@NotNull JavaParser.ClassBodyContext ctx); @Override void enterMethodDeclaration(@NotNull JavaParser.MethodDeclarationContext ctx); @Override void exitMethodDeclaration(
      org.eclipse.steady.java.antlr.JavaParser.MethodDeclarationContext ctx); @Override void enterConstructorDeclaration(@NotNull JavaParser.ConstructorDeclarationContext ctx); @Override void exitConstructorDeclaration(
      org.eclipse.steady.java.antlr.JavaParser.ConstructorDeclarationContext ctx); @Override Map<ConstructId, Construct> getConstructs(); @Override boolean containsConstruct(ConstructId _id); @Override Construct getConstruct(ConstructId _id); @Override boolean hasChilds(); @Override Set<FileAnalyzer> getChilds(boolean _recursive); }
JavaFileAnalyzer2 extends JavaParserBaseListener implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs == null) { try { this.constructs = new TreeMap<ConstructId, Construct>(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final InputStream is2 = new BufferedInputStream(new FileInputStream(this.file))) { int cc = -1; while ((cc = is2.read()) >= 0) baos.write(cc); } baos.flush(); this.input = new ANTLRInputStream(new ByteArrayInputStream(baos.toByteArray())); JavaLexer lexer = new JavaLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); JavaParser parser = new JavaParser(tokens); CompilationUnitContext ctx = parser.compilationUnit(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, ctx); } catch (FileNotFoundException e) { throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException( "ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException( "I/O exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (Exception e) { throw new FileAnalysisException( "Exception of type [" + e.getClass().getSimpleName() + "] while analyzing file [" + this.file.toPath().toAbsolutePath() + "]: " + e.getMessage(), e); } } return this.constructs; }  @Override String[] getSupportedFileExtensions(); @Override boolean canAnalyze(File _file); @Override void analyze(final File _file); void setFile(File _file); @Override void enterPackageDeclaration(@NotNull JavaParser.PackageDeclarationContext ctx); @Override void enterEnumDeclaration(@NotNull JavaParser.EnumDeclarationContext ctx); @Override void exitEnumDeclaration(@NotNull JavaParser.EnumDeclarationContext ctx); @Override void enterInterfaceDeclaration(@NotNull JavaParser.InterfaceDeclarationContext ctx); @Override void exitInterfaceDeclaration(@NotNull JavaParser.InterfaceDeclarationContext ctx); @Override void enterClassDeclaration(@NotNull JavaParser.ClassDeclarationContext ctx); @Override void exitClassDeclaration(@NotNull JavaParser.ClassDeclarationContext ctx); @Override void enterClassBody(@NotNull JavaParser.ClassBodyContext ctx); @Override void exitClassBody(@NotNull JavaParser.ClassBodyContext ctx); @Override void enterMethodDeclaration(@NotNull JavaParser.MethodDeclarationContext ctx); @Override void exitMethodDeclaration(
      org.eclipse.steady.java.antlr.JavaParser.MethodDeclarationContext ctx); @Override void enterConstructorDeclaration(@NotNull JavaParser.ConstructorDeclarationContext ctx); @Override void exitConstructorDeclaration(
      org.eclipse.steady.java.antlr.JavaParser.ConstructorDeclarationContext ctx); @Override Map<ConstructId, Construct> getConstructs(); @Override boolean containsConstruct(ConstructId _id); @Override Construct getConstruct(ConstructId _id); @Override boolean hasChilds(); @Override Set<FileAnalyzer> getChilds(boolean _recursive);  }