protected void buttonPressed(int buttonId) {
   if (buttonId == IDialogConstants.OK_ID) {
     StructuredSelection sel = (StructuredSelection) listViewer.getSelection();
     Object[] objs = sel.toArray();
     selectedSkills = new int[objs.length];
     for (int i = 0; i < objs.length; i++) {
       selectedSkills[i] = ((SkillConfig) objs[i]).id;
     }
   }
   super.buttonPressed(buttonId);
 }
 public void toggleExpandState(int state, StructuredSelection selection) {
   TreeItem[] items = fExtensionTree.getTree().getSelection();
   if (state == NEEDS_EXPAND) { // expand sub tree
     traverseChildrenAndSetExpanded(items); // load non-expanded children
     fExtensionTree.refresh();
     expandChildrenElements(selection.toArray(), true);
     fExtensionTree.setSelection(selection, false);
   } else { // collapse sub tree
     for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
       fExtensionTree.setExpandedState(iterator.next(), false);
     }
   }
 }
Exemplo n.º 3
0
  private void onMove(StructuredSelection selection, ToolBarItem destination, int location) {

    /* Determine Moved Items */
    List<ToolBarItem> movedItems = new ArrayList<ToolBarItem>();
    Object[] selectedElements = selection.toArray();
    for (Object element : selectedElements) {
      movedItems.add((ToolBarItem) element);
    }

    /* Determine Visible Items */
    List<ToolBarItem> visibleItems = new ArrayList<ToolBarItem>();
    TableItem[] items = fItemViewer.getTable().getItems();
    for (TableItem item : items) {
      visibleItems.add((ToolBarItem) item.getData());
    }

    /* Return in these unlikely cases */
    if (movedItems.isEmpty() || visibleItems.isEmpty()) return;

    /* Remove all Moved Items from Visible */
    visibleItems.removeAll(movedItems);

    /* Put Moved Items to Destination Index if possible */
    int destinationIndex = visibleItems.indexOf(destination);
    if (destinationIndex >= 0) {

      /* Adjust Destination */
      if (location == ViewerDropAdapter.LOCATION_ON || location == ViewerDropAdapter.LOCATION_AFTER)
        destinationIndex++;

      /* Add to Visible */
      visibleItems.addAll(destinationIndex, movedItems);

      /* Save Visible */
      int[] newToolBarItems = new int[visibleItems.size()];
      for (int i = 0; i < visibleItems.size(); i++)
        newToolBarItems[i] = visibleItems.get(i).item.ordinal();
      fPreferences.putIntegers(DefaultPreferences.TOOLBAR_ITEMS, newToolBarItems);

      /* Show Updates */
      fItemViewer.refresh();

      /* Restore Selection */
      fItemViewer
          .getTable()
          .setSelection(destinationIndex, destinationIndex + movedItems.size() - 1);

      /* Update Buttons */
      updateButtonEnablement();
    }
  }
Exemplo n.º 4
0
  public void run(IAction action) {
    IWorkbenchPartSite site = _part.getSite();
    ISelectionProvider provider = site.getSelectionProvider();
    StructuredSelection selection = (StructuredSelection) provider.getSelection();
    Object[] items = selection.toArray();

    RepositoryAnalyzer ra = RepositoryAnalyzer.getInstance();

    if (items.length != 1) {
      logger.error("ERROR: This should be run only on one item");
    }

    if (items[0] instanceof IJavaProject) {
      try {
        RepositoryAnalyzer.resetMIIdGen();

        IJavaProject project = (IJavaProject) items[0];

        String codesamples_dir_local = codesamples_dir + project.getElementName().toString();

        ra.setLibProject(project);
        ParseSrcFiles psf = new ParseSrcFiles();
        psf.parseSources(project);

        loadPackageInfoToMemory(project);

        /*Debugging section for getting list of classes*/
        try {
          BufferedWriter bw = new BufferedWriter(new FileWriter("APIList.txt"));
          for (Iterator iter = ra.getLibClassMap().values().iterator(); iter.hasNext(); ) {
            LibClassHolder lcc = (LibClassHolder) iter.next();

            bw.write(lcc.getName() + "#");
            for (LibMethodHolder lmh : lcc.getMethods()) {
              bw.write(lmh.toString() + "#");
            }

            bw.write("\n");
          }
          bw.close();
        } catch (Exception ex) {
          ex.printStackTrace();
        }

        /*End of Debug Section*/

        // Analysing code samples collected from Google code search engine
        RepositoryCreator rcObj = new RepositoryCreator();
        rcObj.createLocalRepos(codesamples_dir_local);

        logger.debug("Finished downloading files...");
        ra.analyzeRepository(codesamples_dir_local);

        // Debugging output of all collected sequences from the samples
        logger.info("Outputting all gathered sequenes...");
        List<String> seqList = ra.getMethodIDSequences();
        BufferedWriter bw = new BufferedWriter(new FileWriter("MethodSequences.txt"));
        int counter = 0;
        for (String sequence : seqList) {
          counter++;
          bw.write("Sequence " + counter + "\n");

          String elementArr[] = sequence.split(" ");
          for (String elem : elementArr) {
            LibMethodHolder lmh = ra.getIdToLibMethod().get(Integer.parseInt(elem));
            bw.write(
                "\t "
                    + /*lmh.getDescriptor() + " : " +*/ lmh.getContainingClass().getName()
                    + " : "
                    + lmh
                    + "\n");
          }
        }
        bw.close();
        // End of debugging output

        // MAFIA: Writing files for mining (mcseq.txt and mcseq.spec)
        /*List<String> seqIDList = ra.getMethodIDSequences();
         		BufferedWriter bwBideMcSeq = new BufferedWriter(new FileWriter("mcseq.txt"));
         		int seqCounter = 0, maxLen = 0, totalSeqLength = 0;
         		for(String IDSequence : seqIDList)
         		{
         			bwBideMcSeq.write(IDSequence + " \n");
         			seqCounter++;
         			if(IDSequence.length() > maxLen)
         				maxLen = IDSequence.length();
         			totalSeqLength += IDSequence.length();
         		}
         		bwBideMcSeq.write(" \n");
         		bwBideMcSeq.close();
         		//End of Mafia output

         		//Executing Mafia tool
         		try
        {
        	Runtime javaRuntime = Runtime.getRuntime();
        	String command = "mafia.exe -mfi .008 -ascii mcseq.txt frequent.dat ";

        	@SuppressWarnings("unused")
        	Process bideProcess = javaRuntime.exec(command);
        	Thread.sleep(60 * 1000); //TODO: To replace with WAIT later
        	//bideProcess.waitFor();  //NOTE: This method hangs if the process initiated process any console output and it is not consumed
        }
        catch(Exception ex)
        {
        	logger.error("Error in executing MAFIA!!!" + ex);
        }

         		//Reading the BIDE output: Each frequent sequence must include only APIs categorized
        //as hotspots
        HashSet<Integer> hotspotSet = new HashSet<Integer>();
        BufferedWriter bw_freqSeq = new BufferedWriter(new FileWriter("FrequentSeq.txt"));
         		Scanner bide_out = new Scanner(new File("frequent.dat"));

         		HashSet<CodeExampleStore> codeExampleStore = RepositoryAnalyzer.getInstance().getCodeExampleSet();


         		int fcounter = 0;
         		while(bide_out.hasNextLine())
         		{
         			fcounter++;
         			String freqSeq = bide_out.nextLine();
         			String[] freqSeqList = (freqSeq.substring(0,freqSeq.indexOf("("))).split(" ");
         			bw_freqSeq.write("Frequent Usage Scenario: " + fcounter + "\n");

         			HashSet<Integer> currentSeqSet = new HashSet<Integer>();
         			String scenarioType = "InvokesUS";
         			for(String miId : freqSeqList)
         			{
         				Integer intObj = new Integer(miId);
         				hotspotSet.add(intObj);
         				currentSeqSet.add(intObj);
         				LibMethodHolder lmh = ra.getIdToLibMethod().get(intObj);

         				bw_freqSeq.write("\t " + lmh.getContainingClass().getName() + " : " + lmh + "\n");
         				if(lmh.getName().indexOf("ExtendsClass") != -1) {
         					scenarioType = "ExtendsUS";
         				}

         				if(lmh.getName().indexOf("ImplementsInterface") != -1) {
         					scenarioType = "ImplementsUS";
         				}

         				//if((lmh.getMethodType() & LibMethodHolder.TEMPLATE) == 0 && (lmh.getMethodType() & LibMethodHolder.HOOK) != 0)
         				//{
         				//	logger.warn("Warning: Hook method appeared in main sequence " + lmh);
         				//}

         				//Get the corresponding hook hotspots
         				//HashSet<LibMethodHolder> methodsInvoked = lmh.getInvokedMethods();
         				//for(LibMethodHolder invokedLMH : methodsInvoked)
         				//{
         				//	if((invokedLMH.getMethodType() & LibMethodHolder.TEMPLATE) == 0 && (invokedLMH.getMethodType() & LibMethodHolder.HOOK) != 0)
         				//	{
         				//		bw_freqSeq.write("\t\tStrict Hook: " + invokedLMH.getContainingClass().getName() + " : " + invokedLMH + "\n");
         				//	} else if ((invokedLMH.getMethodType() & LibMethodHolder.HOOK) != 0)
         				//	{
         				//		bw_freqSeq.write("\t\tOptional Hook: " + invokedLMH.getContainingClass().getName() + " : " + invokedLMH + "\n");
         				//	}
         				//}
         			}
         			bw_freqSeq.write("Scenario Type : " + scenarioType);
         			//Identify the equivalent example
         			for(CodeExampleStore cesObj : codeExampleStore) {
         				if(cesObj.methodIds.containsAll(currentSeqSet))
         				{
         					bw_freqSeq.write(" FileName : " + cesObj.filename + " MethodName : " + cesObj.methodname + "\n");
         					break;
         				}
         			}
         		}

        bide_out.close();
        bw_freqSeq.close();


        logger.info("Number of Final Hotspots: " + hotspotSet.size());
        logger.info("Hotspot IDs: " + hotspotSet);
        */
        // Freeing the memory
        RepositoryAnalyzer.clearInstance();

      } catch (Throwable th) {
        th.printStackTrace();
      }

    } else {
      logger.error("ERROR: This should be run only on a Java project");
    }
  }
Exemplo n.º 5
0
 /**
  * 取得选中的对象。
  *
  * @return 选中的对象
  */
 public Object[] getSelectedObjects() {
   int tabIndex = dataTypeTabFolder.getSelectionIndex();
   StructuredSelection sel = (StructuredSelection) dataTreeViewers[tabIndex].getSelection();
   return sel.toArray();
 }