本文整理汇总了Java中org.apache.bcel.classfile.Field.getAccessFlags方法的典型用法代码示例。如果您正苦于以下问题:Java Field.getAccessFlags方法的具体用法?Java Field.getAccessFlags怎么用?Java Field.getAccessFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.Field
的用法示例。
在下文中一共展示了Field.getAccessFlags方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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));
}
}
示例3: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public void visit(Field obj) {
super.visit(obj);
FieldAnnotation f = FieldAnnotation.fromVisitedField(this);
int flags = obj.getAccessFlags();
boolean publicField = (flags & ACC_PUBLIC) != 0;
boolean volatileField = (flags & ACC_VOLATILE) != 0;
boolean finalField = (flags & ACC_FINAL) != 0;
if (publicField)
publicFields.add(f);
if (volatileField || finalField)
volatileOrFinalFields.add(f);
}
示例4: findXField
import org.apache.bcel.classfile.Field; //导入方法依赖的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);
}
}
示例5: Attribute
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public Attribute(JavaClass javaClass, Field field, boolean isParseAnnotation) {
this.javaClass = javaClass;
this.javaClassId = javaClass.getId();
this.access_flags = field.getAccessFlags();
this.info = field.toString();
this.name = field.getName();
this.signature = SignatureUtil.getSignature(field);
this.types = new ArrayList<String>();
for (String type : ParseUtil.signatureToTypes(this.signature)) {
this.types.add(type);
}
if (field.isStatic() && field.getConstantValue() != null) {
staticValue = field.getConstantValue().toString();
}
this.annotationRefs = new AnnotationRefs();
// 处理Annotation
if (isParseAnnotation) {
for (AnnotationEntry annotationEntry : field.getAnnotationEntries()) {
if (annotationEntry.getAnnotationType().equals(AnnotationParse.Autowired)) {
this.annotationRefs.setAutowired(AnnotationParse.parseAutowired(annotationEntry));
} else if (annotationEntry.getAnnotationType().equals(AnnotationParse.Qualifier)) {
this.annotationRefs.setQualifier(AnnotationParse.parseQualifier(annotationEntry));
}
}
}
}
示例6: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
super.visit(obj);
int flags = obj.getAccessFlags();
boolean isStatic = (flags & ACC_STATIC) != 0;
if (!isStatic) {
return;
}
boolean isVolatile = (flags & ACC_VOLATILE) != 0;
if (isVolatile) {
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;
}
if (isEclipseNLS && getFieldSig().equals("Ljava/lang/String;")) {
return;
}
seen.add(getXField());
}
示例7: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
int accessFlags = obj.getAccessFlags();
if ((accessFlags & ACC_STATIC) != 0)
return;
if (!obj.getName().startsWith("this$") && !obj.isSynthetic() && !obj.isTransient())
hasFields = true;
}
示例8: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
int accessFlags = obj.getAccessFlags();
if ((accessFlags & ACC_STATIC) != 0)
return;
if (!obj.getName().startsWith("this$") && !BCELUtil.isSynthetic(obj) && !obj.isTransient())
hasFields = true;
}
示例9: FieldGen
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/**
* Instantiate from existing field.
*
* @param field Field object
* @param cp constant pool (must contain the same entries as the field's constant pool)
*/
public FieldGen(Field field, ConstantPoolGen cp) {
this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp);
Attribute[] attrs = field.getAttributes();
for (int i = 0; i < attrs.length; i++) {
if (attrs[i] instanceof ConstantValue) {
setValue(((ConstantValue) attrs[i]).getConstantValueIndex());
} else {
addAttribute(attrs[i]);
}
}
}
示例10: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public void visit(Field obj) {
int accessFlags = obj.getAccessFlags();
if ((accessFlags & ACC_STATIC) != 0) return;
if (!obj.getName().startsWith("this$"))
hasFields = true;
}
示例11: 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);
}
示例12: 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.");
}
}
}