本文整理汇总了Java中com.sun.jdi.Method类的典型用法代码示例。如果您正苦于以下问题:Java Method类的具体用法?Java Method怎么用?Java Method使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Method类属于com.sun.jdi包,在下文中一共展示了Method类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test1
import com.sun.jdi.Method; //导入依赖的package包/类
@SuppressWarnings("unused") // called via reflection
private void test1() throws Exception {
System.out.println("DEBUG: ------------> Running test1");
try {
Field field = targetClass.fieldByName("fooCls");
ClassType clsType = (ClassType)field.type();
Method constructor = getConstructorForClass(clsType);
for (int i = 0; i < 15; i++) {
@SuppressWarnings({ "rawtypes", "unchecked" })
ObjectReference objRef = clsType.newInstance(mainThread,
constructor,
new ArrayList(0),
ObjectReference.INVOKE_NONVIRTUAL);
if (objRef.isCollected()) {
System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
continue;
}
invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
}
} catch (InvocationException e) {
handleFailure(e);
}
}
示例2: allMethods
import com.sun.jdi.Method; //导入依赖的package包/类
/**
* Shared implementation of {@linkplain ClassType#allMethods()} and
* {@linkplain InterfaceType#allMethods()}
* @return A list of all methods (recursively)
*/
public final List<Method> allMethods() {
ArrayList<Method> list = new ArrayList<>(methods());
ClassType clazz = superclass();
while (clazz != null) {
list.addAll(clazz.methods());
clazz = clazz.superclass();
}
/*
* Avoid duplicate checking on each method by iterating through
* duplicate-free allInterfaces() rather than recursing
*/
for (InterfaceType interfaze : getAllInterfaces()) {
list.addAll(interfaze.methods());
}
return list;
}
示例3: ungrabWindowAWT
import com.sun.jdi.Method; //导入依赖的package包/类
private boolean ungrabWindowAWT(ThreadReference tr, ObjectReference grabbedWindow) {
// Call XBaseWindow.ungrabInput()
try {
VirtualMachine vm = MirrorWrapper.virtualMachine(grabbedWindow);
List<ReferenceType> xbaseWindowClassesByName = VirtualMachineWrapper.classesByName(vm, "sun.awt.X11.XBaseWindow");
if (xbaseWindowClassesByName.isEmpty()) {
logger.info("Unable to release X grab, no XBaseWindow class in target VM "+VirtualMachineWrapper.description(vm));
return false;
}
ClassType XBaseWindowClass = (ClassType) xbaseWindowClassesByName.get(0);
Method ungrabInput = XBaseWindowClass.concreteMethodByName("ungrabInput", "()V");
if (ungrabInput == null) {
logger.info("Unable to release X grab, method ungrabInput not found in target VM "+VirtualMachineWrapper.description(vm));
return false;
}
XBaseWindowClass.invokeMethod(tr, ungrabInput, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
} catch (VMDisconnectedExceptionWrapper vmdex) {
return true; // Disconnected, all is good.
} catch (Exception ex) {
logger.log(Level.INFO, "Unable to release X grab.", ex);
return false;
}
return true;
}
示例4: isSyntheticMethod
import com.sun.jdi.Method; //导入依赖的package包/类
/**
* Test whether the method is considered to be synthetic
* @param m The method
* @param loc The current location in that method
* @return 0 when not synthetic
* positive when suggested step depth is returned
* negative when is synthetic and no further step depth is suggested.
*/
public static int isSyntheticMethod(Method m, Location loc) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper {
String name = TypeComponentWrapper.name(m);
if (name.startsWith("lambda$")) { // NOI18N
int lineNumber = LocationWrapper.lineNumber(loc);
if (lineNumber == 1) {
// We're in the initialization of the Lambda. We need to step over it.
return StepRequest.STEP_OVER;
}
return 0; // Do not treat Lambda methods as synthetic, because they contain user code.
} else {
// Do check the class for being Lambda synthetic class:
ReferenceType declaringType = LocationWrapper.declaringType(loc);
try {
String className = ReferenceTypeWrapper.name(declaringType);
if (className.contains("$$Lambda$")) { // NOI18N
// Lambda synthetic class
return -1;
}
} catch (ObjectCollectedExceptionWrapper ex) {
}
}
return TypeComponentWrapper.isSynthetic(m) ? -1 : 0;
}
示例5: getConcreteMethod
import com.sun.jdi.Method; //导入依赖的package包/类
private static Method getConcreteMethod(ReferenceType type, String methodName,
String firstParamSignature,
List<? extends TypeMirror> typeArguments) throws UnsuitableArgumentsException {
List<Method> methods = type.methodsByName(methodName);
String signature = createSignature(firstParamSignature, typeArguments);
boolean constructor = "<init>".equals(methodName);
for (Method method : methods) {
if (!method.isAbstract() &&
(!constructor || type.equals(method.declaringType())) &&
equalMethodSignatures(method.signature(), signature)) {
return method;
}
}
if (methods.size() > 0) {
throw new UnsuitableArgumentsException();
}
return null;
}
示例6: addVisibleMethods
import com.sun.jdi.Method; //导入依赖的package包/类
@Override
final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
/*
* Add methods from
* parent types first, so that the methods in this class will
* overwrite them in the hash table
*/
Iterator<InterfaceType> iter = interfaces().iterator();
while (iter.hasNext()) {
InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
if (!seenInterfaces.contains(interfaze)) {
interfaze.addVisibleMethods(methodMap, seenInterfaces);
seenInterfaces.add(interfaze);
}
}
ClassTypeImpl clazz = (ClassTypeImpl) superclass();
if (clazz != null) {
clazz.addVisibleMethods(methodMap, seenInterfaces);
}
addToMethodMap(methodMap, methods());
}
示例7: LocalVariableImpl
import com.sun.jdi.Method; //导入依赖的package包/类
LocalVariableImpl(VirtualMachine vm, Method method,
int slot, Location scopeStart, Location scopeEnd,
String name, String signature,
String genericSignature) {
super(vm);
this.method = method;
this.slot = slot;
this.scopeStart = scopeStart;
this.scopeEnd = scopeEnd;
this.name = name;
this.signature = signature;
if (genericSignature != null && genericSignature.length() > 0) {
this.genericSignature = genericSignature;
} else {
// The Spec says to return null for non-generic types
this.genericSignature = null;
}
}
示例8: isVisible
import com.sun.jdi.Method; //导入依赖的package包/类
public boolean isVisible(StackFrame frame) {
validateMirror(frame);
Method frameMethod = frame.location().method();
if (!frameMethod.equals(method)) {
throw new IllegalArgumentException(
"frame method different than variable's method");
}
// this is here to cover the possibility that we will
// allow LocalVariables for native methods. If we do
// so we will have to re-examinine this.
if (frameMethod.isNative()) {
return false;
}
return ((scopeStart.compareTo(frame.location()) <= 0)
&& (scopeEnd.compareTo(frame.location()) >= 0));
}
示例9: getMethodMirror
import com.sun.jdi.Method; //导入依赖的package包/类
Method getMethodMirror(long ref) {
if (ref == 0) {
// obsolete method
return new ObsoleteMethodImpl(vm, this);
}
// Fetch all methods for the class, check performance impact
// Needs no synchronization now, since methods() returns
// unmodifiable local data
Iterator<Method> it = methods().iterator();
while (it.hasNext()) {
MethodImpl method = (MethodImpl)it.next();
if (method.ref() == ref) {
return method;
}
}
throw new IllegalArgumentException("Invalid method id: " + ref);
}
示例10: methods1_4
import com.sun.jdi.Method; //导入依赖的package包/类
private List<Method> methods1_4() {
List<Method> methods;
JDWP.ReferenceType.Methods.MethodInfo[] declared;
try {
declared = JDWP.ReferenceType.Methods.
process(vm, this).declared;
} catch (JDWPException exc) {
throw exc.toJDIException();
}
methods = new ArrayList<Method>(declared.length);
for (int i=0; i<declared.length; i++) {
JDWP.ReferenceType.Methods.MethodInfo mi = declared[i];
Method method = MethodImpl.createMethodImpl(vm, this,
mi.methodID,
mi.name, mi.signature,
null,
mi.modBits);
methods.add(method);
}
return methods;
}
示例11: visibleMethods
import com.sun.jdi.Method; //导入依赖的package包/类
public List<Method> visibleMethods() {
/*
* Build a collection of all visible methods. The hash
* map allows us to do this efficiently by keying on the
* concatenation of name and signature.
*/
Map<String, Method> map = new HashMap<String, Method>();
addVisibleMethods(map, new HashSet<InterfaceType>());
/*
* ... but the hash map destroys order. Methods should be
* returned in a sensible order, as they are in allMethods().
* So, start over with allMethods() and use the hash map
* to filter that ordered collection.
*/
List<Method> list = allMethods();
list.retainAll(new HashSet<Method>(map.values()));
return list;
}
示例12: allLineLocations
import com.sun.jdi.Method; //导入依赖的package包/类
public List<Location> allLineLocations(String stratumID, String sourceName)
throws AbsentInformationException {
boolean someAbsent = false; // A method that should have info, didn't
SDE.Stratum stratum = stratum(stratumID);
List<Location> list = new ArrayList<Location>(); // location list
for (Iterator<Method> iter = methods().iterator(); iter.hasNext(); ) {
MethodImpl method = (MethodImpl)iter.next();
try {
list.addAll(
method.allLineLocations(stratum, sourceName));
} catch(AbsentInformationException exc) {
someAbsent = true;
}
}
// If we retrieved no line info, and at least one of the methods
// should have had some (as determined by an
// AbsentInformationException being thrown) then we rethrow
// the AbsentInformationException.
if (someAbsent && list.size() == 0) {
throw new AbsentInformationException();
}
return list;
}
示例13: validateMethodInvocation
import com.sun.jdi.Method; //导入依赖的package包/类
void validateMethodInvocation(Method method, int options)
throws InvalidTypeException,
InvocationException {
/*
* Method must be in this object's class, a superclass, or
* implemented interface
*/
ReferenceTypeImpl declType = (ReferenceTypeImpl)method.declaringType();
if (!declType.isAssignableFrom(this)) {
throw new IllegalArgumentException("Invalid method");
}
if (declType instanceof ClassTypeImpl) {
validateClassMethodInvocation(method, options);
} else if (declType instanceof InterfaceTypeImpl) {
validateIfaceMethodInvocation(method, options);
} else {
throw new InvalidTypeException();
}
}
示例14: validateClassMethodInvocation
import com.sun.jdi.Method; //导入依赖的package包/类
void validateClassMethodInvocation(Method method, int options)
throws InvalidTypeException,
InvocationException {
/*
* Method must be a non-constructor
*/
if (method.isConstructor()) {
throw new IllegalArgumentException("Cannot invoke constructor");
}
/*
* For nonvirtual invokes, method must have a body
*/
if (isNonVirtual(options)) {
if (method.isAbstract()) {
throw new IllegalArgumentException("Abstract method");
}
}
}
示例15: validateConstructorInvocation
import com.sun.jdi.Method; //导入依赖的package包/类
void validateConstructorInvocation(Method method)
throws InvalidTypeException,
InvocationException {
/*
* Method must be in this class.
*/
ReferenceTypeImpl declType = (ReferenceTypeImpl)method.declaringType();
if (!declType.equals(this)) {
throw new IllegalArgumentException("Invalid constructor");
}
/*
* Method must be a constructor
*/
if (!method.isConstructor()) {
throw new IllegalArgumentException("Cannot create instance with non-constructor");
}
}