Package lapsePlus

Examples of lapsePlus.HistoryDefinitionLocation


    super(new ViewLabelProvider(null, null), null);
  }
 
  public Color getForeground(Object element) {
    Display display = Display.getCurrent();
    HistoryDefinitionLocation loc = (HistoryDefinitionLocation) element;

    if(loc.isConstant()) {
      return display.getSystemColor(SWT.COLOR_DARK_BLUE);
    } else {
        String fullCalleeName = null;
      if(loc.getASTNode() instanceof MethodInvocation) {
        MethodInvocation mi = (MethodInvocation) loc.getASTNode();
        Expression s=mi.getExpression();
        fullCalleeName = mi.getName().getFullyQualifiedName();
      }else
        if(loc.getASTNode() instanceof ClassInstanceCreation) {
            ClassInstanceCreation mi = (ClassInstanceCreation) loc.getASTNode();
        fullCalleeName = mi.getType().toString();
      }
       
        if(fullCalleeName != null) {
        if(SourceView.isSourceName(fullCalleeName)) {
View Full Code Here


    return display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
  }

  public Image getImage(Object element) {
    if(!(element instanceof HistoryDefinitionLocation)) return null;
    HistoryDefinitionLocation hdl = (HistoryDefinitionLocation)element;
    Image result = null;
    switch(hdl.getType()) {
      case HistoryDefinitionLocation.CALL_ARG     :
        result = JavaPluginImages.get(JavaPluginImages.IMG_MISC_PRIVATE);      // actual parameter of a call
        break;
      case HistoryDefinitionLocation.FORMAL_PARAMETER  :
        result = JavaPluginImages.get(JavaPluginImages.IMG_MISC_PROTECTED);      // formal parameter of a method
        break;
      case HistoryDefinitionLocation.RETURN  :
        result = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INTERFACE_DEFAULT)// return result of a method
        break;
      case HistoryDefinitionLocation.DECLARATION     :
        result = JavaPluginImages.get(JavaPluginImages.IMG_MISC_PUBLIC);      // local declaration
        break;
      case HistoryDefinitionLocation.UNDEFINED       :
        result = JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE);      // no definition found for some reason
        break;
      case HistoryDefinitionLocation.INITIAL         :
        result = JavaPluginImages.get(JavaPluginImages.IMG_MISC_DEFAULT);      // initial query
        break;
      default:     
        result = JavaPluginImages.get(JavaPluginImages.IMG_MISC_PROTECTED);     
    }
    int flags = 0;
    if (hdl.isRecursive()) {
      flags |= CallHierarchyImageDescriptor.RECURSIVE;
    }
    if (hdl.isMaxLevel()) {
      flags |= CallHierarchyImageDescriptor.MAX_LEVEL;
    }
    // adorn the image with a small arrow
    ImageDescriptor baseImage= new ImageImageDescriptor(result);
        Rectangle bounds= result.getBounds();
View Full Code Here

  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
   */
  public String getText(Object element) {
    HistoryDefinitionLocation curElem = (HistoryDefinitionLocation) element;
    if (curElem == null) {
      return "(error)";
    }
    return curElem.toString();
  }
View Full Code Here

        if(doubleClickAction == null) {
          doubleClickAction = new Action() {
            public void run() {
              //System.err.println("Detected a double-click");
              ISelection selection = fViewer.getSelection();
              HistoryDefinitionLocation dl = (HistoryDefinitionLocation)
                    ((IStructuredSelection) selection).getFirstElement();             
              if(dl.getLineNumber() == DefinitionLocation.INVALID_SOURCE_LINE) {
                setStatusBarMessage("Invalid location", true);
                // invalid location -- get out of here
                return;
              }
             
              ITextEditor editor = null;
              try {
                editor = (ITextEditor) EditorUtility.openInEditor(dl.getResource());
              } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              if(editor == null) {
                JavaPlugin.logErrorMessage("Can't open an editor for " + dl.getASTNode());
                return;
              }
             
              editor.selectAndReveal(
                  dl.getASTNode().getStartPosition(),
                  dl.getASTNode().getLength());             
             
              // activate the new window if necessary
              if(editor != fEditor) {
                try {                 
                  // reset the input
                  setInput(editor);
                 
                  // reactivate the editor
                  editor.getSite().getPage().activate(editor);
                 
                  log("Activated " + editor.getTitle());
                } catch (CoreException e) {
                                    log(e.getMessage(), e);
                  return;
                }
              }
              setStatusBarMessage("Opened " +
                  dl.getResource().getName() + ":" + dl.getLineNumber() +
                  " -- " + dl.toString());
            }
          };
        }

        doubleClickAction.run();
      }
    });
   
    fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
      public void selectionChanged(SelectionChangedEvent event) {
        IStructuredSelection sel = (IStructuredSelection) event.getSelection();
        HistoryDefinitionLocation match = (HistoryDefinitionLocation) sel.getFirstElement();
        if(match != null) {
          IStatusLineManager slManager = getViewSite().getActionBars().getStatusLineManager();
          slManager.setMessage(match.toString());
        }
      }
    });
  }
View Full Code Here

    //Name otherName = decl.getName();
    //String var = Name.getFullyQualifiedName();
   
    //fContentProvider.clearElements();
    // make the root of the slicing tree
    HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
        sn.toString(),
        (IFile)resource,
        cu.getLineNumber(sn.getStartPosition()),
        sn, defl, HistoryDefinitionLocation.INITIAL);
    if(defl==null){
View Full Code Here

      logError(
          "decl: " + decl + " on line " + (decl == null ? DefinitionLocation.INVALID_SOURCE_LINE : fRoot.getLineNumber(decl.getStartPosition())) +
          " and name: " + name + "(" + name.hashCode() + ") on line " + fRoot.getLineNumber(name.getStartPosition()));
     
      // the case of no declaration found -- add a question mark
      /*HistoryDefinitionLocation dl = */new HistoryDefinitionLocation(
          name.toString(),
          null,  // this will be ignored
          DefinitionLocation.INVALID_SOURCE_LINE,
          name, parent, HistoryDefinitionLocation.UNDEFINED);
      //System.out.println("Case 1");
    } else
    if(decl.getParent() instanceof MethodDeclaration){
      // the case of a parameter -- add the actuals and recurse
      //showMessage(decl.toString() + " is a parameter of " + parent.getClass());
      MethodDeclaration methodDecl = (MethodDeclaration) decl.getParent();
      IMethod method = new MethodFinder((IFile) resource).convertMethodDecl2IMethod(methodDecl);
      if(method == null) {
        JavaPlugin.logErrorMessage("Internal error: No method found for " + methodDecl);
        return;
      }

      HistoryDefinitionLocation paramDL = new HistoryDefinitionLocation(
          decl.toString(),
          resource,
          cu.getLineNumber(decl.getStartPosition()),
          decl, parent, HistoryDefinitionLocation.FORMAL_PARAMETER);
      if(!registerExpansion(paramDL)) {
        // recursion detected here
        return;
      }

      Expression onlyCall = (Expression) (stack.isEmpty() ? null : stack.getLast());
      log("Looking for calls from " + onlyCall);
      Collection/*<ExpressionUnitPair>*/ c = CallerFinder.getActualsForFormal(method, name, onlyCall, monitor, null);
      if(c.isEmpty()){
        logError(
            "No suitable actual arguments for formal argument " +
            name + " of " + method.getElementName() + " at " +
            resource.getName() + " found");
      } else
      for (Iterator iter = c.iterator(); iter.hasNext();) {
        Utils.ExpressionUnitPair eup = (Utils.ExpressionUnitPair) iter.next();
        Expression     e        = eup.getExpression();
        CompilationUnit nextCU     = eup.getCompilationUnit();
        IResource     nextResource = eup.getResource();
               
        processExpression(paramDL, e, nextCU, nextResource, stack, monitor, HistoryDefinitionLocation.CALL_ARG,false);
      }
      //System.out.println("Case 2");
    } else {
      /**
       * The case of a declaration -- look at the right hand side.
       * */
      Object obj = (decl.getParent() instanceof VariableDeclaration) ?
          decl.getParent() :
          decl;         
      String desc = obj.toString();
      int type = (decl.getParent() instanceof FieldDeclaration) ?
            HistoryDefinitionLocation.FIELD :
            HistoryDefinitionLocation.DECLARATION;
      // the case of a regilar declaration being found
      HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
          desc,
          resource,
          cu.getLineNumber(decl.getStartPosition()),
          decl, parent, type);
      Expression e = decl.getInitializer();
View Full Code Here

    SimpleName nextName = CallerFinder.SlicingUtils.getVariable(e);
    if(nextName != null) {
      /**
       * Follow a simple assignment.
       * */
      HistoryDefinitionLocation actualDL = new HistoryDefinitionLocation(
          nextName/*.getParent()*/.toString(),
          resource,
          cu.getLineNumber(nextName.getStartPosition()),
          nextName,
          parent, defaultType);
      //showMessage("Type " + nextName.getParent().getClass());         
     
      // marks actualDL as recursive if necessary
      if(registerExpansion(actualDL)) {
        processDecl(nextName, cu, resource, actualDL, stack, monitor);
      }
    } else
    if(e instanceof MethodInvocation) {
      /**
       * Go back through a method invocation.
       * */
      MethodInvocation mi = (MethodInvocation) e;
      SimpleName methodName = mi.getName();
      log("Going back through callee " + methodName.toString());
      HistoryDefinitionLocation callDL;
      if(!first){
      callDL= new HistoryDefinitionLocation(
          mi.toString(),
          resource,
          cu.getLineNumber(mi.getStartPosition()),
          mi,
          parent, HistoryDefinitionLocation.CALL);
      }
      else{
        callDL=parent;
      }
     
      if(registerExpansion(callDL)) {
        Collection/*<MethodDeclarationUnitPair>*/ callees = CallerFinder.findCallees(monitor, methodName.toString(), null, false);
        if(callees.isEmpty()) {
          if(SinkView.isDerivationName(methodName.getFullyQualifiedName()))
          {
              HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
                  mi.getExpression().toString(),
                  resource,
                  cu.getLineNumber(mi.getStartPosition()),
                  mi.getExpression(), callDL, HistoryDefinitionLocation.DERIVATION);
              if(registerExpansion(dl)) {
                Expression expr = mi.getExpression();
                if(expr != null) {
                  // Recurse on the returned expression
                  processExpression(dl, expr, cu, resource, stack, monitor, HistoryDefinitionLocation.DERIVATION,false);
                 
                }
              }
          }
          else{
          logError("No suitable callees for " + methodName + " in " + resource + " found");
          System.out.println("No suitable callees for " + methodName + " in " + resource + " found");
          }
        } else
        for (Iterator iter = callees.iterator(); iter.hasNext();) {
          Utils.MethodDeclarationUnitPair element
                            = (Utils.MethodDeclarationUnitPair) iter.next();
          MethodDeclaration methodDeclaration = element.getMethod();
          CompilationUnit nextCU         = element.getCompilationUnit();
          IResource nextResource         = element.getResource();       
       
          if(methodDeclaration  != null){
            if(!LapsePlugin.FOLLOW_INTO_FUNCTIONS) {
              /*HistoryDefinitionLocation dl = */new HistoryDefinitionLocation(
                  "Method " + methodDeclaration.getName().getFullyQualifiedName(),
                  nextResource,
                  nextCU.getLineNumber(e.getStartPosition()),
                  methodDeclaration, callDL, HistoryDefinitionLocation.RETURN);
            } else {
              Collection/*<ReturnStatement>*/ returns = CallerFinder.findReturns(monitor, methodDeclaration, null);
              for (Iterator iter2 = returns.iterator(); iter2.hasNext();) {
                ReturnStatement returnStmt = (ReturnStatement) iter2.next();
             
                HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
                    returnStmt.toString(),
                    nextResource,
                    nextCU.getLineNumber(returnStmt.getStartPosition()),
                    returnStmt, callDL, HistoryDefinitionLocation.RETURN);
                if(registerExpansion(dl)) {
                  Expression expr = returnStmt.getExpression();
                  if(expr != null) {
                    // Recurse on the returned expression
                    stack.addLast(mi);
                    processExpression(dl, expr, nextCU, nextResource, stack, monitor, HistoryDefinitionLocation.COPY,false);
                    stack.removeLast();
                  }
                }
              }
            }
          }
          else{
            //check if it is a derivtion expression
            if(SinkView.isDerivationName(methodName.getFullyQualifiedName()))
            {
       
                    processExpression(callDL, mi.getExpression(), cu, resource, stack, monitor, HistoryDefinitionLocation.DERIVATION,false);
               
                break;
            }
          } 
        }
      }
    } else
    if ( e instanceof InfixExpression && ( ((InfixExpression)e).getOperator() == InfixExpression.Operator.PLUS ) ) {
      /**
       * Follow arguments of a string concatenation.
       * */
      InfixExpression ie   = (InfixExpression) e;
      Expression leftExpr  = ie.getLeftOperand();
      Expression rightExpr = ie.getRightOperand();
      HistoryDefinitionLocation concatDL;
      if(!first){
      concatDL = new HistoryDefinitionLocation(
          e.toString(),
          resource,
          cu.getLineNumber(e.getStartPosition()),
          e,
          parent, HistoryDefinitionLocation.STRING_CONCAT);
      }
      else
      concatDL=parent;
     
      if(registerExpansion(concatDL)) {
        processExpression(concatDL, leftExpr,  cu, resource, stack, monitor, HistoryDefinitionLocation.COPY,false);
        processExpression(concatDL, rightExpr, cu, resource, stack, monitor, HistoryDefinitionLocation.COPY,false);
        if(ie.extendedOperands() != null) {
            for(Iterator iter = ie.extendedOperands().iterator(); iter.hasNext(); ) {
                Expression ext_e = (Expression) iter.next();
               
                processExpression(concatDL, ext_e, cu, resource, stack, monitor, HistoryDefinitionLocation.COPY,false);                     
            }
        }
      }
    }
    else if(e instanceof ParenthesizedExpression){
      ParenthesizedExpression ex=(ParenthesizedExpression)e;
      processExpression(parent, ex.getExpression(), cu, resource, stack, monitor, HistoryDefinitionLocation.UNDEFINED,false);
    }
    else if(e instanceof CastExpression){
      CastExpression cex=(CastExpression)e;
      processExpression(parent, cex.getExpression(), cu, resource, stack, monitor, HistoryDefinitionLocation.UNDEFINED,false);
    }
    else if(e instanceof ArrayAccess) {
      ArrayAccess ae=(ArrayAccess)e;
     
      HistoryDefinitionLocation arrAccess;
      if(!first){
        arrAccess= new HistoryDefinitionLocation(
          e.toString(),
          resource,
          cu.getLineNumber(e.getStartPosition()),
          e,
          parent, HistoryDefinitionLocation.ARRAYACCESS);
      }
      else arrAccess=parent;
      if(registerExpansion(arrAccess))
        processExpression(arrAccess, ae.getArray(),  cu, resource, stack, monitor, HistoryDefinitionLocation.ARRAYACCESS,false);
     
    }
    else if(e instanceof ClassInstanceCreation)
    {
      ClassInstanceCreation c=(ClassInstanceCreation)e;
      HistoryDefinitionLocation cc;
      if(!first){
      cc= new HistoryDefinitionLocation(
          e.toString(),
          resource,
          cu.getLineNumber(e.getStartPosition()),
          e,
          parent, HistoryDefinitionLocation.CLASS_INSTANCE_CREATION);
      }else
        cc=parent;
      String aux=(c.getType()).toString();
      if(SinkView.isDerivationName(aux)){
        for(Object arg:c.arguments()){
          if(registerExpansion(cc))
          processExpression(cc,(Expression)arg,cu,resource,stack,monitor,HistoryDefinitionLocation.DERIVATION,false);
        }
    }
      }
    else {
      /**
       * Some other expression.
       */
      /*HistoryDefinitionLocation dl = */new HistoryDefinitionLocation(
          e.toString(),
          resource,
          cu.getLineNumber(e.getStartPosition()),
          e, parent, getExpressionType(e, cu, resource));           
    }
View Full Code Here

      // finish the job       
      monitor.done();
      }
    else if(covering instanceof InfixExpression){
      InfixExpression infixExpr = (InfixExpression) covering;
      HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
          infixExpr.toString(),
          (IFile)resource,
          unit.getLineNumber(0),
          covering,null, HistoryDefinitionLocation.STRING_CONCAT);
     
      processExpression(dl, infixExpr, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.INITIAL,true);
      setCurrentInput(dl);
      addHistoryEntry(dl);
      fContentProvider.addElement(dl);
      refresh();
      }
     else if(covering instanceof ArrayAccess) {
       ArrayAccess ae=(ArrayAccess)covering;
       HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
      ae.toString(),
            (IFile)resource,
            unit.getLineNumber(0),
            covering,null, HistoryDefinitionLocation.ARRAYACCESS);
        processExpression(dl, ae, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.INITIAL,true);
        setCurrentInput(dl);
        addHistoryEntry(dl);   
        fContentProvider.addElement(dl);
       
        refresh();
       
      }
       else if(covering instanceof CastExpression) {
         CastExpression ae=(CastExpression)covering;
         HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
              ae.toString(),
              (IFile)resource,
              unit.getLineNumber(0),
              covering,null, HistoryDefinitionLocation.INITIAL);
          processExpression(dl, ae, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.CALL,true);
          setCurrentInput(dl);
          addHistoryEntry(dl);
          fContentProvider.addElement(dl);
          refresh();
        }
       else if(covering instanceof ClassInstanceCreation) {
         ClassInstanceCreation ae=(ClassInstanceCreation)covering;
         HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
              ae.toString(),
              (IFile)resource,
              unit.getLineNumber(0),
              covering,null, HistoryDefinitionLocation.CLASS_INSTANCE_CREATION);
          processExpression(dl, ae, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.CALL,true);
          setCurrentInput(dl);
          addHistoryEntry(dl);
          fContentProvider.addElement(dl);
          refresh();
        }
       else if(covering instanceof MethodInvocation) {
        MethodInvocation mi=(MethodInvocation)covering;
        HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
              mi.toString(),
              (IFile)resource,
              unit.getLineNumber(0),
              covering,null, HistoryDefinitionLocation.CALL);
          processExpression(dl, mi, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.CALL,true);
View Full Code Here

//  private HistoryDefinitionLocation fCurrentInput;
  /**
   * Adds the entry if new. Inserted at the beginning of the history entries list.
   */   
  private void addHistoryEntry(HistoryDefinitionLocation entry) {
    HistoryDefinitionLocation oldEntry = getHistoryEntry(entry);
    if (oldEntry != null) {
      fInputHistory.remove(oldEntry);
    }
   
    fInputHistory.add(0, entry);
View Full Code Here

    historyAction.setEnabled(true);
  }
 
  private HistoryDefinitionLocation getHistoryEntry(HistoryDefinitionLocation entry) {
    for (Iterator iter = fInputHistory.iterator(); iter.hasNext();) {
      HistoryDefinitionLocation element = (HistoryDefinitionLocation) iter.next();
      if(element.getASTNode() == entry.getASTNode()) {
        return element;
      }
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of lapsePlus.HistoryDefinitionLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.