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


Java Method.isStatic方法代码示例

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


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

示例1: visit

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
public void visit(Method obj) {
	if (!validClass)
		return;
	validMethod = false;
	methodName = obj.getName();
	if (methodName.equals("setUp") || methodName.equals("tearDown")) {
		if (methodName.equals("setUp"))
			setUpAnnotation = MethodAnnotation.fromVisitedMethod(this);
		else if (methodName.equals("tearDown"))
			tearDownAnnotation = MethodAnnotation.fromVisitedMethod(this);
		validMethod = true;
		state = SEEN_NOTHING;
		super.visit(obj);
	} else if (methodName.equals("suite") && !obj.isStatic())
		bugReporter.reportBug(new BugInstance(this, "IJU_SUITE_NOT_STATIC", NORMAL_PRIORITY)
		        .addClass(this)
		        .addMethod(MethodAnnotation.fromVisitedMethod(this)));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:19,代码来源:InvalidJUnitTest.java

示例2: visit

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
public void visit(Method obj) {
//		methodIsFinal = obj.isFinal();
		methodIsStatic = obj.isStatic();
//		methodIsVisibleToOtherPackages = obj.isPublic() || obj.isProtected();
		state = 0;
		sawGetClass = -100;
	}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:8,代码来源:InheritanceUnsafeGetResource.java

示例3: findPrototypeMethod

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
/**
	 * Get the method which serves as a "prototype" for the
	 * given InvokeInstruction.  The "prototype" is the method
	 * which defines the contract for the invoked method,
	 * in particular the declared list of exceptions that the
	 * method can throw.
	 * <p/>
	 * <ul>
	 * <li> For invokestatic and invokespecial, this is simply an
	 * exact lookup.
	 * <li> For invokevirtual, the named class is searched,
	 * followed by superclasses  up to the root of the object
	 * hierarchy (java.lang.Object).
	 * <li> For invokeinterface, the named class is searched,
	 * followed by all interfaces transitively declared by the class.
	 * (Question: is the order important here? Maybe the VM spec
	 * requires that the actual interface desired is given,
	 * so the extended lookup will not be required. Should check.)
	 * </ul>
	 *
	 * @param inv the InvokeInstruction
	 * @param cpg the ConstantPoolGen used by the class the InvokeInstruction belongs to
	 * @return the Method, or null if no matching method can be found
	 */
	public static Method findPrototypeMethod(InvokeInstruction inv, ConstantPoolGen cpg)
	        throws ClassNotFoundException {
		Method m = null;

		String className = inv.getClassName(cpg);
		String methodName = inv.getName(cpg);
		String methodSig = inv.getSignature(cpg);

		// Find the method
		if (inv instanceof INVOKESTATIC || inv instanceof INVOKESPECIAL) {
			// Non-virtual dispatch
			m = findExactMethod(inv, cpg);
			if (m == null) {
				// XXX
/*
				System.out.println("Could not resolve " + inv + " in " +
					SignatureConverter.convertMethodSignature(inv, cpg));
*/
			} else if (inv instanceof INVOKESTATIC && !m.isStatic()) {
				m = null;
			}
		} else if (inv instanceof INVOKEVIRTUAL) {
			// Virtual dispatch
			m = findMethod(Repository.lookupClass(className), methodName, methodSig);
			if (m == null) {
				JavaClass[] superClassList = Repository.getSuperClasses(className);
				m = findMethod(superClassList, methodName, methodSig);
			}
		} else if (inv instanceof INVOKEINTERFACE) {
			// Interface dispatch
			m = findMethod(Repository.lookupClass(className), methodName, methodSig);
			if (m == null) {
				JavaClass[] interfaceList = Repository.getInterfaces(className);
				m = findMethod(interfaceList, methodName, methodSig);
			}
		}

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

示例4: isSelfCall

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
/**
 * Is the given instruction a self-call?
 */
private Method isSelfCall(InvokeInstruction inv) {
	ConstantPoolGen cpg = classContext.getConstantPoolGen();
	JavaClass jclass = classContext.getJavaClass();

	String calledClassName = inv.getClassName(cpg);

	// FIXME: is it possible we would see a superclass name here?
	// Not a big deal for now, as we are mostly just interested in calls
	// to private methods, for which we will definitely see the right
	// called class name.
	if (!calledClassName.equals(jclass.getClassName()))
		return null;

	String calledMethodName = inv.getMethodName(cpg);
	String calledMethodSignature = inv.getSignature(cpg);
	boolean isStaticCall = (inv instanceof INVOKESTATIC);

	// Scan methods for one that matches.
	Method[] methods = jclass.getMethods();
	for (int i = 0; i < methods.length; ++i) {
		Method method = methods[i];

		String methodName = method.getName();
		String signature = method.getSignature();
		boolean isStatic = method.isStatic();

		if (methodName.equals(calledMethodName) &&
		        signature.equals(calledMethodSignature) &&
		        isStatic == isStaticCall) {
			// This method looks like a match.
			return wantCallsFor(method) ? method : null;
		}
	}

	// Hmm...no matching method found.
	// This is almost certainly because the named method
	// was inherited from a superclass.
	if (DEBUG) System.out.println("No method found for " + calledClassName + "." + calledMethodName + " : " + calledMethodSignature);
	return null;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:44,代码来源:SelfCalls.java

示例5: isStaticOnlyClass

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

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
public static boolean isMainMethod(Method method) {
	return method.isStatic()
	        && method.getName().equals("main")
	        && method.getSignature().equals("([Ljava/lang/String;)V");
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:6,代码来源:FindOpenStream.java

示例7: execute

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
public void execute() throws CFGBuilderException, DataflowAnalysisException {
	if (CONSERVE_SPACE) throw new IllegalStateException("This should not happen");

	HashSet<Edge> deletedEdgeSet = new HashSet<Edge>();

	if (DEBUG)
		System.out.println("PruneUnconditionalExceptionThrowerEdges: examining " +
		        SignatureConverter.convertMethodSignature(methodGen));

	for (Iterator<BasicBlock> i = cfg.blockIterator(); i.hasNext();) {
		BasicBlock basicBlock = i.next();
		if (!basicBlock.isExceptionThrower())
			continue;

		Instruction exceptionThrower = basicBlock.getExceptionThrower().getInstruction();
		if (!(exceptionThrower instanceof InvokeInstruction))
			continue;

		InvokeInstruction inv = (InvokeInstruction) exceptionThrower;
		try {
			String className = inv.getClassName(cpg);
			if (className.startsWith("["))
				continue;
			JavaClass javaClass = Repository.lookupClass(className);
			ClassContext classContext = analysisContext.getClassContext(javaClass);

			if (DEBUG) System.out.println("\tlooking up method for " + basicBlock.getExceptionThrower());
			Method method = Hierarchy.findExactMethod(inv, cpg);
			if (method == null) {
				if (DEBUG) System.out.println("\tNOT FOUND");
				continue;
			}
			if (DEBUG) System.out.println("\tFound " + method.toString());

			// FIXME: for now, only allow static and private methods.
			// Could also allow final methods (but would require class hierarchy
			// search).
			if (!(method.isStatic() || method.isPrivate()))
				continue;

			// Ignore abstract and native methods
			MethodGen calledMethodGen = classContext.getMethodGen(method);
			if (calledMethodGen == null)
				continue;

			// Analyze exception paths of called method
			// to see if it always throws an unhandled exception.
			CFG calledCFG = classContext.getCFG(method);
			ReturnPathDataflow pathDataflow = classContext.getReturnPathDataflow(method);
			ReturnPath pathValue = pathDataflow.getStartFact(calledCFG.getExit());

			if (pathValue.getKind() != ReturnPath.RETURNS) {
				// Method always throws an unhandled exception
				// or calls System.exit().
				// Remove the normal control flow edge from the CFG.
				Edge fallThrough = cfg.getOutgoingEdgeWithType(basicBlock, FALL_THROUGH_EDGE);
				if (fallThrough != null) {
					if (DEBUG) {
						System.out.println("\tREMOVING normal return for:");
						System.out.println("\t  Call to " + SignatureConverter.convertMethodSignature(calledMethodGen));
						System.out.println("\t  In method " + SignatureConverter.convertMethodSignature(methodGen));
					}
					deletedEdgeSet.add(fallThrough);
				}
			}
		} catch (ClassNotFoundException e) {
			analysisContext.getLookupFailureCallback().reportMissingClass(e);
		}
	}

	// Remove all edges marked for deletion
	for (Iterator<Edge> i = deletedEdgeSet.iterator(); i.hasNext();) {
		Edge edge = i.next();
		cfg.removeEdge(edge);
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:77,代码来源:PruneUnconditionalExceptionThrowerEdges.java

示例8: visitObject

import org.apache.bcel.classfile.Method; //导入方法依赖的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 Method[] methods = javaClass.getMethods();
    // Check all methods
    for (int i = 0; i < methods.length; i++) {
        final Method method = methods[i];
        // Check that the method is a possible match
        if (!method.isPrivate() && method.isStatic())  {
            // Go through all their superclasses
            for (int j = 0; j < superClasses.length; j++) {
                final JavaClass superClass = superClasses[j];
                final String superClassName = superClass.getClassName();
                final Method[] superClassMethods = superClass.getMethods();
                // Go through the methods of the superclasses
                for (int k = 0; k < superClassMethods.length; k++) {
                    final Method superClassMethod = superClassMethods[k];
                    if (superClassMethod.getName().equals(method.getName()) &&
                        !ignore(className, method)) {
                        Type[] methodTypes = method.getArgumentTypes();
                        Type[] superTypes = superClassMethod.
                            getArgumentTypes();
                        if (methodTypes.length == superTypes.length) {
                            boolean match = true;
                            for (int arg = 0; arg < methodTypes.length; arg++) {
                                if (!methodTypes[arg].equals(superTypes[arg])) {
                                    match = false;
                                }
                            }
                            // Same method parameters
                            if (match) {
                                log(
                                    javaClass,
                                    0,
                                    "hidden.static.method",
                                    new Object[] {method, superClassName});
                            }
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:48,代码来源:HiddenStaticMethodCheck.java


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