001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2006, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs;
021:
022: import org.apache.bcel.classfile.JavaClass;
023: import org.apache.bcel.util.ClassPath;
024: import org.apache.bcel.util.Repository;
025:
026: import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
027: import edu.umd.cs.findbugs.classfile.ClassDescriptor;
028: import edu.umd.cs.findbugs.classfile.DescriptorFactory;
029: import edu.umd.cs.findbugs.classfile.Global;
030: import edu.umd.cs.findbugs.internalAnnotations.SlashedClassName;
031: import edu.umd.cs.findbugs.util.ClassName;
032:
033: /**
034: * An implementation of org.apache.bcel.util.Repository that
035: * uses the AnalysisCache as its backing store.
036: *
037: * @author David Hovemeyer
038: */
039: public class AnalysisCacheToRepositoryAdapter implements Repository {
040: /**
041: * Constructor.
042: */
043: public AnalysisCacheToRepositoryAdapter() {
044: }
045:
046: /* (non-Javadoc)
047: * @see org.apache.bcel.util.Repository#clear()
048: */
049: public void clear() {
050: throw new UnsupportedOperationException();
051: }
052:
053: /* (non-Javadoc)
054: * @see org.apache.bcel.util.Repository#findClass(java.lang.String)
055: */
056: public JavaClass findClass(String className) {
057: @SlashedClassName
058: String slashedClassName = ClassName
059: .toSlashedClassName(className);
060: ClassDescriptor classDescriptor = DescriptorFactory.instance()
061: .getClassDescriptor(slashedClassName);
062: return Global.getAnalysisCache().probeClassAnalysis(
063: JavaClass.class, classDescriptor);
064: }
065:
066: /* (non-Javadoc)
067: * @see org.apache.bcel.util.Repository#getClassPath()
068: */
069: public ClassPath getClassPath() {
070: throw new UnsupportedOperationException();
071: }
072:
073: /* (non-Javadoc)
074: * @see org.apache.bcel.util.Repository#loadClass(java.lang.String)
075: */
076: public JavaClass loadClass(String className)
077: throws ClassNotFoundException {
078: if (className.length() == 0)
079: throw new IllegalArgumentException(
080: "Request to load empty class");
081: className = ClassName.toSlashedClassName(className);
082: ClassDescriptor classDescriptor = DescriptorFactory.instance()
083: .getClassDescriptor(className);
084: try {
085: return Global.getAnalysisCache().getClassAnalysis(
086: JavaClass.class, classDescriptor);
087: } catch (CheckedAnalysisException e) {
088: throw new ClassNotFoundException(
089: "Exception while looking for class " + className, e);
090: }
091: }
092:
093: /* (non-Javadoc)
094: * @see org.apache.bcel.util.Repository#loadClass(java.lang.Class)
095: */
096: public JavaClass loadClass(Class cls) throws ClassNotFoundException {
097: return loadClass(cls.getName());
098: }
099:
100: /* (non-Javadoc)
101: * @see org.apache.bcel.util.Repository#removeClass(org.apache.bcel.classfile.JavaClass)
102: */
103: public void removeClass(JavaClass arg0) {
104: throw new UnsupportedOperationException();
105: }
106:
107: /* (non-Javadoc)
108: * @see org.apache.bcel.util.Repository#storeClass(org.apache.bcel.classfile.JavaClass)
109: */
110: public void storeClass(JavaClass cls) {
111: throw new UnsupportedOperationException();
112: }
113: }
|