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


Java Field.isPrivate方法代码示例

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


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

示例1: 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

示例2: scanFields

import org.apache.bcel.classfile.Field; //导入方法依赖的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

示例3: visitObject

import org.apache.bcel.classfile.Field; //导入方法依赖的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

示例4: visit

import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/**
 * Checks if the visited field is of type {@link java.util.Calendar} or
 * {@link java.text.DateFormat} or a subclass of either one. If so and the
 * field is static and non-private it is suspicious and will be reported.
 */
@Override
public void visit(Field aField) {
    if (aField.isPrivate()) {
        /*
         * private fields are harmless, as long as they are used correctly
         * inside their own class. This should be something the rest of this
         * detector can find out, so do not report them, they might be false
         * positives.
         */
        return;
    }
    String superclassName = getSuperclassName();
    if (!aField.isStatic() && !superclassName.equals("java/lang/Enum"))
        return;
    if (!aField.isPublic() && !aField.isProtected())
        return;
    ClassDescriptor classOfField = DescriptorFactory.createClassDescriptorFromFieldSignature(aField.getSignature());
    String tBugType = null;
    int priority = aField.isPublic() && aField.isFinal() && aField.getName().equals(aField.getName().toUpperCase())
            && getThisClass().isPublic() ? HIGH_PRIORITY : NORMAL_PRIORITY;
    if (classOfField != null)
        try {
            if (subtypes2.isSubtype(classOfField, calendarType)) {
                tBugType = "STCAL_STATIC_CALENDAR_INSTANCE";
                priority++;
            } else if (subtypes2.isSubtype(classOfField, dateFormatType)) {
                tBugType = "STCAL_STATIC_SIMPLE_DATE_FORMAT_INSTANCE";
            }
            if (getClassContext().getXClass().usesConcurrency())
                priority--;
            if (tBugType != null) {

                pendingBugs.put(getXField(), new BugInstance(this, tBugType, priority).addClass(currentClass).addField(this));
            }
        } catch (ClassNotFoundException e) {
            AnalysisContext.reportMissingClass(e);
        }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:45,代码来源:StaticCalendarDetector.java

示例5: isStaticOnlyClass

import org.apache.bcel.classfile.Field; //导入方法依赖的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

示例6: visit

import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(JavaClass obj) {
    classFields.clear();

    Field[] fields = obj.getFields();
    String fieldName;
    for (Field field : fields)
        if (!field.isStatic() && !field.isPrivate()) {
            fieldName = field.getName();
            classFields.put(fieldName, field);
        }

    // Walk up the super class chain, looking for name collisions

    XClass c = getXClass();
    while (true) {
        ClassDescriptor s = c.getSuperclassDescriptor();
        if (s == null || s.getClassName().equals("java/lang/Object"))
            break;
        try {
            c = Global.getAnalysisCache().getClassAnalysis(XClass.class, s);
        } catch (CheckedAnalysisException e) {
            break;
        }
        XClass superClass = c;
        for (XField fld : c.getXFields()) {
            if (!fld.isStatic() && (fld.isPublic() || fld.isProtected())) {
                fieldName = fld.getName();
                if (fieldName.length() == 1)
                    continue;
                if (fieldName.equals("serialVersionUID"))
                    continue;
                String superClassName = s.getClassName();
                if (superClassName.startsWith("java/io")
                        && (superClassName.endsWith("InputStream") && fieldName.equals("in") || superClassName
                                .endsWith("OutputStream") && fieldName.equals("out")))
                    continue;
                if (classFields.containsKey(fieldName)) {
                    Field maskingField = classFields.get(fieldName);
                    String mClassName = getDottedClassName();
                    FieldAnnotation fa = new FieldAnnotation(mClassName, maskingField.getName(), maskingField.getSignature(),
                            maskingField.isStatic());
                    int priority = NORMAL_PRIORITY;
                    if (maskingField.isStatic() || maskingField.isFinal())
                        priority++;
                    else if (fld.getSignature().charAt(0) == 'L' && !fld.getSignature().startsWith("Ljava/lang/")
                            || fld.getSignature().charAt(0) == '[')
                        priority--;
                    if (!fld.getSignature().equals(maskingField.getSignature()))
                        priority += 2;
                    else if (fld.getAccessFlags() != maskingField.getAccessFlags())
                        priority++;
                    if (fld.isSynthetic() || fld.getName().indexOf('$') >= 0)
                        priority++;

                    FieldAnnotation maskedFieldAnnotation = FieldAnnotation.fromFieldDescriptor(fld.getFieldDescriptor());
                    BugInstance bug = new BugInstance(this, "MF_CLASS_MASKS_FIELD", priority).addClass(this).addField(fa)
                            .describe("FIELD_MASKING").addField(maskedFieldAnnotation).describe("FIELD_MASKED");
                    rememberedBugs.add(new RememberedBug(bug, fa, maskedFieldAnnotation));

                }
            }
        }
    }

    super.visit(obj);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:68,代码来源:FindMaskedFields.java

示例7: visitField

import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public void visitField(Field obj){

			if (jc.isClass()){
				int maxone=0;
				if (obj.isPrivate()) {
                    maxone++;
                }
				if (obj.isProtected()) {
                    maxone++;
                }
				if (obj.isPublic()) {
                    maxone++;
                }
				if (maxone > 1){
					throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
				}

				if (obj.isFinal() && obj.isVolatile()){
					throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set.");
				}
			}
			else{ // isInterface!
				if (!obj.isPublic()){
					throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!");
				}
				if (!obj.isStatic()){
					throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!");
				}
				if (!obj.isFinal()){
					throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_FINAL modifier set but hasn't!");
				}
			}

			if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_VOLATILE|ACC_TRANSIENT)) > 0){
				addMessage("Field '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored).");
			}

			checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

			String name = obj.getName();
			if (! validFieldName(name)){
				throw new ClassConstraintException("Field '"+tostring(obj)+"' has illegal name '"+obj.getName()+"'.");
			}

			// A descriptor is often named signature in BCEL
			checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);

			String sig  = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)

			try{
				Type.getType(sig);  /* Don't need the return value */
			}
			catch (ClassFormatException cfe){
                throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
			}

			String nameanddesc = (name+sig);
			if (field_names_and_desc.contains(nameanddesc)){
				throw new ClassConstraintException("No two fields (like '"+tostring(obj)+"') are allowed have same names and descriptors!");
			}
			if (field_names.contains(name)){
				addMessage("More than one field of name '"+name+"' detected (but with different type descriptors). This is very unusual.");
			}
			field_names_and_desc.add(nameanddesc);
			field_names.add(name);

			Attribute[] atts = obj.getAttributes();
			for (int i=0; i<atts.length; i++){
				if ((! (atts[i] instanceof ConstantValue)) &&
				    (! (atts[i] instanceof Synthetic))     &&
				    (! (atts[i] instanceof Deprecated))){
					addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is unknown and will therefore be ignored.");
				}
				if  (! (atts[i] instanceof ConstantValue)){
					addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is not a ConstantValue and is therefore only of use for debuggers and such.");
				}
			}
		}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:79,代码来源:Pass2Verifier.java


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