Package org.apache.jdo.impl.enhancer.classfile

Examples of org.apache.jdo.impl.enhancer.classfile.ClassMethod


    private void scanMethods()
    {
        // check methods
        for (final Enumeration e = classFile.methods().elements();
             e.hasMoreElements();) {
            final ClassMethod method = (ClassMethod)e.nextElement();
            final String name = method.name().asString();
            final String sig = method.signature().asString();
            affirm(name != null);
            affirm(sig != null);

            final String key = methodKey(name, sig);
            affirm(key != null);

            // for non-abstract, non-native methods, map names to class methods
            if (!method.isAbstract() && !method.isNative()) {
                final Object m = annotatableMethods.put(key, method);
                affirm(m == null);
            }

            // for 'jdo*' like methods, map names to class methods
View Full Code Here


        int res = NEGATIVE;
       
        Enumeration e = classFile.methods().elements();
        while (e.hasMoreElements()) {
            final ClassMethod method = (ClassMethod)e.nextElement();
            final String methodSig = method.signature().asString();
            final String methodArgs = Descriptor.userMethodArgs(methodSig);
            final String methodName = method.name().asString() + methodArgs;
           
            // check class-specific enhancement
            final StringWriter s = new StringWriter();
            int r = hasAnnotation(new PrintWriter(s), method, methodName);
            if (r < NEGATIVE) {
View Full Code Here

                               Set found,
                               Set missing,
                               boolean annotatable)
    {
        final String key = methodKey(methodName, expectedSig);
        final ClassMethod method = (ClassMethod)jdoLikeMethods.get(key);
        if (method == null) {
            missing.add(key);
            return;
        }
        found.add(key);

        final String foundSig = method.signature().asString();
        final int foundMods = method.access();
        if (!expectedSig.equals(foundSig) || expectedMods != foundMods) {
            env.error(
                getI18N("enhancer.class_has_illegally_declared_jdo_member",
                        new Object[]{ userClassName,
                                      methodName,
View Full Code Here

                new SyntheticAttribute(
                    pool.addUtf8(SyntheticAttribute.expectedAttrName)));
        }
       
        // create and add the method
        final ClassMethod method
            = new ClassMethod(accessFlags,
                              pool.addUtf8(methodName),
                              pool.addUtf8(methodSig),
                              methodAttrs);
        affirm(classFile.findMethod(methodName, methodSig) == null,
               "Attempt to add a repeated method.");
View Full Code Here

                    + Descriptor.userMethodResult(methodSig)
                    + " " + methodName
                    + Descriptor.userMethodArgs(methodSig));

        // get method
        final ClassMethod method = classFile.findMethod(methodName, methodSig);
        affirm(method != null,
               "Attempt to add code to a non-existing method.");

        // check the found method
        affirm(!method.isAbstract(),
               "Attempt to add code to an abstract method.");
        affirm(!method.isNative(),
               "Attempt to add code to a native method.");
        final CodeAttribute foundCodeAttr = method.codeAttribute();
        affirm(foundCodeAttr != null)// by JVM spec

        // prepend the new code to the current one
        final Insn firstInsn = codeAttr.theCode();
        affirm(firstInsn != null);
        final Insn foundFirstInsn = foundCodeAttr.theCode();
        affirm(foundFirstInsn != null);
        final Insn lastInsn = firstInsn.append(foundFirstInsn);
        affirm(lastInsn != null);
        foundCodeAttr.setTheCode(firstInsn);

        // ajust the method's stack and locals demand
        foundCodeAttr.setStackUsed(max(foundCodeAttr.stackUsed(),
                                       codeAttr.stackUsed()));
        foundCodeAttr.setLocalsUsed(max(foundCodeAttr.localsUsed(),
                                        codeAttr.localsUsed()));

        // add the exception attribute or its exceptions
        if (exceptAttr != null) {
            affirm((exceptAttr.getExceptions().size()
                    == new HashSet(exceptAttr.getExceptions()).size()),
                   "Exception attribute contains duplicate exceptions.");
           
            final ExceptionsAttribute foundExceptAttr
                = method.exceptionsAttribute();
            if (foundExceptAttr == null) {
                // add the exception attribute
                final AttributeVector methodAttrs = method.attributes();
                affirm(methodAttrs != null);
                methodAttrs.addElement(exceptAttr);
            } else {
                // add those exceptions not already present
                final List foundEx = foundExceptAttr.getExceptions();
View Full Code Here

        final Map[] classMethods = { new HashMap(), new HashMap() };
        for (int i = 0; i < 2; i++) {
            for (Enumeration e = classFiles[i].methods().elements();
                 e.hasMoreElements();) {
                final ClassMethod method = (ClassMethod)e.nextElement();
                final String methodSig = method.signature().asString();
                final String methodArgs = Descriptor.userMethodArgs(methodSig);
                final String methodName = method.name().asString();

                if (methodName.startsWith("jdo")) {
                //if (methodName.equals("jdoReplaceField")) {
                    final Object obj
                        = classMethods[i].put(methodName + methodArgs, method);
                    affirm(obj == null);
                }
            }
        }
       
        final Set keySet = new HashSet();
        keySet.addAll(classMethods[0].keySet());
        keySet.addAll(classMethods[1].keySet());
        for (Iterator i = keySet.iterator(); i.hasNext();) {
            final Object key = i.next();

            final ClassMethod method0
                = (ClassMethod)classMethods[0].remove(key);
            final ClassMethod method1
                = (ClassMethod)classMethods[1].remove(key);
            affirm(method0 != method1);
            affirm(method0 != null || method1 != null);
           
            if (method0 == null || method1 == null) {
                out.println("    !!! ERROR: missing method: " + key);
                out.println("        <<< method: " + method0);
                out.println("        >>> method: " + method1);
                res = ERROR;
                continue;
            }

            final Stack msg = new Stack();
            if (method0.isEqual(msg, method1)) {
                if (verbose) {
                    out.println("    +++ equal augmentation: " + key);
                }
            } else {
                out.println("    !!! not equal augmentation: " + key);
                msg.push("method = " + method1);
                msg.push("method = " + method0);
                final StringWriter s0 = new StringWriter();
                final StringWriter s1 = new StringWriter();
                final PrintWriter p0 = new PrintWriter(s0);
                final PrintWriter p1 = new PrintWriter(s1);
                int j = 0;
                while (!msg.empty()) {
                    p0.println("    <<< " + pad(j) + msg.pop());
                    p1.println("    >>> " + pad(j) + msg.pop());
                    j += 4;
                }
                out.println(s0.toString());
                out.println(s1.toString());

                if (verbose) {
                    ByteArrayOutputStream b0 = new ByteArrayOutputStream();
                    ByteArrayOutputStream b1 = new ByteArrayOutputStream();
                    method0.print(new PrintStream(b0), 4);
                    method1.print(new PrintStream(b1), 4);
                    out.println(b0.toString());
                    out.println(b1.toString());
                    if (res == NEGATIVE) {
                        res = AFFIRMATIVE;
                    }
View Full Code Here

        env.message("annotating class " + userClassName);

        boolean annotated = false;
        for (final Iterator i = analyzer.getAnnotatableMethods().iterator();
             i.hasNext();) {
            final ClassMethod method = (ClassMethod)i.next();
            annotated |= annotated(method);
        }
       
        // notify controller if class changed
        if (annotated) {
View Full Code Here

        final Map[] classMethods = { new HashMap(), new HashMap() };
        for (int i = 0; i < 2; i++) {
            for (Enumeration e = classFiles[i].methods().elements();
                 e.hasMoreElements();) {
                final ClassMethod method = (ClassMethod)e.nextElement();
                final String methodSig = method.signature().asString();
                final String methodArgs = Descriptor.userMethodArgs(methodSig);
                final String methodName = method.name().asString();

                if (methodName.startsWith("jdo")) {
                //if (methodName.equals("jdoReplaceField")) {
                    final Object obj
                        = classMethods[i].put(methodName + methodArgs, method);
                    affirm(obj == null);
                }
            }
        }
       
        final Set keySet = new HashSet();
        keySet.addAll(classMethods[0].keySet());
        keySet.addAll(classMethods[1].keySet());
        for (Iterator i = keySet.iterator(); i.hasNext();) {
            final Object key = i.next();

            final ClassMethod method0
                = (ClassMethod)classMethods[0].remove(key);
            final ClassMethod method1
                = (ClassMethod)classMethods[1].remove(key);
            affirm(method0 != method1);
            affirm(method0 != null || method1 != null);
           
            if (method0 == null || method1 == null) {
                out.println("    !!! ERROR: missing method: " + key);
                out.println("        <<< method: " + method0);
                out.println("        >>> method: " + method1);
                res = ERROR;
                continue;
            }

            final Stack msg = new Stack();
            if (method0.isEqual(msg, method1)) {
                if (verbose) {
                    out.println("    +++ equal augmentation: " + key);
                }
            } else {
                out.println("    !!! not equal augmentation: " + key);
                msg.push("method = " + method1);
                msg.push("method = " + method0);
                final StringWriter s0 = new StringWriter();
                final StringWriter s1 = new StringWriter();
                final PrintWriter p0 = new PrintWriter(s0);
                final PrintWriter p1 = new PrintWriter(s1);
                int j = 0;
                while (!msg.empty()) {
                    p0.println("    <<< " + pad(j) + msg.pop());
                    p1.println("    >>> " + pad(j) + msg.pop());
                    j += 4;
                }
                out.println(s0.toString());
                out.println(s1.toString());

                if (verbose) {
                    ByteArrayOutputStream b0 = new ByteArrayOutputStream();
                    ByteArrayOutputStream b1 = new ByteArrayOutputStream();
                    method0.print(new PrintStream(b0), 4);
                    method1.print(new PrintStream(b1), 4);
                    out.println(b0.toString());
                    out.println(b1.toString());
                    if (res == NEGATIVE) {
                        res = AFFIRMATIVE;
                    }
View Full Code Here

        int res = NEGATIVE;
       
        Enumeration e = classFile.methods().elements();
        while (e.hasMoreElements()) {
            final ClassMethod method = (ClassMethod)e.nextElement();
            final String methodSig = method.signature().asString();
            final String methodArgs = Descriptor.userMethodArgs(methodSig);
            final String methodName = method.name().asString() + methodArgs;
           
            // check class-specific enhancement
            final StringWriter s = new StringWriter();
            int r = hasAnnotation(new PrintWriter(s), method, methodName);
            if (r < NEGATIVE) {
View Full Code Here

    private void scanMethods()
    {
        // check methods
        for (final Enumeration e = classFile.methods().elements();
             e.hasMoreElements();) {
            final ClassMethod method = (ClassMethod)e.nextElement();
            final String name = method.name().asString();
            final String sig = method.signature().asString();
            affirm(name != null);
            affirm(sig != null);

            final String key = methodKey(name, sig);
            affirm(key != null);

            // for non-abstract, non-native methods, map names to class methods
            if (!method.isAbstract() && !method.isNative()) {
                final Object m = annotatableMethods.put(key, method);
                affirm(m == null);
            }

            // for 'jdo*' like methods, map names to class methods
View Full Code Here

TOP

Related Classes of org.apache.jdo.impl.enhancer.classfile.ClassMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.