static ReferenceType getReferenceTypeFromToken(String idToken) { ReferenceType cls = null; if (Character.isDigit(idToken.charAt(0))) { cls = null; } else if (idToken.startsWith("*.")) { // This notation saves typing by letting the user omit leading // package names. The first // loaded class whose name matches this limited regular // expression is selected. idToken = idToken.substring(1); for (ReferenceType type : Env.vm().allClasses()) { if (type.name().endsWith(idToken)) { cls = type; break; } } } else { // It's a class name List<ReferenceType> classes = Env.vm().classesByName(idToken); if (classes.size() > 0) { // TO DO: handle multiples cls = classes.get(0); } } return cls; }
public void visit(ReferenceType n, Object arg) { Scope currentScope = (Scope) n.getData(); n.setData(currentScope.resolve(n.toString())); n.getType().accept(this, arg); for (int i = 0; i < n.getArrayCount(); i++) {} }
@Override public void visit(final MethodDeclaration n, final A arg) { visitComment(n.getComment(), arg); visitAnnotations(n, arg); if (n.getTypeParameters() != null) { for (final TypeParameter t : n.getTypeParameters()) { t.accept(this, arg); } } n.getElementType().accept(this, arg); n.getNameExpr().accept(this, arg); if (n.getParameters() != null) { for (final Parameter p : n.getParameters()) { p.accept(this, arg); } } if (n.getThrows() != null) { for (final ReferenceType name : n.getThrows()) { name.accept(this, arg); } } if (n.getBody() != null) { n.getBody().accept(this, arg); } }
private void commandMethods(StringTokenizer t) throws NoSessionException { if (!t.hasMoreTokens()) { env.error("No class specified."); return; } String idClass = t.nextToken(); ReferenceType cls = findClass(idClass); if (cls != null) { List<Method> methods = cls.allMethods(); OutputSink out = env.getOutputSink(); for (int i = 0; i < methods.size(); i++) { Method method = methods.get(i); out.print(method.declaringType().name() + " " + method.name() + "("); Iterator<String> it = method.argumentTypeNames().iterator(); if (it.hasNext()) { while (true) { out.print(it.next()); if (!it.hasNext()) { break; } out.print(", "); } } out.println(")"); } out.show(); } else { // ### Should validate class name syntax. env.failure("\"" + idClass + "\" is not a valid id or class name."); } }
protected static String calcLabel(ValueDescriptor descriptor) { final ValueDescriptorImpl valueDescriptor = (ValueDescriptorImpl) descriptor; final Value value = valueDescriptor.getValue(); if (value instanceof ObjectReference) { if (value instanceof StringReference) { return ((StringReference) value).value(); } else if (value instanceof ClassObjectReference) { ReferenceType type = ((ClassObjectReference) value).reflectedType(); return (type != null) ? type.name() : "{...}"; } else { final ObjectReference objRef = (ObjectReference) value; final Type type = objRef.type(); if (type instanceof ClassType && ((ClassType) type).isEnum()) { final String name = getEnumConstantName(objRef, (ClassType) type); if (name != null) { return name; } else { return type.name(); } } else { return ""; } } } else if (value == null) { //noinspection HardCodedStringLiteral return "null"; } else { return DebuggerBundle.message("label.undefined"); } }
public void exceptionEvent(ExceptionEvent event) { ObjectReference or = event.exception(); ReferenceType rt = or.referenceType(); String exceptionName = rt.name(); // Field messageField = Throwable.class.getField("detailMessage"); Field messageField = rt.fieldByName("detailMessage"); // System.out.println("field " + messageField); Value messageValue = or.getValue(messageField); // System.out.println("mess val " + messageValue); // "java.lang.ArrayIndexOutOfBoundsException" int last = exceptionName.lastIndexOf('.'); String message = exceptionName.substring(last + 1); if (messageValue != null) { String messageStr = messageValue.toString(); if (messageStr.startsWith("\"")) { messageStr = messageStr.substring(1, messageStr.length() - 1); } message += ": " + messageStr; } // System.out.println("mess type " + messageValue.type()); // StringReference messageReference = (StringReference) messageValue.type(); // First just report the exception and its placement reportException(message, or, event.thread()); // Then try to pretty it up with a better message handleCommonErrors(exceptionName, message, listener); if (editor != null) { editor.deactivateRun(); } }
/** Does the specified ReferenceType match this spec. */ @Override public boolean matches(ReferenceType refType) { if (isWild) { return refType.name().endsWith(classId); } else { return refType.name().equals(classId); } }
private void commandClasses() throws NoSessionException { OutputSink out = env.getOutputSink(); // out.println("** classes list **"); for (ReferenceType refType : runtime.allClasses()) { out.println(refType.name()); } out.show(); }
/** The 'refType' is known to match, return the EventRequest. */ EventRequest resolveEventRequest(ReferenceType refType) throws NoSuchFieldException { Field field = refType.fieldByName(fieldId); EventRequestManager em = refType.virtualMachine().eventRequestManager(); EventRequest wp = em.createAccessWatchpointRequest(field); wp.setSuspendPolicy(suspendPolicy); wp.enable(); return wp; }
@Override public void visit(final UnionType n, final A arg) { visitComment(n.getComment(), arg); visitAnnotations(n, arg); for (ReferenceType element : n.getElements()) { element.accept(this, arg); } }
public static String getLocationMethodQName(@NotNull Location location) { StringBuilder res = new StringBuilder(); ReferenceType type = location.declaringType(); if (type != null) { res.append(type.name()).append('.'); } res.append(location.method().name()); return res.toString(); }
public List<ReferenceType> definedClasses() { ArrayList<ReferenceType> definedClasses = new ArrayList<ReferenceType>(); for (ReferenceType type : vm.allClasses()) { if (type.isPrepared() && equals(type.classLoader())) { definedClasses.add(type); } } return definedClasses; }
/** Return a description of an object. */ static String description(ObjectReference ref) { ReferenceType clazz = ref.referenceType(); long id = ref.uniqueID(); if (clazz == null) { return toHex(id); } else { return MessageOutput.format( "object description and hex id", new Object[] {clazz.name(), toHex(id)}); } }
@Override public Boolean visit(final ReferenceType n1, final Node arg) { final ReferenceType n2 = (ReferenceType) arg; if (n1.getArrayCount() != n2.getArrayCount()) { return Boolean.FALSE; } if (!nodeEquals(n1.getType(), n2.getType())) { return Boolean.FALSE; } if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { return Boolean.FALSE; } List<List<AnnotationExpr>> n1a = n1.getArraysAnnotations(); List<List<AnnotationExpr>> n2a = n2.getArraysAnnotations(); if (n1a != null && n2a != null) { if (n1a.size() != n2a.size()) { return Boolean.FALSE; } else { int i = 0; for (List<AnnotationExpr> aux : n1a) { if (!nodesEquals(aux, n2a.get(i))) { return Boolean.FALSE; } i++; } } } else if (n1a != n2a) { return Boolean.FALSE; } return Boolean.TRUE; }
public static void checkReferenceType(ReferenceType<?> reference, Collection<String> validTypes) { // Check required fields assertNotNull(reference.getHref(), String.format(NOT_NULL_OBJECT_FMT, "Href", "ReferenceType")); // Check optional fields String id = reference.getId(); if (id != null) checkId(id); String type = reference.getType(); if (type != null) checkType(type, validTypes); // NOTE name cannot be checked }
Type findType(String signature) throws ClassNotLoadedException { List<ReferenceType> types = visibleClasses(); Iterator<ReferenceType> iter = types.iterator(); while (iter.hasNext()) { ReferenceType type = iter.next(); if (type.signature().equals(signature)) { return type; } } JNITypeParser parser = new JNITypeParser(signature); throw new ClassNotLoadedException( parser.typeName(), "Class " + parser.typeName() + " not loaded"); }
/** ******** test assist ********* */ Method getMethod(String className, String methodName) { List refs = vm().classesByName(className); if (refs.size() != 1) { failure("Test failure: " + refs.size() + " ReferenceTypes named: " + className); return null; } ReferenceType refType = (ReferenceType) refs.get(0); List meths = refType.methodsByName(methodName); if (meths.size() != 1) { failure("Test failure: " + meths.size() + " methods named: " + methodName); return null; } return (Method) meths.get(0); }
public List<ReferenceType> nestedTypes(ReferenceType refType) { List<ReferenceType> nestedTypes = myNestedClassesCache.get(refType); if (nestedTypes == null) { List<ReferenceType> list = Collections.emptyList(); try { list = refType.nestedTypes(); } catch (Throwable e) { // sometimes some strange errors are thrown from JDI. Do not crash debugger because of this. // Example: // java.lang.StringIndexOutOfBoundsException: String index out of range: 487700285 // at java.lang.String.checkBounds(String.java:375) // at java.lang.String.<init>(String.java:415) // at com.sun.tools.jdi.PacketStream.readString(PacketStream.java:392) // at // com.sun.tools.jdi.JDWP$VirtualMachine$AllClassesWithGeneric$ClassInfo.<init>(JDWP.java:1644) LOG.info(e); } if (!list.isEmpty()) { final Set<ReferenceType> candidates = new HashSet<>(); final ClassLoaderReference outerLoader = refType.classLoader(); for (ReferenceType nested : list) { try { if (outerLoader == null ? nested.classLoader() == null : outerLoader.equals(nested.classLoader())) { candidates.add(nested); } } catch (ObjectCollectedException ignored) { } } if (!candidates.isEmpty()) { // keep only direct nested types final Set<ReferenceType> nested2 = new HashSet<>(); for (final ReferenceType candidate : candidates) { nested2.addAll(nestedTypes(candidate)); } candidates.removeAll(nested2); } nestedTypes = candidates.isEmpty() ? Collections.emptyList() : new ArrayList<>(candidates); } else { nestedTypes = Collections.emptyList(); } myNestedClassesCache.put(refType, nestedTypes); } return nestedTypes; }
public static ReferenceType getSuperClass( final String baseQualifiedName, ReferenceType checkedType) { if (baseQualifiedName.equals(checkedType.name())) { return checkedType; } if (checkedType instanceof ClassType) { ClassType classType = (ClassType) checkedType; ClassType superClassType = classType.superclass(); if (superClassType != null) { ReferenceType superClass = getSuperClass(baseQualifiedName, superClassType); if (superClass != null) { return superClass; } } List<InterfaceType> interfaces = classType.allInterfaces(); for (InterfaceType iface : interfaces) { ReferenceType superClass = getSuperClass(baseQualifiedName, iface); if (superClass != null) { return superClass; } } } if (checkedType instanceof InterfaceType) { List<InterfaceType> list = ((InterfaceType) checkedType).superinterfaces(); for (InterfaceType superInterface : list) { ReferenceType superClass = getSuperClass(baseQualifiedName, superInterface); if (superClass != null) { return superClass; } } } return null; }
/** * @ast method * @aspect AccessControl * @declaredat /home/uoji/JastAddJ/Java1.4Frontend/AccessControl.jrag:167 */ public void accessControl() { super.accessControl(); if (!isCircular()) { // 9.1.2 HashSet set = new HashSet(); for (int i = 0; i < getNumSuperInterfaceId(); i++) { TypeDecl decl = getSuperInterfaceId(i).type(); if (!decl.isInterfaceDecl() && !decl.isUnknown()) error( "interface " + fullName() + " tries to extend non interface type " + decl.fullName()); if (!decl.isCircular() && !decl.accessibleFrom(this)) error( "interface " + fullName() + " can not extend non accessible type " + decl.fullName()); if (set.contains(decl)) error( "extended interface " + decl.fullName() + " mentionened multiple times in extends clause"); set.add(decl); } } }
@Override public void buildChildren( final Value value, final ChildrenBuilder builder, final EvaluationContext evaluationContext) { DebuggerManagerThreadImpl.assertIsManagerThread(); final ValueDescriptorImpl parentDescriptor = (ValueDescriptorImpl) builder.getParentDescriptor(); final NodeManager nodeManager = builder.getNodeManager(); final NodeDescriptorFactory nodeDescriptorFactory = builder.getDescriptorManager(); List<DebuggerTreeNode> children = new ArrayList<>(); if (value instanceof ObjectReference) { final ObjectReference objRef = (ObjectReference) value; final ReferenceType refType = objRef.referenceType(); // default ObjectReference processing List<Field> fields = refType.allFields(); if (!fields.isEmpty()) { Set<String> names = new HashSet<>(); for (Field field : fields) { if (shouldDisplay(evaluationContext, objRef, field)) { FieldDescriptor fieldDescriptor = createFieldDescriptor( parentDescriptor, nodeDescriptorFactory, objRef, field, evaluationContext); String name = fieldDescriptor.getName(); if (names.contains(name)) { fieldDescriptor.putUserData(FieldDescriptor.SHOW_DECLARING_TYPE, Boolean.TRUE); } else { names.add(name); } children.add(nodeManager.createNode(fieldDescriptor, evaluationContext)); } } if (children.isEmpty()) { children.add( nodeManager.createMessageNode( DebuggerBundle.message("message.node.class.no.fields.to.display"))); } else if (XDebuggerSettingsManager.getInstance().getDataViewSettings().isSortValues()) { children.sort(NodeManagerImpl.getNodeComparator()); } } else { children.add( nodeManager.createMessageNode(MessageDescriptor.CLASS_HAS_NO_FIELDS.getLabel())); } } builder.setChildren(children); }
/** Does the specified ReferenceType match this spec. */ public boolean matches(ReferenceType refType) { try { if (refType.sourceName().equals(sourceName)) { try { refType.locationsOfLine(linenumber); // if we don't throw an exception then it was found return true; } catch (AbsentInformationException exc) { } catch (ObjectCollectedException exc) { } catch (InvalidLineNumberException exc) { // } catch(ClassNotPreparedException exc) { // -- should not happen, so don't catch this --- } } } catch (AbsentInformationException exc) { // for sourceName(), fall through } return false; }
private void dump( OutputSink out, ObjectReference obj, ReferenceType refType, ReferenceType refTypeBase) { for (Field field : refType.fields()) { out.print(" "); if (!refType.equals(refTypeBase)) { out.print(refType.name() + "."); } out.print(field.name() + ": "); Object o = obj.getValue(field); out.println((o == null) ? "null" : o.toString()); // Bug ID 4374471 } if (refType instanceof ClassType) { ClassType sup = ((ClassType) refType).superclass(); if (sup != null) { dump(out, obj, sup, refTypeBase); } } else if (refType instanceof InterfaceType) { for (InterfaceType sup : ((InterfaceType) refType).superinterfaces()) { dump(out, obj, sup, refTypeBase); } } }
/** Get source object associated with a class or interface. Returns null if not available. */ public SourceModel sourceForClass(ReferenceType refType) { SourceModel sm = classToSource.get(refType); if (sm != null) { return sm; } try { String filename = refType.sourceName(); String refName = refType.name(); int iDot = refName.lastIndexOf('.'); String pkgName = (iDot >= 0) ? refName.substring(0, iDot + 1) : ""; String full = pkgName.replace('.', File.separatorChar) + filename; File path = sourcePath.resolve(full); if (path != null) { sm = sourceForFile(path); classToSource.put(refType, sm); return sm; } return null; } catch (AbsentInformationException e) { return null; } }
@Override public Boolean visit(final UnionType n1, final Node arg) { final UnionType n2 = (UnionType) arg; List<ReferenceType> n1Elements = n1.getElements(); List<ReferenceType> n2Elements = n2.getElements(); if (n1Elements != null && n2Elements != null) { if (n1Elements.size() != n2Elements.size()) { return Boolean.FALSE; } else { int i = 0; for (ReferenceType aux : n1Elements) { if (aux.accept(this, n2Elements.get(i))) { return Boolean.FALSE; } i++; } } } else if (n1Elements != n2Elements) { return Boolean.FALSE; } return Boolean.TRUE; }
public StringBuilder appendFields( ObjectLocator locator, StringBuilder buffer, ToStringStrategy strategy) { super.appendFields(locator, buffer, strategy); { Object theRequestMessage; theRequestMessage = this.getRequestMessage(); strategy.appendField(locator, this, "requestMessage", buffer, theRequestMessage); } { String theRequestMessageReference; theRequestMessageReference = this.getRequestMessageReference(); strategy.appendField( locator, this, "requestMessageReference", buffer, theRequestMessageReference); } return buffer; }
/** @apilevel low-level */ public void flushCache() { super.flushCache(); methodsSignatureMap_computed = false; methodsSignatureMap_value = null; ancestorMethods_String_values = null; memberTypes_String_values = null; memberFieldsMap_computed = false; memberFieldsMap_value = null; memberFields_String_values = null; isStatic_computed = false; castingConversionTo_TypeDecl_values = null; instanceOf_TypeDecl_values = null; isCircular_visited = -1; isCircular_computed = false; isCircular_initialized = false; typeDescriptor_computed = false; typeDescriptor_value = null; }
/** Does the specified ReferenceType match this spec. */ public boolean matches(ReferenceType refType) { String refName = refType.name().replace('$', '.'); String compName; compName = refName; if (anonymous) { String anonymousBase = anonymousBaseName(refName); if (anonymousBase != null) compName = anonymousBase; else return false; } if (classId.startsWith("*")) { return compName.endsWith(stem); } else if (classId.endsWith("*")) { return compName.startsWith(stem); } else if (checkJavaLang && compName.startsWith("java.lang.") && compName.substring(10).equals(stem)) { return true; } else { return compName.equals(transClassId); } }
/** * @ast method * @aspect TypeHierarchyCheck * @declaredat /home/uoji/JastAddJ/Java1.4Frontend/TypeHierarchyCheck.jrag:312 */ public void nameCheck() { super.nameCheck(); if (isCircular()) error("circular inheritance dependency in " + typeName()); else { for (int i = 0; i < getNumSuperInterfaceId(); i++) { TypeDecl typeDecl = getSuperInterfaceId(i).type(); if (typeDecl.isCircular()) error("circular inheritance dependency in " + typeName()); } } for (Iterator iter = methodsSignatureMap().values().iterator(); iter.hasNext(); ) { SimpleSet set = (SimpleSet) iter.next(); if (set.size() > 1) { Iterator i2 = set.iterator(); MethodDecl m = (MethodDecl) i2.next(); while (i2.hasNext()) { MethodDecl n = (MethodDecl) i2.next(); if (!n.mayOverrideReturn(m) && !m.mayOverrideReturn(n)) error( "multiply inherited methods with the same signature must have the same return type"); } } } }
private String getName(ReferenceType element) { org.eclipse.emf.ecore.EStructuralFeature nameAttr = element.eClass().getEStructuralFeature(NAME_FEATURE); if (element.eIsProxy()) { String fragment = ((org.eclipse.emf.ecore.InternalEObject) element).eProxyURI().fragment(); if (fragment != null && fragment.startsWith( ssl.resource.ssl.ISslContextDependentURIFragment.INTERNAL_URI_FRAGMENT_PREFIX)) { fragment = fragment.substring( ssl.resource.ssl.ISslContextDependentURIFragment.INTERNAL_URI_FRAGMENT_PREFIX .length()); fragment = fragment.substring(fragment.indexOf("_") + 1); } return fragment; } else if (nameAttr instanceof org.eclipse.emf.ecore.EAttribute) { return (String) element.eGet(nameAttr); } else { // try any other string attribute found for (org.eclipse.emf.ecore.EAttribute strAttribute : element.eClass().getEAllAttributes()) { if (!strAttribute.isMany() && strAttribute.getEType().getInstanceClassName().equals("String")) { return (String) element.eGet(strAttribute); } } for (org.eclipse.emf.ecore.EOperation o : element.eClass().getEAllOperations()) { if (o.getName().toLowerCase().endsWith(NAME_FEATURE) && o.getEParameters().size() == 0) { String result = (String) ssl.resource.ssl.util.SslEObjectUtil.invokeOperation(element, o); if (result != null) { return result; } } } } return null; }