Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dennis Ushakov
2015-01-24 13:34:43 +02:00
25 changed files with 399 additions and 91 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

@@ -16,6 +16,8 @@
package com.intellij.lang.parameterInfo;
import com.intellij.util.Function;
import java.awt.*;
import java.util.EnumSet;
@@ -37,4 +39,6 @@ public interface ParameterInfoUIContextEx extends ParameterInfoUIContext {
enum Flag {
HIGHLIGHT, DISABLE, STRIKEOUT // more to come
}
void setEscapeFunction(Function<String, String> escapeFunction);
}
@@ -27,6 +27,7 @@ import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.SideBorder;
import com.intellij.util.Function;
import com.intellij.util.ui.UIUtil;
import com.intellij.xml.util.XmlStringUtil;
import org.jetbrains.annotations.NotNull;
@@ -138,6 +139,7 @@ public class ParameterInfoComponent extends JPanel {
class MyParameterContext implements ParameterInfoUIContextEx {
private int i;
private Function<String, String> myEscapeFunction;
@Override
public String setupUIComponentPresentation(String text,
@@ -148,18 +150,23 @@ public class ParameterInfoComponent extends JPanel {
boolean isDisabledBeforeHighlight,
Color background) {
final String resultedText =
myPanels[i].setup(text, highlightStartOffset, highlightEndOffset, isDisabled, strikeout, isDisabledBeforeHighlight, background);
myPanels[i].setup(text, myEscapeFunction, highlightStartOffset, highlightEndOffset, isDisabled, strikeout, isDisabledBeforeHighlight, background);
myPanels[i].setBorder(isLastParameterOwner() ? BACKGROUND_BORDER : new SideBorder(new JBColor(JBColor.LIGHT_GRAY, Gray._90), SideBorder.BOTTOM));
return resultedText;
}
@Override
public String setupUIComponentPresentation(final String[] texts, final EnumSet<Flag>[] flags, final Color background) {
final String resultedText = myPanels[i].setup(texts, flags, background);
final String resultedText = myPanels[i].setup(texts, myEscapeFunction, flags, background);
myPanels[i].setBorder(isLastParameterOwner() ? BACKGROUND_BORDER : new SideBorder(new JBColor(JBColor.LIGHT_GRAY, Gray._90), SideBorder.BOTTOM));
return resultedText;
}
@Override
public void setEscapeFunction(Function<String, String> escapeFunction) {
myEscapeFunction = escapeFunction;
}
@Override
public boolean isUIComponentEnabled() {
return isEnabled(i);
@@ -246,7 +253,14 @@ public class ParameterInfoComponent extends JPanel {
myOneLineComponents = new OneLineComponent[0]; //TODO ???
}
private String setup(String text, int highlightStartOffset, int highlightEndOffset, boolean isDisabled, boolean strikeout, boolean isDisabledBeforeHighlight, Color background) {
private String setup(String text,
Function<String, String> escapeFunction,
int highlightStartOffset,
int highlightEndOffset,
boolean isDisabled,
boolean strikeout,
boolean isDisabledBeforeHighlight,
Color background) {
StringBuilder buf = new StringBuilder();
removeAll();
@@ -268,9 +282,9 @@ public class ParameterInfoComponent extends JPanel {
TextRange hr = highlightingRange == null ? null : lRange.intersection(highlightingRange);
hr = hr == null ? null : hr.shiftRight(-lineOffset);
String before = escapeString(hr == null ? line : line.substring(0, hr.getStartOffset()));
String in = hr == null ? "" : escapeString(hr.substring(line));
String after = hr == null ? "" : escapeString(line.substring(hr.getEndOffset(), line.length()));
String before = escapeString(hr == null ? line : line.substring(0, hr.getStartOffset()), escapeFunction);
String in = hr == null ? "" : escapeString(hr.substring(line), escapeFunction);
String after = hr == null ? "" : escapeString(line.substring(hr.getEndOffset(), line.length()), escapeFunction);
TextRange escapedHighlightingRange = in.isEmpty() ? null : TextRange.create(before.length(), before.length() + in.length());
buf.append(myOneLineComponents[i].setup(before + in + after, isDisabled, strikeout, background, escapedHighlightingRange));
@@ -288,11 +302,15 @@ public class ParameterInfoComponent extends JPanel {
return buf.toString();
}
private String escapeString(String line) {
return XmlStringUtil.escapeString(line);
private String escapeString(String line, Function<String, String> escapeFunction) {
line = XmlStringUtil.escapeString(line);
return escapeFunction == null ? line : escapeFunction.fun(line);
}
public String setup(final String[] texts, final EnumSet<ParameterInfoUIContextEx.Flag>[] flags, final Color background) {
public String setup(final String[] texts,
Function<String, String> escapeFunction,
final EnumSet<ParameterInfoUIContextEx.Flag>[] flags,
final Color background) {
StringBuilder buf = new StringBuilder();
removeAll();
setBackground(background);
@@ -304,7 +322,7 @@ public class ParameterInfoComponent extends JPanel {
String line = "";
for (int i = 0; i < texts.length; i++) {
String paramText = escapeString(texts[i]);
String paramText = escapeString(texts[i], escapeFunction);
if (paramText == null) break;
line += texts[i];
final EnumSet<ParameterInfoUIContextEx.Flag> flag = flags[i];
@@ -323,7 +341,7 @@ public class ParameterInfoComponent extends JPanel {
curOffset += paramText.length();
if (line.length() >= 50) {
final OneLineComponent component = new OneLineComponent();
buf.append(component.setup(escapeString(line), flagsMap, background));
buf.append(component.setup(escapeString(line, escapeFunction), flagsMap, background));
add(component, new GridBagConstraints(0, index, 1, 1, 1, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
index += 1;
@@ -334,7 +352,7 @@ public class ParameterInfoComponent extends JPanel {
}
}
final OneLineComponent component = new OneLineComponent();
buf.append(component.setup(escapeString(line), flagsMap, background));
buf.append(component.setup(escapeString(line, escapeFunction), flagsMap, background));
add(component, new GridBagConstraints(0, index, 1, 1, 1, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
components.add(component);
@@ -38,7 +38,6 @@ import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.IdeGlassPaneUtil;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.ColorUtil;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.JBColor;
import com.intellij.ui.UIBundle;
import com.intellij.ui.border.CustomLineBorder;
@@ -49,6 +48,7 @@ import com.intellij.util.ArrayUtil;
import com.intellij.util.TimeoutUtil;
import com.intellij.util.ui.AwtVisitor;
import com.intellij.util.ui.DialogUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import com.intellij.xml.util.XmlStringUtil;
import org.intellij.lang.annotations.MagicConstant;
@@ -148,7 +148,7 @@ public abstract class DialogWrapper {
*/
private int myButtonAlignment = SwingConstants.RIGHT;
private boolean myCrossClosesWindow = true;
private Insets myButtonMargins = new Insets(2, 16, 2, 16);
private Insets myButtonMargins = JBUI.insets(2, 16);
protected Action myOKAction;
protected Action myCancelAction;
@@ -442,7 +442,7 @@ public abstract class DialogWrapper {
@Nullable
protected Border createContentPaneBorder() {
if (getStyle() == DialogStyle.COMPACT) {
return new EmptyBorder(0,0,0,0);
return JBUI.Borders.empty();
}
return ourDefaultBorder;
}
@@ -465,6 +465,8 @@ public abstract class DialogWrapper {
&& Arrays.asList(actions).contains(getHelpAction())) {
hasHelpToMoveToLeftSide = true;
actions = ArrayUtil.remove(actions, getHelpAction());
} else if (Registry.is("ide.remove.help.button.from.dialogs")) {
actions = ArrayUtil.remove(actions, getHelpAction());
}
if (SystemInfo.isMac) {
@@ -483,7 +485,7 @@ public abstract class DialogWrapper {
JPanel panel = new JPanel(new BorderLayout());
final JPanel lrButtonsPanel = new JPanel(new GridBagLayout());
final Insets insets = SystemInfo.isMacOSLeopard ? new Insets(0, 0, 0, 0) : new Insets(8, 0, 0, 0);
final Insets insets = SystemInfo.isMacOSLeopard ? JBUI.emptyInsets() : new Insets(8, 0, 0, 0); //don't wrap to JBInsets
if (actions.length > 0 || leftSideActions.length > 0) {
int gridX = 0;
@@ -563,10 +565,10 @@ public abstract class DialogWrapper {
}
if (getStyle() == DialogStyle.COMPACT) {
CustomLineBorder line = new CustomLineBorder(OnePixelDivider.BACKGROUND, 1, 0, 0, 0);
panel.setBorder(new CompoundBorder(line, BorderFactory.createEmptyBorder(8, 12, 8, 12)));
Border line = new CustomLineBorder(OnePixelDivider.BACKGROUND, 1, 0, 0, 0);
panel.setBorder(new CompoundBorder(line, JBUI.Borders.empty(8, 12)));
} else {
panel.setBorder(IdeBorderFactory.createEmptyBorder(new Insets(8, 0, 0, 0)));
panel.setBorder(JBUI.Borders.emptyTop(8));
}
return panel;
@@ -606,7 +608,7 @@ public abstract class DialogWrapper {
panel.add(wrapper, BorderLayout.WEST);
panel.add(southPanel, BorderLayout.EAST);
checkBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20));
checkBox.setBorder(JBUI.Borders.emptyRight(20));
return panel;
}
@@ -1954,7 +1956,7 @@ public abstract class DialogWrapper {
setLayout(new BorderLayout());
JBScrollPane pane =
new JBScrollPane(myLabel, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pane.setBorder(IdeBorderFactory.createEmptyBorder());
pane.setBorder(JBUI.Borders.empty());
pane.setBackground(null);
pane.getViewport().setBackground(null);
pane.setOpaque(false);
@@ -1975,7 +1977,7 @@ public abstract class DialogWrapper {
myLabel
.setText(XmlStringUtil.wrapInHtml("<font color='#" + ColorUtil.toHex(JBColor.RED) + "'><left>" + text + "</left></b></font>"));
myLabel.setIcon(AllIcons.Actions.Lightning);
myLabel.setBorder(new EmptyBorder(4, 10, 0, 2));
myLabel.setBorder(JBUI.Borders.empty(4, 10, 0, 2));
setVisible(true);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -23,6 +23,7 @@ import com.intellij.openapi.wm.IdeGlassPane;
import com.intellij.openapi.wm.IdeGlassPaneUtil;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.util.ui.JBUI;
import javax.swing.*;
import java.awt.*;
@@ -82,7 +83,7 @@ public class OnePixelDivider extends Divider {
final MouseEvent event = getTargetEvent(e);
final Point p = event.getPoint();
final int r = Math.abs(isVertical() ? p.y : p.x);
return r < 6;
return r < JBUI.scale(6);
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -30,17 +30,20 @@ import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.ui.OnePixelSplitter;
import com.intellij.ui.border.CustomLineBorder;
import com.intellij.ui.components.panels.VerticalLayout;
import com.intellij.ui.treeStructure.SimpleNode;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author Sergey.Malenkov
@@ -221,7 +224,7 @@ final class SettingsEditor extends AbstractEditor implements DataProvider {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.WEST, mySearchPanel);
panel.add(BorderLayout.CENTER, myBanner);
panel.setBorder(new CustomLineBorder(OnePixelDivider.BACKGROUND, 0, 0, 1, 0));
panel.setBorder(JBUI.Borders.customLine(OnePixelDivider.BACKGROUND, 0, 0, 1, 0));
add(BorderLayout.NORTH, panel);
}
mySplitter = new OnePixelSplitter(false, myProperties.getFloat(SPLITTER_PROPORTION, .2f));
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -31,6 +31,7 @@ import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.ui.MouseDragHelper;
import com.intellij.ui.PopupHandler;
import com.intellij.util.ui.JBImageIcon;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -107,7 +108,7 @@ public final class StripeButton extends AnchoredButton implements ActionListener
private void init() {
setFocusable(false);
setBackground(ourBackgroundColor);
final Border border = BorderFactory.createEmptyBorder(5, 5, 0, 5);
final Border border = JBUI.Borders.empty(5, 5, 0, 5);
setBorder(border);
updatePresentation();
apply(myDecorator.getWindowInfo());
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -17,6 +17,7 @@ package com.intellij.openapi.wm.impl;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.ui.Gray;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import javax.swing.*;
@@ -48,8 +49,8 @@ public final class StripeButtonUI extends MetalToggleButtonUI{
final AnchoredButton button=(AnchoredButton)c;
final Dimension dim=super.getPreferredSize(button);
dim.width=(int)(4+dim.width*1.1f);
dim.height+=2;
dim.width=(int)(JBUI.scale(4) + dim.width*1.1f);
dim.height+= JBUI.scale(2);
final ToolWindowAnchor anchor=button.getAnchor();
if(ToolWindowAnchor.LEFT==anchor||ToolWindowAnchor.RIGHT==anchor){
@@ -106,16 +107,17 @@ public final class StripeButtonUI extends MetalToggleButtonUI{
final ButtonModel model=button.getModel();
final Color background = button.getBackground();
ourIconRect.x -= 2;
ourTextRect.x -= 2;
ourIconRect.x -= JBUI.scale(2);
ourTextRect.x -= JBUI.scale(2);
final int off = JBUI.scale(1);
if (model.isArmed() && model.isPressed() || model.isSelected() || model.isRollover()) {
if (anchor == ToolWindowAnchor.LEFT) g2.translate(-1, 0);
if (anchor.isHorizontal()) g2.translate(0, -1);
if (anchor == ToolWindowAnchor.LEFT) g2.translate(-off, 0);
if (anchor.isHorizontal()) g2.translate(0, -off);
final boolean dark = UIUtil.isUnderDarcula();
g2.setColor(dark ? Gray._15.withAlpha(model.isSelected() ? 85: 40) : Gray._85.withAlpha(model.isSelected()? 85: 40));
g2.fillRect(0, 0, button.getWidth(), button.getHeight());
if (anchor == ToolWindowAnchor.LEFT) g2.translate(1, 0);
if (anchor.isHorizontal()) g2.translate(0, 1);
if (anchor == ToolWindowAnchor.LEFT) g2.translate(off, 0);
if (anchor.isHorizontal()) g2.translate(0, off);
}
@@ -518,3 +518,5 @@ lcd.contrast.value.description=Set LCD text contrast value from 100 to 250
removable.welcome.screen.projects=true
removable.welcomesreen.projects.description=Allows removing recent projects from welcome screen with mouse
ide.find.show.preview=true
ide.remove.help.button.from.dialogs=false
ide.remove.help.button.from.dialogs.description=Removes help button from dialogs
@@ -731,6 +731,7 @@ public class AllIcons {
public static final Icon DeleteContentRoot = IconLoader.getIcon("/modules/deleteContentRoot.png"); // 9x9
public static final Icon DeleteContentRootRollover = IconLoader.getIcon("/modules/deleteContentRootRollover.png"); // 9x9
public static final Icon Edit = IconLoader.getIcon("/modules/edit.png"); // 14x14
public static final Icon EditFolder = IconLoader.getIcon("/modules/editFolder.png"); // 16x16
public static final Icon ExcludedGeneratedRoot = IconLoader.getIcon("/modules/excludedGeneratedRoot.png"); // 16x16
public static final Icon ExcludeRoot = IconLoader.getIcon("/modules/excludeRoot.png"); // 16x16
public static final Icon GeneratedFolder = IconLoader.getIcon("/modules/generatedFolder.png"); // 16x16
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -15,7 +15,10 @@
*/
package com.intellij.util.ui;
import com.intellij.ui.border.CustomLineBorder;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
/**
@@ -52,6 +55,22 @@ public class JBUI {
return new JBInsets(0, 0, 0, 0);
}
public static JBInsets insetsTop(int t) {
return insets(t, 0, 0, 0);
}
public static JBInsets insetsLeft(int l) {
return insets(0, l, 0, 0);
}
public static JBInsets insetsBottom(int b) {
return insets(0, 0, b, 0);
}
public static JBInsets insetsRight(int r) {
return insets(0, 0, 0, r);
}
public static EmptyIcon emptyIcon(int i) {
return (EmptyIcon)EmptyIcon.create(scale(i));
}
@@ -99,8 +118,32 @@ public class JBUI {
return new JBEmptyBorder(top, left, bottom, right);
}
public static JBEmptyBorder empty(int topAndBottom, int leftAndRight) {
return new JBEmptyBorder(topAndBottom, leftAndRight, topAndBottom, leftAndRight);
}
public static JBEmptyBorder emptyTop(int offset) {
return new JBEmptyBorder(offset, 0, 0, 0);
}
public static JBEmptyBorder emptyLeft(int offset) {
return new JBEmptyBorder(0, offset, 0, 0);
}
public static JBEmptyBorder emptyBottom(int offset) {
return new JBEmptyBorder(0, 0, offset, 0);
}
public static JBEmptyBorder emptyRight(int offset) {
return new JBEmptyBorder(0, 0, 0, offset);
}
public static JBEmptyBorder empty() {
return new JBEmptyBorder(0);
}
public static Border customLine(Color color, int top, int left, int bottom, int right) {
return new CustomLineBorder(color, insets(top, left, bottom, right));
}
}
}
@@ -198,13 +198,13 @@ public class VcsRootProblemNotifier {
private static String makeTitle(@NotNull Collection<VcsRootError> unregisteredRoots, @NotNull Collection<VcsRootError> invalidRoots) {
String title;
if (unregisteredRoots.isEmpty()) {
title = "Invalid Vcs root " + pluralize("mapping", invalidRoots.size());
title = "Invalid VCS root " + pluralize("mapping", invalidRoots.size());
}
else if (invalidRoots.isEmpty()) {
title = "Unregistered Vcs " + pluralize("root", unregisteredRoots.size()) + " detected";
title = "Unregistered VCS " + pluralize("root", unregisteredRoots.size()) + " detected";
}
else {
title = "Vcs root configuration problems";
title = "VCS root configuration problems";
}
return title;
}
@@ -1242,6 +1242,10 @@
implementationClass="com.siyeh.ig.javabeans.SuspiciousGetterSetterInspection"/>
<!--group.names.javadoc.issues-->
<localInspection language="JAVA" shortName="DanglingJavadoc" bundle="com.siyeh.InspectionGadgetsBundle"
key="dangling.javadoc.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.javadoc.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.javadoc.DanglingJavadocInspection"/>
<localInspection language="JAVA" shortName="HtmlTagCanBeJavadocTag" bundle="com.siyeh.InspectionGadgetsBundle"
key="html.tag.can.be.javadoc.tag.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.javadoc.issues" enabledByDefault="false" level="WARNING"
@@ -1780,7 +1780,7 @@ unnecessary.javadoc.link.display.name=Unnecessary Javadoc link
unnecessary.javadoc.link.super.method.problem.descriptor=<code>#ref</code> pointing to super method is unnecessary #loc
unnecessary.javadoc.link.this.method.problem.descriptor=<code>#ref</code> pointing to this method is unnecessary #loc
unnecessary.javadoc.link.this.class.problem.descriptor=<code>#ref</code> pointing to containing class is unnecessary #loc
unnecessary.javadoc.link.quickfix=Remove unnecessary '{0}'
unnecessary.javadoc.link.quickfix=Remove unnecessary ''{0}''
thread.local.not.static.final.display.name=ThreadLocal field not declared static final
thread.local.not.static.final.problem.descriptor=ThreadLocal <code>#ref</code> is not declared 'static final' #loc
remove.try.finally.block.quickfix=Remove 'try-finally' block
@@ -2144,3 +2144,7 @@ use.of.clone.display.name=Use of 'clone()' or 'Cloneable'
use.of.clone.call.problem.descriptor=Call to <code>#ref()</code>
use.of.clone.call.method.problem.descriptor=Implementation of <code>#ref()</code>
use.of.clone.reference.problem.descriptor=Use of <code>#ref</code>
dangling.javadoc.display.name=Dangling Javadoc comment
dangling.javadoc.problem.descriptor=Dangling Javadoc comment #loc
dangling.javadoc.convert.quickfix=Replace with block comment
dangling.javadoc.delete.quickfix=Remove dangling comment
@@ -0,0 +1,137 @@
/*
* Copyright 2000-2015 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.javadoc;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.javadoc.PsiDocToken;
import com.intellij.psi.tree.IElementType;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
/**
* @author Bas Leijdekkers
*/
public class DanglingJavadocInspection extends BaseInspection {
@Nls
@NotNull
@Override
public String getDisplayName() {
return InspectionGadgetsBundle.message("dangling.javadoc.display.name");
}
@NotNull
@Override
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message("dangling.javadoc.problem.descriptor");
}
@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
return new InspectionGadgetsFix[] {
new DeleteCommentFix(),
new ConvertCommentFix()
};
}
private static class ConvertCommentFix extends InspectionGadgetsFix {
@Nls
@NotNull
@Override
public String getName() {
return InspectionGadgetsBundle.message("dangling.javadoc.convert.quickfix");
}
@NotNull
@Override
public String getFamilyName() {
return getName();
}
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiElement docComment = element.getParent();
final StringBuilder newCommentText = new StringBuilder();
for (PsiElement child : docComment.getChildren()) {
if (child instanceof PsiDocToken) {
final PsiDocToken docToken = (PsiDocToken)child;
final IElementType tokenType = docToken.getTokenType();
if (JavaDocTokenType.DOC_COMMENT_START.equals(tokenType)) {
newCommentText.append("/*");
}
else if (!JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS.equals(tokenType)) {
newCommentText.append(child.getText());
}
}
else {
newCommentText.append(child.getText());
}
}
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
final PsiComment newComment = factory.createCommentFromText(newCommentText.toString(), element);
docComment.replace(newComment);
}
}
private static class DeleteCommentFix extends InspectionGadgetsFix {
@Nls
@NotNull
@Override
public String getName() {
return InspectionGadgetsBundle.message("dangling.javadoc.delete.quickfix");
}
@NotNull
@Override
public String getFamilyName() {
return getName();
}
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
element.getParent().delete();
}
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new DanglingJavadocVisitor();
}
private static class DanglingJavadocVisitor extends BaseInspectionVisitor {
@Override
public void visitDocComment(PsiDocComment comment) {
super.visitDocComment(comment);
final PsiDocCommentOwner owner = comment.getOwner();
if (owner != null) {
return;
}
registerError(comment.getFirstChild());
}
}
}
@@ -0,0 +1,10 @@
<html>
<body>
Reports dangling Javadoc comments.
Javadoc comment are dangling if they don't belong to any class, method or field.
For example a Javadoc comment in between method declarations that have their own javadoc comments.
<!-- tooltip end -->
<p>
<small>New in 14.1</small>
</body>
</html>
@@ -0,0 +1,6 @@
class DanglingJavadoc {
<warning descr="Dangling Javadoc comment">/**</warning>
* yada yada
*/
}
@@ -0,0 +1,41 @@
/*
* Copyright 2000-2015 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.
*/
/**
* (c) 2015 Silent Forest AB
* created: 23 January 2015
*/
package com.siyeh.ig.javadoc;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightInspectionTestCase;
import org.jetbrains.annotations.Nullable;
/**
* @author Bas Leijdekkers
*/
public class DanglingJavadocInspectionTest extends LightInspectionTestCase {
public void testDanglingJavadoc() {
doTest();
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new DanglingJavadocInspection();
}
}
@@ -185,7 +185,7 @@ public class GitConfig {
}
boolean merge = mergeName != null;
final String remoteBranchName = (merge ? mergeName : rebaseName);
final String remoteBranchName = StringUtil.unquoteString(merge ? mergeName : rebaseName);
GitLocalBranch localBranch = findLocalBranch(branchName, localBranches);
GitRemoteBranch remoteBranch = findRemoteBranch(remoteBranchName, remoteName, remoteBranches);
@@ -18,16 +18,17 @@ package git4idea.repo;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsTestUtil;
import com.intellij.util.LineSeparator;
import com.intellij.util.containers.ContainerUtil;
import git4idea.GitBranch;
import git4idea.GitLocalBranch;
import git4idea.GitRemoteBranch;
import git4idea.GitStandardRemoteBranch;
import git4idea.test.GitPlatformTest;
import git4idea.test.GitTestUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -36,8 +37,72 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.util.*;
import static git4idea.test.GitExecutor.git;
public class GitConfigTest extends GitPlatformTest {
public void testRemotes() throws IOException {
Collection<TestSpec> objects = loadRemotes();
for (TestSpec spec : objects) {
doTestRemotes(spec.name, spec.config, spec.result);
}
}
public void testBranches() throws IOException {
Collection<TestSpec> objects = loadBranches();
for (TestSpec spec : objects) {
doTestBranches(spec.name, spec.config, spec.result);
}
}
//inspired by IDEA-135557
public void test_branch_with_hash_symbol() throws IOException {
GitTestUtil.createRepository(myProject, myProjectPath, true);
git("remote add origin http://example.git"); // define a remote to be able to set up tracking
git("update-ref refs/remotes/origin/a#branch HEAD");
git("branch --track a#branch origin/a#branch");
File gitDir = new File(myProjectPath, ".git");
GitConfig config = GitConfig.read(myPlatformFacade, new File(gitDir, "config"));
GitBranchState state = new GitRepositoryReader(gitDir).readState(config.parseRemotes());
Collection<GitBranchTrackInfo> trackInfos = config.parseTrackInfos(state.getLocalBranches(), state.getRemoteBranches());
assertTrue("Couldn't find correct a#branch tracking information among: [" + trackInfos + "]",
ContainerUtil.exists(trackInfos, new Condition<GitBranchTrackInfo>() {
@Override
public boolean value(GitBranchTrackInfo info) {
return info.getLocalBranch().getName().equals("a#branch") &&
info.getRemoteBranch().getNameForLocalOperations().equals("origin/a#branch");
}
}));
}
private void doTestRemotes(String testName, File configFile, File resultFile) throws IOException {
GitConfig config = GitConfig.read(myPlatformFacade, configFile);
VcsTestUtil.assertEqualCollections(testName, config.parseRemotes(), readRemoteResults(resultFile));
}
private void doTestBranches(String testName, File configFile, File resultFile) throws IOException {
Collection<GitBranchTrackInfo> expectedInfos = readBranchResults(resultFile);
Collection<GitLocalBranch> localBranches = Collections2.transform(expectedInfos, new Function<GitBranchTrackInfo, GitLocalBranch>() {
@Override
public GitLocalBranch apply(@Nullable GitBranchTrackInfo input) {
assert input != null;
return input.getLocalBranch();
}
});
Collection<GitRemoteBranch> remoteBranches = Collections2.transform(expectedInfos, new Function<GitBranchTrackInfo, GitRemoteBranch>() {
@Override
public GitRemoteBranch apply(@Nullable GitBranchTrackInfo input) {
assert input != null;
return input.getRemoteBranch();
}
});
VcsTestUtil.assertEqualCollections(testName,
GitConfig.read(myPlatformFacade, configFile).parseTrackInfos(localBranches, remoteBranches),
expectedInfos);
}
public Collection<TestSpec> loadRemotes() throws IOException {
return loadConfigData(getTestDataFolder("remote"));
}
@@ -95,47 +160,6 @@ public class GitConfigTest extends GitPlatformTest {
return new File(pluginRoot, "testData");
}
public void testRemotes() throws IOException {
Collection<TestSpec> objects = loadRemotes();
for (TestSpec spec : objects) {
doTestRemotes(spec.name, spec.config, spec.result);
}
}
public void testBranches() throws IOException {
Collection<TestSpec> objects = loadBranches();
for (TestSpec spec : objects) {
doTestBranches(spec.name, spec.config, spec.result);
}
}
private void doTestRemotes(String testName, File configFile, File resultFile) throws IOException {
GitConfig config = GitConfig.read(myPlatformFacade, configFile);
VcsTestUtil.assertEqualCollections(testName, config.parseRemotes(), readRemoteResults(resultFile));
}
private void doTestBranches(String testName, File configFile, File resultFile) throws IOException {
Collection<GitBranchTrackInfo> expectedInfos = readBranchResults(resultFile);
Collection<GitLocalBranch> localBranches = Collections2.transform(expectedInfos, new Function<GitBranchTrackInfo, GitLocalBranch>() {
@Override
public GitLocalBranch apply(@Nullable GitBranchTrackInfo input) {
assert input != null;
return input.getLocalBranch();
}
});
Collection<GitRemoteBranch> remoteBranches = Collections2.transform(expectedInfos, new Function<GitBranchTrackInfo, GitRemoteBranch>() {
@Override
public GitRemoteBranch apply(@Nullable GitBranchTrackInfo input) {
assert input != null;
return input.getRemoteBranch();
}
});
VcsTestUtil.assertEqualCollections(testName,
GitConfig.read(myPlatformFacade, configFile).parseTrackInfos(localBranches, remoteBranches),
expectedInfos);
}
private static Collection<GitBranchTrackInfo> readBranchResults(File file) throws IOException {
String content = FileUtil.loadFile(file);
Collection<GitBranchTrackInfo> remotes = new ArrayList<GitBranchTrackInfo>();
@@ -49,7 +49,7 @@ class InCommandStrategy extends Strategy {
@NotNull
@Override
public String getSubText() {
return "D";
return "Tab will display list of arguments in next commit";
}
@NotNull
@@ -33,7 +33,7 @@ class NoCommandStrategy extends Strategy {
@NotNull
@Override
String getSubText() {
return "vse ploho";
return "Enter command here"; // TODO: Use u18n
}
@NotNull
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.jetbrains.python.fixtures.LightMarkedTestCase;
@@ -455,6 +456,10 @@ public class PyParameterInfoTest extends LightMarkedTestCase {
return StringUtil.join(texts, "");
}
@Override
public void setEscapeFunction(Function<String, String> escapeFunction) {
}
@Override
public String setupUIComponentPresentation(String text, int highlightStartOffset, int highlightEndOffset, boolean isDisabled,
boolean strikeout, boolean isDisabledBeforeHighlight, Color background) {