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


Java Field类代码示例

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


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

示例1: findField

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
Field findField(String className, String fieldName) {
	try {
		// System.out.println("Looking for " + className);
		JavaClass fieldDefinedIn = getThisClass();
		if (!className.equals(getClassName())) {
			// System.out.println("Using repository to look for " + className);

			fieldDefinedIn = Repository.lookupClass(className);
		}
		Field[] f = fieldDefinedIn.getFields();
		for (int i = 0; i < f.length; i++)
			if (f[i].getName().equals(fieldName)) {
				// System.out.println("Found " + f[i]);
				return f[i];
			}
		return null;
	} catch (ClassNotFoundException e) {
		return null;
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:21,代码来源:FindDoubleCheck.java

示例2: visit

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
public void visit(Field obj) {
if (getFieldName().length() == 1) return;

if (!obj.isFinal() 
	&& Character.isLetter(getFieldName().charAt(0))
	&& !Character.isLowerCase(getFieldName().charAt(0))
	&& getFieldName().indexOf("_") == -1
	&& Character.isLetter(getFieldName().charAt(1))
	&& Character.isLowerCase(getFieldName().charAt(1)))
	bugReporter.reportBug(new BugInstance(this, 
		"NM_FIELD_NAMING_CONVENTION", 
		classIsPublicOrProtected 
		 && (obj.isPublic() || obj.isProtected())  
		? NORMAL_PRIORITY
		: LOW_PRIORITY)
	        .addClass(this)
	        .addVisitedField(this)
		);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:20,代码来源:Naming.java

示例3: visit

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
public void visit(Field obj) {
	super.visit(obj);
	int flags = obj.getAccessFlags();
	boolean isStatic = (flags & ACC_STATIC) != 0;
	if (!isStatic) return;
	boolean isFinal = (flags & ACC_FINAL) != 0;
	boolean isPublic = publicClass && (flags & ACC_PUBLIC) != 0;
	boolean isProtected = publicClass && (flags & ACC_PROTECTED) != 0;
	if (!isPublic && !isProtected) return;

	boolean isHashtable = 
		getFieldSig().equals("Ljava/util/Hashtable;");
	boolean isArray = getFieldSig().charAt(0) == '[';

	if (isFinal && !(isHashtable || isArray)) return;

	FieldRecord f = new FieldRecord();
	f.className = getDottedClassName();
	f.name = getFieldName();
	f.signature = getDottedFieldSig();
	f.isPublic = isPublic;
	f.isFinal = isFinal;

	seen.add(f);

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:MutableStaticFields.java

示例4: findField

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
/**
 * Find a field with given name defined in given class.
 *
 * @param className the name of the class
 * @param fieldName the name of the field
 * @return the Field, or null if no such field could be found
 */
public static Field findField(String className, String fieldName) throws ClassNotFoundException {
	JavaClass jclass = Repository.lookupClass(className);

	while (jclass != null) {
		Field[] fieldList = jclass.getFields();
		for (int i = 0; i < fieldList.length; ++i) {
			Field field = fieldList[i];
			if (field.getName().equals(fieldName)) {
				return field;
			}
		}

		jclass = jclass.getSuperClass();
	}

	return null;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:25,代码来源:Hierarchy.java

示例5: leaveSet

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor */
public void leaveSet(Set aJavaClasses)
{
    final Iterator it = aJavaClasses.iterator();
    while (it.hasNext()) {
        final JavaClass javaClass = (JavaClass) it.next();
        final String className = javaClass.getClassName();
        final JavaClassDefinition classDef = findJavaClassDef(javaClass);
        final FieldDefinition[] fieldDefs = classDef.getFieldDefs();
        for (int i = 0; i < fieldDefs.length; i++) {
            if (fieldDefs[i].getReadReferenceCount() == 0) {
                final Field field = fieldDefs[i].getField();
                if (!field.isFinal()
                    && (!ignore(className, field))
                    )
                {
                    log(
                        javaClass,
                        0,
                        "unread.field",
                        new Object[] {fieldDefs[i]});
                }
            }
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:UnreadFieldCheck.java

示例6: visitClassContext

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
@Override
public void visitClassContext(ClassContext classContext) {
    JavaClass javaClass = classContext.getJavaClass();
    if (OBJECT_MAPPER_CLASSES.contains(javaClass.getClassName())) {
        return;
    }
    for (Field field : javaClass.getFields()) {
        analyzeField(field, javaClass);
    }
    for (Method m : javaClass.getMethods()) {
        try {
            analyzeMethod(m, classContext);
        }
        catch (CFGBuilderException | DataflowAnalysisException e) {
        }
    }
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:18,代码来源:UnsafeJacksonDeserializationDetector.java

示例7: analyzeField

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
private void analyzeField(Field field, JavaClass javaClass) {
    for (AnnotationEntry annotation : field.getAnnotationEntries())  {
        if (ANNOTATION_TYPES.contains(annotation.getAnnotationType()) ||
                annotation.getAnnotationType().contains("JsonTypeInfo")) {
            for (ElementValuePair elementValuePair : annotation.getElementValuePairs()) {
                if ("use".equals((elementValuePair.getNameString())) &&
                        VULNERABLE_USE_NAMES.contains(elementValuePair.getValue().stringifyValue())) {
                    bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY)
                            .addClass(javaClass)
                            .addString(javaClass.getClassName() + " on field " +
                                    field.getName() + " of type " + field.getType() +
                                    " annotated with " + annotation.toShortString())
                            .addField(FieldAnnotation.fromBCELField(javaClass, field))
                            .addString("")
                    );
                }
            }
        }
    }
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:21,代码来源:UnsafeJacksonDeserializationDetector.java

示例8: getFields

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
protected Field[] getFields(final ClassItem classItem, final boolean staticFields) {
  final Set<Field> fieldSet = new TreeSet<Field>(new Comparator<Field>() {

    @Override
    public int compare(final Field o1, final Field o2) {
      return o1.getName().compareTo(o2.getName());
    }
  });

  final Field[] fields = classItem.getJavaClass().getFields();
  for (final Field field : fields) {
    if (staticFields) {
      if (field.isStatic()) {
        fieldSet.add(field);
      }
    } else {
      if (!field.isStatic()) {
        fieldSet.add(field);
      }
    }
  }

  return fieldSet.toArray(new Field[fieldSet.size()]);
}
 
开发者ID:raydac,项目名称:j-j-jvm,代码行数:25,代码来源:GenerateStubDialog.java

示例9: field2str

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
protected String field2str(final Field field) {
  String modifier = "";

  if (field.isPrivate()) {
    modifier = "private ";
  } else if (field.isProtected()) {
    modifier = "protected ";
  } else if (field.isPublic()) {
    modifier = "public ";
  }

  if (field.isStatic()) {
    modifier += "static ";
  }

  if (field.isFinal()) {
    modifier += "final ";
  }

  modifier += field.getType().toString();

  modifier += ' ' + field.getName();

  return modifier;
}
 
开发者ID:raydac,项目名称:j-j-jvm,代码行数:26,代码来源:GenerateStubDialog.java

示例10: collectValidFields

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
/**
 * Collect valid fields of the wrapped class. Valid fields includes all
 * except private static and private transient.
 *
 * @param clazz
 *            - the wrapped class.
 * @return a {@link Vector} of valid fields.
 */
private Vector<Field> collectValidFields(JavaClass clazz) {
    Field[] allFields = clazz.getFields();
    Vector<Field> validFields = new Vector<Field>();
    suidField = null;

    int PRIVATE_STATIC = Modifier.PRIVATE | Modifier.STATIC;
    int PRIVATE_TRANSIENT = Modifier.PRIVATE | Modifier.TRANSIENT;

    // Excluding all PRIVATE_STATIC and PRIVATE_TRANSIENT fields
    for (int i = 0; i < allFields.length; i++) {
        if ((allFields[i].getModifiers() != PRIVATE_STATIC)
            && (allFields[i].getModifiers() != PRIVATE_TRANSIENT)) {
            // Adding
            validFields.add(allFields[i]);

            // Let's check if the Field is a existing SUID
            if (allFields[i].getName().equals("serialVersionUID")) {
                suidField = allFields[i];
            }
        }
    }
    return validFields;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:32,代码来源:Clazz.java

示例11: doVisitField

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
private void doVisitField(Field field) {
    if (visitingField)
        throw new IllegalStateException("visitField called when already visiting a field");
    visitingField = true;
    this.field = field;
    try {
        fieldName = fieldSig = dottedFieldSig = fullyQualifiedFieldName = null;
        thisFieldInfo = (FieldInfo) thisClassInfo.findField(getFieldName(), getFieldSig(), field.isStatic());
        assert thisFieldInfo !=  null : "Can't get field info for " + getFullyQualifiedFieldName();
        fieldIsStatic = field.isStatic();
        field.accept(this);
        Attribute[] attributes = field.getAttributes();
        for (Attribute attribute : attributes)
            attribute.accept(this);
    } finally {
        visitingField = false;
        this.field = null;
        this.thisFieldInfo = null;
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:21,代码来源:PreorderVisitor.java

示例12: findField

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
Field findField(String className, String fieldName) {
    try {
        // System.out.println("Looking for " + className);
        JavaClass fieldDefinedIn = getThisClass();
        if (!className.equals(getClassName())) {
            // System.out.println("Using repository to look for " +
            // className);

            fieldDefinedIn = Repository.lookupClass(className);
        }
        Field[] f = fieldDefinedIn.getFields();
        for (Field aF : f)
            if (aF.getName().equals(fieldName)) {
                // System.out.println("Found " + f[i]);
                return aF;
            }
        return null;
    } catch (ClassNotFoundException e) {
        return null;
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:22,代码来源:FindDoubleCheck.java

示例13: visit

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
@Override
public void visit(Field obj) {
    if (getFieldName().length() == 1)
        return;

    if (isEclipseNLS) {
        int flags = obj.getAccessFlags();
        if ((flags & ACC_STATIC) != 0 && ((flags & ACC_PUBLIC) != 0) && getFieldSig().equals("Ljava/lang/String;")) {
            // ignore "public statis String InstallIUCommandTooltip;"
            // messages from Eclipse NLS bundles
            return;
        }
    }
    if (badFieldName(obj)) {
        bugReporter.reportBug(new BugInstance(this, "NM_FIELD_NAMING_CONVENTION", classIsPublicOrProtected
                && (obj.isPublic() || obj.isProtected()) && !hasBadFieldNames ? NORMAL_PRIORITY : LOW_PRIORITY)
                .addClass(this).addVisitedField(this));
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:20,代码来源:Naming.java

示例14: findField

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
/**
 * Find a field with given name defined in given class.
 * 
 * @param className
 *            the name of the class
 * @param fieldName
 *            the name of the field
 * @return the Field, or null if no such field could be found
 */
public static Field findField(String className, String fieldName) throws ClassNotFoundException {
    JavaClass jclass = Repository.lookupClass(className);

    while (jclass != null) {
        Field[] fieldList = jclass.getFields();
        for (Field field : fieldList) {
            if (field.getName().equals(fieldName)) {
                return field;
            }
        }

        jclass = jclass.getSuperClass();
    }

    return null;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:Hierarchy.java

示例15: isJSP

import org.apache.bcel.classfile.Field; //导入依赖的package包/类
public static boolean isJSP(JavaClass javaClass) {
    @DottedClassName String className = javaClass.getClassName();
    if ( className.endsWith("_jsp") || className.endsWith("_tag"))
        return true;
    for(Method m : javaClass.getMethods())
        if (m.getName().startsWith("_jsp"))
            return true;
    
    for(Field f : javaClass.getFields())
        if (f.getName().startsWith("_jsp"))
            return true;
    return Subtypes2.instanceOf(className, "javax.servlet.jsp.JspPage")
            || Subtypes2.instanceOf(className, "org.apache.jasper.runtime.HttpJspBase")
            || Subtypes2.instanceOf(className, "javax.servlet.jsp.tagext.SimpleTagSupport")
            || Subtypes2.instanceOf(className, " org.apache.jasper.runtime.JspSourceDependent");
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:17,代码来源:Subtypes2.java


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