コード例 #1
0
ファイル: DebuggerUtilsEx.java プロジェクト: jared2501/test
 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();
 }
コード例 #2
0
ファイル: DebuggerUtilsEx.java プロジェクト: jared2501/test
  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;
  }
コード例 #3
0
 @Override
 protected void createRequestForPreparedClass(
     final DebugProcessImpl debugProcess, final ReferenceType classType) {
   if (!isInScopeOf(debugProcess, classType.name())) {
     if (LOG.isDebugEnabled()) {
       LOG.debug(
           classType.name()
               + " is out of debug-process scope, breakpoint request won't be created for line "
               + getLineIndex());
     }
     return;
   }
   try {
     List<Location> locations =
         debugProcess.getPositionManager().locationsOfLine(classType, getSourcePosition());
     if (!locations.isEmpty()) {
       for (Location loc : locations) {
         if (LOG.isDebugEnabled()) {
           LOG.debug(
               "Found location [codeIndex="
                   + loc.codeIndex()
                   + "] for reference type "
                   + classType.name()
                   + " at line "
                   + getLineIndex()
                   + "; isObsolete: "
                   + (debugProcess.getVirtualMachineProxy().versionHigher("1.4")
                       && loc.method().isObsolete()));
         }
         if (!acceptLocation(debugProcess, classType, loc)) {
           continue;
         }
         final BreakpointRequest request =
             debugProcess.getRequestsManager().createBreakpointRequest(this, loc);
         debugProcess.getRequestsManager().enableRequest(request);
         if (LOG.isDebugEnabled()) {
           LOG.debug(
               "Created breakpoint request for reference type "
                   + classType.name()
                   + " at line "
                   + getLineIndex()
                   + "; codeIndex="
                   + loc.codeIndex());
         }
       }
     } else {
       // there's no executable code in this class
       debugProcess
           .getRequestsManager()
           .setInvalid(
               this,
               DebuggerBundle.message(
                   "error.invalid.breakpoint.no.executable.code",
                   (getLineIndex() + 1),
                   classType.name()));
       if (LOG.isDebugEnabled()) {
         LOG.debug(
             "No locations of type " + classType.name() + " found at line " + getLineIndex());
       }
     }
   } catch (ClassNotPreparedException ex) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("ClassNotPreparedException: " + ex.getMessage());
     }
     // there's a chance to add a breakpoint when the class is prepared
   } catch (ObjectCollectedException ex) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("ObjectCollectedException: " + ex.getMessage());
     }
     // there's a chance to add a breakpoint when the class is prepared
   } catch (InvalidLineNumberException ex) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("InvalidLineNumberException: " + ex.getMessage());
     }
     debugProcess
         .getRequestsManager()
         .setInvalid(this, DebuggerBundle.message("error.invalid.breakpoint.bad.line.number"));
   } catch (InternalException ex) {
     LOG.info(ex);
   } catch (Exception ex) {
     LOG.info(ex);
   }
   updateUI();
 }
コード例 #4
0
 private static boolean isAnonymousClass(ReferenceType classType) {
   if (classType instanceof ClassType) {
     return ourAnonymousPattern.matcher(classType.name()).matches();
   }
   return false;
 }
コード例 #5
0
  // copied from FrameVariablesTree
  private void buildVariables(
      DebuggerContextImpl debuggerContext,
      final EvaluationContextImpl evaluationContext,
      @NotNull DebugProcessImpl debugProcess,
      XValueChildrenList children,
      ObjectReference thisObjectReference,
      Location location)
      throws EvaluateException {
    final Set<String> visibleLocals = new HashSet<String>();
    if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) {
      if (thisObjectReference != null
          && debugProcess.getVirtualMachineProxy().canGetSyntheticAttribute()) {
        final ReferenceType thisRefType = thisObjectReference.referenceType();
        if (thisRefType instanceof ClassType
            && location != null
            && thisRefType.equals(location.declaringType())
            && thisRefType.name().contains("$")) { // makes sense for nested classes only
          for (Field field : thisRefType.fields()) {
            if (DebuggerUtils.isSynthetic(field)
                && StringUtil.startsWith(
                    field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
              final FieldDescriptorImpl fieldDescriptor =
                  myNodeManager.getFieldDescriptor(myDescriptor, thisObjectReference, field);
              children.add(JavaValue.create(fieldDescriptor, evaluationContext, myNodeManager));
              visibleLocals.add(fieldDescriptor.calcValueName());
            }
          }
        }
      }
    }

    boolean myAutoWatchMode = DebuggerSettings.getInstance().AUTO_VARIABLES_MODE;
    if (evaluationContext == null) {
      return;
    }
    final SourcePosition sourcePosition = debuggerContext.getSourcePosition();
    if (sourcePosition == null) {
      return;
    }

    try {
      if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions()
          && !myAutoWatchMode) {
        // optimization
        superBuildVariables(evaluationContext, children);
      } else {
        final Map<String, LocalVariableProxyImpl> visibleVariables =
            getVisibleVariables(getStackFrameProxy());
        final Pair<Set<String>, Set<TextWithImports>> usedVars =
            ApplicationManager.getApplication()
                .runReadAction(
                    new Computable<Pair<Set<String>, Set<TextWithImports>>>() {
                      @Override
                      public Pair<Set<String>, Set<TextWithImports>> compute() {
                        return findReferencedVars(
                            ContainerUtil.union(visibleVariables.keySet(), visibleLocals),
                            sourcePosition);
                      }
                    });
        // add locals
        if (myAutoWatchMode) {
          for (String var : usedVars.first) {
            LocalVariableProxyImpl local = visibleVariables.get(var);
            if (local != null) {
              children.add(
                  JavaValue.create(
                      myNodeManager.getLocalVariableDescriptor(null, local),
                      evaluationContext,
                      myNodeManager));
            }
          }
        } else {
          superBuildVariables(evaluationContext, children);
        }
        final EvaluationContextImpl evalContextCopy =
            evaluationContext.createEvaluationContext(evaluationContext.getThisObject());
        evalContextCopy.setAutoLoadClasses(false);

        final Set<TextWithImports> extraVars =
            computeExtraVars(usedVars, sourcePosition, evaluationContext);

        // add extra vars
        addToChildrenFrom(extraVars, children, evaluationContext);

        // add expressions
        addToChildrenFrom(usedVars.second, children, evalContextCopy);
      }
    } catch (EvaluateException e) {
      if (e.getCause() instanceof AbsentInformationException) {
        children.add(
            new DummyMessageValueNode(
                MessageDescriptor.LOCAL_VARIABLES_INFO_UNAVAILABLE.getLabel(),
                XDebuggerUIConstants.INFORMATION_MESSAGE_ICON));
        // trying to collect values from variable slots
        try {
          for (Map.Entry<DecompiledLocalVariable, Value> entry :
              LocalVariablesUtil.fetchValues(getStackFrameProxy(), debugProcess).entrySet()) {
            children.add(
                JavaValue.create(
                    myNodeManager.getArgumentValueDescriptor(
                        null, entry.getKey(), entry.getValue()),
                    evaluationContext,
                    myNodeManager));
          }
        } catch (Exception ex) {
          LOG.info(ex);
        }
      } else {
        throw e;
      }
    }
  }