import com.intellij.util.ui.JBUI; import java.awt.*; import static com.intellij.util.ui.JBUI.insets; class UseJBUIInsetsThatCanBeSimplified { private static final Insets INSETS_CONSTANT_CAN_BE_SIMPLIFIED = JBUI.insets(0); private static final Insets INSETS_CONSTANT_CORRECT1 = JBUI.insets(1, 2, 3, 4); // correct private static final Insets INSETS_CONSTANT_CORRECT2 = JBUI.insets(1); // correct private static final int ZERO = 0; private static final int ONE = 1; void any() { // cases that can be simplified: JBUI.insets(0); Insets insets1 = JBUI.insets(0); takeInsets(JBUI.insets(0)); takeInsets(JBUI.insets(0, 0)); takeInsets(JBUI.insets(1, 1)); // all the same takeInsets(JBUI.insets(0, 0, 0, 0)); takeInsets(JBUI.insets(1, 1, 1, 1)); // 1st == 3rd and 2nd == 4th takeInsets(JBUI.insets(1, 2, 1, 2)); // 3 zeros takeInsets(JBUI.insets(1, 0, 0, 0)); takeInsets(JBUI.insets(0, 1, 0, 0)); takeInsets(JBUI.insets(0, 0, 1, 0)); takeInsets(JBUI.insets(0, 0, 0, 1)); // static import: insets(0); // constant used to check expressions evaluation: takeInsets(JBUI.insets(ONE, ZERO, 0, ZERO)); takeInsets(JBUI.insets(ONE, 2, ONE, 2)); // correct cases: JBUI.insets(1); JBUI.insets(1, 2); JBUI.insets(1, 1, 0, 0); JBUI.insets(1, 2, 3, 4); } void takeInsets(Insets insets) { // do nothing } }