本文整理汇总了Java中org.apache.bcel.classfile.Field.isStatic方法的典型用法代码示例。如果您正苦于以下问题:Java Field.isStatic方法的具体用法?Java Field.isStatic怎么用?Java Field.isStatic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.Field
的用法示例。
在下文中一共展示了Field.isStatic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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()]);
}
示例2: 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;
}
示例3: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field field) {
if (!field.isStatic())
return;
String signature = field.getSignature();
if (signature.startsWith("Ljava/util/") && !signature.equals("Ljava/util/regex/Pattern;")
&& !signature.equals("Ljava/util/logging/Logger;") && !signature.equals("Ljava/util/BitSet;")
&& !signature.equals("Ljava/util/ResourceBundle;")
&& !signature.equals("Ljava/util/Comparator;")
&& getXField().getAnnotation(ConstantAnnotation) == null) {
boolean flagged = analysisContextContained(getXClass());
bugReporter.reportBug(new BugInstance(this, "TESTING", flagged ? NORMAL_PRIORITY : LOW_PRIORITY).addClass(this).addField(this).addType(signature));
}
}
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:17,代码来源:CheckAnalysisContextContainedAnnotation.java
示例4: visitGETSTATIC
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
public void visitGETSTATIC(GETSTATIC o){
try {
String field_name = o.getFieldName(cpg);
JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
Field[] fields = jc.getFields();
Field f = null;
for (int i=0; i<fields.length; i++){
if (fields[i].getName().equals(field_name)){
f = fields[i];
break;
}
}
if (f == null){
throw new AssertionViolatedException("Field not found?!?");
}
if (! (f.isStatic())){
constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
}
} catch (ClassNotFoundException e) {
// FIXME: maybe not the best way to handle this
throw new AssertionViolatedException("Missing class: " + e.toString());
}
}
示例5: 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()));
}
}
}
示例6: 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);
}
}
示例7: shouldIgnoreField
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
public static boolean shouldIgnoreField(JavaClass clazz, Field field) {
if (clazz.isEnum() && field.isStatic()) {
return true;
}
if (field.isSynthetic() || field.getType() instanceof BasicType) {
return true;
}
return false;
}
示例8: 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));
}
}
}
}
示例9: searchForFields
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/**
* Searches the given class for the static final fields type of which
* is a primitive data type.
*
* @param clss - a searched class.
*/
private void searchForFields(JavaClass clss) {
Field field[] = clss.getFields();
for (int i = 0; i < field.length; i++) {
Field f = field[i];
if (f.isStatic() && f.isFinal()) {
if (Type.getReturnType(f.getSignature()) instanceof BasicType) {
fields.addElement(new ClazzField(this, f));
}
}
}
}
示例10: 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);
}
}
示例11: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
if (obj.getName().equals("this$0"))
isInnerClass = true;
if (!obj.isFinal() && !obj.isStatic() && !obj.isSynthetic())
hasNonFinalFields = true;
}
示例12: visit
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
@Override
public void visit(Field obj) {
if (obj.getName().equals("this$0"))
isInnerClass = true;
if (!obj.isFinal() && !obj.isStatic() && !BCELUtil.isSynthetic(obj))
hasNonFinalFields = true;
}
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:8,代码来源:FunctionsThatMightBeMistakenForProcedures.java
示例13: visitPUTSTATIC
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
public void visitPUTSTATIC(PUTSTATIC o){
try {
String field_name = o.getFieldName(cpg);
JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
Field[] fields = jc.getFields();
Field f = null;
for (int i=0; i<fields.length; i++){
if (fields[i].getName().equals(field_name)){
f = fields[i];
break;
}
}
if (f == null){
throw new AssertionViolatedException("Field not found?!?");
}
if (f.isFinal()){
if (!(myOwner.getClassName().equals(o.getClassType(cpg).getClassName()))){
constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getClassType(cpg).getClassName()+"'.");
}
}
if (! (f.isStatic())){
constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
}
String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getName();
// If it's an interface, it can be set only in <clinit>.
if ((!(jc.isClass())) && (!(meth_name.equals(Constants.STATIC_INITIALIZER_NAME)))){
constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Constants.STATIC_INITIALIZER_NAME+"' method.");
}
} catch (ClassNotFoundException e) {
// FIXME: maybe not the best way to handle this
throw new AssertionViolatedException("Missing class: " + e.toString());
}
}
示例14: 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;
}
示例15: visitGETFIELD
import org.apache.bcel.classfile.Field; //导入方法依赖的package包/类
/**
* Ensures the specific preconditions of the said instruction.
*/
public void visitGETFIELD(GETFIELD o){
Type objectref = stack().peek();
if (! ( (objectref instanceof ObjectType) || (objectref == Type.NULL) ) ){
constraintViolated(o, "Stack top should be an object reference that's not an array reference, but is '"+objectref+"'.");
}
String field_name = o.getFieldName(cpg);
JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
Field[] fields = jc.getFields();
Field f = null;
for (int i=0; i<fields.length; i++){
if (fields[i].getName().equals(field_name)){
f = fields[i];
break;
}
}
if (f == null){
throw new AssertionViolatedException("Field not found?!?");
}
if (f.isProtected()){
ObjectType classtype = o.getClassType(cpg);
ObjectType curr = new ObjectType(mg.getClassName());
if ( classtype.equals(curr) ||
curr.subclassOf(classtype) ){
Type t = stack().peek();
if (t == Type.NULL){
return;
}
if (! (t instanceof ObjectType) ){
constraintViolated(o, "The 'objectref' must refer to an object that's not an array. Found instead: '"+t+"'.");
}
ObjectType objreftype = (ObjectType) t;
if (! ( objreftype.equals(curr) ||
objreftype.subclassOf(curr) ) ){
//TODO: One day move to Staerk-et-al's "Set of object types" instead of "wider" object types
// created during the verification.
// "Wider" object types don't allow us to check for things like that below.
//constraintViolated(o, "The referenced field has the ACC_PROTECTED modifier, and it's a member of the current class or a superclass of the current class. However, the referenced object type '"+stack().peek()+"' is not the current class or a subclass of the current class.");
}
}
}
// TODO: Could go into Pass 3a.
if (f.isStatic()){
constraintViolated(o, "Referenced field '"+f+"' is static which it shouldn't be.");
}
}