Skip to content

Commit

Permalink
CheckStyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz committed Jul 30, 2019
1 parent 2f6292c commit 4ba304a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
4 changes: 2 additions & 2 deletions resources/messages/IgnoreBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ settings.languagesSettings=Languages settings
settings.languagesSettings.table.name=Language
settings.languagesSettings.table.newFile=Show in "New > .ignore file"
settings.languagesSettings.table.enable=Enable ignoring
action.exportTemplates=Export templates
action.exportTemplates=Export Templates
action.exportTemplates.description=Export ignore templates to file
action.exportTemplates.wrapper=Export Selected User Templates to File...
action.exportTemplates.error=User templates export failed.
action.exportTemplates.success=Exported templates: {0}
action.exportTemplates.success.title=Ignore User Templates
action.importTemplates=Import templates
action.importTemplates=Import Templates
action.importTemplates.description=Import ignore templates from file
action.importTemplates.wrapper=Import Ignore Templates
action.importTemplates.wrapper.description=Please select the user ignore templates file to import.
Expand Down
8 changes: 6 additions & 2 deletions src/mobi/hsz/idea/gitignore/IgnoreBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ private IgnoreBundle() {
));

/**Highlighting for the mentioned languages already provided by IDEA core**/
public static final IgnoreLanguage[] IGNORE_LANGUAGES_HIGHLIGHTING_EXCLUDED =
{GitLanguage.INSTANCE, GitExcludeLanguage.INSTANCE, MercurialLanguage.INSTANCE, PerforceLanguage.INSTANCE};
public static final IgnoreLanguage[] IGNORE_LANGUAGES_HIGHLIGHTING_EXCLUDED = {
GitLanguage.INSTANCE,
GitExcludeLanguage.INSTANCE,
MercurialLanguage.INSTANCE,
PerforceLanguage.INSTANCE
};

/** Available IgnoreFileType instances filtered with {@link IgnoreLanguage#isVCS()} condition. */
public static final IgnoreLanguages VCS_LANGUAGES = new IgnoreLanguages(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public void update(@NotNull AnActionEvent e) {

for (IgnoreLanguage language : IgnoreBundle.LANGUAGES) {
//skip already bundled languages for ignore action
if (!(this instanceof UnignoreFileGroupAction) && (language instanceof GitLanguage || language instanceof MercurialLanguage)) continue;
if (!(this instanceof UnignoreFileGroupAction)
&& (language instanceof GitLanguage || language instanceof MercurialLanguage)) {
continue;
}

final IgnoreFileType fileType = language.getFileType();
List<VirtualFile> list = Utils.getSuitableIgnoreFiles(project, fileType, file);
Expand Down
4 changes: 3 additions & 1 deletion src/mobi/hsz/idea/gitignore/file/IgnoreFileTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public void createFileTypes(@NotNull FileTypeConsumer consumer) {
consume(consumer, IgnoreFileType.INSTANCE);
for (final IgnoreLanguage language : IgnoreBundle.LANGUAGES) {
//skip already bundled languages
if (language instanceof GitLanguage || language instanceof MercurialLanguage) continue;
if (language instanceof GitLanguage || language instanceof MercurialLanguage) {
continue;
}

consume(consumer, language.getFileType());
}
Expand Down
15 changes: 12 additions & 3 deletions src/mobi/hsz/idea/gitignore/outer/OuterIgnoreLoaderComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void disposeComponent() {
}

/** Listener for ignore editor manager. */
private class IgnoreEditorManagerListener implements FileEditorManagerListener {
private static class IgnoreEditorManagerListener implements FileEditorManagerListener {
/** Current project. */
private final Project project;

Expand All @@ -132,7 +132,9 @@ public void fileOpened(@NotNull final FileEditorManager source, @NotNull final V
}

IgnoreLanguage language = determineIgnoreLanguage(file, fileType);
if (language == null) return;
if (language == null) {
return;
}

DumbService.getInstance(project).runWhenSmart(() -> {
final List<VirtualFile> outerFiles =
Expand Down Expand Up @@ -168,9 +170,16 @@ public void fileOpened(@NotNull final FileEditorManager source, @NotNull final V
});
}

/**
* If language provided by platform (e.g. GitLanguage) then map to language provided by plugin
* with extended functionality.
*
* @param file file to check
* @param fileType file's FileType
* @return mapped language
*/
@Nullable
private IgnoreLanguage determineIgnoreLanguage(@NotNull VirtualFile file, FileType fileType) {
//if language provided by platform (e.g. GitLanguage) then map to language provided by plugin with extended functionality
FileTypeRegistry typeRegistry = FileTypeRegistry.getInstance();
if (typeRegistry.isFileOfType(file, GitIgnoreFileType.INSTANCE)) {
return GitLanguage.INSTANCE;
Expand Down
29 changes: 15 additions & 14 deletions src/mobi/hsz/idea/gitignore/ui/IgnoreSettingsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ boolean isVisible(JTable table, Object value, boolean isSelected, boolean hasFoc
/**
* Boolean {@link JTable} cell renderer with ability to control visibility of {@link JCheckBox} component.
*/
static abstract class ConditionalBooleanRenderer extends JPanel implements TableCellRenderer {
private static final Border noFocusBorder = JBUI.Borders.empty(1);
abstract static class ConditionalBooleanRenderer extends JPanel implements TableCellRenderer {
private static final Border NO_FOCUS_BORDER = JBUI.Borders.empty(1);

private JCheckBox checkBox;

Expand All @@ -177,23 +177,24 @@ static abstract class ConditionalBooleanRenderer extends JPanel implements Table
add(checkBox);
}

abstract boolean isVisible(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column);
abstract boolean isVisible(JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
int column);

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
}
else {
} else {
setForeground(table.getForeground());
setBackground(table.getBackground());
}

if (hasFocus) {
setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
} else {
setBorder(noFocusBorder);
setBorder(NO_FOCUS_BORDER);
}

checkBox.setVisible(isVisible(table, value, isSelected, hasFocus, row, column));
Expand Down Expand Up @@ -581,7 +582,6 @@ public String getErrorText(String inputString) {
*
* @param userTemplates templates list
*/
@SuppressWarnings("unchecked")
public void resetForm(@NotNull List<IgnoreSettings.UserTemplate> userTemplates) {
myListModel.clear();
for (IgnoreSettings.UserTemplate template : userTemplates) {
Expand Down Expand Up @@ -789,12 +789,10 @@ public Class<?> getColumnClass(int columnIndex) {
@Override
public boolean isCellEditable(int row, int column) {
final IgnoreLanguage language = ContainerUtil.newArrayList(settings.keySet()).get(row);
if (language == null) {
return column != 0;
if (language != null && column == 2 && IgnoreBundle.isExcludedFromHighlighting(language)) {
return false;
}

if (column == 2 && IgnoreBundle.isExcludedFromHighlighting(language)) return false;

return column != 0;
}

Expand Down Expand Up @@ -829,9 +827,12 @@ public Object getValueAt(int row, int column) {
}

@NotNull
private Boolean getBoolean(IgnoreSettings.IgnoreLanguagesSettings.KEY key, TreeMap<IgnoreSettings.IgnoreLanguagesSettings.KEY, Object> data) {
private Boolean getBoolean(IgnoreSettings.IgnoreLanguagesSettings.KEY key,
TreeMap<IgnoreSettings.IgnoreLanguagesSettings.KEY, Object> data) {
Object objectByKey = data.get(key);
if (objectByKey == null) return false;
if (objectByKey == null) {
return false;
}

return Boolean.valueOf(objectByKey.toString());
}
Expand Down

0 comments on commit 4ba304a

Please sign in to comment.