All Downloads are FREE. Search and download functionalities are using the official Maven repository.

stubparser.src.org.checkerframework.stubparser.JavaParser Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java’s type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.42.0
Show newest version
/*
 * Copyright (C) 2008 Júlio Vilmar Gesser.
 *
 * This file is part of Java 1.5 parser and Abstract Syntax Tree.
 *
 * Java 1.5 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Java 1.5 parser and Abstract Syntax Tree is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Java 1.5 parser and Abstract Syntax Tree.  If not, see .
 */
/*
 * Created on 05/10/2006
 */
package org.checkerframework.stubparser;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.checkerframework.stubparser.ast.CompilationUnit;
import org.checkerframework.stubparser.ast.IndexUnit;

/**
 * 

This class was generated automatically by javacc, do not edit.

*

Parse Java 1.5 source code and creates Abstract Syntax Tree classes.

*

Note: To use this parser asynchronously, disable de parser cache * by calling the method {@link #setCacheParser} with false * as argument.

* * @author Júlio Vilmar Gesser */ public final class JavaParser { private static ASTParser parser; private static boolean cacheParser = true; private JavaParser() { // hide the constructor } /** * Changes the way that the parser acts when starts to parse. If the * parser cache is enabled, only one insance of this object will be * used in every call to parse methods. * If this parser is intend to be used asynchonously, the cache must * be disabled setting this flag to false. * By default, the cache is enabled. * @param value false to disable the parser instance cache. */ public static void setCacheParser(boolean value) { cacheParser = value; if (!value) { parser = null; } } /** * Parses the Java code contained in the {@link InputStream} and returns * a {@link CompilationUnit} that represents it. * @param in {@link InputStream} containing Java source code * @param encoding encoding of the source code * @return CompilationUnit representing the Java source code * @throws ParseException if the source code has parser errors */ public static IndexUnit parse(InputStream in, String encoding) throws ParseException { if (cacheParser) { if (parser == null) { parser = new ASTParser(in, encoding); } else { parser.reset(in, encoding); } return parser.IndexUnit(); } return new ASTParser(in, encoding).IndexUnit(); } /** * Parses the Java code contained in the {@link InputStream} and returns * a {@link CompilationUnit} that represents it. * @param in {@link InputStream} containing Java source code * @return CompilationUnit representing the Java source code * @throws ParseException if the source code has parser errors */ public static IndexUnit parse(InputStream in) throws ParseException { return parse(in, null); } /** * Parses the Java code contained in a {@link File} and returns * a {@link CompilationUnit} that represents it. * @param file {@link File} containing Java source code * @param encoding encoding of the source code * @return CompilationUnit representing the Java source code * @throws ParseException if the source code has parser errors */ public static IndexUnit parse(File file, String encoding) throws ParseException, IOException { FileInputStream in = new FileInputStream(file); try { return parse(in, encoding); } finally { in.close(); } } /** * Parses the Java code contained in a {@link File} and returns * a {@link CompilationUnit} that represents it. * @param file {@link File} containing Java source code * @return CompilationUnit representing the Java source code * @throws ParseException if the source code has parser errors */ public static IndexUnit parse(File file) throws ParseException, IOException { return parse(file, null); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy