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

📄 bugtreemodel.java

📁 A static analysis tool to find bugs in Java programs
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		/* Recursively traverses the tree, opens all nodes matching any bug 		 * in the list, then creates the full paths to the bugs that are selected		 * This keeps whatever bugs were selected selected when sorting		 *	DEPRECATED--Too Slow, use openPreviouslySelected		 */		public void crawlToOpen(TreePath path, ArrayList<BugLeafNode> bugLeafNodes, ArrayList<TreePath> treePaths)		{			for (int i = 0; i < getChildCount(path.getLastPathComponent()); i++)			{				if (!isLeaf(getChild(path.getLastPathComponent(), i)))					for (BugLeafNode p : bugLeafNodes)					{						if (p.matches((BugAspects) getChild(path.getLastPathComponent(), i)))						{							tree.expandPath(path);							crawlToOpen(path.pathByAddingChild(getChild(path.getLastPathComponent(), i)), bugLeafNodes, treePaths);							break;						}					}				else				{					for (BugLeafNode b: bugLeafNodes)					{						if (getChild(path.getLastPathComponent(),i).equals(b) )						{							tree.expandPath(path);							treePaths.add(path.pathByAddingChild(getChild(path.getLastPathComponent(), i)));						}					}				}			}		}		public static boolean TRACE = false;		public void resetData()//FIXME:  Does this need a setAsRootAndCache() on the new BugSet?		{			if (TRACE) System.out.println("Reseting data in bug tree model");			data=new BugSet(data);		}		FilterListener bugTreeFilterListener = new MyFilterListener();		class MyFilterListener implements FilterListener {		public void clearCache()		{			if (TRACE) System.out.println("clearing cache in bug tree model");			resetData();			BugSet.setAsRootAndCache(data);//FIXME:  Should this be in resetData?  Does this allow our main list to not be the same as the data in our tree?			root.setCount(data.size());			rebuild();		}		public void unsuppressBug(TreePath path)		{			if (TRACE) System.out.println("unsuppressing bug");			if (path==null)				return;			TreePath pathToFirstDeleted=null;			Object[] objPath=path.getParentPath().getPath();			ArrayList<Object> reconstruct=new ArrayList<Object>();			boolean earlyStop=false;			for (int x=0; x<objPath.length;x++)			{				Object o=objPath[x];				reconstruct.add(o);				if (o instanceof BugAspects)				{					pathToFirstDeleted=new TreePath(reconstruct.toArray());					((BugAspects)o).setCount(((BugAspects)o).getCount()+1);					if (((BugAspects)o).getCount()==2 && reconstruct.size() >1)					{						earlyStop=true;						break;					}					for (TreeModelListener l: listeners)					{						if (pathToFirstDeleted.getParentPath()!=null)							l.treeNodesChanged(new TreeModelEvent(this, pathToFirstDeleted.getParentPath(),new int[]{getIndexOfChild(pathToFirstDeleted.getParentPath().getLastPathComponent(),pathToFirstDeleted.getLastPathComponent())}, new Object[]{pathToFirstDeleted.getLastPathComponent()}));										}				}			}			if (path.getParentPath()==null)//They are unsuppressing from the root, but we don't allow root to be suppressed, Dont know what to do here			{				throw new RuntimeException();			}			if (pathToFirstDeleted==null)			{				pathToFirstDeleted=path;			}			if (earlyStop==false)			{				pathToFirstDeleted=pathToFirstDeleted.pathByAddingChild(path.getLastPathComponent());			}			Object parent=pathToFirstDeleted.getParentPath().getLastPathComponent();			Object child=pathToFirstDeleted.getLastPathComponent();			TreeModelEvent insertionEvent=new TreeModelEvent(this, pathToFirstDeleted.getParentPath(),new int[]{getIndexOfChild(parent,child)}, new Object[]{child});			for (TreeModelListener l: listeners)						{				l.treeNodesInserted(insertionEvent);			}			if (!isLeaf(child))			{				TreeModelEvent structureEvent=new TreeModelEvent(this, pathToFirstDeleted,new int[0], new Object[0]);				for (TreeModelListener l: listeners)							{								l.treeStructureChanged(structureEvent);				}			}		}		public void suppressBug(TreePath path)		{			if (TRACE) System.out.println("unsuppressing bug");			Debug.println(path);			Object[] objPath=path.getParentPath().getPath();			ArrayList<Object> reconstruct=new ArrayList<Object>();			for (int x=0; x< objPath.length;x++)			{				Object o=objPath[x];				((BugAspects)o).setCount(((BugAspects)o).getCount()-1);			}			for (int x=0; x< objPath.length;x++)			{				Object o=objPath[x];				reconstruct.add(o);				if (o instanceof BugAspects)				{					if (((BugAspects)o).getCount()==0)					{						path=new TreePath(reconstruct.toArray());						break;					}				}			}			TreeModelEvent event;			if (path.getParentPath()==null)//They are suppressing the last bug in the tree			{				event=new TreeModelEvent(this,path,new int[]{0},new Object[]{BugTreeModel.this.getChild(root,0)});				root.setCount(0);			}			else			{				Object parent = path.getParentPath().getLastPathComponent();				Object child = path.getLastPathComponent();				int indexOfChild=getIndexOfChild(parent,child);				if (indexOfChild!=-1)				{					event=new TreeModelEvent(this, path.getParentPath(),new int[]{indexOfChild}, new Object[]{child});					resetData();				}				else//They are suppressing something that has already been filtered out by setting a designation of a bug to a type that has been filtered out.				{					resetData();					for (TreeModelListener l: listeners)					{						l.treeStructureChanged(new TreeModelEvent(this, path.getParentPath()));					}					return;				}			}			for (TreeModelListener l: listeners)						{				l.treeNodesRemoved(event);			}		}		}		void treeNodeChanged(TreePath path)		{			Debug.println("Tree Node Changed: " + path);			if (path.getParentPath()==null)			{				TreeModelEvent event=new TreeModelEvent(this,path,null,null);				for (TreeModelListener l:listeners)				{					l.treeNodesChanged(event);				}				return;			}			TreeModelEvent event=new TreeModelEvent(this,path.getParentPath(),new int[]{getIndexOfChild(path.getParentPath().getLastPathComponent(),path.getLastPathComponent())},new Object[] {path.getLastPathComponent()});			for (TreeModelListener l: listeners)			{				l.treeNodesChanged(event);			}		}		public TreePath getPathToBug(BugInstance b)		{			//ArrayList<Sortables> order=MainFrame.getInstance().getSorter().getOrder();			List<Sortables> order=st.getOrderBeforeDivider();			//Create an array of BugAspects of lengths from one to the full BugAspect list of the bugInstance				BugAspects[] toBug=new BugAspects[order.size()];			for (int i=0; i < order.size(); i++)				toBug[i]=new BugAspects();			for (int x=0; x< order.size();x++)			{				for (int y=0; y<=x;y++)				{					Sortables s = order.get(y);					toBug[x].add(new SortableValue(s,s.getFrom(b)));				}			}			//Add this array as elements of the path			TreePath pathToBug=new TreePath(root);			for (int x=0;x<order.size();x++)			{				int index=getIndexOfChild(pathToBug.getLastPathComponent(),toBug[x]);				if (index==-1)				{					if (MainFrame.DEBUG) System.err.println("Node does not exist in the tree");//For example, not a bug bugs are filtered, they set a bug to be not a bug it filters out					return null;				}				pathToBug=pathToBug.pathByAddingChild(getChild(pathToBug.getLastPathComponent(),index));			}			//Using a hashlist to store bugs in BugSet will make getIndexOfChild Waaaaaay faster, thus making this O(1) (avg case)			int index=getIndexOfChild(pathToBug.getLastPathComponent(),new BugLeafNode(b));			if(index == -1)				return null;			pathToBug=pathToBug.pathByAddingChild(getChild(pathToBug.getLastPathComponent(),index));			return pathToBug;		}		public TreePath getPathToNewlyUnsuppressedBug(BugInstance b)		{			resetData();			return getPathToBug(b);		}		@Override		protected void finalize() throws Throwable		{			super.finalize();			//this will inform us when the garbage collector finds our old bug tree models and deletes them, thus preventing obnoxiously hard to find bugs from not remembering to remove the model from our listeners			Debug.println("The BugTreeModel has been DELETED!  This means there are no more references to it, and its finally off all of the stupid listener lists");		}		public void columnMarginChanged(ChangeEvent arg0) {}		public void columnSelectionChanged(ListSelectionEvent arg0) {}		public void treeExpanded(TreeExpansionEvent event) {		}		public void treeCollapsed(TreeExpansionEvent event) {		}		private void setOldSelectedBugs()		{			selectedBugLeafNodes.clear();			if (tree.getSelectionPaths() != null) // Who the cussword wrote this API anyway?				for (TreePath path : tree.getSelectionPaths())					if (isLeaf(path.getLastPathComponent()))						selectedBugLeafNodes.add((BugLeafNode) path.getLastPathComponent());		}		Vector<BugLeafNode> getOldSelectedBugs()		{			return selectedBugLeafNodes;		}		void checkSorter()		{			if (sortOrderChanged==true || sortsAddedOrRemoved==true)			{				sortOrderChanged=false;				sortsAddedOrRemoved=false;				rebuild();			}//			This old version isn't wrong... it just worries me, as it looks like we could rebuild twice, although//			we never do.  Above version should be safer.//			if (sortOrderChanged==true)//			{//				sortOrderChanged=false;//				rebuild();//			}//			if (sortsAddedOrRemoved==true)//			{//				sortsAddedOrRemoved=false;//				rebuild();//			}		}				static void pleaseWait()		{			pleaseWait(null);		}		static void pleaseWait(final String message)		{			MainFrame.getInstance().showWaitCard();		}		public TreeModelEvent restructureBranch(ArrayList<String> stringsToBranch, boolean removing) throws BranchOperationException		{			if (removing)				return branchOperations(stringsToBranch, TreeModification.REMOVERESTRUCTURE);			else				return branchOperations(stringsToBranch, TreeModification.INSERTRESTRUCTURE);		}		public TreeModelEvent insertBranch(ArrayList<String> stringsToBranch) throws BranchOperationException		{			return branchOperations(stringsToBranch, TreeModification.INSERT);		}		public TreeModelEvent removeBranch(ArrayList<String> stringsToBranch) throws BranchOperationException		{			return branchOperations(stringsToBranch, TreeModification.REMOVE);		}		public void sortBranch(TreePath pathToBranch)		{			BugSet bs=data.query((BugAspects)pathToBranch.getLastPathComponent());			bs.sortList();			Debug.println("Data in sorted branch: " + pathToBranch.getLastPathComponent());			for (BugLeafNode b: bs)			{				Debug.println(b);			}			Object[] children=new Object[getChildCount(pathToBranch.getLastPathComponent())];			int[] childIndices=new int[children.length];			for (int x=0; x<children.length; x++)			{				children[x]=getChild(pathToBranch.getLastPathComponent(),x);				childIndices[x]=x;			}			for (TreeModelListener l: listeners)			{				TreeModelEvent event=new TreeModelEvent(this,pathToBranch,childIndices,children);				l.treeNodesChanged(event);			}		}		@SuppressWarnings("serial")		static class BranchOperationException extends Exception		{			public BranchOperationException(String s)			{				super(s);			}		}		enum TreeModification {REMOVE, INSERT, REMOVERESTRUCTURE, INSERTRESTRUCTURE};		private TreeModelEvent branchOperations(ArrayList<String> stringsToBranch, TreeModification whatToDo) throws BranchOperationException		{			TreeModelEvent event=null;			if (whatToDo==TreeModification.REMOVE)				Debug.println("Removing a branch......");			else if (whatToDo==TreeModification.INSERT)				Debug.println("Inserting a branch......");			else if (whatToDo==TreeModification.REMOVERESTRUCTURE)				Debug.println("Restructuring from branch to remove......");			else if (whatToDo==TreeModification.INSERTRESTRUCTURE)				Debug.println("Restructuring from branch to insert......");			Debug.println(stringsToBranch);			if (whatToDo==TreeModification.INSERT || whatToDo==TreeModification.INSERTRESTRUCTURE)			{				resetData();			}			//ArrayList<Sortables> order=MainFrame.getInstance().getSorter().getOrder();			List<Sortables> order=st.getOrderBeforeDivider();			//Create an array of BugAspects of lengths from one to the full BugAspect list of the bugInstance				BugAspects[] toBug=new BugAspects[stringsToBranch.size()];			for (int x=0; x < stringsToBranch.size(); x++) {				toBug[x]=new BugAspects();				for (int y=0; y<=x;y++)				{					Sortables s = order.get(y);					toBug[x].add(new SortableValue(s,stringsToBranch.get(y)));				}			}			//Add this array as elements of the path			TreePath pathToBranch=new TreePath(root);			for (int x=0;x<stringsToBranch.size();x++)			{				BugAspects child=toBug[x];				BugAspects parent=(BugAspects) pathToBranch.getLastPathComponent();				if (getIndexOfChild(parent,child)!=-1)				{					pathToBranch=pathToBranch.pathByAddingChild(child);				}				else				{					Debug.println(parent + " does not contain " + child);					throw new BranchOperationException("Branch has been filtered out by another filter.");//					break;				}			}			if (pathToBranch.getParentPath()!=null)				while (getChildCount(pathToBranch.getParentPath().getLastPathComponent())==1)				{					if (pathToBranch.getParentPath().getLastPathComponent().equals(root))						break;					pathToBranch=pathToBranch.getParentPath();				}			Debug.println(pathToBranch);			if (whatToDo==TreeModification.INSERT)			{				event=new TreeModelEvent(this,pathToBranch.getParentPath(),new int[]{getIndexOfChild(pathToBranch.getParentPath().getLastPathComponent(),pathToBranch.getLastPathComponent())}, new Object[]{pathToBranch.getLastPathComponent()});							}			else if (whatToDo==TreeModification.INSERTRESTRUCTURE)			{				event=new TreeModelEvent(this,pathToBranch);			}			if (whatToDo==TreeModification.REMOVE)			{				event=new TreeModelEvent(this,pathToBranch.getParentPath(),new int[]{getIndexOfChild(pathToBranch.getParentPath().getLastPathComponent(),pathToBranch.getLastPathComponent())}, new Object[]{pathToBranch.getLastPathComponent()});			}			else if (whatToDo==TreeModification.REMOVERESTRUCTURE)			{				event=new TreeModelEvent(this,pathToBranch);			}			if (whatToDo==TreeModification.REMOVE || whatToDo==TreeModification.REMOVERESTRUCTURE)				resetData();			return event;		}				void sendEvent(TreeModelEvent event, TreeModification whatToDo)		{			Debug.println("Sending An Event!");			if (event==null)			{				throw new IllegalStateException("Dont throw null events.");			}			resetData();			for (TreeModelListener l: listeners)			{				if (whatToDo==TreeModification.REMOVE)					l.treeNodesRemoved(event);				else if (whatToDo==TreeModification.INSERT)				{					l.treeNodesInserted(event);					l.treeStructureChanged(new TreeModelEvent(this,new TreePath(event.getPath()).pathByAddingChild(event.getChildren()[0])));				}				else if (whatToDo==TreeModification.INSERTRESTRUCTURE || whatToDo==TreeModification.REMOVERESTRUCTURE)				{					l.treeStructureChanged(event);				}			}			root.setCount(data.size());			TreePath changedPath=new TreePath(root);			treeNodeChanged(changedPath);			changedPath=new TreePath(event.getPath());			while (changedPath.getParentPath()!=null)			{				treeNodeChanged(changedPath);				changedPath=changedPath.getParentPath();			}		}	}

⌨️ 快捷键说明

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