当前位置: 首页>>代码示例>>Java>>正文


Java CannotCompileException类代码示例

本文整理汇总了Java中scouter.javassist.CannotCompileException的典型用法代码示例。如果您正苦于以下问题:Java CannotCompileException类的具体用法?Java CannotCompileException怎么用?Java CannotCompileException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CannotCompileException类属于scouter.javassist包,在下文中一共展示了CannotCompileException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setSuperclass

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
/**
 * Sets the super class.
 * 
 * <p>
 * The new super class should inherit from the old super class.
 * This method modifies constructors so that they call constructors declared
 * in the new super class.
 */
public void setSuperclass(String superclass) throws CannotCompileException {
    if (superclass == null)
        superclass = "java.lang.Object";

    try {
        this.superClass = constPool.addClassInfo(superclass);
        ArrayList list = methods;
        int n = list.size();
        for (int i = 0; i < n; ++i) {
            MethodInfo minfo = (MethodInfo)list.get(i);
            minfo.setSuperclass(superclass);
        }
    }
    catch (BadBytecode e) {
        throw new CannotCompileException(e);
    }
    cachedSuperclass = superclass;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:27,代码来源:ClassFile.java

示例2: exportObject

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
/**
 * Exports an object.
 * This method produces the bytecode of the proxy class used
 * to access the exported object.  A remote applet can load
 * the proxy class and call a method on the exported object.
 *
 * @param name      the name used for looking the object up.
 * @param obj       the exported object.
 * @return          the object identifier
 *
 * @see ObjectImporter#lookupObject(String)
 */
public synchronized int exportObject(String name, Object obj)
    throws CannotCompileException
{
    Class clazz = obj.getClass();
    ExportedObject eo = new ExportedObject();
    eo.object = obj;
    eo.methods = clazz.getMethods();
    exportedObjects.addElement(eo);
    eo.identifier = exportedObjects.size() - 1;
    if (name != null)
        exportedNames.put(name, eo);

    try {
        stubGen.makeProxyClass(clazz);
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }

    return eo.identifier;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:34,代码来源:AppletServer.java

示例3: createClass3

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
private void createClass3(ClassLoader cl) {
    // we need a new class so we need a new class name
    allocateClassName();

    try {
        ClassFile cf = make();
        if (writeDirectory != null)
            FactoryHelper.writeFile(cf, writeDirectory);

        thisClass = FactoryHelper.toClass(cf, cl, getDomain());
        setField(FILTER_SIGNATURE_FIELD, signature);
        // legacy behaviour : we only set the default interceptor static field if we are not using the cache
        if (!factoryUseCache) {
            setField(DEFAULT_INTERCEPTOR, handler);
        }
    }
    catch (CannotCompileException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:22,代码来源:ProxyFactory.java

示例4: overrideMethods

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
private int overrideMethods(ClassFile cf, ConstPool cp, String className, ArrayList forwarders)
    throws CannotCompileException
{
    String prefix = makeUniqueName("_d", signatureMethods);
    Iterator it = signatureMethods.iterator();
    int index = 0;
    while (it.hasNext()) {
        Map.Entry e = (Map.Entry)it.next();
        String key = (String)e.getKey();
        Method meth = (Method)e.getValue();
        if (ClassFile.MAJOR_VERSION < ClassFile.JAVA_5 || !isBridge(meth))
        	if (testBit(signature, index)) {
        		override(className, meth, prefix, index,
        				 keyToDesc(key, meth), cf, cp, forwarders);
        	}

        index++;
    }

    return index;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:22,代码来源:ProxyFactory.java

示例5: override

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
private void override(String thisClassname, Method meth, String prefix,
                      int index, String desc, ClassFile cf, ConstPool cp, ArrayList forwarders)
    throws CannotCompileException
{
    Class declClass = meth.getDeclaringClass();
    String delegatorName = prefix + index + meth.getName();
    if (Modifier.isAbstract(meth.getModifiers()))
        delegatorName = null;
    else {
        MethodInfo delegator
            = makeDelegator(meth, desc, cp, declClass, delegatorName);
        // delegator is not a bridge method.  See Sec. 15.12.4.5 of JLS 3rd Ed.
        delegator.setAccessFlags(delegator.getAccessFlags() & ~AccessFlag.BRIDGE);
        cf.addMethod(delegator);
    }

    MethodInfo forwarder
        = makeForwarder(thisClassname, meth, desc, cp, declClass,
                        delegatorName, index, forwarders);
    cf.addMethod(forwarder);
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:22,代码来源:ProxyFactory.java

示例6: makeConstructors

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
private void makeConstructors(String thisClassName, ClassFile cf,
        ConstPool cp, String classname) throws CannotCompileException
{
    Constructor[] cons = SecurityActions.getDeclaredConstructors(superClass);
    // legacy: if we are not caching then we need to initialise the default handler
    boolean doHandlerInit = !factoryUseCache;
    for (int i = 0; i < cons.length; i++) {
        Constructor c = cons[i];
        int mod = c.getModifiers();
        if (!Modifier.isFinal(mod) && !Modifier.isPrivate(mod)
                && isVisible(mod, basename, c)) {
            MethodInfo m = makeConstructor(thisClassName, c, cp, superClass, doHandlerInit);
            cf.addMethod(m);
        }
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:17,代码来源:ProxyFactory.java

示例7: writeFile0

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
private static void writeFile0(ClassFile cf, String directoryName)
        throws CannotCompileException, IOException {
    String classname = cf.getName();
    String filename = directoryName + File.separatorChar
            + classname.replace('.', File.separatorChar) + ".class";
    int pos = filename.lastIndexOf(File.separatorChar);
    if (pos > 0) {
        String dir = filename.substring(0, pos);
        if (!dir.equals("."))
            new File(dir).mkdirs();
    }

    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
            new FileOutputStream(filename)));
    try {
        cf.write(out);
    }
    catch (IOException e) {
        throw e;
    }
    finally {
        out.close();
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:25,代码来源:FactoryHelper.java

示例8: doit

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
/**
 * Visits each bytecode in the given range. 
 */
boolean doit(CtClass clazz, MethodInfo minfo, LoopContext context,
             CodeIterator iterator, int endPos)
    throws CannotCompileException
{
    boolean edited = false;
    while (iterator.hasNext() && iterator.lookAhead() < endPos) {
        int size = iterator.getCodeLength();
        if (loopBody(iterator, clazz, minfo, context)) {
            edited = true;
            int size2 = iterator.getCodeLength();
            if (size != size2)  // the body was modified.
                endPos += size2 - size;
        }
    }

    return edited;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:21,代码来源:ExprEditor.java

示例9: toClass

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
/**
 * Convert a javassist class to a java class
 * 
 * @param ct
 *            the javassist class
 * @param loader
 *            the loader
 * @throws CannotCompileException
 *             for any error
 */
public Class toClass(CtClass ct, ClassLoader loader, ProtectionDomain domain)
        throws CannotCompileException {
    // We need to pass up the classloader stored in this pool, as the
    // default implementation uses the Thread context cl.
    // In the case of JSP's in Tomcat,
    // org.apache.jasper.servlet.JasperLoader will be stored here, while
    // it's parent
    // org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader is used as the Thread
    // context cl. The invocation class needs to
    // be generated in the JasperLoader classloader since in the case of
    // method invocations, the package name will be
    // the same as for the class generated from the jsp, i.e.
    // org.apache.jsp. For classes belonging to org.apache.jsp,
    // JasperLoader does NOT delegate to its parent if it cannot find them.
    lockInCache(ct);
    return super.toClass(ct, getClassLoader0(), domain);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:28,代码来源:ScopedClassPool.java

示例10: modifySuperclass

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
/**
 * Adds a default constructor to the super classes.
 */
private void modifySuperclass(CtClass orgclass)
    throws CannotCompileException, NotFoundException
{
    CtClass superclazz;
    for (;; orgclass = superclazz) {
        superclazz = orgclass.getSuperclass();
        if (superclazz == null)
            break;

        try {
            superclazz.getDeclaredConstructor(null);
            break;  // the constructor with no arguments is found.
        }
        catch (NotFoundException e) {
        }

        superclazz.addConstructor(
                    CtNewConstructor.defaultConstructor(superclazz));
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:24,代码来源:StubGenerator.java

示例11: makeReflective

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
/**
 * Produces a reflective class.  It modifies the given
 * <code>CtClass</code> object and makes it reflective.
 * If the super class is also made reflective, it must be done
 * before the sub class.
 *
 * @param clazz             the reflective class.
 * @param metaobject        the class of metaobjects.
 *                          It must be a subclass of
 *                          <code>Metaobject</code>.
 * @param metaclass         the class of the class metaobject.
 *                          It must be a subclass of
 *                          <code>ClassMetaobject</code>.
 * @return <code>false</code>       if the class is already reflective.
 *
 * @see Metaobject
 * @see ClassMetaobject
 */
public boolean makeReflective(CtClass clazz,
                              CtClass metaobject, CtClass metaclass)
    throws CannotCompileException, CannotReflectException,
           NotFoundException
{
    if (clazz.isInterface())
        throw new CannotReflectException(
                "Cannot reflect an interface: " + clazz.getName());

    if (clazz.subclassOf(classPool.get(classMetaobjectClassName)))
        throw new CannotReflectException(
            "Cannot reflect a subclass of ClassMetaobject: "
            + clazz.getName());

    if (clazz.subclassOf(classPool.get(metaobjectClassName)))
        throw new CannotReflectException(
            "Cannot reflect a subclass of Metaobject: "
            + clazz.getName());

    registerReflectiveClass(clazz);
    return modifyClassfile(clazz, metaobject, metaclass);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:41,代码来源:Reflection.java

示例12: runEditor

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
protected void runEditor(ExprEditor ed, CodeIterator oldIterator)
    throws CannotCompileException
{
    CodeAttribute codeAttr = oldIterator.get();
    int orgLocals = codeAttr.getMaxLocals();
    int orgStack = codeAttr.getMaxStack();
    int newLocals = locals();
    codeAttr.setMaxStack(stack());
    codeAttr.setMaxLocals(newLocals);
    ExprEditor.LoopContext context
        = new ExprEditor.LoopContext(newLocals);
    int size = oldIterator.getCodeLength();
    int endPos = oldIterator.lookAhead();
    oldIterator.move(currentPos);
    if (ed.doit(thisClass, thisMethod, context, oldIterator, endPos))
        edited = true;

    oldIterator.move(endPos + oldIterator.getCodeLength() - size);
    codeAttr.setMaxLocals(orgLocals);
    codeAttr.setMaxStack(orgStack);
    maxLocals = context.maxLocals;
    maxStack += context.maxStack;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:24,代码来源:Expr.java

示例13: compile

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
/**
 * Compiles a method, constructor, or field declaration
 * to a class.
 * A field declaration can declare only one field.
 *
 * <p>In a method or constructor body, $0, $1, ... and $_
 * are not available.
 *
 * @return          a <code>CtMethod</code>, <code>CtConstructor</code>,
 *                  or <code>CtField</code> object.
 * @see #recordProceed(String,String)
 */
public CtMember compile(String src) throws CompileError {
    Parser p = new Parser(new Lex(src));
    ASTList mem = p.parseMember1(stable);
    try {
        if (mem instanceof FieldDecl)
            return compileField((FieldDecl)mem);
        else {
            CtBehavior cb = compileMethod(p, (MethodDecl)mem);
            CtClass decl = cb.getDeclaringClass();
            cb.getMethodInfo2()
              .rebuildStackMapIf6(decl.getClassPool(),
                                  decl.getClassFile2());
            return cb;
        }
    }
    catch (BadBytecode bb) {
        throw new CompileError(bb.getMessage());
    }
    catch (CannotCompileException e) {
        throw new CompileError(e.getMessage());
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:35,代码来源:Javac.java

示例14: initialize

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
public void initialize(ConstPool cp, CtClass clazz, MethodInfo minfo) throws CannotCompileException {
    /*
     * This transformer must be isolated from other transformers, since some
     * of them affect the local variable and stack maximums without updating
     * the code attribute to reflect the changes. This screws up the
     * data-flow analyzer, since it relies on consistent code state. Even
     * if the attribute values were updated correctly, we would have to
     * detect it, and redo analysis, which is not cheap. Instead, we are
     * better off doing all changes in initialize() before everyone else has
     * a chance to muck things up.
     */
    CodeIterator iterator = minfo.getCodeAttribute().iterator();
    while (iterator.hasNext()) {
        try {
            int pos = iterator.next();
            int c = iterator.byteAt(pos);

            if (c == AALOAD)
                initFrames(clazz, minfo);

            if (c == AALOAD || c == BALOAD || c == CALOAD || c == DALOAD
                    || c == FALOAD || c == IALOAD || c == LALOAD
                    || c == SALOAD) {
                pos = replace(cp, iterator, pos, c, getLoadReplacementSignature(c));
            } else if (c == AASTORE || c == BASTORE || c == CASTORE
                    || c == DASTORE || c == FASTORE || c == IASTORE
                    || c == LASTORE || c == SASTORE) {
                pos = replace(cp, iterator, pos, c, getStoreReplacementSignature(c));
            }

        } catch (Exception e) {
            throw new CannotCompileException(e);
        }
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:36,代码来源:TransformAccessArrayField.java

示例15: transform

import scouter.javassist.CannotCompileException; //导入依赖的package包/类
/**
 * Modifies a sequence of
 *    NEW classname
 *    DUP
 *    ...
 *    INVOKESPECIAL classname:method
 */
public int transform(CtClass clazz, int pos, CodeIterator iterator,
                     ConstPool cp) throws CannotCompileException
{
    int index;
    int c = iterator.byteAt(pos);
    if (c == NEW) {
        index = iterator.u16bitAt(pos + 1);
        if (cp.getClassInfo(index).equals(classname)) {
            if (iterator.byteAt(pos + 3) != DUP)
                throw new CannotCompileException(
                            "NEW followed by no DUP was found");

            if (newClassIndex == 0)
                newClassIndex = cp.addClassInfo(newClassName);

            iterator.write16bit(newClassIndex, pos + 1);
            ++nested;
        }
    }
    else if (c == INVOKESPECIAL) {
        index = iterator.u16bitAt(pos + 1);
        int typedesc = cp.isConstructor(classname, index);
        if (typedesc != 0 && nested > 0) {
            int nt = cp.getMethodrefNameAndType(index);
            if (newMethodNTIndex != nt) {
                newMethodNTIndex = nt;
                newMethodIndex = cp.addMethodrefInfo(newClassIndex, nt);
            }

            iterator.write16bit(newMethodIndex, pos + 1);
            --nested;
        }
    }

    return pos;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:44,代码来源:TransformNewClass.java


注:本文中的scouter.javassist.CannotCompileException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。