diff --git a/java/java-impl/src/com/intellij/lang/java/JavaFormattingModelBuilder.java b/java/java-impl/src/com/intellij/lang/java/JavaFormattingModelBuilder.java index 4d7b9eaed580..5947c80d683e 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaFormattingModelBuilder.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaFormattingModelBuilder.java @@ -19,6 +19,7 @@ */ package com.intellij.lang.java; +import com.intellij.formatting.Block; import com.intellij.formatting.FormattingModel; import com.intellij.formatting.FormattingModelBuilder; import com.intellij.lang.ASTNode; @@ -47,9 +48,9 @@ public class JavaFormattingModelBuilder implements FormattingModelBuilder { public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) { final FileElement fileElement = TreeUtil.getFileElement((TreeElement)SourceTreeToPsiMap.psiElementToTree(element)); LOG.assertTrue(fileElement != null, "File element should not be null for " + element); - return new PsiBasedFormatterModelWithShiftIndentInside (element.getContainingFile(), AbstractJavaBlock.createJavaBlock(fileElement, - settings), - FormattingDocumentModelImpl.createOn(element.getContainingFile())); + Block block = AbstractJavaBlock.createJavaBlock(fileElement, settings); + FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile()); + return new PsiBasedFormatterModelWithShiftIndentInside (element.getContainingFile(), block, model); } public TextRange getRangeAffectingIndent(final PsiFile file, final int offset, final ASTNode elementAtOffset) { diff --git a/java/java-impl/src/com/intellij/lang/java/JavaImportOptimizer.java b/java/java-impl/src/com/intellij/lang/java/JavaImportOptimizer.java index e551b0ac9b37..40dc91e2a70c 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaImportOptimizer.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaImportOptimizer.java @@ -37,32 +37,30 @@ public class JavaImportOptimizer implements ImportOptimizer { @NotNull public Runnable processFile(final PsiFile file) { - if (file instanceof PsiJavaFile) { - Project project = file.getProject(); - final PsiImportList newImportList = JavaCodeStyleManager.getInstance(project).prepareOptimizeImportsResult((PsiJavaFile)file); - return new Runnable() { - public void run() { - try { - if (newImportList != null) { - final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject()); - final Document document = manager.getDocument(file); - if (document != null) { - manager.commitDocument(document); - } - final PsiImportList oldImportList = ((PsiJavaFile)file).getImportList(); - assert oldImportList != null; - oldImportList.replace(newImportList); - } - } - catch (IncorrectOperationException e) { - LOG.error(e); - } - } - }; - } - else { + if (!(file instanceof PsiJavaFile)) { return EmptyRunnable.getInstance(); } + Project project = file.getProject(); + final PsiImportList newImportList = JavaCodeStyleManager.getInstance(project).prepareOptimizeImportsResult((PsiJavaFile)file); + return new Runnable() { + public void run() { + try { + if (newImportList != null) { + final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject()); + final Document document = manager.getDocument(file); + if (document != null) { + manager.commitDocument(document); + } + final PsiImportList oldImportList = ((PsiJavaFile)file).getImportList(); + assert oldImportList != null; + oldImportList.replace(newImportList); + } + } + catch (IncorrectOperationException e) { + LOG.error(e); + } + } + }; } public boolean supports(PsiFile file) { diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ImportHelper.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ImportHelper.java index e32516478435..07ac0a68ce1f 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ImportHelper.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/ImportHelper.java @@ -76,15 +76,12 @@ public class ImportHelper{ List> resultList = new ArrayList>(names.size()); for(int i = 0; i < entries.length; i++){ - PackageEntry entry = entries[i]; - //if (!entry.isSpecial()) { - for(int j = 0; j < names.size(); j++){ - if (entryForName[j] == i){ - resultList.add(names.get(j)); - names.set(j, null); - } + for(int j = 0; j < names.size(); j++){ + if (entryForName[j] == i){ + resultList.add(names.get(j)); + names.set(j, null); } - //} + } } for (Pair name : names) { if (name != null) resultList.add(name); diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaHelper.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaHelper.java index a9f47c806db3..01e8b0389519 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaHelper.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaHelper.java @@ -36,9 +36,8 @@ public class JavaHelper extends Helper { if (element.getTreePrev() != null) { ASTNode prev = element.getTreePrev(); - ASTNode lastCompositePrev; while (prev instanceof CompositeElement && !TreeUtil.isStrongWhitespaceHolder(prev.getElementType())) { - lastCompositePrev = prev; + ASTNode lastCompositePrev = prev; prev = prev.getLastChildNode(); if (prev == null) { // element.prev is "empty composite" return getIndentInner(lastCompositePrev, includeNonSpace, recursionLevel + 1); diff --git a/java/java-tests/testData/refactoring/pushDown/staticImportsInsidePushedMethod/after/b/B.java b/java/java-tests/testData/refactoring/pushDown/staticImportsInsidePushedMethod/after/b/B.java index fcc2b89da8d8..b152d217729a 100644 --- a/java/java-tests/testData/refactoring/pushDown/staticImportsInsidePushedMethod/after/b/B.java +++ b/java/java-tests/testData/refactoring/pushDown/staticImportsInsidePushedMethod/after/b/B.java @@ -1,5 +1,6 @@ package b; import a.*; + import static u.U.C; public class B extends A { diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/PackageEntry.java b/platform/lang-api/src/com/intellij/psi/codeStyle/PackageEntry.java index 5eaf66cc7c96..18f189bdd914 100755 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/PackageEntry.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/PackageEntry.java @@ -103,10 +103,12 @@ public class PackageEntry { if (entry.isWithSubpackages() != isWithSubpackages()) { return !isWithSubpackages(); } - + if (entry == ALL_OTHER_IMPORTS_ENTRY || entry == ALL_OTHER_STATIC_IMPORTS_ENTRY) return true; + if (this == ALL_OTHER_IMPORTS_ENTRY || this == ALL_OTHER_STATIC_IMPORTS_ENTRY) return false; return StringUtil.countChars(entry.getPackageName(), '.') < StringUtil.countChars(getPackageName(), '.'); } + @NonNls @Override public String toString() { return (isStatic() ? "static " : "") + getPackageName(); diff --git a/platform/lang-impl/src/com/intellij/psi/formatter/DocumentBasedFormattingModel.java b/platform/lang-impl/src/com/intellij/psi/formatter/DocumentBasedFormattingModel.java index 45c7f3f0b94d..d8c54a6ac83e 100644 --- a/platform/lang-impl/src/com/intellij/psi/formatter/DocumentBasedFormattingModel.java +++ b/platform/lang-impl/src/com/intellij/psi/formatter/DocumentBasedFormattingModel.java @@ -66,7 +66,7 @@ public class DocumentBasedFormattingModel implements FormattingModel { mySettings = settings; myFileType = fileType; myDocumentModel = FormattingDocumentModelImpl.createOn(file); - myDocument = ((FormattingDocumentModelImpl)myDocumentModel).getDocument(); + myDocument = myDocumentModel.getDocument(); } @NotNull @@ -85,8 +85,8 @@ public class DocumentBasedFormattingModel implements FormattingModel { // When processing injection in cdata / comment we need not remove start / end markers that present as whitespace during check in // com.intellij.formatting.WhiteSpace and during building formatter model = blocks in e.g. com.intellij.psi.formatter.xml.XmlTagBlock - if ((removesStartMarker = (removesPattern(textRange, whiteSpace, marker = "") || removesPattern(textRange, whiteSpace, marker = "]-->") ) { diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index ac1816b2faa9..2dfabea586c9 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -533,7 +533,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da fileName), text, LocalTimeCounter.currentTime(), false); } - protected static PsiFile createPseudoPhysicalFile(String fileName, String text) throws IncorrectOperationException { + protected static PsiFile createPseudoPhysicalFile(@NonNls String fileName, String text) throws IncorrectOperationException { FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName); return PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, fileType, text, LocalTimeCounter.currentTime(), true); }