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


Java AccessFlag.STATIC属性代码示例

本文整理汇总了Java中javassist.bytecode.AccessFlag.STATIC属性的典型用法代码示例。如果您正苦于以下问题:Java AccessFlag.STATIC属性的具体用法?Java AccessFlag.STATIC怎么用?Java AccessFlag.STATIC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javassist.bytecode.AccessFlag的用法示例。


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

示例1: updateInnerEntry

private static void updateInnerEntry(int mod, String name, CtClass clazz, boolean outer) {
    ClassFile cf = clazz.getClassFile2();
    InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(
                                            InnerClassesAttribute.tag);
    if (ica == null)
        return;

    int n = ica.tableLength();
    for (int i = 0; i < n; i++)
        if (name.equals(ica.innerClass(i))) {
            int acc = ica.accessFlags(i) & AccessFlag.STATIC;
            ica.setAccessFlags(i, mod | acc);
            String outName = ica.outerClass(i);
            if (outName != null && outer)
                try {
                    CtClass parent = clazz.getClassPool().get(outName);
                    updateInnerEntry(mod, name, parent, false);
                }
                catch (NotFoundException e) {
                    throw new RuntimeException("cannot find the declaring class: "
                                               + outName);
                }

            break;
        }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:26,代码来源:CtNewNestedClass.java

示例2: firstFrame

private Frame firstFrame(MethodInfo method, int maxLocals, int maxStack) {
    int pos = 0;

    Frame first = new Frame(maxLocals, maxStack);
    if ((method.getAccessFlags() & AccessFlag.STATIC) == 0) {
        first.setLocal(pos++, Type.get(clazz));
    }

    CtClass[] parameters;
    try {
        parameters = Descriptor.getParameterTypes(method.getDescriptor(), clazz.getClassPool());
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }

    for (int i = 0; i < parameters.length; i++) {
        Type type = zeroExtend(Type.get(parameters[i]));
        first.setLocal(pos++, type);
        if (type.getSize() == 2)
            first.setLocal(pos++, Type.TOP);
    }

    return first;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:24,代码来源:Analyzer.java

示例3: addReadWriteMethods

private void addReadWriteMethods(ClassFile classfile)
		throws CannotCompileException {
	List fields = classfile.getFields();
	for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
		FieldInfo finfo = (FieldInfo) field_iter.next();
		if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0
		    && (!finfo.getName().equals(HANDLER_FIELD_NAME))) {
			// case of non-static field
			if (filter.handleRead(finfo.getDescriptor(), finfo
					.getName())) {
				addReadMethod(classfile, finfo);
				readableFields.put(finfo.getName(), finfo
						.getDescriptor());
			}
			if (filter.handleWrite(finfo.getDescriptor(), finfo
					.getName())) {
				addWriteMethod(classfile, finfo);
				writableFields.put(finfo.getName(), finfo
						.getDescriptor());
			}
		}
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:23,代码来源:FieldTransformer.java

示例4: addReadWriteMethods

private void addReadWriteMethods(ClassFile classfile) throws CannotCompileException, BadBytecode {
	final List fields = classfile.getFields();
	for ( Object field : fields ) {
		final FieldInfo finfo = (FieldInfo) field;
		if ( (finfo.getAccessFlags() & AccessFlag.STATIC) == 0 && (!finfo.getName().equals( HANDLER_FIELD_NAME )) ) {
			// case of non-static field
			if ( filter.handleRead( finfo.getDescriptor(), finfo.getName() ) ) {
				addReadMethod( classfile, finfo );
			}
			if ( filter.handleWrite( finfo.getDescriptor(), finfo.getName() ) ) {
				addWriteMethod( classfile, finfo );
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:FieldTransformer.java

示例5: getModifiers

public int getModifiers() {
    ClassFile cf = getClassFile2();
    int acc = cf.getAccessFlags();
    acc = AccessFlag.clear(acc, AccessFlag.SUPER);
    int inner = cf.getInnerAccessFlags();
    if (inner != -1 && (inner & AccessFlag.STATIC) != 0)
        acc |= AccessFlag.STATIC;

    return AccessFlag.toModifier(acc);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:10,代码来源:CtClassType.java

示例6: setModifiers

public void setModifiers(int mod) {
    ClassFile cf = getClassFile2();
    if (Modifier.isStatic(mod)) {
        int flags = cf.getInnerAccessFlags();
        if (flags != -1 && (flags & AccessFlag.STATIC) != 0)
            mod = mod & ~Modifier.STATIC;
        else
            throw new RuntimeException("cannot change " + getName() + " into a static class");
    }

    checkModify();
    cf.setAccessFlags(AccessFlag.of(mod));
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:13,代码来源:CtClassType.java

示例7: getSignature

static String getSignature(CtBehavior method)
    throws NotFoundException {
  CtClass parameterTypes[] = method.getParameterTypes();

  CodeAttribute codeAttribute = method.getMethodInfo().getCodeAttribute();

  // LocalVariableAttribute locals =
  //   (LocalVariableAttribute) codeAttribute.getAttribute("LocalVariableTable");

  StringBuffer sb = new StringBuffer();
  // jsjeon: want to print "this" as well
  boolean notStatic = method instanceof CtMethod
      && 0 == (method.getModifiers() & AccessFlag.STATIC);
  if (notStatic) {
    CtClass owner = method.getDeclaringClass();
    sb.append(" + " + printArg(owner, "$0"));
  }
  for (int i = 0; i < parameterTypes.length; i++) {
    if (notStatic || i > 0) {
      sb.append(" + \", \" ");
    }

    CtClass parameterType = parameterTypes[i];

    sb.append(" + \"");
    // jsjeon: 1=value1, 2=value2, ... => value1, value2, ...
    // sb.append(parameterNameFor(method, locals, i));
    // sb.append("\" + \"=");

    sb.append("\" + " + printArg(parameterType, "$"+(i+1)));
  }

  String signature = sb.toString();
  return signature;
}
 
开发者ID:plum-umd,项目名称:pasket,代码行数:35,代码来源:JavassistHelper.java

示例8: insertCode

@Override
    protected void insertCode(List<CtClass> box, File jarFile) throws CannotCompileException, IOException, NotFoundException {
        ZipOutputStream outStream = new JarOutputStream(new FileOutputStream(jarFile));
//        new ForkJoinPool().submit {
        for (CtClass ctClass : box) {
            if (isNeedInsertClass(ctClass.getName())) {
                //change class modifier
                ctClass.setModifiers(AccessFlag.setPublic(ctClass.getModifiers()));
                if (ctClass.isInterface() || ctClass.getDeclaredMethods().length < 1) {
                    //skip the unsatisfied class
                    zipFile(ctClass.toBytecode(), outStream, ctClass.getName().replaceAll("\\.", "/") + ".class");
                    continue;
                }

                boolean addIncrementalChange = false;
                for (CtBehavior ctBehavior : ctClass.getDeclaredBehaviors()) {
                    if (!addIncrementalChange) {
                        //insert the field
                        addIncrementalChange = true;
                        ClassPool classPool = ctBehavior.getDeclaringClass().getClassPool();
                        CtClass type = classPool.getOrNull(Constants.INTERFACE_NAME);
                        CtField ctField = new CtField(type, Constants.INSERT_FIELD_NAME, ctClass);
                        ctField.setModifiers(AccessFlag.PUBLIC | AccessFlag.STATIC);
                        ctClass.addField(ctField);
                    }
                    if (!isQualifiedMethod(ctBehavior)) {
                        continue;
                    }
                    //here comes the method will be inserted code
                    methodMap.put(ctBehavior.getLongName(), insertMethodCount.incrementAndGet());
                    try {
                        if (ctBehavior.getMethodInfo().isMethod()) {
                            CtMethod ctMethod = (CtMethod) ctBehavior;
                            boolean isStatic = (ctMethod.getModifiers() & AccessFlag.STATIC) != 0;
                            CtClass returnType = ctMethod.getReturnType();
                            String returnTypeString = returnType.getName();
                            //construct the code will be inserted in string format
                            String body = "Object argThis = null;";
                            if (!isStatic) {
                                body += "argThis = $0;";
                            }
                            String parametersClassType = getParametersClassType(ctMethod);
//                                body += "   if (com.meituan.robust.PatchProxy.isSupport(\$args, argThis, ${Constants.INSERT_FIELD_NAME}, $isStatic, " + methodMap.get(ctBehavior.longName) + ",${parametersClassType},${returnTypeString}.class)) {"
                            body += "   if (com.meituan.robust.PatchProxy.isSupport($args, argThis, " + Constants.INSERT_FIELD_NAME + ", " + isStatic +
                                    ", " + methodMap.get(ctBehavior.getLongName()) + "," + parametersClassType + "," + returnTypeString + ".class)) {";
                            body += getReturnStatement(returnTypeString, isStatic, methodMap.get(ctBehavior.getLongName()), parametersClassType, returnTypeString + ".class");
                            body += "   }";
                            //finish the insert-code body ,let`s insert it
                            ctBehavior.insertBefore(body);
                        }
                    } catch (Throwable t) {
                        //here we ignore the error
                        t.printStackTrace();
                        System.out.println("ctClass: " + ctClass.getName() + " error: " + t.getMessage());
                    }
                }
            }
            //zip the inserted-classes into output file
            zipFile(ctClass.toBytecode(), outStream, ctClass.getName().replaceAll("\\.", "/") + ".class");
        }
//        }.get()
        outStream.close();
    }
 
开发者ID:Meituan-Dianping,项目名称:Robust,代码行数:63,代码来源:JavaAssistInsertImpl.java

示例9: withinStatic

/**
 * Returns true if this method is static.
 */
protected final boolean withinStatic() {
    return (thisMethod.getAccessFlags() & AccessFlag.STATIC) != 0;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:6,代码来源:Expr.java


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