org.apache.bcel.classfile.Method.getAttributes()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中org.apache.bcel.classfile.Method.getAttributes()方法的一些代码示例,展示了Method.getAttributes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.getAttributes()方法的具体详情如下:
包路径:org.apache.bcel.classfile.Method
类名称:Method
方法名:getAttributes

Method.getAttributes介绍

暂无

代码示例

代码示例来源:origin: spotbugs/spotbugs

/**
 * Methods marked with the "Synthetic" attribute do not appear in the source
 * code
 */
private boolean isSynthetic(Method m) {
  if ((m.getAccessFlags() & Const.ACC_SYNTHETIC) != 0) {
    return true;
  }
  Attribute[] attrs = m.getAttributes();
  for (Attribute attr : attrs) {
    if (attr instanceof Synthetic) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: spotbugs/spotbugs

private boolean markedAsNotUsable(Method obj) {
  for (Attribute a : obj.getAttributes()) {
    if (a instanceof Deprecated) {
      return true;
    }
  }
  Code code = obj.getCode();
  if (code == null) {
    return false;
  }
  byte[] codeBytes = code.getCode();
  if (codeBytes.length > 1 && codeBytes.length < 10) {
    int lastOpcode = codeBytes[codeBytes.length - 1] & 0xff;
    if (lastOpcode != Const.ATHROW) {
      return false;
    }
    for (int b : codeBytes) {
      if ((b & 0xff) == Const.RETURN) {
        return false;
      }
    }
    return true;
  }
  return false;
}

代码示例来源:origin: oracle/opengrok

fout.write(RBRA);
ArrayList<LocalVariable[]> locals = new ArrayList<>();
for (Attribute a : m.getAttributes()) {
  if (a.getTag() == org.apache.bcel.Const.ATTR_EXCEPTIONS) {
    for (int i : ((ExceptionTable) a).getExceptionIndexTable()) {

代码示例来源:origin: spotbugs/spotbugs

public void doVisitMethod(Method method) {
  if (visitingMethod) {
    throw new IllegalStateException("doVisitMethod called when already visiting a method");
  }
  visitingMethod = true;
  try {
    this.method = method;
    methodName = methodSig = dottedMethodSig = fullyQualifiedMethodName = null;
    thisMethodInfo = (MethodInfo) thisClassInfo.findMethod(getMethodName(), getMethodSig(), method.isStatic());
    assert thisMethodInfo != null : "Can't get method info for " + getFullyQualifiedMethodName();
    this.method.accept(this);
    Attribute[] attributes = method.getAttributes();
    for (Attribute attribute : attributes) {
      attribute.accept(this);
    }
  } finally {
    visitingMethod = false;
    this.method = null;
    this.thisMethodInfo = null;
  }
}

代码示例来源:origin: spotbugs/spotbugs

GenericSignatureParser parser = null;
String genericSignature = null;
for (Attribute a : target.getAttributes()) {
  if (a instanceof Signature) {

代码示例来源:origin: spotbugs/spotbugs

Attribute[] atts = getMethod().getAttributes();
for (Attribute att : atts) {
  if (att.getClass().equals(Synthetic.class)) {

代码示例来源:origin: spotbugs/spotbugs

for (Attribute a : obj.getAttributes()) {
  if (a instanceof Code) {
    code = (Code) a;

代码示例来源:origin: org.apache.bcel/bcel

/**
   * @return Annotations on the parameters of a method
   * @since 6.0
   */
  public ParameterAnnotationEntry[] getParameterAnnotationEntries() {
    if (parameterAnnotationEntries == null) {
      parameterAnnotationEntries = ParameterAnnotationEntry.createParameterAnnotationEntries(getAttributes());
    }
    return parameterAnnotationEntries;
  }
}

代码示例来源:origin: com.google.code.findbugs/findbugs

/**
 * Methods marked with the "Synthetic" attribute do not appear in the source
 * code
 */
private boolean isSynthetic(Method m) {
  if ((m.getAccessFlags() & Constants.ACC_SYNTHETIC) != 0) {
    return true;
  }
  Attribute[] attrs = m.getAttributes();
  for (Attribute attr : attrs) {
    if (attr instanceof Synthetic) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.apache.bcel/bcel

@Override
public void visitMethod(final Method method)
{
  stack.push(method);
  method.accept(visitor);
  final Attribute[] attributes = method.getAttributes();
  for (final Attribute attribute : attributes) {
    attribute.accept(this);
  }
  stack.pop();
}

代码示例来源:origin: bcel/bcel

public void visitMethod(Method method) {
 stack.push(method);
 method.accept(visitor);
 
 Attribute[] attributes = method.getAttributes();
 for(int i=0; i < attributes.length; i++)
  attributes[i].accept(this);
 stack.pop();
}

代码示例来源:origin: com.google.code.findbugs/findbugs

private boolean markedAsNotUsable(Method obj) {
  for (Attribute a : obj.getAttributes()) {
    if (a instanceof Deprecated) {
      return true;
    }
  }
  Code code = obj.getCode();
  if (code == null) {
    return false;
  }
  byte[] codeBytes = code.getCode();
  if (codeBytes.length > 1 && codeBytes.length < 10) {
    int lastOpcode = codeBytes[codeBytes.length - 1] & 0xff;
    if (lastOpcode != ATHROW) {
      return false;
    }
    for (int b : codeBytes) {
      if ((b & 0xff) == RETURN) {
        return false;
      }
    }
    return true;
  }
  return false;
}

代码示例来源:origin: Syncleus/aparapi

public ClassModelMethod(org.apache.bcel.classfile.Method method, int _index) {
  index = _index;
  methodAccessFlags = method.getAccessFlags();
  nameIndex = method.getNameIndex();
  descriptorIndex = method.getSignatureIndex();
  methodAttributePool = new AttributePool(method.getAttributes(), getName());
  codeEntry = methodAttributePool.codeEntry;
}

代码示例来源:origin: com.google.code.findbugs/findbugs

public void doVisitMethod(Method method) {
  if (visitingMethod) {
    throw new IllegalStateException("doVisitMethod called when already visiting a method");
  }
  visitingMethod = true;
  try {
    this.method = method;
    methodName = methodSig = dottedMethodSig = fullyQualifiedMethodName = null;
    thisMethodInfo = (MethodInfo) thisClassInfo.findMethod(getMethodName(), getMethodSig(), method.isStatic());
    assert thisMethodInfo != null : "Can't get method info for " + getFullyQualifiedMethodName();
    this.method.accept(this);
    Attribute[] attributes = method.getAttributes();
    for (Attribute attribute : attributes) {
      attribute.accept(this);
    }
  } finally {
    visitingMethod = false;
    this.method = null;
    this.thisMethodInfo = null;
  }
}

代码示例来源:origin: com.google.code.findbugs/findbugs

GenericSignatureParser parser = null;
String genericSignature = null;
for (Attribute a : target.getAttributes()) {
  if (a instanceof Signature) {

代码示例来源:origin: com.mebigfatguy.fb-contrib/fb-contrib

/**
 * implements the visitor to find methods that declare template parameters that are not bound to any parameter.
 *
 * @param obj
 *            the context object of the currently parsed method
 */
@Override
public void visitMethod(Method obj) {
  Attribute[] attributes = obj.getAttributes();
  for (Attribute a : attributes) {
    if ("Signature".equals(a.getName())) {
      TemplateSignature ts = parseSignatureAttribute((Signature) a);
      if (ts != null) {
        for (TemplateItem templateParm : ts.templateParameters) {
          if (!ts.signature.contains(Values.SIG_GENERIC_TEMPLATE + templateParm.templateType + Values.SIG_QUALIFIED_CLASS_SUFFIX_CHAR)
              && !isTemplateParent(templateParm.templateType, ts.templateParameters)) {
            bugReporter.reportBug(new BugInstance(this, BugType.UMTP_UNBOUND_METHOD_TEMPLATE_PARAMETER.name(), NORMAL_PRIORITY).addClass(this)
                .addMethod(this).addString("Template Parameter: " + templateParm.templateType));
            return;
          }
        }
      }
      return;
    }
  }
}

代码示例来源:origin: mebigfatguy/fb-contrib

/**
 * implements the visitor to find methods that declare template parameters that are not bound to any parameter.
 *
 * @param obj
 *            the context object of the currently parsed method
 */
@Override
public void visitMethod(Method obj) {
  Attribute[] attributes = obj.getAttributes();
  for (Attribute a : attributes) {
    if ("Signature".equals(a.getName())) {
      TemplateSignature ts = parseSignatureAttribute((Signature) a);
      if (ts != null) {
        for (TemplateItem templateParm : ts.templateParameters) {
          if (!ts.signature.contains(Values.SIG_GENERIC_TEMPLATE + templateParm.templateType + Values.SIG_QUALIFIED_CLASS_SUFFIX_CHAR)
              && !isTemplateParent(templateParm.templateType, ts.templateParameters)) {
            bugReporter.reportBug(new BugInstance(this, BugType.UMTP_UNBOUND_METHOD_TEMPLATE_PARAMETER.name(), NORMAL_PRIORITY).addClass(this)
                .addMethod(this).addString("Template Parameter: " + templateParm.templateType));
            return;
          }
        }
      }
      return;
    }
  }
}

代码示例来源:origin: com.google.code.findbugs/findbugs

Attribute[] atts = getMethod().getAttributes();
for (Attribute att : atts) {
  if (att.getClass().equals(Synthetic.class)) {

代码示例来源:origin: dragome/dragome-sdk

private void addDefaults(Type type)
{
  try
  {
    ClassUnit classUnit= Project.singleton.getClassUnit(type.toString());
    JavaClass aClass= Repository.lookupClass(type.toString());
    for (Method method : aClass.getMethods())
    {
      final AnnotationDefault a= (AnnotationDefault) findAttribute("AnnotationDefault", method.getAttributes());
      if (a != null)
        if (a.getDefaultValue() instanceof ClassElementValue)
        {
          ClassElementValue aClass1= (ClassElementValue) a.getDefaultValue();
          classUnit.addAnnotationDefault(method.getName(), aClass1.getClassString());
        }
        else
          classUnit.addAnnotationDefault(method.getName(), a.getDefaultValue().toString());
    }
  }
  catch (Exception e)
  {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.apache.bcel/bcel

/**
   * For values in an annotation that have default values, we should be able
   * to query the AnnotationDefault attribute against the method to discover
   * the default value that was originally declared.
   */
  public void testMethodAnnotations() throws ClassNotFoundException
  {
    final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.SimpleAnnotation");
    final Method m = getMethod(clazz, "fruit");
    final AnnotationDefault a = (AnnotationDefault) findAttribute(
        "AnnotationDefault", m.getAttributes());
    final SimpleElementValue val = (SimpleElementValue) a.getDefaultValue();
    assertTrue("Should be STRING but is " + val.getElementValueType(), val
        .getElementValueType() == ElementValue.STRING);
    assertTrue("Should have default of bananas but default is "
        + val.getValueString(), val.getValueString().equals("bananas"));
  }
}

相关文章