exceptions

This commit is contained in:
Olesya Smirnova
2005-10-27 17:18:35 +04:00
parent fba94c291e
commit 11a4a9dea4
7 changed files with 65 additions and 45 deletions
@@ -1,5 +1,6 @@
package com.intellij.cvsSupport2.cvsoperations.common;
import com.intellij.openapi.diagnostic.Logger;
import org.netbeans.lib.cvsclient.file.AbstractFileObject;
import org.netbeans.lib.cvsclient.file.DirectoryObject;
import org.netbeans.lib.cvsclient.file.FileObject;
@@ -7,8 +8,6 @@ import org.netbeans.lib.cvsclient.file.FileObject;
import java.io.File;
import java.util.*;
import com.intellij.openapi.diagnostic.Logger;
/**
* author: lesya
*/
@@ -30,13 +29,13 @@ public class CreateFileObjects {
}
public Collection execute(){
for (int i = 0; i < myFiles.length; i++) {
File file = myFiles[i];
LOG.assertTrue(file.isDirectory() || file.isFile() || file.getParentFile().isDirectory(), file.getAbsolutePath());
String fileAbsolutePath = file.getAbsolutePath();
String filePath = fileAbsolutePath.equals(myRootPath) ? "/" : fileAbsolutePath.substring(myRootPath.length() + 1);
File relativeFile = new File(filePath);
myResult.add(createAbstractFileObject(relativeFile.getParentFile(), relativeFile, file.isDirectory()));
for (File file : myFiles) {
if (file.isDirectory() || ! file.isFile() || !file.getParentFile().isDirectory()) {
String fileAbsolutePath = file.getAbsolutePath();
String filePath = fileAbsolutePath.equals(myRootPath) ? "/" : fileAbsolutePath.substring(myRootPath.length() + 1);
File relativeFile = new File(filePath);
myResult.add(createAbstractFileObject(relativeFile.getParentFile(), relativeFile, file.isDirectory()));
}
}
return myResult;
@@ -10,6 +10,7 @@ import java.io.*;
/**
* author: lesya
*/
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"})
public class StreamLogger implements IStreamLogger {
private int myCloseCount = 0;
@@ -25,9 +26,6 @@ public class StreamLogger implements IStreamLogger {
private static final long MAX_OUTPUT_SIZE = 1000000;
@NonNls private static final String OUTPUT_PATHNAME = "cvs.output";
public StreamLogger() {
}
private OutputStream createFileOutputStream(final File cvsOutputFile) {
try {
return new FileOutputStream(cvsOutputFile, true);
@@ -69,14 +67,14 @@ public class StreamLogger implements IStreamLogger {
public void close() throws IOException {
myCloseCount++;
if (myCloseCount == 2) {
if (myCloseCount == 2 && myLogOutput != null) {
myLogOutput.close();
myLogOutput = null;
myCloseCount = 0;
}
}
public int read(byte b[], int off, int len) throws IOException {
public int read(byte[] b, int off, int len) throws IOException {
if (len == 0) return 0;
final int read = read();
if (read == -1) return -1;
@@ -24,7 +24,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@SuppressWarnings({"unchecked"})
@SuppressWarnings({"unchecked", "CastToIncompatibleInterface", "InstanceofIncompatibleInterface"})
public abstract class BasePsiNode <T extends PsiElement> extends ProjectViewNode<T> {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.projectView.impl.nodes.BasePsiNode");
@@ -83,11 +83,14 @@ public abstract class BasePsiNode <T extends PsiElement> extends ProjectViewNode
public void update(PresentationData data) {
final T value = getValue();
T value = getValue();
if (value == null || !value.isValid()) {
setValue(null);
}
if (getValue() == null) return;
value = getValue();
if (value == null) return;
int flags = Iconable.ICON_FLAG_VISIBILITY;
if (isMarkReadOnly()) {
@@ -107,6 +110,7 @@ public abstract class BasePsiNode <T extends PsiElement> extends ProjectViewNode
updateImpl(data);
}
@SuppressWarnings({"InstanceofIncompatibleInterface", "CastToIncompatibleInterface"})
private boolean isDeprecated() {
final T element = getValue();
if (element == null || !element.isValid()) return false;
@@ -118,6 +122,9 @@ public abstract class BasePsiNode <T extends PsiElement> extends ProjectViewNode
public boolean contains(VirtualFile file) {
if (getValue() == null) return false;
PsiFile containingFile = getValue().getContainingFile();
if (containingFile == null) {
return false;
}
final VirtualFile valueFile = containingFile.getVirtualFile();
if (valueFile != null) {
return file.equals(valueFile);
@@ -37,9 +37,9 @@ public interface MergeVersion {
private final String myOriginalText;
public MergeDocumentVersion(Document document, String originalText) {
LOG.assertTrue(originalText != null);
LOG.assertTrue(document != null);
LOG.assertTrue(document.isWritable());
LOG.assertTrue(originalText != null, "text should not be null");
LOG.assertTrue(document != null, "document should not be null");
LOG.assertTrue(document.isWritable(), "document should be writable");
myDocument = document;
myOriginalText = originalText;
}
@@ -1,13 +1,12 @@
package com.intellij.openapi.localVcs.impl;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.localVcs.UpToDateLineNumberProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ex.LineStatusTracker;
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx;
import com.intellij.openapi.vcs.ex.Range;
import com.intellij.openapi.localVcs.UpToDateLineNumberProvider;
import java.util.Iterator;
import java.util.List;
/**
@@ -38,8 +37,8 @@ public class UpToDateLineNumberProviderImpl implements UpToDateLineNumberProvide
List ranges = tracker.getRanges();
int result = currentNumber;
for (Iterator each = ranges.iterator(); each.hasNext();) {
Range range = (Range) each.next();
for (final Object range1 : ranges) {
Range range = (Range)range1;
int startOffset = range.getOffset1();
int endOffset = range.getOffset2();
@@ -2,6 +2,7 @@ package com.intellij.openapi.vcs.actions;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.diff.DiffProvider;
import com.intellij.openapi.vcs.history.HistoryAsTreeProvider;
@@ -18,13 +19,14 @@ import com.intellij.util.TreeItem;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.tree.TreeUtil;
import com.intellij.util.ui.treetable.ListTreeTableModelOnColumns;
import com.intellij.CommonBundle;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.util.Iterator;
import java.util.List;
public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
@@ -34,7 +36,7 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
return object.getRevision().getBranchName();
}
};
private static final ColumnInfo<TreeNodeAdapter,String> REVISION_COLUMN = new ColumnInfo<TreeNodeAdapter, String>(VcsBundle.message("column.name.revision.list.revision")){
public String valueOf(final TreeNodeAdapter object) {
return object.getRevision().getRevisionNumber().asString();
@@ -52,7 +54,7 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
return object.getRevision().getAuthor();
}
};
public void update(VcsContext e, Presentation presentation) {
AbstractShowDiffAction.updateDiffAction(presentation, e);
}
@@ -68,7 +70,7 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
final List<VcsFileRevision> revisions = session.getRevisionList();
final HistoryAsTreeProvider treeHistoryProvider = vcsHistoryProvider.getTreeHistoryProvider();
if (treeHistoryProvider != null) {
showTreePopup(treeHistoryProvider.createTreeOn(revisions), file, project, vcs.getDiffProvider());
showTreePopup(treeHistoryProvider.createTreeOn(revisions), file, project, vcs.getDiffProvider());
}
else {
showListPopup(revisions, vcs, file, project);
@@ -76,14 +78,14 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
}
catch (VcsException e1) {
e1.printStackTrace();
Messages.showErrorDialog(VcsBundle.message("message.text.cannot.show.differences"), CommonBundle.message("title.error"));
}
}
private void showTreePopup(final List<TreeItem<VcsFileRevision>> roots, final VirtualFile file, final Project project, final DiffProvider diffProvider) {
final TreeTableView treeTable = new TreeTableView(new ListTreeTableModelOnColumns(new TreeNodeAdapter(null, null, roots),
final TreeTableView treeTable = new TreeTableView(new ListTreeTableModelOnColumns(new TreeNodeAdapter(null, null, roots),
new ColumnInfo[]{BRANCH_COLUMN, REVISION_COLUMN,
DATE_COLUMN, AUTHOR_COLUMN}));
Runnable runnable = new Runnable() {
@@ -93,8 +95,10 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
return;
}
VcsFileRevision revision = getRevisionAt(treeTable, index);
AbstractShowDiffAction.showDiff(diffProvider, revision.getRevisionNumber(),
file, project);
if (revision != null) {
AbstractShowDiffAction.showDiff(diffProvider, revision.getRevisionNumber(),
file, project);
}
}
};
@@ -131,18 +135,25 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
int y = r.y + r.height / 2 - popupSize.height / 2;
popup.show(x, y);
}
private VcsFileRevision getRevisionAt(final TreeTableView treeTable, final int index) {
return ((TreeNodeAdapter)treeTable.getItems().get(index)).getRevision();
@Nullable private VcsFileRevision getRevisionAt(final TreeTableView treeTable, final int index) {
final List items = treeTable.getItems();
if (items.size() <= index) {
return null;
} else {
return ((TreeNodeAdapter)items.get(index)).getRevision();
}
}
private JPanel createMainPanel(final TreeTableView treeTable) {
JScrollPane scrollPane = new JScrollPane(treeTable);
treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
treeTable.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
if (treeTable.getRowCount() >= 20) {
@@ -151,7 +162,7 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
else {
scrollPane.getViewport().setPreferredSize(treeTable.getPreferredSize());
}
JPanel panel = new JPanel(new BorderLayout());
panel.add(scrollPane, BorderLayout.CENTER);
final JTextArea textArea = createTextArea();
@@ -162,7 +173,11 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
textArea.setText("");
} else {
final VcsFileRevision revision = getRevisionAt(treeTable, index);
textArea.setText(revision.getCommitMessage());
if (revision != null) {
textArea.setText(revision.getCommitMessage());
} else {
textArea.setText("");
}
}
}
});
@@ -183,8 +198,8 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
private void showListPopup(final List<VcsFileRevision> revisions, final AbstractVcs vcs, final VirtualFile file, final Project project) {
final DefaultListModel model = new DefaultListModel();
for (Iterator<VcsFileRevision> iterator = revisions.iterator(); iterator.hasNext();) {
model.addElement(iterator.next());
for (final VcsFileRevision revision : revisions) {
model.addElement(revision);
}
final JList list = new JList(model);
list.setCellRenderer(new VcsRevisionListCellRenderer());
@@ -236,6 +251,7 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
Dimension viewPreferredSize = new Dimension(listPreferredSize.width, Math.min(listPreferredSize.height, r.height - 20));
final Container parent = list.getParent();
if (parent instanceof JComponent) {
//noinspection RedundantCast
((JComponent)parent).setPreferredSize(viewPreferredSize);
}
}
@@ -266,7 +282,7 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
final JScrollPane textScrollPane = new JScrollPane(textArea);
textScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.lightGray),VcsBundle.message("border.selected.revision.commit.message")));
jPanel.add(textScrollPane, BorderLayout.SOUTH);
jPanel.setPreferredSize(new Dimension(300, jPanel.getPreferredSize().height + 10));
return jPanel;
}
@@ -279,8 +295,7 @@ public class CompareWithSelectedRevisionAction extends AbstractVcsAction {
parent.add(this);
}
myRevision = revision;
for (Iterator<TreeItem<VcsFileRevision>> iterator = children.iterator(); iterator.hasNext();) {
TreeItem<VcsFileRevision> treeItem = iterator.next();
for (TreeItem<VcsFileRevision> treeItem : children) {
new TreeNodeAdapter(this, treeItem, treeItem.getChildren());
}
}
@@ -73,7 +73,9 @@ public class ListTableModel <Item> extends TableViewModel<Item> implements ItemR
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
myColumnInfos[columnIndex].setValue(myItems.get(rowIndex), aValue);
if (rowIndex < myItems.size()) {
myColumnInfos[columnIndex].setValue(myItems.get(rowIndex), aValue);
}
}
public List<Item> getItems() {