當前位置: 首頁>>代碼示例>>Java>>正文


Java JavaClass.getFields方法代碼示例

本文整理匯總了Java中org.apache.bcel.classfile.JavaClass.getFields方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaClass.getFields方法的具體用法?Java JavaClass.getFields怎麽用?Java JavaClass.getFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.bcel.classfile.JavaClass的用法示例。


在下文中一共展示了JavaClass.getFields方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findField

import org.apache.bcel.classfile.JavaClass; //導入方法依賴的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: findField

import org.apache.bcel.classfile.JavaClass; //導入方法依賴的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

示例3: visitClassContext

import org.apache.bcel.classfile.JavaClass; //導入方法依賴的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

示例4: scanFields

import org.apache.bcel.classfile.JavaClass; //導入方法依賴的package包/類
private void scanFields(JavaClass jclass, Set<XField> assignableFieldSet) {
	JavaClass myClass = classContext.getJavaClass();
	String myClassName = myClass.getClassName();
	String myPackageName = myClass.getPackageName();

	String superClassName = jclass.getClassName();
	String superPackageName = jclass.getPackageName();

	Field[] fieldList = jclass.getFields();
	for (int i = 0; i < fieldList.length; ++i) {
		Field field = fieldList[i];
		if (field.isStatic())
			continue;
		boolean assignable = false;
		if (field.isPublic() || field.isProtected())
			assignable = true;
		else if (field.isPrivate())
			assignable = myClassName.equals(superClassName);
		else // package protected
			assignable = myPackageName.equals(superPackageName);

		if (assignable) {
			assignableFieldSet.add(new InstanceField(superClassName, field.getName(), field.getSignature(),
			        field.getAccessFlags()));
		}
	}
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:28,代碼來源:AssignedFieldMap.java

示例5: findXField

import org.apache.bcel.classfile.JavaClass; //導入方法依賴的package包/類
/**
 * Look up a field with given name and signature in given class,
 * returning it as an {@link XField XField} object.
 * If a field can't be found in the immediate class,
 * its superclass is search, and so forth.
 *
 * @param className name of the class through which the field
 *                  is referenced
 * @param fieldName name of the field
 * @param fieldSig  signature of the field
 * @return an XField object representing the field, or null if no such field could be found
 */
public static XField findXField(String className, String fieldName, String fieldSig)
        throws ClassNotFoundException {

	JavaClass classDefiningField = Repository.lookupClass(className);

	Field field = null;
	loop:
		while (classDefiningField != null) {
			Field[] fieldList = classDefiningField.getFields();
			for (int i = 0; i < fieldList.length; ++i) {
				field = fieldList[i];
				if (field.getName().equals(fieldName) && field.getSignature().equals(fieldSig)) {
					break loop;
				}
			}

			classDefiningField = classDefiningField.getSuperClass();
		}

	if (classDefiningField == null)
		return null;
	else {
		String realClassName = classDefiningField.getClassName();
		int accessFlags = field.getAccessFlags();
		return field.isStatic()
		        ? (XField) new StaticField(realClassName, fieldName, fieldSig, accessFlags)
		        : (XField) new InstanceField(realClassName, fieldName, fieldSig, accessFlags);
	}
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:42,代碼來源:Hierarchy.java

示例6: visitObject

import org.apache.bcel.classfile.JavaClass; //導入方法依賴的package包/類
/** @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor */
public void visitObject(Object aJavaClass)
{
    final JavaClass javaClass = (JavaClass) aJavaClass;
    final String className = javaClass.getClassName();
    final JavaClass[] superClasses = javaClass.getSuperClasses();
    final Field[] fields = javaClass.getFields();
    // Check all fields
    for (int i = 0; i < fields.length; i++) {
        final Field field = fields[i];
        // Go through all superclasses
        for (int j = 0; j < superClasses.length; j++) {
            final JavaClass superClass = superClasses[j];
            final String superClassName = superClass.getClassName();
            final Field[] superClassFields = superClass.getFields();
            // Go through the filds of the superclasses
            for (int k = 0; k < superClassFields.length; k++) {
                final Field superClassField = superClassFields[k];
                if (!superClassField.isPrivate() &&
                    superClassField.getName().equals(field.getName()) &&
                    !ignore(className, field)) {
                    log(
                        javaClass,
                        0,
                        "hidden.inherited.field",
                        new Object[] {fields[i], superClassName});
                }
            }
        }
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:32,代碼來源:HiddenInheritedFieldCheck.java

示例7: JavaClassDefinition

import org.apache.bcel.classfile.JavaClass; //導入方法依賴的package包/類
/**
 * Creates a JavaClassDefinition from a JavaClass. The fields and
 * methods of the JavaClassDefinition are those whose scopes are
 * in restricted sets of Scopes.
 * @param aJavaClass the JavaClass for the definition.
 * @param aFieldScopes the restricted set of field scopes.
 * @param aMethodScopes the restriced set of method scopes.
 */
public JavaClassDefinition(
    JavaClass aJavaClass,
    Set aFieldScopes,
    Set aMethodScopes)
{
    mJavaClass = aJavaClass;

    // create method definitions, restricted by scope
    final Method[] methods = aJavaClass.getMethods();
    final Set methodSet = new HashSet();
    mMethodDefs = new MethodDefinition[methods.length];
    for (int i = 0; i < methods.length; i++) {
        if (Utils.inScope(methods[i], aMethodScopes)) {
            methodSet.add(new MethodDefinition(methods[i]));
        }
    }
    mMethodDefs =
        (MethodDefinition[]) methodSet.toArray(
            new MethodDefinition[methodSet.size()]);

    // create field definitions, restricted by scope
    final Field[] fields = aJavaClass.getFields();
    mFieldDefs = new HashMap(fields.length);
    for (int i = 0; i < fields.length; i++) {
        if (Utils.inScope(fields[i], aFieldScopes)) {
            mFieldDefs.put(
                fields[i].getName(),
                new FieldDefinition(fields[i]));
        }
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:40,代碼來源:JavaClassDefinition.java

示例8: isStaticOnlyClass

import org.apache.bcel.classfile.JavaClass; //導入方法依賴的package包/類
private boolean isStaticOnlyClass(String clsName) throws ClassNotFoundException {
JavaClass cls = Repository.lookupClass(clsName);
if (cls.getInterfaceNames().length > 0)
	return false;
String superClassName = cls.getSuperclassName();
if (!superClassName.equals("java.lang.Object"))
	return false;

Method[] methods = cls.getMethods();
int staticCount = 0;
for (int i = 0; i < methods.length; i++) {
	Method m = methods[i];
	if (m.isStatic()) {
		staticCount++;
		continue;
		}
	
	if (m.getName().equals("<init>")) {
		if (!m.getSignature().equals("()V"))
			return false;
		
		Code c = m.getCode();

		if (c.getCode().length > 5)
			return false;
	} else {
		return false;
	}
}

Field[] fields = cls.getFields();
for (int i = 0; i < fields.length; i++) {
	Field f = fields[i];
	if (f.isStatic()) {
		staticCount++;
		continue;
		}
	
	if (!f.isPrivate())
		return false;
}

if (staticCount == 0) return false;
return true;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:46,代碼來源:InstantiateStaticClass.java


注:本文中的org.apache.bcel.classfile.JavaClass.getFields方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。