IG: remove newline after modifier list if necessary (IDEA-162989) appcode/171.353 clion/171.354 phpstorm/171.352
authorBas Leijdekkers <basleijdekkers@gmail.com>
Sat, 22 Oct 2016 10:56:31 +0000 (12:56 +0200)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Sat, 22 Oct 2016 10:57:17 +0000 (12:57 +0200)
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/JUnitDatapointInspection.java
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MakePublicStaticFix.java

index fdca2818f665d5aa138c0b059d0cf203129f9232..7a600418e5c912f7d21befc5931578c03a81a0be 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2000-2016 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.junit;
 
 import com.intellij.codeInsight.AnnotationUtil;
index 0e54556e29ff3f83f35068f8818f892e8d40e1ec..97bc74f7f62d2d8282e4ed4413696e650bd55c7f 100644 (file)
@@ -1,10 +1,26 @@
+/*
+ * Copyright 2000-2016 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.junit;
 
 import com.intellij.codeInspection.ProblemDescriptor;
 import com.intellij.openapi.project.Project;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiMember;
-import com.intellij.psi.PsiModifier;
+import com.intellij.psi.*;
+import com.intellij.psi.codeStyle.CodeStyleManager;
+import com.intellij.psi.codeStyle.JavaCodeStyleManager;
+import com.intellij.psi.codeStyle.JavaCodeStyleSettingsFacade;
 import com.intellij.psi.util.PsiUtil;
 import com.intellij.util.IncorrectOperationException;
 import com.siyeh.ig.InspectionGadgetsFix;
@@ -15,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
 * Date: 5/22/13
 */
 class MakePublicStaticFix extends InspectionGadgetsFix {
+
   private final String myName;
   private final boolean myMakeStatic;
 
@@ -24,14 +41,25 @@ class MakePublicStaticFix extends InspectionGadgetsFix {
   }
 
   @Override
-  protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
+  protected void doFix(Project project, ProblemDescriptor descriptor) {
     final PsiElement element = descriptor.getPsiElement();
-    if (element != null) {
-      final PsiElement parent = element.getParent();
-      if (parent instanceof PsiMember) {
-        PsiUtil.setModifierProperty((PsiMember)parent, PsiModifier.PUBLIC, true);
-        PsiUtil.setModifierProperty((PsiMember)parent, PsiModifier.STATIC, myMakeStatic);
-      }
+    if (element == null) {
+      return;
+    }
+    final PsiElement parent = element.getParent();
+    if (!(parent instanceof PsiMember)) {
+      return;
+    }
+    final PsiMember member = (PsiMember)parent;
+    final PsiModifierList modifierList = member.getModifierList();
+    if (modifierList == null) {
+      return;
+    }
+    modifierList.setModifierProperty(PsiModifier.PUBLIC, true);
+    modifierList.setModifierProperty(PsiModifier.STATIC, myMakeStatic);
+    final PsiElement sibling = modifierList.getNextSibling();
+    if (sibling instanceof PsiWhiteSpace && sibling.getText().contains("\n")) {
+      sibling.replace(PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText(" "));
     }
   }