package org.apache.maven.natives.util;

/* ====================================================================
 *   Copyright 2001-2004 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * ====================================================================
 */
 
import java.io.IOException;

import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;

/**
 * @author Kasper Nielsen
 *
 */
public class JavaSourceTool {
    
    
    /**
     * Parses the java class file and returns an isntance of a Bcel Class
     *
     * @param absoluteFileName the absolute file name to transform
     * @return the Bcel Class.
     * @throws IOException upon failure to read the java file
     */
    public static final JavaClass getBcelClass(String absoluteFileName) throws IOException {
        try {
            ClassParser parser = new ClassParser(absoluteFileName);
            JavaClass clazz= parser.parse();
            return clazz;
            
        } catch (Exception e) {
            System.out.println("\nError parsing " + absoluteFileName + ": " + e + "\n");
            return null;
        }
    }
}
