⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commentsarea.java

📁 A static analysis tool to find bugs in Java programs
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				count++;		}		String[] ary = new String[list.length - count];		int j = 0;		for (String str : list) {			if (!str.equals("")) {				ary[j] = str;				j++;			}		}		String[] temp;		prevCommentsList = new LinkedList<String>();		if ((ary.length) > prevCommentsMaxSize) {			temp = new String[prevCommentsMaxSize];			for (int i = 0; i < temp.length && i < ary.length; i++)				temp[i] = ary[i];		} else {			temp = new String[ary.length];			for (int i = 0; i < ary.length; i++)				temp[i] = ary[i];		}		for (String str : temp)			prevCommentsList.add(str);		resetPrevCommentsComboBox();	}	/**	 * Adds the comment into the list. If the comment is already in the list	 * then simply moves to the front. If the list is too big when adding the	 * comment then deletes the last comment on the list.	 * 	 * @param comment	 */	private void addToPrevComments(String comment) {		if (comment.equals(""))			return;		if (prevCommentsList.contains(comment)) {			int index = prevCommentsList.indexOf(comment);			if (index == 0)				return;			prevCommentsList.remove(index);		}		prevCommentsList.addFirst(comment);		while (prevCommentsList.size() > prevCommentsMaxSize)			prevCommentsList.removeLast();		resetPrevCommentsComboBox();	}	/**	 * Removes all items in the comboBox for previous comments. Then refills it	 * using prevCommentsList.	 * 	 */	private void resetPrevCommentsComboBox() {		prevCommentsComboBox.removeAllItems();		prevCommentsComboBox.addItem("");		for (String str : prevCommentsList) {			if (str.length() < 20)				prevCommentsComboBox.addItem(str);			else				prevCommentsComboBox.addItem(str.substring(0, 17) + "...");		}	}	/**	 * Returns the text in the current user comments textArea.	 * 	 * @return	 */	private String getCurrentUserCommentsText() {		return userCommentsText.getText();	}	/**	 * Sets the current user comments text area to comment.	 * 	 * @param comment	 */	private void setCurrentUserCommentsText(String comment) {		changed = true;		userCommentsText.setText(comment);	}	/**	 * Returns the current selected previous comments. Returns as an object.	 */	private String getCurrentPrevCommentsSelection() {		return prevCommentsList				.get(prevCommentsComboBox.getSelectedIndex() - 1);	}	void addDesignationItem(JMenu menu, final String menuName, int keyEvent) {		JMenuItem toggleItem = new JMenuItem(menuName);		toggleItem.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent arg0) {				if (frame.currentSelectedBugLeaf == null)					setDesignationNonLeaf(menuName);				else					setDesignation(menuName);			}		});		MainFrame.attachAcceleratorKey(toggleItem, keyEvent);		menu.add(toggleItem);	}	void setDesignation(String designationName) {		if (frame.currentSelectedBugLeaf == null)			return;		String designationKey = convertDesignationNameToDesignationKey(designationName);		if (designationKey == null)			return;		if (changeDesignationOfBug(frame.currentSelectedBugLeaf, designationKey)){			changed = true;			setProjectChanged(true);		}		setDesignationComboBox(designationKey);	}	protected void setDesignationNonLeaf(String designationName) {		String designationKey = convertDesignationNameToDesignationKey(designationName);		if (designationKey == null || frame.currentSelectedBugAspects == null)			return;		BugSet filteredSet = frame.currentSelectedBugAspects				.getMatchingBugs(BugSet.getMainBugSet());		for (BugLeafNode nextNode : filteredSet)			if (changeDesignationOfBug(nextNode, designationKey)){				changed = true;				setProjectChanged(true);			}		setDesignationComboBox(designationKey);	}	protected boolean changeDesignationOfBug(BugLeafNode theNode, String selection) {		BugDesignation userDesignation = theNode.getBug().getNonnullUserDesignation();		if (userDesignation.getDesignationKey().equals(selection)) return false;		userDesignation.setDesignationKey(selection);		return true;	}	protected void updateDesignationComboBox() {		if (frame.currentSelectedBugLeaf == null)			updateCommentsFromNonLeafInformationFromSwingThread(frame.currentSelectedBugAspects);		else {			int selectedIndex = designationComboBox								.getSelectedIndex();			if (selectedIndex >= 0) setDesignationComboBox(designationKeys.get(selectedIndex));			else				Debug.println("Couldn't find selected index in designationComboBox: " + designationComboBox.getSelectedItem());		}	}	protected void updateCommentsFromNonLeafInformationFromSwingThread(BugAspects theAspects) {		if (theAspects == null)			return;		BugSet filteredSet = theAspects.getMatchingBugs(BugSet.getMainBugSet());		boolean allSame = true;		int first = -1;		for (BugLeafNode nextNode : filteredSet) {			int designationIndex = designationKeys.indexOf(nextNode.getBug()					.getNonnullUserDesignation().getDesignationKey());			if (first == -1) {				first = designationIndex;			} else {				if (designationIndex != first)					allSame = false;			}		}		;		if (allSame) {			designationComboBox.setSelectedIndex(first);		} else {			designationComboBox.setSelectedIndex(0);		}		userCommentsText.setText(getNonLeafCommentsText(theAspects));		changed = false;		// setUserCommentInputEnableFromSwingThread(true);	}	protected String getNonLeafCommentsText(BugAspects theAspects)	{	if (theAspects == null)			return "";		BugSet filteredSet = theAspects.getMatchingBugs(BugSet.getMainBugSet());		boolean allSame = true;		String comments = null;		for (BugLeafNode nextNode : filteredSet) {		String commentsOnThisBug = nextNode.getBug().getAnnotationText();			if (comments == null) {				comments = commentsOnThisBug;			} else {				if (!commentsOnThisBug.equals(comments))					allSame = false;			}		}		if((comments == null) || (allSame == false))			return "";		else return comments;	}	/*	protected String getNonLeafCommentsText(BugAspects theAspects)	{	if (theAspects == null)			return "";		BugSet filteredSet = theAspects.getMatchingBugs(BugSet.getMainBugSet());		boolean allSame = true;		String comments = null;		for (BugLeafNode nextNode : filteredSet) {		String commentsOnThisBug = nextNode.getBug().getAnnotationText();			if (comments == null) {				comments = commentsOnThisBug;			} else {				if (!commentsOnThisBug.equals(comments))					allSame = false;			}		}		if((comments == null) || (allSame == false))			return "";		else return comments;	}	*/	protected void setDesignationComboBox(String designationKey) {		int numItems = designationComboBox.getItemCount();		for (int i = 0; i < numItems; i++) {			String value = designationKeys.get(i);			if (designationKey.equals(value)) {				designationComboBox.setSelectedIndex(i);				return;				}		}		if (MainFrame.DEBUG) System.out.println("Couldn't find combo box for " + designationKey);	}	public void moveNodeAccordingToDesignation(BugLeafNode theNode,			String selection) {		if (!getSorter().getOrder().contains(Sortables.DESIGNATION)) {			// designation not sorted on at all			theNode.getBug().getNonnullUserDesignation().setDesignationKey(					selection);		} else if (getSorter().getOrderBeforeDivider().contains(				Sortables.DESIGNATION)) {			BugTreeModel model = getModel();			TreePath path = model.getPathToBug(theNode.getBug());			if (path == null) {				theNode.getBug().getNonnullUserDesignation().setDesignationKey(						selection);				return;			}			Object[] objPath = path.getParentPath().getPath();			ArrayList<Object> reconstruct = new ArrayList<Object>();			ArrayList<TreePath> listOfNodesToReconstruct = new ArrayList<TreePath>();			for (int x = 0; x < objPath.length; x++) {				Object o = objPath[x];				reconstruct.add(o);				if (o instanceof BugAspects) {					if (((BugAspects) o).getCount() == 1) {						// Debug.println((BugAspects)(o));						break;					}				}				TreePath pathToNode = new TreePath(reconstruct.toArray());				listOfNodesToReconstruct.add(pathToNode);			}			theNode.getBug().getNonnullUserDesignation().setDesignationKey(					selection);			model.bugTreeFilterListener.suppressBug(path);			TreePath unsuppressPath = model.getPathToBug(theNode.getBug());			if (unsuppressPath != null)// If choosing their designation has not										// moved the bug under any filters			{				model.bugTreeFilterListener.unsuppressBug(unsuppressPath);				// tree.setSelectionPath(unsuppressPath);			}			for (TreePath pathToNode : listOfNodesToReconstruct) {				model.treeNodeChanged(pathToNode);			}			setProjectChanged(true);		} else if (getSorter().getOrderAfterDivider().contains(				Sortables.DESIGNATION)) {			theNode.getBug().getNonnullUserDesignation().setDesignationKey(					selection);			BugTreeModel model = getModel();			TreePath path = model.getPathToBug(theNode.getBug());			if (path != null)				model.sortBranch(path.getParentPath());		}	}	protected @CheckForNull	String convertDesignationNameToDesignationKey(String name) {		/*		 * This converts a designation name from human-readable format ("mostly		 * harmless", "critical") to the program's internal format		 * ("MOSTLY_HARMLESS", "CRITICAL") etc. This uses the		 * DesignationComboBox (this should probably be changed)		 */		int itemCount = designationComboBox.getItemCount();		for (int i = 1; i < itemCount; i++)			if (name.equals(designationComboBox.getItemAt(i)))				return designationKeys.get(i);		return null;	}	private void setProjectChanged(boolean b) {		frame.setProjectChanged(b);	}	/**	 * Returns the SorterTableColumnModel of the MainFrame.	 * 	 * @return	 */	SorterTableColumnModel getSorter() {		return frame.getSorter();	}	public void resized() {		resetPrevCommentsComboBox();		userCommentsText.validate();	}	BugTreeModel getModel() {		return (BugTreeModel) frame.tree.getModel();	}	public boolean hasFocus() {		return userCommentsText.hasFocus();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -