parameterInfos) {
+ public void setParameterInfos(List parameterInfos) {
myParametersTableModel.setParameterInfos(parameterInfos);
updateSignature();
}
@@ -148,7 +160,8 @@ public abstract class ChangeSignatureDialogBase
getParameters() {
- List
result = new ArrayList
(myParametersTableModel.getRowCount());
- for (ParameterTableModelItemBase
item : myParametersTableModel.getItems()) {
+ public List getParameters() {
+ List result = new ArrayList(myParametersTableModel.getRowCount());
+ for (ParameterTableModelItemBase item : myParametersTableModel.getItems()) {
result.add(item.parameter);
}
return result;
@@ -319,18 +332,17 @@ public abstract class ChangeSignatureDialogBase
> chooser = new Ref>();
- Consumer> callback = new Consumer>() {
+ final Ref> chooser = new Ref>();
+ Consumer> callback = new Consumer>() {
@Override
- public void consume(Set callers) {
+ public void consume(Set callers) {
myMethodsToPropagateParameters = callers;
myParameterPropagationTreeToReuse = chooser.get().getTree();
}
};
try {
- chooser.set(
- createCallerChooser(RefactoringBundle.message("changeSignature.parameter.caller.chooser"), myParameterPropagationTreeToReuse,
- callback));
+ String message = RefactoringBundle.message("changeSignature.parameter.caller.chooser");
+ chooser.set(createCallerChooser(message, myParameterPropagationTreeToReuse, callback));
}
catch (ProcessCanceledException ex) {
// user cancelled initial callers search, don't show dialog
@@ -368,7 +380,7 @@ public abstract class ChangeSignatureDialogBase
>(myParametersTableModel) {
+ myParametersTable = new TableView(myParametersTableModel) {
public void removeEditor() {
clearEditorListeners();
@@ -427,7 +439,7 @@ public abstract class ChangeSignatureDialogBase
> items = myParametersTable.getItems();
+ final List items = myParametersTable.getItems();
final JComponent component = getRowPresentation(items.get(row), selected, focused);
for (EditorTextField editorTextField : UIUtil.findComponentsOfType(component, EditorTextField.class)) {
editorTextField.addSettingsProvider(new EditorSettingsProvider() {
@@ -442,14 +454,15 @@ public abstract class ChangeSignatureDialogBase
> items = myParametersTable.getItems();
+ final List items = myParametersTable.getItems();
return isEmptyRow(items.get(row));
}
@Override
protected JBTableRowEditor getRowEditor(final int row) {
- final List> items = myParametersTable.getItems();
+ final List items = myParametersTable.getItems();
JBTableRowEditor editor = getTableEditor(myParametersList.getTable(), items.get(row));
+ LOG.assertTrue(editor != null);
editor.addDocumentListener(new JBTableRowEditor.RowDocumentListener() {
@Override
public void documentChanged(DocumentEvent e, int column) {
@@ -496,19 +509,21 @@ public abstract class ChangeSignatureDialogBase
infos = getParameters();
+ final List infos = getParameters();
if (infos.size() <= myMethod.getParametersCount()) return false;
for (int i = 0; i < myMethod.getParametersCount(); i++) {
if (infos.get(i).getOldIndex() != i) return false;
diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ParameterTableModelBase.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ParameterTableModelBase.java
index 976933fb98b3..67c1a7e5b301 100644
--- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ParameterTableModelBase.java
+++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ParameterTableModelBase.java
@@ -35,8 +35,7 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.List;
-public abstract class ParameterTableModelBase
extends ListTableModel>
- implements RowEditableTableModel {
+public abstract class ParameterTableModelBase
> extends ListTableModel implements RowEditableTableModel {
protected final PsiElement myTypeContext;
protected final PsiElement myDefaultValueContext;
@@ -49,14 +48,14 @@ public abstract class ParameterTableModelBase
extends L
myDefaultValueContext = defaultValueContext;
}
- protected abstract ParameterTableModelItemBase
createRowItem(@Nullable P parameterInfo);
+ protected abstract TableItem createRowItem(@Nullable P parameterInfo);
public void addRow() {
addRow(createRowItem(null));
}
public void setParameterInfos(List
parameterInfos) {
- List> items = new ArrayList>(parameterInfos.size());
+ List items = new ArrayList(parameterInfos.size());
for (P parameterInfo : parameterInfos) {
items.add(createRowItem(parameterInfo));
}
@@ -73,8 +72,8 @@ public abstract class ParameterTableModelBase
extends L
fireTableCellUpdated(rowIndex, columnIndex); // to update signature
}
- protected static abstract class ColumnInfoBase
, Aspect>
+ extends ColumnInfo {
private TableCellRenderer myRenderer;
private TableCellEditor myEditor;
@@ -83,7 +82,7 @@ public abstract class ParameterTableModelBase
extends L
}
@Override
- public final TableCellEditor getEditor(ParameterTableModelItemBase
o) {
+ public final TableCellEditor getEditor(TableItem o) {
if (myEditor == null) {
myEditor = doCreateEditor(o);
}
@@ -91,7 +90,7 @@ public abstract class ParameterTableModelBase
extends L
}
@Override
- public final TableCellRenderer getRenderer(ParameterTableModelItemBase
item) {
+ public final TableCellRenderer getRenderer(TableItem item) {
if (myRenderer == null) {
final TableCellRenderer original = doCreateRenderer(item);
myRenderer = new TableCellRenderer() {
@@ -119,12 +118,12 @@ public abstract class ParameterTableModelBase
extends L
return myRenderer;
}
- protected abstract TableCellRenderer doCreateRenderer(ParameterTableModelItemBase
{
protected final Project myProject;
private final FileType myFileType;
@@ -139,25 +138,25 @@ public abstract class ParameterTableModelBase
extends L
}
@Override
- public PsiCodeFragment valueOf(ParameterTableModelItemBase
item) {
+ public PsiCodeFragment valueOf(TableItem item) {
return item.typeCodeFragment;
}
@Override
- public boolean isCellEditable(ParameterTableModelItemBase
pParameterTableModelItemBase) {
+ public boolean isCellEditable(TableItem pParameterTableModelItemBase) {
return true;
}
- public TableCellRenderer doCreateRenderer(ParameterTableModelItemBase
pParameterTableModelItemBase) {
+ public TableCellRenderer doCreateRenderer(TableItem pParameterTableModelItemBase) {
return new CodeFragmentTableCellRenderer(myProject, myFileType);
}
- public TableCellEditor doCreateEditor(ParameterTableModelItemBase
o) {
+ public TableCellEditor doCreateEditor(TableItem o) {
return new CodeFragmentTableCellEditorBase(myProject, myFileType);
}
}
- protected static class NameColumn
extends ColumnInfoBase
{
+ protected static class NameColumn
> extends ColumnInfoBase
{
private final Project myProject;
public NameColumn(Project project) {
@@ -170,21 +169,21 @@ public abstract class ParameterTableModelBase
extends L
}
@Override
- public String valueOf(ParameterTableModelItemBase
item) {
+ public String valueOf(TableItem item) {
return item.parameter.getName();
}
@Override
- public void setValue(ParameterTableModelItemBase
item, String value) {
+ public void setValue(TableItem item, String value) {
item.parameter.setName(value);
}
@Override
- public boolean isCellEditable(ParameterTableModelItemBase
pParameterTableModelItemBase) {
+ public boolean isCellEditable(TableItem pParameterTableModelItemBase) {
return true;
}
- public TableCellRenderer doCreateRenderer(ParameterTableModelItemBase
item) {
+ public TableCellRenderer doCreateRenderer(TableItem item) {
return new ColoredTableCellRenderer() {
public void customizeCellRenderer(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
@@ -194,12 +193,12 @@ public abstract class ParameterTableModelBase
extends L
};
}
- public TableCellEditor doCreateEditor(ParameterTableModelItemBase
o) {
+ public TableCellEditor doCreateEditor(TableItem o) {
return new StringTableCellEditor(myProject);
}
}
- protected static class DefaultValueColumn
extends ColumnInfoBase
{
+ protected static class DefaultValueColumn
> extends ColumnInfoBase
{
private final Project myProject;
private final FileType myFileType;
@@ -214,50 +213,50 @@ public abstract class ParameterTableModelBase
extends L
}
@Override
- public boolean isCellEditable(ParameterTableModelItemBase
item) {
+ public boolean isCellEditable(TableItem item) {
return !item.isEllipsisType() && item.parameter.getOldIndex() == -1;
}
@Override
- public PsiCodeFragment valueOf(ParameterTableModelItemBase
item) {
+ public PsiCodeFragment valueOf(TableItem item) {
return item.defaultValueCodeFragment;
}
- public TableCellRenderer doCreateRenderer(ParameterTableModelItemBase
item) {
+ public TableCellRenderer doCreateRenderer(TableItem item) {
return new CodeFragmentTableCellRenderer(myProject, myFileType);
}
- public TableCellEditor doCreateEditor(ParameterTableModelItemBase
item) {
+ public TableCellEditor doCreateEditor(TableItem item) {
return new CodeFragmentTableCellEditorBase(myProject, myFileType);
}
}
- protected static class AnyVarColumn
extends ColumnInfoBase
{
+ protected static class AnyVarColumn
> extends ColumnInfoBase
{
public AnyVarColumn() {
super(RefactoringBundle.message("column.name.any.var"));
}
@Override
- public boolean isCellEditable(ParameterTableModelItemBase
item) {
+ public boolean isCellEditable(TableItem item) {
return !item.isEllipsisType() && item.parameter.getOldIndex() == -1;
}
@Override
- public Boolean valueOf(ParameterTableModelItemBase
item) {
+ public Boolean valueOf(TableItem item) {
return item.parameter.isUseAnySingleVariable();
}
@Override
- public void setValue(ParameterTableModelItemBase
item, Boolean value) {
+ public void setValue(TableItem item, Boolean value) {
item.parameter.setUseAnySingleVariable(value);
}
- public TableCellRenderer doCreateRenderer(ParameterTableModelItemBase
item) {
+ public TableCellRenderer doCreateRenderer(TableItem item) {
return new BooleanTableCellRenderer();
}
- public TableCellEditor doCreateEditor(ParameterTableModelItemBase
item) {
+ public TableCellEditor doCreateEditor(TableItem item) {
return new BooleanTableCellEditor(false);
}
diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/AutomaticRenamingDialog.java b/platform/lang-impl/src/com/intellij/refactoring/rename/AutomaticRenamingDialog.java
index e22dcc4d8923..9e6dfc0a4d16 100644
--- a/platform/lang-impl/src/com/intellij/refactoring/rename/AutomaticRenamingDialog.java
+++ b/platform/lang-impl/src/com/intellij/refactoring/rename/AutomaticRenamingDialog.java
@@ -36,7 +36,6 @@ import com.intellij.ui.TableUtil;
import com.intellij.ui.table.JBTable;
import com.intellij.usageView.UsageInfo;
import com.intellij.usages.impl.UsagePreviewPanel;
-import com.intellij.util.ui.Table;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
@@ -134,9 +133,11 @@ public class AutomaticRenamingDialog extends DialogWrapper {
protected void handleChanges() {
final int selectedRow = myTable.getSelectedRow();
- final boolean validName = RenameUtil.isValidName(myProject, myRenames[selectedRow], myNewNames[selectedRow]);
- getOKAction().setEnabled(validName);
- setErrorText(validName ? null : "Identifier \'" + myNewNames[selectedRow] + "\' is invalid");
+ if (selectedRow > -1) {
+ final boolean validName = RenameUtil.isValidName(myProject, myRenames[selectedRow], myNewNames[selectedRow]);
+ getOKAction().setEnabled(validName);
+ setErrorText(validName ? null : "Identifier \'" + myNewNames[selectedRow] + "\' is invalid");
+ }
}
protected JComponent createCenterPanel() {
diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java
index 7f743742985f..ad16b2b986fe 100644
--- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java
+++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java
@@ -696,20 +696,21 @@ public abstract class InplaceRefactoring {
releaseIfNotRestart();
}
});
- myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
+ final Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(myEditor);
+ topLevelEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
- myBalloon.show(new PositionTracker(myEditor.getContentComponent()) {
+ myBalloon.show(new PositionTracker(topLevelEditor.getContentComponent()) {
@Override
public RelativePoint recalculateLocation(Balloon object) {
- if (myTarget != null && !popupFactory.isBestPopupLocationVisible(myEditor)) {
+ if (myTarget != null && !popupFactory.isBestPopupLocationVisible(topLevelEditor)) {
return myTarget;
}
- final RelativePoint target = popupFactory.guessBestPopupLocation(myEditor);
+ final RelativePoint target = popupFactory.guessBestPopupLocation(topLevelEditor);
if (target == null) return myTarget;
final Point screenPoint = target.getScreenPoint();
int y = screenPoint.y;
- if (target.getPoint().getY() > myEditor.getLineHeight() + myBalloon.getPreferredSize().getHeight()) {
- y -= myEditor.getLineHeight();
+ if (target.getPoint().getY() > topLevelEditor.getLineHeight() + myBalloon.getPreferredSize().getHeight()) {
+ y -= topLevelEditor.getLineHeight();
}
myTarget = new RelativePoint(new Point(screenPoint.x, y));
return myTarget;
diff --git a/platform/lang-impl/src/com/intellij/ui/debugger/ShowUIDefaultsAction.java b/platform/lang-impl/src/com/intellij/ui/debugger/ShowUIDefaultsAction.java
index 737f4f6da3fa..f1b11c6d469a 100644
--- a/platform/lang-impl/src/com/intellij/ui/debugger/ShowUIDefaultsAction.java
+++ b/platform/lang-impl/src/com/intellij/ui/debugger/ShowUIDefaultsAction.java
@@ -19,11 +19,14 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.ui.Cell;
import com.intellij.ui.ColorPicker;
import com.intellij.ui.ColorUtil;
import com.intellij.ui.TableSpeedSearch;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.table.JBTable;
+import com.intellij.util.PairFunction;
+import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.Border;
@@ -31,6 +34,7 @@ import javax.swing.plaf.ColorUIResource;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
+import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Enumeration;
@@ -76,7 +80,7 @@ public class ShowUIDefaultsAction extends AnAction {
}) {
@Override
public boolean editCellAt(int row, int column, EventObject e) {
- if (isCellEditable(row, column)) {
+ if (isCellEditable(row, column) && e instanceof MouseEvent) {
final Object color = getValueAt(row, column);
final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color)color, true, null);
if (newColor != null) {
@@ -107,16 +111,20 @@ public class ShowUIDefaultsAction extends AnAction {
panel.setBackground(c);
return panel;
} else if (value instanceof Icon) {
- //final Icon icon = (Icon)value;
- //if (icon.getIconHeight() <= 20) {
- // //label.setIcon(icon);
- //}
- //label.setText(String.format("(%dx%d) %s)",icon.getIconWidth(), icon.getIconHeight(), label.getText()));
+ try {
+ final Icon icon = (Icon)value;
+ if (icon.getIconHeight() <= 20) {
+ label.setIcon(icon);
+ }
+ label.setText(String.format("(%dx%d) %s)",icon.getIconWidth(), icon.getIconHeight(), label.getText()));
+ }
+ catch (Throwable e1) {//
+ }
return panel;
} else if (value instanceof Border) {
try {
final Insets i = ((Border)value).getBorderInsets(null);
- label.setText(String.format("border[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
+ label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
return panel;
} catch (Exception ignore) {}
}
@@ -124,7 +132,13 @@ public class ShowUIDefaultsAction extends AnAction {
}
});
final JBScrollPane pane = new JBScrollPane(table);
- new TableSpeedSearch(table);
+ new TableSpeedSearch(table, new PairFunction
- *
- *
Examples:
- *
- * ['a', 'b'] => 'a b'
- * ['a="1 2"', 'b'] => '"a \"1 2\"" b'
- *
- *
- * @param parameters a list of parameters to join.
- * @return a string with parameters.
+ * @see ParametersListUtil#join(java.util.List)
*/
@NotNull
public static String join(@NotNull final List parameters) {
- return ParametersTokenizer.encode(parameters);
- }
-
- @NotNull
- public static String join(final String... parameters) {
- return ParametersTokenizer.encode(Arrays.asList(parameters));
+ return ParametersListUtil.join(parameters);
}
/**
- *
Converts single parameter string (as created by {@link #join(java.util.List)}) into list of parameters.
- *
- *
- * Conversion rules:
- *
- *
starting/whitespaces are trimmed;
- *
parameters are split by whitespaces, whitespaces itself are dropped
- *
parameters inside double quotes ("a b") are kept as single one;
- *
double quotes are dropped, escaped double quotes (\") are un-escaped.
- *
- *
- *
- *
Examples:
- *
- * ' a b ' => ['a', 'b']
- * 'a="1 2" b' => ['a=1 2', 'b']
- * 'a " " b' => ['a', ' ', 'b']
- * '"a \"1 2\"" b' => ['a="1 2"', 'b']
- *
- *
- * @param string parameter string to split.
- * @return array of parameters.
+ * @see ParametersListUtil#join(java.util.List)
+ */
+ @NotNull
+ public static String join(final String... parameters) {
+ return ParametersListUtil.join(parameters);
+ }
+
+ /**
+ * @see ParametersListUtil#parseToArray(String)
*/
@NotNull
public static String[] parse(@NotNull final String string) {
- final List params = ParametersTokenizer.decode(string);
- return ArrayUtil.toStringArray(params);
+ return ParametersListUtil.parseToArray(string);
}
public String expandMacros(String text) {
@@ -356,84 +319,4 @@ public class ParametersList implements Cloneable {
return myParameters.toString();
}
- private static class ParametersTokenizer {
- private ParametersTokenizer() {
- }
-
- @NotNull
- public static String encode(@NotNull final List parameters) {
- final StringBuilder buffer = new StringBuilder();
- for (final String parameter : parameters) {
- if (buffer.length() > 0) {
- buffer.append(' ');
- }
- buffer.append(encode(parameter));
- }
- return buffer.toString();
- }
-
- @NotNull
- public static String encode(@NotNull String parameter) {
- final StringBuilder builder = StringBuilderSpinAllocator.alloc();
- try {
- builder.append(parameter);
- StringUtil.escapeQuotes(builder);
- if (builder.length() == 0 || StringUtil.indexOf(builder, ' ') >= 0 || StringUtil.indexOf(builder, '|') >= 0) {
- StringUtil.quote(builder);
- }
- return builder.toString();
- }
- finally {
- StringBuilderSpinAllocator.dispose(builder);
- }
- }
-
- @NotNull
- public static List decode(@NotNull String parameterString) {
- parameterString = parameterString.trim();
-
- final ArrayList params = ContainerUtil.newArrayList();
- final StringBuilder token = new StringBuilder(128);
- boolean inQuotes = false;
- boolean escapedQuote = false;
- boolean nonEmpty = false;
-
- for (int i = 0; i < parameterString.length(); i++) {
- final char ch = parameterString.charAt(i);
-
- if (ch == '\"') {
- if (!escapedQuote) {
- inQuotes = !inQuotes;
- nonEmpty = true;
- continue;
- }
- escapedQuote = false;
- }
- else if (Character.isWhitespace(ch)) {
- if (!inQuotes) {
- if (token.length() > 0 || nonEmpty) {
- params.add(token.toString());
- token.setLength(0);
- nonEmpty = false;
- }
- continue;
- }
- }
- else if (ch == '\\') {
- if (i < parameterString.length() - 1 && parameterString.charAt(i + 1) == '"') {
- escapedQuote = true;
- continue;
- }
- }
-
- token.append(ch);
- }
-
- if (token.length() > 0 || nonEmpty) {
- params.add(token.toString());
- }
-
- return params;
- }
- }
}
diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/PresentableNodeDescriptor.java b/platform/platform-api/src/com/intellij/ide/util/treeView/PresentableNodeDescriptor.java
index c4add9f856f1..6816f1442adc 100644
--- a/platform/platform-api/src/com/intellij/ide/util/treeView/PresentableNodeDescriptor.java
+++ b/platform/platform-api/src/com/intellij/ide/util/treeView/PresentableNodeDescriptor.java
@@ -17,6 +17,7 @@ package com.intellij.ide.util.treeView;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.openapi.project.Project;
+import com.intellij.ui.Gray;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
@@ -167,7 +168,7 @@ public abstract class PresentableNodeDescriptor extends NodeDescriptor {
}
public Color getHighlightColor() {
- return UIUtil.isUnderDarcula() ? UIUtil.getPanelBackground().brighter() : UIUtil.getTreeBackground().brighter();
+ return UIUtil.isUnderDarcula() ? Gray._100 : UIUtil.getTreeBackground().brighter();
}
public static class ColoredFragment {
diff --git a/platform/platform-api/src/com/intellij/xml/util/XmlStringUtil.java b/platform/platform-api/src/com/intellij/xml/util/XmlStringUtil.java
index b211e11310a4..844be9811c0a 100644
--- a/platform/platform-api/src/com/intellij/xml/util/XmlStringUtil.java
+++ b/platform/platform-api/src/com/intellij/xml/util/XmlStringUtil.java
@@ -16,6 +16,8 @@
package com.intellij.xml.util;
+import org.jetbrains.annotations.Nullable;
+
/**
* @author yole
*/
@@ -23,11 +25,11 @@ public class XmlStringUtil {
private XmlStringUtil() {
}
- public static String escapeString(String str) {
+ public static String escapeString(@Nullable String str) {
return escapeString(str, false);
}
- public static String escapeString(String str, final boolean escapeWhiteSpace) {
+ public static String escapeString(@Nullable String str, final boolean escapeWhiteSpace) {
return XmlTagUtilBase.escapeString(str, escapeWhiteSpace);
}
}
\ No newline at end of file
diff --git a/platform/platform-api/src/com/intellij/xml/util/XmlTagUtilBase.java b/platform/platform-api/src/com/intellij/xml/util/XmlTagUtilBase.java
index b93a7b722e88..f3d9c9a86ae1 100644
--- a/platform/platform-api/src/com/intellij/xml/util/XmlTagUtilBase.java
+++ b/platform/platform-api/src/com/intellij/xml/util/XmlTagUtilBase.java
@@ -16,9 +16,10 @@
package com.intellij.xml.util;
import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.Nullable;
public class XmlTagUtilBase {
- public static String escapeString(final String str, final boolean escapeWhiteSpace) {
+ public static String escapeString(@Nullable final String str, final boolean escapeWhiteSpace) {
if (str == null) return null;
StringBuffer buffer = null;
for (int i = 0; i < str.length(); i++) {
diff --git a/platform/platform-impl/src/com/intellij/ide/dnd/FileCopyPasteUtil.java b/platform/platform-impl/src/com/intellij/ide/dnd/FileCopyPasteUtil.java
index 215a90fd41c5..382c9736322e 100644
--- a/platform/platform-impl/src/com/intellij/ide/dnd/FileCopyPasteUtil.java
+++ b/platform/platform-impl/src/com/intellij/ide/dnd/FileCopyPasteUtil.java
@@ -16,6 +16,9 @@
package com.intellij.ide.dnd;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -94,8 +97,14 @@ public class FileCopyPasteUtil {
public static List getFileList(@NotNull final Transferable transferable) {
try {
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
- @SuppressWarnings({"unchecked"}) final List fileList = (List)transferable.getTransferData(DataFlavor.javaFileListFlavor);
- return fileList;
+ @SuppressWarnings({"unchecked"})
+ final List fileList = (List)transferable.getTransferData(DataFlavor.javaFileListFlavor);
+ return ContainerUtil.filter(fileList, new Condition() {
+ @Override
+ public boolean value(File file) {
+ return !StringUtil.isEmptyOrSpaces(file.getPath());
+ }
+ });
}
else {
return LinuxDragAndDropSupport.getFiles(transferable);
@@ -105,4 +114,5 @@ public class FileCopyPasteUtil {
return null;
}
+
}
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java
index 449e2dc54eab..721770359a4e 100644
--- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java
@@ -21,7 +21,8 @@ import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.ColorUtil;
-import org.jetbrains.annotations.Nullable;
+import com.intellij.util.containers.hash.HashMap;
+import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
@@ -104,8 +105,7 @@ public final class DarculaLaf extends BasicLookAndFeel {
@SuppressWarnings({"HardCodedStringLiteral"})
static void initIdeaDefaults(UIDefaults defaults) {
- loadDefaults(defaults, null); //load defaults
- loadDefaults(defaults, SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux"); // load OS customization
+ loadDefaults(defaults);
defaults.put("Table.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] {
"ctrl C", "copy",
"ctrl V", "paste",
@@ -158,44 +158,70 @@ public final class DarculaLaf extends BasicLookAndFeel {
}));
}
- private static void loadDefaults(UIDefaults defaults, @Nullable String postfix) {
+ private static void loadDefaults(UIDefaults defaults) {
+ final Properties properties = new Properties();
+ final String osSuffix = SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux";
try {
- final Properties properties = new Properties();
- final String secondPart = postfix == null ? "" : "_" + postfix;
- final String name = "darcula" + secondPart + ".properties";
- final InputStream stream = DarculaLaf.class.getResourceAsStream(name);
+ InputStream stream = DarculaLaf.class.getResourceAsStream("darcula.properties");
properties.load(stream);
+ stream.close();
+
+ stream = DarculaLaf.class.getResourceAsStream("darcula_" + osSuffix + ".properties");
+ properties.load(stream);
+ stream.close();
+
+ HashMap darculaGlobalSettings = new HashMap();
+ final String prefix = "darcula.";
for (String key : properties.stringPropertyNames()) {
- final String value = properties.getProperty(key);
- if (key.endsWith("Insets")) {
- final List numbers = StringUtil.split(value, ",");
- defaults.put(key, new InsetsUIResource(Integer.parseInt(numbers.get(0)),
- Integer.parseInt(numbers.get(1)),
- Integer.parseInt(numbers.get(2)),
- Integer.parseInt(numbers.get(3))));
- } else if (key.endsWith(".border")) {
- try {
- defaults.put(key, Class.forName(value).newInstance());
- } catch (Exception e) {log(e);}
- } else {
- final Color color = ColorUtil.fromHex(value, null);
- final Integer invVal = getInteger(value);
- Icon icon = value != null && value.startsWith("AllIcons.") ? IconLoader.getIcon(value) : null;
- if (color != null) {
- defaults.put(key, new ColorUIResource(color));
- } else if (invVal != null) {
- defaults.put(key, invVal);
- } else if (icon != null) {
- defaults.put(key, new IconUIResource(icon));
- } else {
- defaults.put(key, value);
+ if (key.startsWith(prefix)) {
+ darculaGlobalSettings.put(key.substring(prefix.length()), parseValue(key, properties.getProperty(key)));
+ }
+ }
+
+ for (Object key : defaults.keySet()) {
+ if (key instanceof String && ((String)key).contains(".")) {
+ final String s = (String)key;
+ final String darculaKey = s.substring(s.lastIndexOf('.') + 1);
+ if (darculaGlobalSettings.containsKey(darculaKey)) {
+ defaults.put(key, darculaGlobalSettings.get(darculaKey));
}
}
}
+
+ for (String key : properties.stringPropertyNames()) {
+ final String value = properties.getProperty(key);
+ defaults.put(key, parseValue(key, value));
+ }
}
catch (IOException e) {log(e);}
}
+ private static Object parseValue(String key, @NotNull String value) {
+ if (key.endsWith("Insets")) {
+ final List numbers = StringUtil.split(value, ",");
+ return new InsetsUIResource(Integer.parseInt(numbers.get(0)),
+ Integer.parseInt(numbers.get(1)),
+ Integer.parseInt(numbers.get(2)),
+ Integer.parseInt(numbers.get(3)));
+ } else if (key.endsWith(".border")) {
+ try {
+ return Class.forName(value).newInstance();
+ } catch (Exception e) {log(e);}
+ } else {
+ final Color color = ColorUtil.fromHex(value, null);
+ final Integer invVal = getInteger(value);
+ Icon icon = value.startsWith("AllIcons.") ? IconLoader.getIcon(value) : null;
+ if (color != null) {
+ return new ColorUIResource(color);
+ } else if (invVal != null) {
+ return invVal;
+ } else if (icon != null) {
+ return new IconUIResource(icon);
+ }
+ }
+ return value;
+ }
+
private static Integer getInteger(String value) {
try {
return Integer.parseInt(value);
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties
index a767d6aef668..9a1a2bee2097 100644
--- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties
@@ -1,84 +1,50 @@
+darcula.background=535353
+darcula.textBackground=535353
+darcula.foreground=eeeeee
+darcula.textForeground=eeeeee
+darcula.caretForeground=eeeeee
+
text=eeeeee
Menu.maxGutterIconWidth=18
MenuItem.maxGutterIconWidth=18
MenuItem.acceleratorDelimiter=-
-#Trees
-Tree.background=535353
-Tree.foreground=eeeeee
-Tree.textForeground=eeeeee
-Tree.textBackground=535353
-#Tree.selectionBackground=BEBEBE
-#Tree.selectionForeground=535353
-
-EditorPane.background=535353
EditorPane.inactiveBackground=535353
-EditorPane.foreground=eeeeee
EditorPane.inactiveForeground=eeeeee
EditorPaneUI=com.intellij.ide.ui.laf.darcula.ui.DarculaEditorPaneUI
-#Lists
-List.background=535353
-List.foreground=eeeeee
-#Tables
-Table.background=535353
-Table.foreground=eeeeee
control=535353
-Panel.background=535353
-Panel.foreground=eeeeee
+
+ScrollBarUI=com.intellij.ide.ui.laf.darcula.ui.DarculaScrollBarUI
+
Menu.selectionBackground=bebebe
-MenuBar.background=535353
MenuBar.disabledBackground=535353
MenuBar.shadow=535353
-Menu.background=535353
-MenuItem.background=535353
-Menu.foreground=eeeeee
-MenuItem.foreground=eeeeee
TabbedPane.tabInsets=0,4,0,4
-ToggleButton.foreground=eeeeee
-Separator.background=535353
Separator.foreground=888888
-Label.background=535353
-Label.foreground=eeeeee
Focus.color=ff0000
-TextField.background=535353
-TextField.foreground=eeeeee
-TextField.caretForeground=eeeeee
-#TextFieldUI=com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI
+TextField.background=737373
+TextFieldUI=com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI
+TextField.border=com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder
-PasswordField.background=535353
-PasswordField.foreground=eeeeee
-PasswordField.caretForeground=eeeeee
+PasswordField.background=aaaaaa
-TextArea.background=535353
-TextArea.foreground=eeeeee
-TextArea.caretForeground=eeeeee
-
-TextPane.background=535353
-TextPane.foreground=eeeeee
-TextPane.caretForeground=eeeeee
-
-CheckBox.background=535353
-CheckBox.foreground=eeeeee
CheckBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxUI
-
-RadioButton.foreground=eeeeee
-RadioButton.background=535353
+#ComboBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI
+ComboBox.background=eeeeee
+ComboBox.foreground=000000
RadioButtonUI=com.intellij.ide.ui.laf.darcula.ui.DarculaRadioButtonUI
StatusBar.topColor=2c2c2c
StatusBar.top2Color=2c2c2c
StatusBar.bottomColor=2c2c2c
-Button.foreground=eeeeee
-Button.background=535353
Button.border=com.intellij.ide.ui.laf.darcula.ui.DarculaButtonPainter
#ButtonUI=com.intellij.ide.ui.laf.borders.DarculaButtonUI
MenuItem.acceleratorForeground=eeeeee
-PopupMenu.background=535353
PopupMenu.translucentBackground=535353
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaButtonPainter.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaButtonPainter.java
index 6c4e03292e74..b571c8e5a78c 100644
--- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaButtonPainter.java
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaButtonPainter.java
@@ -63,6 +63,6 @@ public class DarculaButtonPainter implements Border, UIResource {
@Override
public boolean isBorderOpaque() {
- return false;
+ return true;
}
}
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxButton.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxButton.java
new file mode 100644
index 000000000000..3669d47c86aa
--- /dev/null
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxButton.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.ui.laf.darcula.ui;
+
+import com.intellij.icons.AllIcons;
+
+import javax.swing.*;
+import javax.swing.plaf.basic.BasicButtonUI;
+import java.awt.*;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public class DarculaComboBoxButton extends JButton {
+ private final JComboBox myComboBox;
+
+ public DarculaComboBoxButton(JComboBox comboBox) {
+ myComboBox = comboBox;
+ setUI(new BasicButtonUI() {
+ @Override
+ public void paint(Graphics g, JComponent c) {
+ final Icon i;
+ if (myComboBox.isEditable()) {
+ g.drawLine(0,0,0,c.getHeight());
+ i = AllIcons.Mac.Tree_white_down_arrow;
+ } else {
+ i = AllIcons.Ide.Statusbar_arrows;
+ }
+ i.paintIcon(c, g, (c.getWidth() - i.getIconWidth()) / 2, (c.getHeight() - i.getIconHeight()) / 2);
+ }
+
+ @Override
+ public Dimension getPreferredSize(JComponent c) {
+ return super.getPreferredSize(c);
+ }
+ });
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ }
+}
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java
new file mode 100644
index 000000000000..f9a5b2b6144c
--- /dev/null
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.ui.laf.darcula.ui;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicComboBoxUI;
+import java.awt.*;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public class DarculaComboBoxUI extends BasicComboBoxUI {
+ private final JComboBox myComboBox;
+
+ public DarculaComboBoxUI(JComboBox c) {
+ myComboBox = c;
+ c.setBorder(null);
+ }
+
+ @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
+ public static ComponentUI createUI(JComponent c) {
+ return new DarculaComboBoxUI(((JComboBox)c));
+ }
+
+ @Override
+ protected LayoutManager createLayoutManager() {
+ return new DarculaComboBoxLayoutManager();
+ }
+
+ @Override
+ public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus) {
+ super.paintCurrentValueBackground(g, bounds, false);
+ }
+
+ @Override
+ public void paint(Graphics g, JComponent c) {
+ super.paint(g, c);
+ }
+
+ @Override
+ protected JButton createArrowButton() {
+ return new DarculaComboBoxButton(myComboBox);
+ }
+
+ class DarculaComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
+ public void layoutContainer(final Container parent) {
+ if (arrowButton != null && !comboBox.isEditable()) {
+ final Insets insets = comboBox.getInsets();
+ final int width = comboBox.getWidth();
+ final int height = comboBox.getHeight();
+ arrowButton.setBounds(insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom));
+ return;
+ }
+
+ final JComboBox cb = (JComboBox)parent;
+ final int width = cb.getWidth();
+ final int height = cb.getHeight();
+
+ final Insets insets = getInsets();
+ final int buttonHeight = height - (insets.top + insets.bottom);
+ final int buttonWidth = 20;
+
+ if (arrowButton != null) {
+ arrowButton.setBounds(width - (insets.right + buttonWidth), insets.top, buttonWidth, buttonHeight);
+ }
+
+ if (editor != null) {
+ final Rectangle editorRect = rectangleForCurrentValue();
+ editorRect.width += 4;
+ editor.setBounds(editorRect);
+ }
+ }
+ }
+}
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaScrollBarUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaScrollBarUI.java
new file mode 100644
index 000000000000..39704f20de1d
--- /dev/null
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaScrollBarUI.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.ui.laf.darcula.ui;
+
+import com.intellij.util.ui.ButtonlessScrollBarUI;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public class DarculaScrollBarUI extends ButtonlessScrollBarUI {
+
+ @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
+ public static ComponentUI createUI(JComponent c) {
+ return new DarculaScrollBarUI();
+ }
+}
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTest.form b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTest.form
new file mode 100644
index 000000000000..f79276e2ca53
--- /dev/null
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTest.form
@@ -0,0 +1,417 @@
+
+
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTest.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTest.java
new file mode 100644
index 000000000000..75fb440d792a
--- /dev/null
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.ui.laf.darcula.ui;
+
+import com.intellij.ide.ui.laf.darcula.DarculaLaf;
+import com.intellij.ui.components.JBCheckBox;
+
+import javax.swing.*;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public class DarculaTest {
+ private JBCheckBox myJBCheckBox1;
+ private JBCheckBox myJBCheckBox2;
+ private JBCheckBox myJBCheckBox3;
+ private JBCheckBox myJBCheckBox4;
+ private JBCheckBox myJBCheckBox5;
+ private JComboBox myComboBox1;
+ private JComboBox myComboBox2;
+ private JComboBox myComboBox3;
+ private JComboBox myComboBox4;
+ private JComboBox myComboBox5;
+ private JTextField myTextField1;
+ private JTextField myThisTextIsDisabledTextField;
+ private JPasswordField myPasswordField1;
+ private JPanel myRoot;
+
+ public static void main(String[] args) {
+ try {
+ UIManager.setLookAndFeel(new DarculaLaf());
+ }
+ catch (UnsupportedLookAndFeelException ignored) {}
+ final JFrame frame = new JFrame("Darcula Demo");
+ frame.setSize(600, 500);
+ frame.setContentPane(new DarculaTest().myRoot);
+ frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ frame.setVisible(true);
+ }
+ });
+ }
+}
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextBorder.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextBorder.java
new file mode 100644
index 000000000000..65f1993bcc8c
--- /dev/null
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextBorder.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.ui.laf.darcula.ui;
+
+import com.intellij.ide.ui.laf.darcula.DarculaUIUtil;
+import com.intellij.openapi.ui.GraphicsConfig;
+import com.intellij.openapi.util.SystemInfo;
+import com.intellij.ui.ColorUtil;
+import com.intellij.util.ui.JBInsets;
+
+import javax.swing.border.Border;
+import javax.swing.plaf.UIResource;
+import java.awt.*;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public class DarculaTextBorder implements Border, UIResource {
+ private JBInsets myInsets = new JBInsets(4, 7, 4, 7);
+
+ @Override
+ public JBInsets getBorderInsets(Component c) {
+ return myInsets;
+ }
+
+ @Override
+ public boolean isBorderOpaque() {
+ return false;
+ }
+
+ @Override
+ public void paintBorder(Component c, Graphics g2, int x, int y, int width, int height) {
+ Graphics2D g = ((Graphics2D)g2);
+ g.setColor(ColorUtil.fromHex("737373"));
+ int cX = myInsets.right;
+ int cY = myInsets.top;
+ int cW = width - myInsets.width();
+ int cH = height - myInsets.height();
+ final GraphicsConfig config = new GraphicsConfig(g);
+ g.translate(x, y);
+
+ if (c.hasFocus()) {
+ int sysOffX = SystemInfo.isMac ? 0 : 1;
+ int sysOffY = SystemInfo.isMac ? 0 : -1;
+ DarculaUIUtil.paintFocusRing(g, 2, 2, width-4, height-4);
+
+ //g.setColor(DarculaUIUtil.GLOW_COLOR.darker().darker());
+ //g.drawRect(1, 1, width - 2, height - 2);
+ //g.drawRect(2, 2, width-4, height-4);
+ //g.setColor(ColorUtil.toAlpha(DarculaUIUtil.GLOW_COLOR, 70));
+ //g.drawRoundRect(0, 0, width, height, 5, 5);
+ //g.setColor(ColorUtil.toAlpha(DarculaUIUtil.GLOW_COLOR, 80));
+ //g.drawRoundRect(1, 1, width - 2, height-2, 5, 5);
+ //g.setColor(ColorUtil.toAlpha(DarculaUIUtil.GLOW_COLOR, 120));
+ //g.drawRoundRect(2, 2, width - 4, height - 4, 5, 5);
+ //g.setColor(ColorUtil.toAlpha(DarculaUIUtil.GLOW_COLOR, 140));
+ //g.drawRoundRect(3, 2, width - 6, height - 4, 5, 5);
+ } else {
+ //g.fillRect(2, 1, cX-2, height - 2); //left
+ //g.fillRect(cX + cW , 1, width-cW - cX, height - 2); //right
+ //g.fillRect(1, 1, width - 2, cY); //top
+ //g.fillRect(1, cY + cH, width - 2, height - 2); //bottom
+ g.setColor(ColorUtil.fromHex("939393"));
+ g.drawRect(1, 1, width - 2, height - 2);
+ }
+ g.translate(-x, -y);
+ config.restore();
+ }
+}
diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java
index 6ce1da2d01d3..04cbd44f9107 100644
--- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java
+++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTextFieldUI.java
@@ -15,9 +15,17 @@
*/
package com.intellij.ide.ui.laf.darcula.ui;
+import com.intellij.openapi.ui.GraphicsConfig;
+import com.intellij.util.ui.JBInsets;
+
import javax.swing.*;
+import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTextFieldUI;
+import javax.swing.text.JTextComponent;
+import java.awt.*;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
/**
* @author Konstantin Bulenkov
@@ -25,7 +33,57 @@ import javax.swing.plaf.basic.BasicTextFieldUI;
public class DarculaTextFieldUI extends BasicTextFieldUI {
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass")
- public static ComponentUI createUI(JComponent c) {
+ public static ComponentUI createUI(final JComponent c) {
+ c.addFocusListener(new FocusAdapter() {
+ @Override
+ public void focusGained(FocusEvent e) {
+ c.repaint();
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ c.repaint();
+ }
+ });
return new DarculaTextFieldUI();
}
+
+ @Override
+ protected void installDefaults() {
+ super.installDefaults();
+ }
+
+ @Override
+ protected void paintSafely(Graphics g) {
+ super.paintSafely(g);
+ }
+
+ @Override
+ protected void paintBackground(Graphics g) {
+ final JTextComponent c = getComponent();
+ final Container parent = c.getParent();
+ if (parent != null) {
+ g.setColor(parent.getBackground());
+ g.fillRect(0,0,c.getWidth(), c.getHeight());
+ }
+ final Border border = c.getBorder();
+ if (border instanceof DarculaTextBorder) {
+ g.setColor(c.getBackground());
+ final int width = c.getWidth();
+ final int height = c.getHeight();
+ final JBInsets insets = ((DarculaTextBorder)border).getBorderInsets(c);
+ if (c.hasFocus()) {
+ final GraphicsConfig config = new GraphicsConfig(g);
+ ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
+
+ g.fillRoundRect(insets.left-5, insets.top-2, width - insets.width() + 10, height - insets.height() + 6, 5, 5);
+ config.restore();
+ } else {
+ g.fillRect(insets.left-5, insets.top-2, width - insets.width() + 12, height - insets.height() + 6);
+ }
+ } else {
+ super.paintBackground(g);
+ }
+ }
}
diff --git a/platform/platform-impl/src/com/intellij/internal/anomalies/TopAnomaliesAction.java b/platform/platform-impl/src/com/intellij/internal/anomalies/TopAnomaliesAction.java
new file mode 100644
index 000000000000..e6e892dad43f
--- /dev/null
+++ b/platform/platform-impl/src/com/intellij/internal/anomalies/TopAnomaliesAction.java
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.internal.anomalies;
+
+import com.intellij.openapi.Disposable;
+import com.intellij.openapi.actionSystem.ActionGroup;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.objectTree.ObjectNode;
+import com.intellij.openapi.util.objectTree.ObjectTree;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import java.awt.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.*;
+
+/**
+ * User: Vassiliy.Kudryashov
+ */
+public class TopAnomaliesAction extends ActionGroup {
+ private static final Comparator> COMPARATOR = new Comparator>() {
+ @Override
+ public int compare(Pair, Integer> o1, Pair, Integer> o2) {
+ int i = o2.getSecond() - o1.getSecond();
+ if (i != 0) {
+ return i;
+ }
+ int h1 = o1.hashCode();
+ int h2 = o2.hashCode();
+ if (h1 > h2) {
+ return 1;
+ }
+ if (h1 < h2) {
+ return -1;
+ }
+ return 0;
+ }
+ };
+ private static final int LIMIT = 10;
+
+ private static final ResettableAction TOP_PARENTS = new ResettableAction("Parents") {
+ TreeSet> top = new TreeSet>(COMPARATOR);
+ TreeSet> old = new TreeSet>(COMPARATOR);
+
+ @Override
+ public void update(AnActionEvent e) {
+ e.getPresentation().setText("Top " + LIMIT + " component parents");
+ }
+
+ @Override
+ void reset() {
+ top.clear();
+ old.clear();
+ }
+
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ old = new TreeSet>(top);
+ top.clear();
+ Window[] windows = Window.getWindows();
+ for (Window window : windows) {
+ if (window.isVisible() && (window instanceof JFrame)) {
+ JFrame f = (JFrame)window;
+ checkParents((JComponent)f.getContentPane(), top, LIMIT);
+ }
+ }
+
+ System.out.println("Top " + LIMIT + " component parents");
+ for (Pair pair : top) {
+ System.out.println(
+ pair.first.getClass().getName() + " (" + pair.second + " children)" + getChange(old, pair.first, pair.second));
+ }
+ }
+
+ private void checkParents(JComponent component, Set> top, int limit) {
+ top.add(Pair.create(component, component.getComponentCount()));
+
+ trimToLimit(top, limit);
+
+ for (int i = 0; i < component.getComponentCount(); i++) {
+ Component child = component.getComponent(i);
+ if (child instanceof JComponent) {
+ checkParents((JComponent)child, top, limit);
+ }
+ }
+ }
+ };
+
+ private static final ResettableAction TOP_UI_PROPERTIES = new ResettableAction("ClientProperties") {
+ TreeSet> top = new TreeSet>(COMPARATOR);
+ TreeSet> old = new TreeSet>(COMPARATOR);
+
+ @Override
+ public void update(AnActionEvent e) {
+ e.getPresentation().setText("Top " + LIMIT + " ClientProperties");
+ }
+
+ @Override
+ void reset() {
+ top.clear();
+ old.clear();
+ }
+
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ old = new TreeSet>(top);
+ top.clear();
+ Window[] windows = Window.getWindows();
+ for (Window window : windows) {
+ if (window.isVisible() && (window instanceof JFrame)) {
+ JFrame f = (JFrame)window;
+ checkClientProperties((JComponent)f.getContentPane(), top, LIMIT);
+ }
+ }
+ System.out.println("Top " + LIMIT + " ClientProperties");
+ for (Pair pair : top) {
+ System.out.println(pair.first.getClass().getName() + " (" + pair.second + " properties)" + getChange(old, pair.first, pair.second));
+ }
+ }
+
+ private void checkClientProperties(JComponent component, Set> top, int limit) {
+ try {
+ Field clientProperties = JComponent.class.getDeclaredField("clientProperties");
+ clientProperties.setAccessible(true);
+ Object o = clientProperties.get(component);
+ if (o != null) {
+ Method size = o.getClass().getMethod("size");
+ size.setAccessible(true);
+ Object sizeResult = size.invoke(o);
+ if (sizeResult instanceof Integer) {
+ top.add(Pair.create(component, (Integer)sizeResult));
+ trimToLimit(top, limit);
+ }
+ }
+ }
+ catch (NoSuchMethodException e) {
+ }
+ catch (InvocationTargetException e) {
+ }
+ catch (IllegalAccessException e) {
+ }
+ catch (NoSuchFieldException e) {
+ }
+ for (int i = 0; i < component.getComponentCount(); i++) {
+ Component child = component.getComponent(i);
+ if (child instanceof JComponent) {
+ checkClientProperties((JComponent)child, top, limit);
+ }
+ }
+ }
+ };
+
+ private static final ResettableAction TOP_DISPOSABLE = new ResettableAction("Disposable") {
+ TreeSet> top = new TreeSet>(COMPARATOR);
+ TreeSet> old = new TreeSet>(COMPARATOR);
+
+ @Override
+ public void update(AnActionEvent e) {
+ e.getPresentation().setText("Top " + LIMIT + " disposables");
+ }
+
+ @Override
+ void reset() {
+ top.clear();
+ old.clear();
+ }
+
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ old = new TreeSet>(top);
+ top.clear();
+ ObjectTree tree = Disposer.getTree();
+ Set roots = tree.getRootObjects();
+ for (Disposable root : roots) {
+ checkDisposables(tree, root, top, LIMIT);
+ }
+ System.out.println("Top " + LIMIT + " disposables");
+ for (Pair
+ *
+ *
Examples:
+ *
+ * ['a', 'b'] => 'a b'
+ * ['a="1 2"', 'b'] => '"a \"1 2\"" b'
+ *
+ *
+ * @param parameters a list of parameters to join.
+ * @return a string with parameters.
+ */
+ @NotNull
+ public static String join(@NotNull final List parameters) {
+ return encode(parameters);
+ }
+
+ @NotNull
+ public static String join(final String... parameters) {
+ return encode(Arrays.asList(parameters));
+ }
+
+ /**
+ * @see #parse(String)
+ */
+ @NotNull
+ public static String[] parseToArray(@NotNull final String string) {
+ final List params = parse(string);
+ return ArrayUtil.toStringArray(params);
+ }
+
+ /**
+ *
Converts single parameter string (as created by {@link #join(java.util.List)}) into list of parameters.
+ *
+ *
+ * Conversion rules:
+ *
+ *
starting/whitespaces are trimmed;
+ *
parameters are split by whitespaces, whitespaces itself are dropped
+ *
parameters inside double quotes ("a b") are kept as single one;
+ *
double quotes are dropped, escaped double quotes (\") are un-escaped.
+ *
+ *
+ *
+ *
Examples:
+ *
+ * ' a b ' => ['a', 'b']
+ * 'a="1 2" b' => ['a=1 2', 'b']
+ * 'a " " b' => ['a', ' ', 'b']
+ * '"a \"1 2\"" b' => ['a="1 2"', 'b']
+ *
+ *
+ * @param string parameter string to split.
+ * @return array of parameters.
+ */
+ @NotNull
+ public static List parse(@NotNull String parameterString) {
+ parameterString = parameterString.trim();
+
+ final ArrayList params = ContainerUtilRt.newArrayList();
+ final StringBuilder token = new StringBuilder(128);
+ boolean inQuotes = false;
+ boolean escapedQuote = false;
+ boolean nonEmpty = false;
+
+ for (int i = 0; i < parameterString.length(); i++) {
+ final char ch = parameterString.charAt(i);
+
+ if (ch == '\"') {
+ if (!escapedQuote) {
+ inQuotes = !inQuotes;
+ nonEmpty = true;
+ continue;
+ }
+ escapedQuote = false;
+ }
+ else if (Character.isWhitespace(ch)) {
+ if (!inQuotes) {
+ if (token.length() > 0 || nonEmpty) {
+ params.add(token.toString());
+ token.setLength(0);
+ nonEmpty = false;
+ }
+ continue;
+ }
+ }
+ else if (ch == '\\') {
+ if (i < parameterString.length() - 1 && parameterString.charAt(i + 1) == '"') {
+ escapedQuote = true;
+ continue;
+ }
+ }
+
+ token.append(ch);
+ }
+
+ if (token.length() > 0 || nonEmpty) {
+ params.add(token.toString());
+ }
+
+ return params;
+ }
+
+ @NotNull
+ private static String encode(@NotNull final List parameters) {
+ final StringBuilder buffer = new StringBuilder();
+ for (final String parameter : parameters) {
+ if (buffer.length() > 0) {
+ buffer.append(' ');
+ }
+ buffer.append(encode(parameter));
+ }
+ return buffer.toString();
+ }
+
+ @NotNull
+ private static String encode(@NotNull String parameter) {
+ final StringBuilder builder = StringBuilderSpinAllocator.alloc();
+ try {
+ builder.append(parameter);
+ StringUtil.escapeQuotes(builder);
+ if (builder.length() == 0 || StringUtil.indexOf(builder, ' ') >= 0 || StringUtil.indexOf(builder, '|') >= 0) {
+ StringUtil.quote(builder);
+ }
+ return builder.toString();
+ }
+ finally {
+ StringBuilderSpinAllocator.dispose(builder);
+ }
+ }
+}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ObjectsConvertor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ObjectsConvertor.java
index 282a4900a12a..0f5645adf4fb 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ObjectsConvertor.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ObjectsConvertor.java
@@ -74,24 +74,24 @@ public class ObjectsConvertor {
private ObjectsConvertor() {
}
- public static List fp2vf(final Collection in) {
+ public static List fp2vf(@NotNull final Collection in) {
return convert(in, FILEPATH_TO_VIRTUAL);
}
- public static List vf2fp(final List in) {
+ public static List vf2fp(@NotNull final List in) {
return convert(in, VIRTUAL_FILEPATH);
}
- public static List fp2jiof(final Collection in) {
+ public static List fp2jiof(@NotNull final Collection in) {
return convert(in, FILEPATH_FILE);
}
- public static List convert(final Collection in, final Convertor convertor) {
+ public static List convert(@NotNull final Collection in, final Convertor convertor) {
return convert(in, convertor, null);
}
- public static List convert(final Collection in, final Convertor convertor,
- @Nullable final NotNullFunction outFilter) {
+ public static List convert(@NotNull final Collection in, final Convertor convertor,
+ @Nullable final NotNullFunction outFilter) {
final List out = new ArrayList();
for (T t : in) {
final S converted = convertor.convert(t);
diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
index d621336c5735..7509709015be 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
+++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
@@ -1337,6 +1337,7 @@ switch.statement.with.too.few.branches.problem.descriptor='#ref' ha
switch.statement.without.default.ignore.option=Ignore if all cases of an enumerated type are covered
unnecessary.label.remove.quickfix=Remove label
unnecessary.return.problem.descriptor=#ref is unnecessary as the last statement in a 'void' method #loc
+unnecessary.return.constructor.problem.descriptor=#ref is unnecessary as the last statement in a constructor #loc
unused.label.remove.quickfix=Remove unused label
unnecessarily.qualified.static.usage.problem.descriptor=Unnecessarily qualified static method call #ref() #loc
unnecessarily.qualified.static.usage.problem.descriptor1=Unnecessarily qualified static access #ref #loc
@@ -1945,7 +1946,7 @@ parameter.of.concrete.class.option=Ignore parameters whose type is abstract clas
static.variable.of.concrete.class.option=Ignore static fields whose type is an abstract class
class.only.used.in.one.package.display.name=Class only used from one other package
class.only.used.in.one.package.problem.descriptor=Class #ref has only dependencies on and/or dependents in package ''{0}'' #loc
-unnecessary.return.option=Ignore in then branch branch of 'if' statement with 'else' branch
+unnecessary.return.option=Ignore in then branch of 'if' statement with 'else' branch
usage.of.obsolete.assert.display.name=Usage of obsolete 'junit.framework.Assert'
use.of.obsolete.assert.problem.descriptor=Call to #ref() from 'org.junit.framework.Assert' should be replaced with call to method from 'org.junit.Assert' #loc
use.of.obsolete.assert.quickfix=Replace with 'org.junit.Assert' method call
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/UnnecessaryReturnInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/UnnecessaryReturnInspection.java
index c0e1f312a90d..2ba67d48bf3c 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/UnnecessaryReturnInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/UnnecessaryReturnInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,8 +41,18 @@ public class UnnecessaryReturnInspection extends BaseInspection {
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "unnecessary.return.display.name");
+ return InspectionGadgetsBundle.message("unnecessary.return.display.name");
+ }
+
+ @Override
+ @NotNull
+ public String buildErrorString(Object... infos) {
+ if (((Boolean)infos[0]).booleanValue()) {
+ return InspectionGadgetsBundle.message("unnecessary.return.constructor.problem.descriptor");
+ }
+ else {
+ return InspectionGadgetsBundle.message("unnecessary.return.problem.descriptor");
+ }
}
@Override
@@ -52,15 +62,7 @@ public class UnnecessaryReturnInspection extends BaseInspection {
@Override
public JComponent createOptionsPanel() {
- return new SingleCheckboxOptionsPanel(
- InspectionGadgetsBundle.message("unnecessary.return.option"),
- this, "ignoreInThenBranch");
- }
-
- @Override
- @NotNull
- public String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message("unnecessary.return.problem.descriptor");
+ return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message("unnecessary.return.option"), this, "ignoreInThenBranch");
}
@Override
@@ -85,41 +87,43 @@ public class UnnecessaryReturnInspection extends BaseInspection {
}
final PsiElement methodParent = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, PsiLambdaExpression.class);
PsiCodeBlock codeBlock = null;
+ final boolean constructor;
if (methodParent instanceof PsiMethod) {
- codeBlock = ((PsiMethod)methodParent).getBody();
+ final PsiMethod method = (PsiMethod)methodParent;
+ codeBlock = method.getBody();
+ constructor = method.isConstructor();
}
else if (methodParent instanceof PsiLambdaExpression) {
- final PsiElement lambdaBody = ((PsiLambdaExpression)methodParent).getBody();
+ constructor = false;
+ final PsiLambdaExpression lambdaExpression = (PsiLambdaExpression)methodParent;
+ final PsiElement lambdaBody = lambdaExpression.getBody();
if (lambdaBody instanceof PsiCodeBlock) {
codeBlock = (PsiCodeBlock)lambdaBody;
}
}
+ else {
+ return;
+ }
if (codeBlock == null) {
return;
}
if (!ControlFlowUtils.blockCompletesWithStatement(codeBlock, statement)) {
return;
}
- if (ignoreInThenBranch && isInThenBranch(statement, statement.getParent())) {
+ if (ignoreInThenBranch && isInThenBranch(statement)) {
return;
}
- registerStatementError(statement);
+ registerStatementError(statement, Boolean.valueOf(constructor));
}
- private boolean isInThenBranch(PsiReturnStatement statement, PsiElement parent) {
- if (!(parent instanceof PsiCodeBlock)) {
+ private boolean isInThenBranch(PsiStatement statement) {
+ final PsiIfStatement ifStatement =
+ PsiTreeUtil.getParentOfType(statement, PsiIfStatement.class, true, PsiMethod.class, PsiLambdaExpression.class);
+ if (ifStatement == null) {
return false;
}
- final PsiElement grandParent = parent.getParent();
- if (grandParent == null) {
- return false;
- }
- final PsiElement greatGrandParent = grandParent.getParent();
- if (!(greatGrandParent instanceof PsiIfStatement)) {
- return false;
- }
- final PsiStatement elseBranch = ((PsiIfStatement)greatGrandParent).getElseBranch();
- return elseBranch == null || !PsiTreeUtil.isAncestor(elseBranch, statement, true);
+ final PsiStatement elseBranch = ifStatement.getElseBranch();
+ return elseBranch != null && !PsiTreeUtil.isAncestor(elseBranch, statement, true);
}
}
}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/imports/StaticImportInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/imports/StaticImportInspection.java
index 6d2fe1ba3c48..f2809b40c0f4 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/imports/StaticImportInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/imports/StaticImportInspection.java
@@ -18,6 +18,7 @@ package com.siyeh.ig.imports;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
+import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
@@ -34,8 +35,10 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public class StaticImportInspection extends BaseInspection {
@@ -139,27 +142,22 @@ public class StaticImportInspection extends BaseInspection {
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final PsiElementFactory factory = psiFacade.getElementFactory();
final PsiClass aClass = target.getContainingClass();
+ if (aClass == null) {
+ return;
+ }
final String qualifiedName = aClass.getQualifiedName();
final String text = reference.getText();
final String referenceText = qualifiedName + '.' + text;
if (reference instanceof PsiReferenceExpression) {
- try {
- final PsiExpression newReference = factory.createExpressionFromText(referenceText, reference);
- reference.replace(newReference);
- }
- catch (IncorrectOperationException e) {
- throw new RuntimeException(e);
- }
+ final PsiExpression newReference = factory.createExpressionFromText(referenceText, reference);
+ final PsiElement insertedElement = reference.replace(newReference);
+ JavaCodeStyleManager.getInstance(project).shortenClassReferences(insertedElement);
}
else {
final PsiJavaCodeReferenceElement referenceElement =
factory.createReferenceElementByFQClassName(referenceText, reference.getResolveScope());
- try {
- reference.replace(referenceElement);
- }
- catch (IncorrectOperationException e) {
- throw new RuntimeException(e);
- }
+ final PsiElement insertedElement = reference.replace(referenceElement);
+ JavaCodeStyleManager.getInstance(project).shortenClassReferences(insertedElement);
}
}
@@ -204,7 +202,7 @@ public class StaticImportInspection extends BaseInspection {
final PsiMember member = (PsiMember)target;
for (JavaResolveResult importTarget : importTargets) {
final PsiElement targetElement = importTarget.getElement();
- if (targetElement instanceof PsiMethod) {
+ if (targetElement instanceof PsiMethod || targetElement instanceof PsiField) {
if (member.equals(targetElement)) {
addReference(reference);
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/AssertEqualsCalledOnArrayInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/AssertEqualsCalledOnArrayInspection.java
index 8c05fc9b086b..30608ed8588b 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/AssertEqualsCalledOnArrayInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/AssertEqualsCalledOnArrayInspection.java
@@ -24,6 +24,7 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
+import com.siyeh.ig.psiutils.ImportUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -47,8 +48,7 @@ public class AssertEqualsCalledOnArrayInspection extends BaseInspection {
return new AssertEqualsCalledOnArrayFix();
}
- private static class AssertEqualsCalledOnArrayFix
- extends InspectionGadgetsFix {
+ private static class AssertEqualsCalledOnArrayFix extends InspectionGadgetsFix {
@Override
@NotNull
@@ -59,17 +59,17 @@ public class AssertEqualsCalledOnArrayInspection extends BaseInspection {
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement methodNameIdentifier = descriptor.getPsiElement();
- final PsiReferenceExpression methodExpression = (PsiReferenceExpression)methodNameIdentifier.getParent();
- if (methodExpression == null) {
+ final PsiElement parent = methodNameIdentifier.getParent();
+ if (!(parent instanceof PsiReferenceExpression)) {
return;
}
+ final PsiReferenceExpression methodExpression = (PsiReferenceExpression)parent;
final PsiExpression qualifier = methodExpression.getQualifierExpression();
- if (qualifier == null) {
+ if (qualifier == null && ImportUtils.addStaticImport("org.junit.Assert", "assertArrayEquals", methodExpression)) {
replaceExpression(methodExpression, "assertArrayEquals");
}
else {
- final String qualifierText = qualifier.getText();
- replaceExpression(methodExpression, qualifierText + ".assertArrayEquals");
+ replaceExpression(methodExpression, "org.junit.Assert.assertArrayEquals");
}
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/AssertEqualsMayBeAssertSameInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/AssertEqualsMayBeAssertSameInspection.java
index cea04d38dc84..362c5a17c41f 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/AssertEqualsMayBeAssertSameInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/AssertEqualsMayBeAssertSameInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2010 Bas Leijdekkers
+ * Copyright 2008-2012 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
+import com.siyeh.ig.psiutils.ImportUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -31,15 +32,13 @@ public class AssertEqualsMayBeAssertSameInspection extends BaseInspection {
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "assertequals.may.be.assertsame.display.name");
+ return InspectionGadgetsBundle.message("assertequals.may.be.assertsame.display.name");
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "assertequals.may.be.assertsame.problem.descriptor");
+ return InspectionGadgetsBundle.message("assertequals.may.be.assertsame.problem.descriptor");
}
@Override
@@ -47,29 +46,45 @@ public class AssertEqualsMayBeAssertSameInspection extends BaseInspection {
return new AssertEqualsMayBeAssertSameFix();
}
- private static class AssertEqualsMayBeAssertSameFix
- extends InspectionGadgetsFix {
+ private static class AssertEqualsMayBeAssertSameFix extends InspectionGadgetsFix {
@NotNull
public String getName() {
- return InspectionGadgetsBundle.message(
- "assertequals.may.be.assertsame.quickfix");
+ return InspectionGadgetsBundle.message("assertequals.may.be.assertsame.quickfix");
}
@Override
- protected void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
+ protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement element = descriptor.getPsiElement();
- final PsiElement grandParent = element.getParent().getParent();
+ final PsiElement parent = element.getParent();
+ if (!(parent instanceof PsiReferenceExpression)) {
+ return;
+ }
+ final PsiReferenceExpression methodExpression = (PsiReferenceExpression)parent;
+ final PsiElement grandParent = methodExpression.getParent();
if (!(grandParent instanceof PsiMethodCallExpression)) {
return;
}
- final PsiMethodCallExpression methodCallExpression =
- (PsiMethodCallExpression)grandParent;
- @NonNls final String text = methodCallExpression.getText();
- final String newExpressionText =
- text.replace("assertEquals", "assertSame");
- replaceExpression(methodCallExpression, newExpressionText);
+ final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)grandParent;
+ final PsiMethod method = methodCallExpression.resolveMethod();
+ if (method == null) {
+ return;
+ }
+ final PsiClass containingClass = method.getContainingClass();
+ if (containingClass == null) {
+ return;
+ }
+ final String className = containingClass.getQualifiedName();
+ if (className == null) {
+ return;
+ }
+ final PsiExpression qualifier = methodExpression.getQualifierExpression();
+ if (qualifier == null && ImportUtils.addStaticImport(className, "assertSame", methodExpression)) {
+ replaceExpression(methodExpression, "assertSame");
+ }
+ else {
+ replaceExpression(methodExpression, className + ".assertSame");
+ }
}
}
@@ -78,22 +93,19 @@ public class AssertEqualsMayBeAssertSameInspection extends BaseInspection {
return new AssertEqualsMayBeAssertSameVisitor();
}
- private static class AssertEqualsMayBeAssertSameVisitor
- extends BaseInspectionVisitor {
+ private static class AssertEqualsMayBeAssertSameVisitor extends BaseInspectionVisitor {
@Override
- public void visitMethodCallExpression(
- PsiMethodCallExpression expression) {
+ public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
@NonNls final String name = methodExpression.getReferenceName();
if (!"assertEquals".equals(name)) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
- if (arguments.length == 3 && arguments.length == 2) {
+ if (arguments.length != 3 && arguments.length != 2) {
return;
}
final PsiMethod method = expression.resolveMethod();
@@ -105,8 +117,7 @@ public class AssertEqualsMayBeAssertSameInspection extends BaseInspection {
return;
}
final String qualifiedName = aClass.getQualifiedName();
- if (!"org.junit.Assert".equals(qualifiedName) &&
- !"junit.framework.Assert".equals(qualifiedName)) {
+ if (!"org.junit.Assert".equals(qualifiedName) && !"junit.framework.Assert".equals(qualifiedName)) {
return;
}
final PsiExpression argument1 = arguments[arguments.length - 2];
@@ -120,9 +131,8 @@ public class AssertEqualsMayBeAssertSameInspection extends BaseInspection {
registerMethodCallError(expression);
}
- private static boolean couldBeAssertSameArgument(
- PsiExpression argument1) {
- final PsiType type = argument1.getType();
+ private static boolean couldBeAssertSameArgument(PsiExpression expression) {
+ final PsiType type = expression.getType();
if (!(type instanceof PsiClassType)) {
return false;
}
@@ -134,19 +144,15 @@ public class AssertEqualsMayBeAssertSameInspection extends BaseInspection {
if (!argumentClass.hasModifierProperty(PsiModifier.FINAL)) {
return false;
}
- final PsiMethod[] methods =
- argumentClass.findMethodsByName("equals", true);
- final PsiManager manager = argument1.getManager();
- final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(
- manager.getProject());
- final PsiClass objectClass = psiFacade.findClass(
- CommonClassNames.JAVA_LANG_OBJECT,
- argumentClass.getResolveScope());
+ final PsiMethod[] methods = argumentClass.findMethodsByName("equals", true);
+ final PsiManager manager = expression.getManager();
+ final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(manager.getProject());
+ final PsiClass objectClass = psiFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, argumentClass.getResolveScope());
if (objectClass == null) {
return false;
}
- for (PsiMethod psiMethod : methods) {
- final PsiClass containingClass = psiMethod.getContainingClass();
+ for (PsiMethod method : methods) {
+ final PsiClass containingClass = method.getContainingClass();
if (!objectClass.equals(containingClass)) {
return false;
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java
index 2b5f8c0b74ab..72080f759e70 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java
@@ -19,7 +19,6 @@ import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -34,15 +33,13 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "simplifiable.junit.assertion.display.name");
+ return InspectionGadgetsBundle.message("simplifiable.junit.assertion.display.name");
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "simplifiable.junit.assertion.problem.descriptor", infos[0]);
+ return InspectionGadgetsBundle.message("simplifiable.junit.assertion.problem.descriptor", infos[0]);
}
@Override
@@ -55,20 +52,17 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
@Override
@NotNull
public String getName() {
- return InspectionGadgetsBundle.message(
- "simplify.junit.assertion.simplify.quickfix");
+ return InspectionGadgetsBundle.message("simplify.junit.assertion.simplify.quickfix");
}
@Override
- public void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
+ public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement methodNameIdentifier = descriptor.getPsiElement();
final PsiElement parent = methodNameIdentifier.getParent();
if (parent == null) {
return;
}
- final PsiMethodCallExpression callExpression =
- (PsiMethodCallExpression)parent.getParent();
+ final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)parent.getParent();
if (isAssertThatCouldBeAssertNull(callExpression)) {
replaceAssertWithAssertNull(callExpression);
}
@@ -86,15 +80,12 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
}
}
- private static void replaceAssertWithFail(
- PsiMethodCallExpression callExpression)
- throws IncorrectOperationException {
+ private static void replaceAssertWithFail(PsiMethodCallExpression callExpression) throws IncorrectOperationException {
final PsiMethod method = callExpression.resolveMethod();
if (method == null) {
return;
}
- final PsiExpressionList argumentList =
- callExpression.getArgumentList();
+ final PsiExpressionList argumentList = callExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
final PsiExpression message;
if (arguments.length == 2) {
@@ -104,19 +95,18 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
message = null;
}
@NonNls final StringBuilder newExpression = new StringBuilder();
- addStaticImportIfPossible(callExpression, "fail", newExpression);
+ if (!ImportUtils.addStaticImport("org.junit.Assert", "fail", callExpression)) {
+ newExpression.append("org.junit.Assert.");
+ }
newExpression.append("fail(");
if (message != null) {
newExpression.append(message.getText());
}
newExpression.append(')');
- replaceExpressionAndShorten(callExpression,
- newExpression.toString());
+ replaceExpressionAndShorten(callExpression, newExpression.toString());
}
- private static void replaceAssertTrueWithAssertEquals(
- PsiMethodCallExpression callExpression)
- throws IncorrectOperationException {
+ private static void replaceAssertTrueWithAssertEquals(PsiMethodCallExpression callExpression) throws IncorrectOperationException {
final PsiMethod method = callExpression.resolveMethod();
if (method == null) {
return;
@@ -125,8 +115,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
final PsiParameter[] parameters = parameterList.getParameters();
final PsiType stringType = TypeUtils.getStringType(callExpression);
final PsiType paramType1 = parameters[0].getType();
- final PsiExpressionList argumentList =
- callExpression.getArgumentList();
+ final PsiExpressionList argumentList = callExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
final int testPosition;
final PsiExpression message;
@@ -142,25 +131,19 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
PsiExpression lhs = null;
PsiExpression rhs = null;
if (testArgument instanceof PsiBinaryExpression) {
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)testArgument;
+ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)testArgument;
lhs = binaryExpression.getLOperand();
rhs = binaryExpression.getROperand();
}
else if (testArgument instanceof PsiMethodCallExpression) {
- final PsiMethodCallExpression call =
- (PsiMethodCallExpression)testArgument;
- final PsiReferenceExpression equalityMethodExpression =
- call.getMethodExpression();
- final PsiExpressionList equalityArgumentList =
- call.getArgumentList();
- final PsiExpression[] equalityArgs =
- equalityArgumentList.getExpressions();
+ final PsiMethodCallExpression call = (PsiMethodCallExpression)testArgument;
+ final PsiReferenceExpression equalityMethodExpression = call.getMethodExpression();
+ final PsiExpressionList equalityArgumentList = call.getArgumentList();
+ final PsiExpression[] equalityArgs = equalityArgumentList.getExpressions();
rhs = equalityArgs[0];
lhs = equalityMethodExpression.getQualifierExpression();
}
- if (!(lhs instanceof PsiLiteralExpression) &&
- rhs instanceof PsiLiteralExpression) {
+ if (!(lhs instanceof PsiLiteralExpression) && rhs instanceof PsiLiteralExpression) {
final PsiExpression temp = lhs;
lhs = rhs;
rhs = temp;
@@ -169,27 +152,22 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return;
}
@NonNls final StringBuilder newExpression = new StringBuilder();
- addStaticImportIfPossible(callExpression, "assertEquals",
- newExpression);
+ if (!ImportUtils.addStaticImport("org.junit.Assert", "assertEquals", callExpression)) {
+ newExpression.append("org.junit.Assert.");
+ }
newExpression.append("assertEquals(");
if (message != null) {
- newExpression.append(message.getText());
- newExpression.append(',');
+ newExpression.append(message.getText()).append(',');
}
- newExpression.append(lhs.getText());
- newExpression.append(',');
- newExpression.append(rhs.getText());
- if (isFloatingPoint(lhs) || isFloatingPoint(rhs)) {
+ newExpression.append(lhs.getText()).append(',').append(rhs.getText());
+ if (TypeUtils.hasFloatingPointType(lhs) || TypeUtils.hasFloatingPointType(rhs)) {
newExpression.append(",0.0");
}
newExpression.append(')');
- replaceExpressionAndShorten(callExpression,
- newExpression.toString());
+ replaceExpressionAndShorten(callExpression, newExpression.toString());
}
- private static void replaceAssertWithAssertNull(
- PsiMethodCallExpression callExpression)
- throws IncorrectOperationException {
+ private static void replaceAssertWithAssertNull(PsiMethodCallExpression callExpression) throws IncorrectOperationException {
final PsiMethod method = callExpression.resolveMethod();
if (method == null) {
return;
@@ -198,8 +176,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
final PsiParameter[] parameters = parameterList.getParameters();
final PsiType stringType = TypeUtils.getStringType(callExpression);
final PsiType paramType1 = parameters[0].getType();
- final PsiExpressionList argumentList =
- callExpression.getArgumentList();
+ final PsiExpressionList argumentList = callExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
final int testPosition;
final PsiExpression message;
@@ -211,48 +188,38 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
testPosition = 0;
message = null;
}
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)arguments[testPosition];
+ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)arguments[testPosition];
final PsiExpression lhs = binaryExpression.getLOperand();
PsiExpression rhs = binaryExpression.getROperand();
if (rhs == null) {
return;
}
- final IElementType tokenType =
- binaryExpression.getOperationTokenType();
- if (!(lhs instanceof PsiLiteralExpression) &&
- rhs instanceof PsiLiteralExpression) {
+ final IElementType tokenType = binaryExpression.getOperationTokenType();
+ if (!(lhs instanceof PsiLiteralExpression) && rhs instanceof PsiLiteralExpression) {
rhs = lhs;
}
@NonNls final StringBuilder newExpression = new StringBuilder();
- final PsiReferenceExpression methodExpression =
- callExpression.getMethodExpression();
- @NonNls final String methodName =
- methodExpression.getReferenceName();
+ final PsiReferenceExpression methodExpression = callExpression.getMethodExpression();
+ @NonNls final String methodName = methodExpression.getReferenceName();
@NonNls final String memberName;
- if ("assertFalse".equals(methodName) ^
- tokenType.equals(JavaTokenType.NE)) {
+ if ("assertFalse".equals(methodName) ^ tokenType.equals(JavaTokenType.NE)) {
memberName = "assertNotNull";
}
else {
memberName = "assertNull";
}
- addStaticImportIfPossible(callExpression, memberName, newExpression);
- newExpression.append(memberName);
- newExpression.append('(');
- if (message != null) {
- newExpression.append(message.getText());
- newExpression.append(',');
+ if (!ImportUtils.addStaticImport("org.junit.Assert", memberName, callExpression)) {
+ newExpression.append("org.junit.Assert.");
}
- newExpression.append(rhs.getText());
- newExpression.append(')');
- replaceExpressionAndShorten(callExpression,
- newExpression.toString());
+ newExpression.append(memberName).append('(');
+ if (message != null) {
+ newExpression.append(message.getText()).append(',');
+ }
+ newExpression.append(rhs.getText()).append(')');
+ replaceExpressionAndShorten(callExpression, newExpression.toString());
}
- private static void replaceAssertWithAssertSame(
- PsiMethodCallExpression callExpression)
- throws IncorrectOperationException {
+ private static void replaceAssertWithAssertSame(PsiMethodCallExpression callExpression) throws IncorrectOperationException {
final PsiMethod method = callExpression.resolveMethod();
if (method == null) {
return;
@@ -261,8 +228,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
final PsiParameter[] parameters = parameterList.getParameters();
final PsiType stringType = TypeUtils.getStringType(callExpression);
final PsiType paramType1 = parameters[0].getType();
- final PsiExpressionList argumentList =
- callExpression.getArgumentList();
+ final PsiExpressionList argumentList = callExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
final int testPosition;
final PsiExpression message;
@@ -274,14 +240,11 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
testPosition = 0;
message = null;
}
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)arguments[testPosition];
+ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)arguments[testPosition];
PsiExpression lhs = binaryExpression.getLOperand();
PsiExpression rhs = binaryExpression.getROperand();
- final IElementType tokenType =
- binaryExpression.getOperationTokenType();
- if (!(lhs instanceof PsiLiteralExpression) &&
- rhs instanceof PsiLiteralExpression) {
+ final IElementType tokenType = binaryExpression.getOperationTokenType();
+ if (!(lhs instanceof PsiLiteralExpression) && rhs instanceof PsiLiteralExpression) {
final PsiExpression temp = lhs;
lhs = rhs;
rhs = temp;
@@ -290,31 +253,24 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return;
}
@NonNls final StringBuilder newExpression = new StringBuilder();
- final PsiReferenceExpression methodExpression =
- callExpression.getMethodExpression();
- @NonNls final String methodName =
- methodExpression.getReferenceName();
+ final PsiReferenceExpression methodExpression = callExpression.getMethodExpression();
+ @NonNls final String methodName = methodExpression.getReferenceName();
@NonNls final String memberName;
- if ("assertFalse".equals(methodName) ^
- tokenType.equals(JavaTokenType.NE)) {
+ if ("assertFalse".equals(methodName) ^ tokenType.equals(JavaTokenType.NE)) {
memberName = "assertNotSame";
}
else {
memberName = "assertSame";
}
- addStaticImportIfPossible(callExpression, memberName, newExpression);
- newExpression.append(memberName);
- newExpression.append('(');
- if (message != null) {
- newExpression.append(message.getText());
- newExpression.append(',');
+ if (!ImportUtils.addStaticImport("org.junit.Assert", memberName, callExpression)) {
+ newExpression.append("org.junit.Assert.");
}
- newExpression.append(lhs.getText());
- newExpression.append(',');
- newExpression.append(rhs.getText());
- newExpression.append(')');
- replaceExpressionAndShorten(callExpression,
- newExpression.toString());
+ newExpression.append(memberName).append('(');
+ if (message != null) {
+ newExpression.append(message.getText()).append(',');
+ }
+ newExpression.append(lhs.getText()).append(',').append(rhs.getText()).append(')');
+ replaceExpressionAndShorten(callExpression, newExpression.toString());
}
private static void replaceAssertEqualsWithAssertLiteral(
@@ -328,8 +284,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
final PsiParameter[] parameters = parameterList.getParameters();
final PsiType stringType = TypeUtils.getStringType(callExpression);
final PsiType paramType1 = parameters[0].getType();
- final PsiExpressionList argumentList =
- callExpression.getArgumentList();
+ final PsiExpressionList argumentList = callExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
final int firstTestPosition;
final int secondTestPosition;
@@ -344,10 +299,8 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
secondTestPosition = 1;
message = null;
}
- final PsiExpression firstTestArgument =
- arguments[firstTestPosition];
- final PsiExpression secondTestArgument =
- arguments[secondTestPosition];
+ final PsiExpression firstTestArgument = arguments[firstTestPosition];
+ final PsiExpression secondTestArgument = arguments[secondTestPosition];
final String literalValue;
final String compareValue;
if (isSimpleLiteral(firstTestArgument, secondTestArgument)) {
@@ -358,47 +311,18 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
literalValue = secondTestArgument.getText();
compareValue = firstTestArgument.getText();
}
- final String uppercaseLiteralValue =
- Character.toUpperCase(literalValue.charAt(0)) +
- literalValue.substring(1);
+ final String uppercaseLiteralValue = Character.toUpperCase(literalValue.charAt(0)) + literalValue.substring(1);
@NonNls final StringBuilder newExpression = new StringBuilder();
@NonNls final String methodName = "assert" + uppercaseLiteralValue;
- addStaticImportIfPossible(callExpression, methodName, newExpression);
- newExpression.append(methodName);
- newExpression.append('(');
+ if (!ImportUtils.addStaticImport("org.junit.Assert", methodName, callExpression)) {
+ newExpression.append("org.junit.Assert.");
+ }
+ newExpression.append(methodName).append('(');
if (message != null) {
- newExpression.append(message.getText());
- newExpression.append(',');
+ newExpression.append(message.getText()).append(',');
}
- newExpression.append(compareValue);
- newExpression.append(')');
- replaceExpressionAndShorten(callExpression,
- newExpression.toString());
- }
-
- private static void addStaticImportIfPossible(
- PsiMethodCallExpression context, @NonNls String memberName,
- @NonNls StringBuilder out) {
- final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(
- context, PsiMethod.class);
- if (TestUtils.isJUnit4TestMethod(containingMethod)) {
- final PsiReferenceExpression methodExpression =
- context.getMethodExpression();
- if (methodExpression.isQualified() ||
- !ImportUtils.nameCanBeStaticallyImported(
- "org.junit.Assert", memberName, context)) {
- out.append("org.junit.Assert.");
- }
- else {
- ImportUtils.addStaticImport(
- "org.junit.Assert", memberName, context);
- }
- }
- }
-
- private static boolean isFloatingPoint(PsiExpression expression) {
- final PsiType type = expression.getType();
- return PsiType.FLOAT.equals(type) || PsiType.DOUBLE.equals(type);
+ newExpression.append(compareValue).append(')');
+ replaceExpressionAndShorten(callExpression, newExpression.toString());
}
}
@@ -407,12 +331,10 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return new SimplifiableJUnitAssertionVisitor();
}
- private static class SimplifiableJUnitAssertionVisitor
- extends BaseInspectionVisitor {
+ private static class SimplifiableJUnitAssertionVisitor extends BaseInspectionVisitor {
@Override
- public void visitMethodCallExpression(
- @NotNull PsiMethodCallExpression expression) {
+ public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
if (isAssertThatCouldBeAssertNull(expression)) {
if (hasEqEqExpressionArgument(expression)) {
@@ -434,8 +356,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
registerMethodCallError(expression, "assertEquals()");
}
else if (isAssertEqualsThatCouldBeAssertLiteral(expression)) {
- registerMethodCallError(expression,
- getReplacementMethodName(expression));
+ registerMethodCallError(expression, getReplacementMethodName(expression));
}
else if (isAssertThatCouldBeFail(expression)) {
registerMethodCallError(expression, "fail()");
@@ -443,14 +364,12 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
}
@NonNls
- private static String getReplacementMethodName(
- PsiMethodCallExpression expression) {
+ private static String getReplacementMethodName(PsiMethodCallExpression expression) {
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
final PsiExpression firstArgument = arguments[0];
if (firstArgument instanceof PsiLiteralExpression) {
- final PsiLiteralExpression literalExpression =
- (PsiLiteralExpression)firstArgument;
+ final PsiLiteralExpression literalExpression = (PsiLiteralExpression)firstArgument;
final Object value = literalExpression.getValue();
if (value == Boolean.TRUE) {
return "assertTrue()";
@@ -464,8 +383,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
}
final PsiExpression secondArgument = arguments[1];
if (secondArgument instanceof PsiLiteralExpression) {
- final PsiLiteralExpression literalExpression =
- (PsiLiteralExpression)secondArgument;
+ final PsiLiteralExpression literalExpression = (PsiLiteralExpression)secondArgument;
final Object value = literalExpression.getValue();
if (value == Boolean.TRUE) {
return "assertTrue()";
@@ -480,18 +398,15 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return "";
}
- private static boolean hasEqEqExpressionArgument(
- PsiMethodCallExpression expression) {
+ private static boolean hasEqEqExpressionArgument(PsiMethodCallExpression expression) {
final PsiExpressionList list = expression.getArgumentList();
final PsiExpression[] arguments = list.getExpressions();
final PsiExpression argument = arguments[0];
if (!(argument instanceof PsiBinaryExpression)) {
return false;
}
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)argument;
- final IElementType tokenType =
- binaryExpression.getOperationTokenType();
+ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)argument;
+ final IElementType tokenType = binaryExpression.getOperationTokenType();
return JavaTokenType.EQEQ.equals(tokenType);
}
}
@@ -501,8 +416,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
if (!isAssertTrue(expression)) {
return false;
}
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiMethod method = (PsiMethod)methodExpression.resolve();
if (method == null) {
return false;
@@ -527,13 +441,11 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return testArgument != null && isEqualityComparison(testArgument);
}
- static boolean isAssertThatCouldBeAssertSame(
- PsiMethodCallExpression expression) {
+ static boolean isAssertThatCouldBeAssertSame(PsiMethodCallExpression expression) {
if (!isAssertTrue(expression) && !isAssertFalse(expression)) {
return false;
}
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiMethod method = (PsiMethod)methodExpression.resolve();
if (method == null) {
return false;
@@ -558,13 +470,11 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return testArgument != null && isIdentityComparison(testArgument);
}
- static boolean isAssertThatCouldBeAssertNull(
- PsiMethodCallExpression expression) {
+ static boolean isAssertThatCouldBeAssertNull(PsiMethodCallExpression expression) {
if (!isAssertTrue(expression) && !isAssertFalse(expression)) {
return false;
}
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiMethod method = (PsiMethod)methodExpression.resolve();
if (method == null) {
return false;
@@ -601,8 +511,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
else {
return false;
}
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiMethod method = (PsiMethod)methodExpression.resolve();
if (method == null) {
return false;
@@ -636,13 +545,11 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
}
}
- static boolean isAssertEqualsThatCouldBeAssertLiteral(
- PsiMethodCallExpression expression) {
+ static boolean isAssertEqualsThatCouldBeAssertLiteral(PsiMethodCallExpression expression) {
if (!isAssertEquals(expression)) {
return false;
}
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiMethod method = (PsiMethod)methodExpression.resolve();
if (method == null) {
return false;
@@ -675,8 +582,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
isSimpleLiteral(secondTestArgument, firstTestArgument);
}
- static boolean isSimpleLiteral(PsiExpression expression1,
- PsiExpression expression2) {
+ static boolean isSimpleLiteral(PsiExpression expression1, PsiExpression expression2) {
if (!(expression1 instanceof PsiLiteralExpression)) {
return false;
}
@@ -684,8 +590,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
if (PsiKeyword.NULL.equals(text)) {
return true;
}
- if (!PsiKeyword.TRUE.equals(text) &&
- !PsiKeyword.FALSE.equals(text)) {
+ if (!PsiKeyword.TRUE.equals(text) && !PsiKeyword.FALSE.equals(text)) {
return false;
}
final PsiType type = expression2.getType();
@@ -694,8 +599,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
private static boolean isEqualityComparison(PsiExpression expression) {
if (expression instanceof PsiBinaryExpression) {
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
+ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression;
final IElementType tokenType = binaryExpression.getOperationTokenType();
if (!tokenType.equals(JavaTokenType.EQEQ)) {
return false;
@@ -709,13 +613,11 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return type != null && ClassUtils.isPrimitive(type);
}
else if (expression instanceof PsiMethodCallExpression) {
- final PsiMethodCallExpression call =
- (PsiMethodCallExpression)expression;
+ final PsiMethodCallExpression call = (PsiMethodCallExpression)expression;
if (!MethodCallUtils.isEqualsCall(call)) {
return false;
}
- final PsiReferenceExpression methodExpression =
- call.getMethodExpression();
+ final PsiReferenceExpression methodExpression = call.getMethodExpression();
return methodExpression.getQualifierExpression() != null;
}
return false;
@@ -725,8 +627,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
if (!(expression instanceof PsiBinaryExpression)) {
return false;
}
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
+ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression;
if (!ComparisonUtils.isEqualityComparison(binaryExpression)) {
return false;
}
@@ -747,8 +648,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
if (!(expression instanceof PsiBinaryExpression)) {
return false;
}
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
+ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression;
if (!ComparisonUtils.isEqualityComparison(binaryExpression)) {
return false;
}
@@ -757,30 +657,24 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return false;
}
final PsiExpression lhs = binaryExpression.getLOperand();
- return PsiKeyword.NULL.equals(lhs.getText()) ||
- PsiKeyword.NULL.equals(rhs.getText());
+ return PsiKeyword.NULL.equals(lhs.getText()) || PsiKeyword.NULL.equals(rhs.getText());
}
- private static boolean isAssertTrue(
- @NotNull PsiMethodCallExpression expression) {
+ private static boolean isAssertTrue(@NotNull PsiMethodCallExpression expression) {
return isAssertMethodCall(expression, "assertTrue");
}
- private static boolean isAssertFalse(
- @NotNull PsiMethodCallExpression expression) {
+ private static boolean isAssertFalse(@NotNull PsiMethodCallExpression expression) {
return isAssertMethodCall(expression, "assertFalse");
}
- private static boolean isAssertEquals(
- @NotNull PsiMethodCallExpression expression) {
+ private static boolean isAssertEquals(@NotNull PsiMethodCallExpression expression) {
return isAssertMethodCall(expression, "assertEquals");
}
- private static boolean isAssertMethodCall(
- @NotNull PsiMethodCallExpression expression,
+ private static boolean isAssertMethodCall(@NotNull PsiMethodCallExpression expression,
@NonNls @NotNull String assertMethodName) {
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
@NonNls final String methodName = methodExpression.getReferenceName();
if (!assertMethodName.equals(methodName)) {
return false;
@@ -794,7 +688,6 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
return false;
}
final String qualifiedName = targetClass.getQualifiedName();
- return "junit.framework.Assert".equals(qualifiedName) ||
- "org.junit.Assert".equals(qualifiedName);
+ return "junit.framework.Assert".equals(qualifiedName) || "org.junit.Assert".equals(qualifiedName);
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java
index 8cd48af13333..b8ab455042d3 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.ComparisonUtils;
+import com.siyeh.ig.psiutils.TypeUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -109,7 +110,7 @@ public class ComparisonToNaNInspection extends BaseInspection {
}
final PsiExpression lhs = expression.getLOperand();
final PsiExpression rhs = expression.getROperand();
- if (rhs == null || !isFloatingPointType(lhs) && !isFloatingPointType(rhs)) {
+ if (rhs == null || !TypeUtils.hasFloatingPointType(lhs) && !TypeUtils.hasFloatingPointType(rhs)) {
return;
}
if (isNaN(lhs)) {
@@ -120,17 +121,6 @@ public class ComparisonToNaNInspection extends BaseInspection {
}
}
- private static boolean isFloatingPointType(PsiExpression expression) {
- if (expression == null) {
- return false;
- }
- final PsiType type = expression.getType();
- if (type == null) {
- return false;
- }
- return PsiType.DOUBLE.equals(type) || PsiType.FLOAT.equals(type);
- }
-
private static boolean isNaN(PsiExpression expression) {
if (!(expression instanceof PsiReferenceExpression)) {
return false;
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/FloatingPointEqualityInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/FloatingPointEqualityInspection.java
index bc9ac42ae111..3b0a32d94094 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/FloatingPointEqualityInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/FloatingPointEqualityInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,38 +17,34 @@ package com.siyeh.ig.numeric;
import com.intellij.psi.PsiBinaryExpression;
import com.intellij.psi.PsiExpression;
-import com.intellij.psi.PsiType;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.psiutils.ComparisonUtils;
import com.siyeh.ig.psiutils.ExpressionUtils;
+import com.siyeh.ig.psiutils.TypeUtils;
import org.jetbrains.annotations.NotNull;
public class FloatingPointEqualityInspection extends BaseInspection {
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "floating.point.equality.display.name");
+ return InspectionGadgetsBundle.message("floating.point.equality.display.name");
}
@NotNull
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "floating.point.equality.problem.descriptor");
+ return InspectionGadgetsBundle.message("floating.point.equality.problem.descriptor");
}
public BaseInspectionVisitor buildVisitor() {
return new FloatingPointEqualityComparisonVisitor();
}
- private static class FloatingPointEqualityComparisonVisitor
- extends BaseInspectionVisitor {
+ private static class FloatingPointEqualityComparisonVisitor extends BaseInspectionVisitor {
@Override
- public void visitBinaryExpression(
- @NotNull PsiBinaryExpression expression) {
+ public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
super.visitBinaryExpression(expression);
final PsiExpression rhs = expression.getROperand();
if (rhs == null) {
@@ -58,8 +54,7 @@ public class FloatingPointEqualityInspection extends BaseInspection {
return;
}
final PsiExpression lhs = expression.getLOperand();
-
- if (!isFloatingPointType(lhs) && !isFloatingPointType(rhs)) {
+ if (!TypeUtils.hasFloatingPointType(lhs) && !TypeUtils.hasFloatingPointType(rhs)) {
return;
}
if (ExpressionUtils.isZero(lhs) || ExpressionUtils.isZero(rhs)) {
@@ -67,16 +62,5 @@ public class FloatingPointEqualityInspection extends BaseInspection {
}
registerError(expression);
}
-
- private static boolean isFloatingPointType(PsiExpression expression) {
- if (expression == null) {
- return false;
- }
- final PsiType type = expression.getType();
- if (type == null) {
- return false;
- }
- return PsiType.DOUBLE.equals(type) || PsiType.FLOAT.equals(type);
- }
}
}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ImportUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ImportUtils.java
index fc3d59e8bebe..caf1b66c010c 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ImportUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ImportUtils.java
@@ -445,64 +445,56 @@ public class ImportUtils {
return false;
}
- public static void addStaticImport(
- @NotNull String qualifierClass, @NotNull String memberName,
- @NotNull PsiElement context)
+ public static boolean addStaticImport(@NotNull String qualifierClass, @NotNull String memberName, @NotNull PsiElement context)
throws IncorrectOperationException {
- final PsiClass containingClass =
- PsiTreeUtil.getParentOfType(context, PsiClass.class);
+ if (!nameCanBeStaticallyImported(qualifierClass, memberName, context)) {
+ return false;
+ }
+ final PsiClass containingClass = PsiTreeUtil.getParentOfType(context, PsiClass.class);
if (InheritanceUtil.isInheritor(containingClass, qualifierClass)) {
- return;
+ return true;
}
final PsiFile psiFile = context.getContainingFile();
if (!(psiFile instanceof PsiJavaFile)) {
- return;
+ return false;
}
final PsiJavaFile javaFile = (PsiJavaFile)psiFile;
final PsiImportList importList = javaFile.getImportList();
if (importList == null) {
- return;
+ return false;
}
- final PsiImportStatementBase existingImportStatement =
- importList.findSingleImportStatement(memberName);
+ final PsiImportStatementBase existingImportStatement = importList.findSingleImportStatement(memberName);
if (existingImportStatement != null) {
- return;
+ return false;
}
- final PsiImportStaticStatement onDemandImportStatement =
- findOnDemandImportStaticStatement(importList, qualifierClass);
- if (onDemandImportStatement != null &&
- !hasOnDemandImportStaticConflict(qualifierClass, memberName,
- context)) {
- return;
+ final PsiImportStaticStatement onDemandImportStatement = findOnDemandImportStaticStatement(importList, qualifierClass);
+ if (onDemandImportStatement != null && !hasOnDemandImportStaticConflict(qualifierClass, memberName, context)) {
+ return true;
}
final Project project = context.getProject();
final GlobalSearchScope scope = context.getResolveScope();
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final PsiClass aClass = psiFacade.findClass(qualifierClass, scope);
if (aClass == null) {
- return;
+ return false;
}
final String qualifiedName = aClass.getQualifiedName();
if (qualifiedName == null) {
- return;
+ return false;
}
- final List imports =
- getMatchingImports(importList, qualifiedName);
- final CodeStyleSettings codeStyleSettings =
- CodeStyleSettingsManager.getSettings(project);
+ final List imports = getMatchingImports(importList, qualifiedName);
+ final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
final PsiElementFactory elementFactory = psiFacade.getElementFactory();
- if (imports.size() <
- codeStyleSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND) {
- importList.add(elementFactory.createImportStaticStatement(aClass,
- memberName));
+ if (imports.size() < codeStyleSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND) {
+ importList.add(elementFactory.createImportStaticStatement(aClass, memberName));
}
else {
for (PsiImportStaticStatement importStatement : imports) {
importStatement.delete();
}
- importList.add(
- elementFactory.createImportStaticStatement(aClass, "*"));
+ importList.add(elementFactory.createImportStaticStatement(aClass, "*"));
}
+ return true;
}
private static PsiImportStaticStatement findOnDemandImportStaticStatement(
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/TypeUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/TypeUtils.java
index 2648bf91df13..093bd308b5b8 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/TypeUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/TypeUtils.java
@@ -65,9 +65,7 @@ public class TypeUtils {
return typeEquals(CommonClassNames.JAVA_LANG_STRING, targetType);
}
- public static boolean expressionHasTypeOrSubtype(
- @Nullable PsiExpression expression,
- @NonNls @NotNull String typeName) {
+ public static boolean expressionHasTypeOrSubtype(@Nullable PsiExpression expression, @NonNls @NotNull String typeName) {
if (expression == null) {
return false;
}
@@ -84,8 +82,7 @@ public class TypeUtils {
}
//getTypeIfOneOfOrSubtype
- public static String expressionHasTypeOrSubtype(
- @Nullable PsiExpression expression,
+ public static String expressionHasTypeOrSubtype(@Nullable PsiExpression expression,
@NonNls @NotNull String... typeNames) {
if (expression == null) {
return null;
@@ -110,9 +107,7 @@ public class TypeUtils {
return null;
}
- public static boolean expressionHasTypeOrSubtype(
- @Nullable PsiExpression expression,
- @NonNls @NotNull Collection typeNames) {
+ public static boolean expressionHasTypeOrSubtype(@Nullable PsiExpression expression, @NonNls @NotNull Collection typeNames) {
if (expression == null) {
return false;
}
@@ -136,9 +131,7 @@ public class TypeUtils {
return false;
}
- public static boolean variableHasTypeOrSubtype(
- @Nullable PsiVariable variable,
- @NonNls @NotNull String... typeNames) {
+ public static boolean variableHasTypeOrSubtype(@Nullable PsiVariable variable, @NonNls @NotNull String... typeNames) {
if (variable == null) {
return false;
}
@@ -158,4 +151,15 @@ public class TypeUtils {
}
return false;
}
+
+ public static boolean hasFloatingPointType(@Nullable PsiExpression expression) {
+ if (expression == null) {
+ return false;
+ }
+ final PsiType type = expression.getType();
+ if (type == null) {
+ return false;
+ }
+ return PsiType.FLOAT.equals(type) || PsiType.DOUBLE.equals(type);
+ }
}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/unnecessary_return/UnnecessaryReturn.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/unnecessary_return/UnnecessaryReturn.java
new file mode 100644
index 000000000000..b8c679dd5f54
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/unnecessary_return/UnnecessaryReturn.java
@@ -0,0 +1,97 @@
+package com.siyeh.igtest.controlflow.unnecessary_return;
+
+import java.util.concurrent.Callable;
+
+public class UnnecessaryReturn
+{
+
+ public UnnecessaryReturn()
+ {
+ return;
+ }
+
+ public void foo()
+ {
+ return;
+ }
+ public void foo2()
+ {
+ {
+ {
+ return;
+ }
+ }
+ }
+
+ public void bar()
+ {
+ if(true)
+ {
+ return;
+ }
+ }
+
+ public void barzoom()
+ {
+ while(true)
+ {
+ return;
+ }
+ }
+
+}
+class C {
+ public C() {
+ return;
+ }
+
+ public void m1() {
+ return;
+ }
+
+ public boolean m2() {
+ return true;
+ }
+
+ public void m3(boolean f) {
+ if (!f) {
+ return;
+ }
+ System.out.println("m3()");
+ if (f) {
+ return;
+ }
+ }
+
+ public void m4(boolean f) {
+ if (f) {
+ System.out.println("m4()");
+ return;
+ }
+ else {
+ return;
+ }
+ }
+
+ public void m5() {
+ while (true) {
+ System.out.println("m5()");
+ return;
+ }
+ }
+
+ public void lambda() {
+ Runnable r = () -> { return; };
+ System.out.println(r);
+
+ Callable c = () -> { return 42; };
+ System.out.println(c);
+ }
+
+ void m5(boolean a) {
+ if (a) return;
+ else {
+ System.out.println();
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/unnecessary_return/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/unnecessary_return/expected.xml
new file mode 100644
index 000000000000..036f82831456
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/unnecessary_return/expected.xml
@@ -0,0 +1,67 @@
+
+
+
+
+ UnnecessaryReturn.java
+ 10
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a constructor #loc
+
+
+
+ UnnecessaryReturn.java
+ 15
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a 'void' method #loc
+
+
+
+ UnnecessaryReturn.java
+ 21
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a 'void' method #loc
+
+
+
+ UnnecessaryReturn.java
+ 30
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a 'void' method #loc
+
+
+
+ UnnecessaryReturn.java
+ 45
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a constructor #loc
+
+
+
+ UnnecessaryReturn.java
+ 49
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a 'void' method #loc
+
+
+
+ UnnecessaryReturn.java
+ 62
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a 'void' method #loc
+
+
+
+ UnnecessaryReturn.java
+ 72
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a 'void' method #loc
+
+
+
+ UnnecessaryReturn.java
+ 84
+ Unnecessary 'return' statement
+ <code>return</code> is unnecessary as the last statement in a 'void' method #loc
+
+
+
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/verbose/UnnecessaryReturnInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/verbose/UnnecessaryReturnInspection.java
deleted file mode 100644
index 08e4fbae335d..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/verbose/UnnecessaryReturnInspection.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.siyeh.igtest.verbose;
-
-public class UnnecessaryReturnInspection
-{
-
- public UnnecessaryReturnInspection()
- {
- return;
- }
-
- public void foo()
- {
- return;
- }
- public void foo2()
- {
- {
- {
- return;
- }
- }
- }
-
- public void bar()
- {
- if(true)
- {
- return;
- }
- }
-
- public void barzoom()
- {
- while(true)
- {
- return;
- }
- }
-
-}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/common/UnnecessaryReturns.java b/plugins/InspectionGadgets/test/common/UnnecessaryReturns.java
deleted file mode 100644
index a681eb3fd156..000000000000
--- a/plugins/InspectionGadgets/test/common/UnnecessaryReturns.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2000-2012 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.util.concurrent.Callable;
-
-class C {
- public C() {
- return;
- }
-
- public void m1() {
- return;
- }
-
- public boolean m2() {
- return true;
- }
-
- public void m3(boolean f) {
- if (!f) {
- return;
- }
- System.out.println("m3()");
- if (f) {
- return;
- }
- }
-
- public void m4(boolean f) {
- if (f) {
- System.out.println("m4()");
- return;
- }
- else {
- return;
- }
- }
-
- public void m5() {
- while (true) {
- System.out.println("m5()");
- return;
- }
- }
-
- public void lambda() {
- Runnable r = () -> { return; };
- System.out.println(r);
-
- Callable c = () -> { return 42; };
- System.out.println(c);
- }
-}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/CommonIGInspectionsTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/CommonIGInspectionsTest.java
deleted file mode 100644
index 15463ce3ae18..000000000000
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/CommonIGInspectionsTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2000-2012 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.siyeh.ig;
-
-import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
-import com.intellij.codeInspection.InspectionProfileEntry;
-import com.intellij.openapi.application.PluginPathManager;
-import com.siyeh.ig.controlflow.UnnecessaryReturnInspection;
-import org.jetbrains.annotations.NotNull;
-
-public class CommonIGInspectionsTest extends LightDaemonAnalyzerTestCase {
- @NotNull
- @Override
- protected String getTestDataPath() {
- return PluginPathManager.getPluginHomePath("InspectionGadgets") + "/test";
- }
-
- private void doTest(boolean checkWarnings, boolean checkInfos, InspectionProfileEntry... tools) throws Exception {
- for (InspectionProfileEntry tool : tools) { enableInspectionTool(tool); }
- doTest("/common/" + getTestName(false) + ".java", checkWarnings, checkInfos);
- }
-
- public void testUnnecessaryReturns() throws Exception {
- final UnnecessaryReturnInspection inspection = new UnnecessaryReturnInspection();
- inspection.ignoreInThenBranch = true;
- doTest(true, false, inspection);
- }
-}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/UnnecessaryReturnInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/UnnecessaryReturnInspectionTest.java
new file mode 100644
index 000000000000..75bbc7d78a66
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/UnnecessaryReturnInspectionTest.java
@@ -0,0 +1,23 @@
+package com.siyeh.ig.controlflow;
+
+import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
+import com.intellij.openapi.roots.LanguageLevelProjectExtension;
+import com.intellij.pom.java.LanguageLevel;
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class UnnecessaryReturnInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ final UnnecessaryReturnInspection inspection = new UnnecessaryReturnInspection();
+ inspection.ignoreInThenBranch = true;
+ final LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject());
+ final LanguageLevel level = levelProjectExtension.getLanguageLevel();
+ try {
+ levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_8);
+ doTest("com/siyeh/igtest/controlflow/unnecessary_return", new LocalInspectionToolWrapper(inspection), "java 1.8");
+ }
+ finally {
+ levelProjectExtension.setLanguageLevel(level);
+ }
+ }
+}
diff --git a/plugins/android/common/src/org/jetbrains/android/util/AndroidCommonUtils.java b/plugins/android/common/src/org/jetbrains/android/util/AndroidCommonUtils.java
index 0353bfa77f2d..dacb858218b8 100644
--- a/plugins/android/common/src/org/jetbrains/android/util/AndroidCommonUtils.java
+++ b/plugins/android/common/src/org/jetbrains/android/util/AndroidCommonUtils.java
@@ -135,7 +135,14 @@ public class AndroidCommonUtils {
return null;
}
- return SdkManager.createManager(path + File.separatorChar, log);
+ // safety from errors inside sdklib
+ try {
+ return SdkManager.createManager(path + File.separatorChar, log);
+ }
+ catch (Exception e) {
+ LOG.error(e);
+ return null;
+ }
}
public static void moveAllFiles(@NotNull File from, @NotNull File to, @NotNull Collection newFiles) throws IOException {
diff --git a/plugins/android/common/src/org/jetbrains/android/util/AndroidExecutionUtil.java b/plugins/android/common/src/org/jetbrains/android/util/AndroidExecutionUtil.java
index 4f709a40268a..228bf274c7fd 100644
--- a/plugins/android/common/src/org/jetbrains/android/util/AndroidExecutionUtil.java
+++ b/plugins/android/common/src/org/jetbrains/android/util/AndroidExecutionUtil.java
@@ -50,7 +50,7 @@ public final class AndroidExecutionUtil {
}
else {
if (code == 0) {
- messages.get(AndroidCompilerMessageKind.INFORMATION).addAll(errMessages);
+ messages.get(AndroidCompilerMessageKind.WARNING).addAll(errMessages);
errMessages.clear();
}
return messages;
@@ -86,6 +86,7 @@ public final class AndroidExecutionUtil {
myMessages = new HashMap>(2);
myMessages.put(AndroidCompilerMessageKind.INFORMATION, information);
myMessages.put(AndroidCompilerMessageKind.ERROR, error);
+ myMessages.put(AndroidCompilerMessageKind.WARNING, new ArrayList());
}
public Map> getMessages() {
diff --git a/plugins/android/common/src/org/jetbrains/android/util/AndroidOSProcessHandler.java b/plugins/android/common/src/org/jetbrains/android/util/AndroidOSProcessHandler.java
index 4a48d0687d9a..2c6b9d36064a 100644
--- a/plugins/android/common/src/org/jetbrains/android/util/AndroidOSProcessHandler.java
+++ b/plugins/android/common/src/org/jetbrains/android/util/AndroidOSProcessHandler.java
@@ -32,6 +32,7 @@ import java.util.List;
public class AndroidOSProcessHandler extends BaseOSProcessHandler {
@NonNls private static final String IGNORING = "ignoring";
@NonNls private static final String SKIPPING = "skipping";
+ @NonNls private static final String DEBUGGABLE_ERROR = "androidmanifest.xml already defines debuggable";
private final List myInfoMessages = new ArrayList();
private final List myErrorMessages = new ArrayList();
@@ -54,7 +55,7 @@ public class AndroidOSProcessHandler extends BaseOSProcessHandler {
myInfoMessages.add(line);
}
else if (outputType == ProcessOutputTypes.STDERR) {
- if (l.contains(IGNORING) || l.contains(SKIPPING)) {
+ if (l.contains(IGNORING) || l.contains(SKIPPING) || l.contains(DEBUGGABLE_ERROR)) {
myInfoMessages.add(line);
}
else {
diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidAdditionalRootProviderService.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidAdditionalRootProviderService.java
index e23a7d31cf50..5a2872e57753 100644
--- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidAdditionalRootProviderService.java
+++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidAdditionalRootProviderService.java
@@ -5,6 +5,7 @@ import org.jetbrains.jps.builders.AdditionalRootsProviderService;
import org.jetbrains.jps.builders.BuildTarget;
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor;
+import org.jetbrains.jps.builders.storage.BuildDataPaths;
import org.jetbrains.jps.incremental.ModuleBuildTarget;
import java.io.File;
@@ -22,9 +23,9 @@ public class AndroidAdditionalRootProviderService extends AdditionalRootsProvide
@NotNull
@Override
- public List getAdditionalRoots(@NotNull BuildTarget target, File dataStorageRoot) {
+ public List getAdditionalRoots(@NotNull BuildTarget target, BuildDataPaths dataPaths) {
ModuleBuildTarget buildTarget = (ModuleBuildTarget)target;
- final File generatedSourcesRoot = AndroidJpsUtil.getGeneratedSourcesStorage(buildTarget.getModule(), dataStorageRoot);
+ final File generatedSourcesRoot = AndroidJpsUtil.getGeneratedSourcesStorage(buildTarget.getModule(), dataPaths);
final List result = new ArrayList();
addRoot(result, buildTarget, new File(generatedSourcesRoot, AndroidJpsUtil.AAPT_GENERATED_SOURCE_ROOT_NAME));
diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidBuilderService.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidBuilderService.java
index 85d1f0f5e35e..d6863127ca92 100644
--- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidBuilderService.java
+++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidBuilderService.java
@@ -28,7 +28,7 @@ public class AndroidBuilderService extends BuilderService {
@NotNull
@Override
- public List extends TargetBuilder>> createBuilders() {
+ public List extends TargetBuilder,?>> createBuilders() {
return Arrays.asList(new AndroidDexBuilder(),
new AndroidPackagingBuilder());
}
diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java
index 7684f661b890..7354f9e55e80 100644
--- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java
+++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java
@@ -33,6 +33,8 @@ import org.jetbrains.jps.ProjectPaths;
import org.jetbrains.jps.android.builder.AndroidProjectBuildTarget;
import org.jetbrains.jps.android.model.JpsAndroidModuleExtension;
import org.jetbrains.jps.android.model.JpsAndroidSdkProperties;
+import org.jetbrains.jps.builders.BuildRootDescriptor;
+import org.jetbrains.jps.builders.DirtyFilesHolder;
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
import org.jetbrains.jps.cmdline.ClasspathBootstrap;
import org.jetbrains.jps.incremental.*;
@@ -53,7 +55,7 @@ import java.util.*;
/**
* @author Eugene.Kudelevsky
*/
-public class AndroidDexBuilder extends TargetBuilder {
+public class AndroidDexBuilder extends TargetBuilder {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.android.AndroidDexBuilder");
@NonNls private static final String BUILDER_NAME = "android-dex";
@@ -66,7 +68,8 @@ public class AndroidDexBuilder extends TargetBuilder
}
@Override
- public void build(@NotNull AndroidProjectBuildTarget target, @NotNull CompileContext context) throws ProjectBuildException {
+ public void build(@NotNull AndroidProjectBuildTarget target, @NotNull CompileContext context,
+ DirtyFilesHolder holder) throws ProjectBuildException {
if (target.getKind() != AndroidProjectBuildTarget.AndroidBuilderKind.DEX && AndroidJpsUtil.isLightBuild(context)) {
return;
}
@@ -83,7 +86,7 @@ public class AndroidDexBuilder extends TargetBuilder
}
private static void doBuild(CompileContext context) throws IOException, ProjectBuildException {
- final File root = context.getProjectDescriptor().dataManager.getDataStorageRoot();
+ final File root = context.getProjectDescriptor().dataManager.getDataPaths().getDataStorageRoot();
AndroidFileSetStorage dexStateStorage = null;
AndroidFileSetStorage proguardStateStorage = null;
diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidJpsUtil.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidJpsUtil.java
index a58439655916..79d8c1e7a22f 100644
--- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidJpsUtil.java
+++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidJpsUtil.java
@@ -16,6 +16,7 @@ import org.jetbrains.android.util.AndroidCompilerMessageKind;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jps.builders.storage.BuildDataPaths;
import org.jetbrains.jps.util.JpsPathUtil;
import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.ProjectPaths;
@@ -153,7 +154,7 @@ public class AndroidJpsUtil {
@NotNull
public static File getDirectoryForIntermediateArtifacts(@NotNull CompileContext context,
@NotNull JpsModule module) {
- final File androidStorage = new File(context.getProjectDescriptor().dataManager.getDataStorageRoot(), ANDROID_STORAGE_DIR);
+ final File androidStorage = new File(context.getProjectDescriptor().dataManager.getDataPaths().getDataStorageRoot(), ANDROID_STORAGE_DIR);
return new File(new File(androidStorage, INTERMEDIATE_ARTIFACTS_STORAGE), module.getName());
}
@@ -520,7 +521,7 @@ public class AndroidJpsUtil {
@NotNull
public static File getResourcesCacheDir(@NotNull CompileContext context, @NotNull JpsModule module) {
- final File androidStorage = new File(context.getProjectDescriptor().dataManager.getDataStorageRoot(), ANDROID_STORAGE_DIR);
+ final File androidStorage = new File(context.getProjectDescriptor().dataManager.getDataPaths().getDataStorageRoot(), ANDROID_STORAGE_DIR);
return new File(new File(androidStorage, RESOURCE_CACHE_STORAGE), module.getName());
}
@@ -585,19 +586,19 @@ public class AndroidJpsUtil {
@NotNull
public static File getGeneratedSourcesStorage(@NotNull JpsModule module, BuildDataManager dataManager) {
- return getGeneratedSourcesStorage(module, dataManager.getDataStorageRoot());
+ return getGeneratedSourcesStorage(module, dataManager.getDataPaths());
}
@NotNull
- public static File getGeneratedSourcesStorage(@NotNull JpsModule module, final File dataStorageRoot) {
- final File androidStorageRoot = new File(dataStorageRoot, ANDROID_STORAGE_DIR);
+ public static File getGeneratedSourcesStorage(@NotNull JpsModule module, final BuildDataPaths dataPaths) {
+ final File androidStorageRoot = new File(dataPaths.getDataStorageRoot(), ANDROID_STORAGE_DIR);
final File generatedSourcesRoot = new File(androidStorageRoot, GENERATED_SOURCES_FOLDER_NAME);
return new File(generatedSourcesRoot, module.getName());
}
@NotNull
public static File getGeneratedResourcesStorage(@NotNull JpsModule module, BuildDataManager dataManager) {
- final File dataStorageRoot = dataManager.getDataStorageRoot();
+ final File dataStorageRoot = dataManager.getDataPaths().getDataStorageRoot();
final File androidStorageRoot = new File(dataStorageRoot, ANDROID_STORAGE_DIR);
final File generatedSourcesRoot = new File(androidStorageRoot, GENERATED_RESOURCES_DIR_NAME);
return new File(generatedSourcesRoot, module.getName());
diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java
index 2421a9fca633..fca96bda9677 100644
--- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java
+++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java
@@ -18,6 +18,8 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.ProjectPaths;
import org.jetbrains.jps.android.builder.AndroidProjectBuildTarget;
import org.jetbrains.jps.android.model.JpsAndroidModuleExtension;
+import org.jetbrains.jps.builders.BuildRootDescriptor;
+import org.jetbrains.jps.builders.DirtyFilesHolder;
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
import org.jetbrains.jps.incremental.*;
import org.jetbrains.jps.incremental.messages.BuildMessage;
@@ -38,7 +40,7 @@ import java.util.*;
/**
* @author Eugene.Kudelevsky
*/
-public class AndroidPackagingBuilder extends TargetBuilder {
+public class AndroidPackagingBuilder extends TargetBuilder {
@NonNls private static final String BUILDER_NAME = "android-packager";
@NonNls private static final String RELEASE_SUFFIX = ".release";
@NonNls private static final String UNSIGNED_SUFFIX = ".unsigned";
@@ -58,7 +60,8 @@ public class AndroidPackagingBuilder extends TargetBuilder holder) throws ProjectBuildException {
if (target.getKind() != AndroidProjectBuildTarget.AndroidBuilderKind.PACKAGING || AndroidJpsUtil.isLightBuild(context)) {
return;
}
@@ -123,7 +126,7 @@ public class AndroidPackagingBuilder extends TargetBuilder modules,
@NotNull Map module2state) throws IOException {
boolean success = true;
- final File dataStorageRoot = context.getProjectDescriptor().dataManager.getDataStorageRoot();
+ final File dataStorageRoot = context.getProjectDescriptor().dataManager.getDataPaths().getDataStorageRoot();
final AndroidFileSetStorage storage = new AndroidFileSetStorage(dataStorageRoot, "resource_caching");
try {
@@ -212,7 +215,7 @@ public class AndroidPackagingBuilder extends TargetBuilder manifestFiles) throws IOException {
boolean success = true;
- final File dataStorageRoot = context.getProjectDescriptor().dataManager.getDataStorageRoot();
+ final File dataStorageRoot = context.getProjectDescriptor().dataManager.getDataPaths().getDataStorageRoot();
final boolean releaseBuild = AndroidJpsUtil.isReleaseBuild(context);
AndroidFileSetStorage resourcesStorage = null;
AndroidFileSetStorage assetsStorage = null;
@@ -292,7 +295,7 @@ public class AndroidPackagingBuilder extends TargetBuilder modules) throws IOException {
final boolean release = AndroidJpsUtil.isReleaseBuild(context);
- final File dataStorageRoot = context.getProjectDescriptor().dataManager.getDataStorageRoot();
+ final File dataStorageRoot = context.getProjectDescriptor().dataManager.getDataPaths().getDataStorageRoot();
boolean success = true;
diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java
index ab3aef84ee90..ee604d2c8b52 100644
--- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java
+++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java
@@ -162,7 +162,7 @@ public class AndroidSourceGeneratingBuilder extends ModuleLevelBuilder {
success = false;
}
- final File dataStorageRoot = dataManager.getDataStorageRoot();
+ final File dataStorageRoot = dataManager.getDataPaths().getDataStorageRoot();
final AndroidAptStateStorage aptStorage = new AndroidAptStateStorage(dataStorageRoot);
try {
diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/builder/AndroidProjectBuildTarget.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/builder/AndroidProjectBuildTarget.java
index 89b7525ed1d4..244355050dbc 100644
--- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/builder/AndroidProjectBuildTarget.java
+++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/builder/AndroidProjectBuildTarget.java
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.android.AndroidJpsUtil;
import org.jetbrains.jps.builders.*;
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
+import org.jetbrains.jps.builders.storage.BuildDataPaths;
import org.jetbrains.jps.incremental.ModuleBuildTarget;
import org.jetbrains.jps.indices.IgnoredFileIndex;
import org.jetbrains.jps.indices.ModuleExcludeIndex;
@@ -81,7 +82,10 @@ public class AndroidProjectBuildTarget extends BuildTarget
@NotNull
@Override
- public List computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex) {
+ public List computeRootDescriptors(JpsModel model,
+ ModuleExcludeIndex index,
+ IgnoredFileIndex ignoredFileIndex,
+ BuildDataPaths dataPaths) {
return Collections.emptyList();
}
diff --git a/plugins/android/src/META-INF/plugin.xml b/plugins/android/src/META-INF/plugin.xml
index 9536901bc038..dcb74c102da0 100644
--- a/plugins/android/src/META-INF/plugin.xml
+++ b/plugins/android/src/META-INF/plugin.xml
@@ -318,6 +318,7 @@