diff --git a/RegExpSupport/test/test/MainParseTest.java b/RegExpSupport/test/test/MainParseTest.java index de43ef77a538..56141057d4d7 100644 --- a/RegExpSupport/test/test/MainParseTest.java +++ b/RegExpSupport/test/test/MainParseTest.java @@ -35,7 +35,7 @@ public class MainParseTest extends BaseParseTestcase { enum Result { OK, ERR } - class Test { + static class Test { boolean showWarnings = true; boolean showInfo = false; Result expectedResult; @@ -158,8 +158,9 @@ public class MainParseTest extends BaseParseTestcase { } private void doTest(String prefix) throws IOException { - int n = 0, failed = 0; - for (String name : myMap.keySet()) { + int n = 0; + int failed = 0; + for (String name : myMap.keySet()) { if (prefix == null && name.contains("/")) { continue; } @@ -174,8 +175,7 @@ public class MainParseTest extends BaseParseTestcase { myFixture.testHighlighting(test.showWarnings, true, test.showInfo, name); if (test.expectedResult == Result.ERR) { - System.out.println(" FAILED. Expression incorrectly parsed OK: " + FileUtil.loadTextAndClose(new FileReader(new File( - getTestDataPath(), name)))); + System.out.println(" FAILED. Expression incorrectly parsed OK: " + FileUtil.loadFile(new File(getTestDataPath(), name))); failed++; } else { System.out.println(" OK"); @@ -185,7 +185,7 @@ public class MainParseTest extends BaseParseTestcase { System.out.println(" OK"); } else { e.printStackTrace(); - System.out.println(" FAILED. Expression = " + FileUtil.loadTextAndClose(new FileReader(new File(getTestDataPath(), name)))); + System.out.println(" FAILED. Expression = " + FileUtil.loadFile(new File(getTestDataPath(), name))); if (myOut.size() > 0) { String line; final BufferedReader reader = new BufferedReader(new StringReader(myOut.toString())); diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/JavaIoFile.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/JavaIoFile.java index bbb48baf0497..a937d9ce5322 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/JavaIoFile.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/JavaIoFile.java @@ -34,7 +34,7 @@ class JavaIoFile extends SimpleJavaFileObject { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { - return new String(FileUtil.loadFileText(myFile)); + return FileUtil.loadFile(myFile); } @Override diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java index e42f48f1c17a..2a322062088f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java @@ -57,7 +57,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase { private void verifyJavaDoc(final PsiElement field) throws IOException { final File htmlPath = new File(JavaTestUtil.getJavaTestDataPath() + "/codeInsight/javadocIG/" + getTestName(true) + ".html"); - String htmlText = new String(FileUtil.loadFileText(htmlPath)); + String htmlText = FileUtil.loadFile(htmlPath); String docInfo = new JavaDocInfoGenerator(getProject(), field).generateDocInfo(null); assertEquals(StringUtil.convertLineSeparators(htmlText.trim()), StringUtil.convertLineSeparators(docInfo.trim())); } @@ -68,7 +68,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase { PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete); final String info = new JavaDocInfoGenerator(getProject(), JavaPsiFacade.getInstance(getProject()).findPackage(getTestName(true))).generateDocInfo(null); - String htmlText = new String(FileUtil.loadFileText(new File(packageInfo + File.separator + "packageInfo.html"))); + String htmlText = FileUtil.loadFile(new File(packageInfo + File.separator + "packageInfo.html")); assertEquals(StringUtil.convertLineSeparators(htmlText.trim()), StringUtil.convertLineSeparators(info.trim())); } diff --git a/java/java-tests/testSrc/com/intellij/ide/fileTemplates/FileTemplatesTest.java b/java/java-tests/testSrc/com/intellij/ide/fileTemplates/FileTemplatesTest.java index b23241f18256..5b1e1bf36b70 100644 --- a/java/java-tests/testSrc/com/intellij/ide/fileTemplates/FileTemplatesTest.java +++ b/java/java-tests/testSrc/com/intellij/ide/fileTemplates/FileTemplatesTest.java @@ -43,8 +43,8 @@ public class FileTemplatesTest extends IdeaTestCase { File propFile = new File(resultFile.getParent(), base + ".prop" + txt); File inFile = new File(resultFile.getParent(), base + txt); - String inputText = new String(FileUtil.loadFileText(inFile, FileTemplate.ourEncoding)); - String outputText = new String(FileUtil.loadFileText(resultFile, FileTemplate.ourEncoding)); + String inputText = FileUtil.loadFile(inFile, FileTemplate.ourEncoding); + String outputText = FileUtil.loadFile(resultFile, FileTemplate.ourEncoding); EncodingAwareProperties properties = new EncodingAwareProperties(); diff --git a/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java b/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java index bde9d0a5c08d..142fee97dbae 100644 --- a/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java @@ -80,7 +80,7 @@ public class ClsBuilderTest extends LightIdeaTestCase { final String goldFilePath = JavaTestUtil.getJavaTestDataPath() + "/psi/cls/stubBuilder/" + goldFile; String expected = ""; try { - expected = new String(FileUtil.loadFileText(new File(goldFilePath))); + expected = FileUtil.loadFile(new File(goldFilePath)); expected = StringUtil.convertLineSeparators(expected); } catch (FileNotFoundException e) { diff --git a/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java b/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java index 0984b7b02fa8..649496558db7 100644 --- a/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java @@ -359,10 +359,10 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { public void testPerformance() throws Exception { final String path = PathManagerEx.getTestDataPath() + "/psi/stub/StubPerformanceTest.java"; - final char[] source = FileUtil.loadFileText(new File(path)); - final PsiJavaFile file = (PsiJavaFile)createLightFile("test.java", new String(source)); + String text = FileUtil.loadFile(new File(path)); + final PsiJavaFile file = (PsiJavaFile)createLightFile("test.java", text); - IdeaTestUtil.assertTiming("Source file size: " + source.length, 2000, new Runnable() { + IdeaTestUtil.assertTiming("Source file size: " + text.length(), 2000, new Runnable() { @Override public void run() { NEW_BUILDER.buildStubTree(file); diff --git a/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java b/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java index 1fc98804f1ac..55c37a52f2f4 100644 --- a/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java @@ -39,7 +39,7 @@ public class NormalizeDeclarationTest extends PsiTestCase{ private static String loadFile(String name) throws Exception { String fullName = BASE_PATH + File.separatorChar + name; - String text = new String(FileUtil.loadFileText(new File(fullName))); + String text = FileUtil.loadFile(new File(fullName)); text = StringUtil.convertLineSeparators(text); return text; } diff --git a/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java b/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java index 8b0816694ea6..a786eedc1342 100644 --- a/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java @@ -80,7 +80,7 @@ public class OptimizeImportsTest extends PsiTestCase{ private static String loadFile(String name) throws Exception { String fullName = BASE_PATH + File.separatorChar + name; - String text = new String(FileUtil.loadFileText(new File(fullName))); + String text = FileUtil.loadFile(new File(fullName)); text = StringUtil.convertLineSeparators(text); return text; } diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/AbstractJavaFormatterTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/AbstractJavaFormatterTest.java index da6d7e23e338..cf97370f707a 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/AbstractJavaFormatterTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/AbstractJavaFormatterTest.java @@ -207,7 +207,7 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase { private static String loadFile(String name) throws Exception { String fullName = BASE_PATH + File.separatorChar + name; - String text = new String(FileUtil.loadFileText(new File(fullName))); + String text = FileUtil.loadFile(new File(fullName)); text = StringUtil.convertLineSeparators(text); return text; } diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java index df6d4c7489f1..b0a51718337d 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java @@ -74,7 +74,7 @@ public class ShortenClassReferencesTest extends PsiTestCase { private String loadFile(String name) throws Exception { String fullName = BASE_PATH + File.separatorChar + name; - String text = new String(FileUtil.loadFileText(new File(fullName))); + String text = FileUtil.loadFile(new File(fullName)); text = StringUtil.convertLineSeparators(text); return text; } diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java index d03a74e5c619..e32d3d541523 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java @@ -65,7 +65,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase @Override public void run() { try { - String contents = StringUtil.convertLineSeparators(new String(FileUtil.loadFileText(testFile, CharsetToolkit.UTF8))); + String contents = StringUtil.convertLineSeparators(FileUtil.loadFile(testFile, CharsetToolkit.UTF8)); quickFixTestCase.configureFromFileText(testFile.getName(), contents); quickFixTestCase.bringRealEditorBack(); final Pair pair = quickFixTestCase.parseActionHintImpl(quickFixTestCase.getFile(), contents); diff --git a/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java b/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java index fb9f52865320..43e157167ea4 100644 --- a/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java +++ b/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java @@ -141,8 +141,8 @@ public class IdeaTestUtil extends PlatformTestUtil { jarFile2 = new JarFile(file2); } catch (IOException e) { - String textAfter = String.valueOf(FileUtil.loadFileText(file1)); - String textBefore = String.valueOf(FileUtil.loadFileText(file2)); + String textAfter = FileUtil.loadFile(file1); + String textBefore = FileUtil.loadFile(file2); textAfter = StringUtil.convertLineSeparators(textAfter); textBefore = StringUtil.convertLineSeparators(textBefore); Assert.assertEquals(file1.getPath(), textAfter, textBefore); diff --git a/java/testFramework/src/com/intellij/testFramework/PsiTestData.java b/java/testFramework/src/com/intellij/testFramework/PsiTestData.java index e93f1ce29ecc..2691de216c35 100644 --- a/java/testFramework/src/com/intellij/testFramework/PsiTestData.java +++ b/java/testFramework/src/com/intellij/testFramework/PsiTestData.java @@ -43,7 +43,7 @@ public class PsiTestData implements JDOMExternalizable { public void loadText(String root) throws IOException{ String fileName = root + "/" + TEXT_FILE; - myText = new String(FileUtil.loadFileText(new File(fileName))); + myText = FileUtil.loadFile(new File(fileName)); myText = StringUtil.convertLineSeparators(myText); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java index 73e5076cf0fe..ff273d03f55f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java @@ -27,6 +27,7 @@ import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.impl.LookupManagerImpl; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; +import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -135,6 +136,7 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { public static boolean chooseActionAndInvoke(PsiFile hostFile, final Editor hostEditor, final IntentionAction action, final String text) { final Project project = hostFile.getProject(); + FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.quickFix"); Pair pair = chooseBetweenHostAndInjected(hostFile, hostEditor, new PairProcessor() { public boolean process(PsiFile psiFile, Editor editor) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java index 12a3b0760a57..80d1f915b936 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java @@ -23,6 +23,7 @@ import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.lookup.*; import com.intellij.codeInsight.lookup.impl.LookupImpl; import com.intellij.codeInsight.template.TemplateManager; +import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; @@ -135,6 +136,7 @@ public class ListTemplatesHandler implements CodeInsightActionHandler { } public void itemSelected(LookupEvent event) { + FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.liveTemplates"); LookupElement item = event.getItem(); if (item != null) { final TemplateImpl template = (TemplateImpl)item.getObject(); diff --git a/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java b/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java index 8aa8856bb54a..8b9ba8442df0 100644 --- a/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java +++ b/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java @@ -23,6 +23,7 @@ import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.CodeStyleSettings; @@ -38,6 +39,7 @@ import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; public class FormatterImpl extends FormatterEx implements ApplicationComponent, @@ -51,7 +53,7 @@ public class FormatterImpl extends FormatterEx private FormattingProgressIndicatorImpl myProgressIndicator; - private int myIsDisabledCount = 0; + private final AtomicInteger myIsDisabledCount = new AtomicInteger(); private final IndentImpl NONE_INDENT = new IndentImpl(Indent.Type.NONE, false, false); private final IndentImpl myAbsoluteNoneIndent = new IndentImpl(Indent.Type.NONE, true, false); private final IndentImpl myLabelIndent = new IndentImpl(Indent.Type.LABEL, false, false); @@ -263,10 +265,10 @@ public class FormatterImpl extends FormatterEx whiteSpace.setReadOnly(false); processor.formatWithoutRealModifications(); return new IndentInfo(whiteSpace.getLineFeeds(), whiteSpace.getIndentOffset(), whiteSpace.getSpaces()); - } finally { + } + finally { enableFormatting(); } - } public void adjustLineIndentsForRange(final FormattingModel model, @@ -295,7 +297,6 @@ public class FormatterImpl extends FormatterEx finally { enableFormatting(); } - } public void formatAroundRange(final FormattingModel model, @@ -329,8 +330,8 @@ public class FormatterImpl extends FormatterEx } processor.formatWithoutRealModifications(); processor.performModifications(model); - - } finally{ + } + finally{ enableFormatting(); } } @@ -357,12 +358,10 @@ public class FormatterImpl extends FormatterEx return offset; } - if (blockAfterOffset != null) { - return adjustLineIndent(offset, documentModel, processor, indentOptions, model, blockAfterOffset.getWhiteSpace()); - } else { - return adjustLineIndent(offset, documentModel, processor, indentOptions, model, processor.getLastWhiteSpace()); - } - } finally { + WhiteSpace whiteSpace = blockAfterOffset != null ? blockAfterOffset.getWhiteSpace() : processor.getLastWhiteSpace(); + return adjustLineIndent(offset, documentModel, processor, indentOptions, model, whiteSpace); + } + finally { enableFormatting(); } } @@ -549,13 +548,16 @@ public class FormatterImpl extends FormatterEx if (whiteSpace.containsLineFeeds() && indentInfoStorage != null) { whiteSpace.setLineFeedsAreReadOnly(true); current.setIndentFromParent(indentInfoStorage.getIndentInfo(current.getStartOffset())); - } else { + } + else { whiteSpace.setReadOnly(true); } - } else { + } + else { if (!changeWSBeforeFirstElement) { whiteSpace.setReadOnly(true); - } else { + } + else { if (!changeLineFeedsBeforeFirstElement) { whiteSpace.setLineFeedsAreReadOnly(true); } @@ -578,7 +580,8 @@ public class FormatterImpl extends FormatterEx assert !(spaceProperty instanceof DependantSpacingImpl); current.setSpaceProperty( getSpacingImpl( - spaceProperty.getMinSpaces(), spaceProperty.getMaxSpaces(), spaceProperty.getMinLineFeeds(), spaceProperty.isReadOnly(), + spaceProperty.getMinSpaces(), spaceProperty.getMaxSpaces(), spaceProperty.getMinLineFeeds(), + spaceProperty.isReadOnly(), spaceProperty.isSafe(), newKeepLineBreaksFlag, newKeepLineBreaks, false, spaceProperty.getPrefLineFeeds() ) ); @@ -590,10 +593,10 @@ public class FormatterImpl extends FormatterEx current = current.getNextBlock(); } processor.format(model); - } finally { + } + finally { enableFormatting(); } - } public void adjustTextRange(final FormattingModel model, @@ -612,17 +615,18 @@ public class FormatterImpl extends FormatterEx if (!whiteSpace.isReadOnly()) { if (whiteSpace.getStartOffset() > affectedRange.getStartOffset()) { whiteSpace.setReadOnly(true); - } else { + } + else { whiteSpace.setReadOnly(false); } } current = current.getNextBlock(); } processor.format(model); - } finally { + } + finally { enableFormatting(); } - } public void saveIndents(final FormattingModel model, final TextRange affectedRange, @@ -722,36 +726,37 @@ public class FormatterImpl extends FormatterEx return relative ? myContinuationIndentRelativeToDirectParent : myContinuationIndentNotRelativeToDirectParent; } - public Indent getContinuationWithoutFirstIndent(boolean relative)//is default - { + //is default + public Indent getContinuationWithoutFirstIndent(boolean relative) { return relative ? myContinuationWithoutFirstIndentRelativeToDirectParent : myContinuationWithoutFirstIndentNotRelativeToDirectParent; } - private final Object DISABLING_LOCK = new Object(); - public boolean isDisabled() { - synchronized (DISABLING_LOCK) { - return myIsDisabledCount > 0; + return myIsDisabledCount.get() > 0; + } + + private void disableFormatting() { + myIsDisabledCount.incrementAndGet(); + } + + private void enableFormatting() { + int old = myIsDisabledCount.getAndDecrement(); + if (old <= 0) { + LOG.error("enableFormatting()/disableFormatting() not paired. DisabledLevel = " + old); } } - public void disableFormatting() { - synchronized (DISABLING_LOCK) { - myIsDisabledCount++; + public T runWithFormattingDisabled(@NotNull Computable runnable) { + disableFormatting(); + try { + return runnable.compute(); } - } - - public void enableFormatting() { - synchronized (DISABLING_LOCK) { - if (myIsDisabledCount <= 0) { - LOG.error("enableFormatting()/disableFormatting() not paired. DisabledLevel = " + myIsDisabledCount); - } - myIsDisabledCount--; + finally { + enableFormatting(); } } private abstract static class MyFormattingTask implements SequentialTask { - private FormatProcessor myProcessor; private boolean myDone; diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateImpl.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateImpl.java index ba95fd157241..9e12123a50a1 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateImpl.java @@ -185,7 +185,7 @@ public class FileTemplateImpl implements FileTemplate, Cloneable{ /** Read template from file. */ private static String readExternal(File file) throws IOException{ - return new String(FileUtil.loadFileText(file, ourEncoding)); + return FileUtil.loadFile(file, ourEncoding); } /** Read template from URL. */ diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandler.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandler.java index c2f13c1a08d2..073c90ac0794 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandler.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandler.java @@ -148,7 +148,7 @@ public class TodoCheckinHandler extends CheckinHandler { worker.execute(); } }; - final boolean completed = ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "", true, myProject); + final boolean completed = ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "Looking for new and edited TODO items...", true, myProject); if (! completed || (worker.getAddedOrEditedTodos().isEmpty() && worker.getInChangedTodos().isEmpty() && worker.getSkipped().isEmpty())) return ReturnResult.COMMIT; diff --git a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java index 5d15f66a5f82..c4727dbf34e2 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/PsiManagerImpl.java @@ -72,8 +72,6 @@ import java.io.IOException; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import static com.intellij.psi.impl.PsiTreeChangeEventImpl.PsiEventType.*; - public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.PsiManagerImpl"); @@ -113,7 +111,8 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { StartupManager startupManager, FileTypeManager fileTypeManager, FileDocumentManager fileDocumentManager, - PsiBuilderFactory psiBuilderFactory, MessageBus messageBus) { + PsiBuilderFactory psiBuilderFactory, + MessageBus messageBus) { myProject = project; myMessageBus = messageBus; @@ -208,56 +207,45 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { } public void performActionWithFormatterDisabled(final Runnable r) { - final PostprocessReformattingAspect component = getProject().getComponent(PostprocessReformattingAspect.class); - try { - ((FormatterImpl)FormatterEx.getInstance()).disableFormatting(); - component.disablePostprocessFormattingInside(new Computable() { - public Object compute() { - r.run(); - return null; - } - }); - } - finally { - ((FormatterImpl)FormatterEx.getInstance()).enableFormatting(); - } + performActionWithFormatterDisabled(new Computable() { + @Override + public Object compute() { + r.run(); + return null; + } + }); } public void performActionWithFormatterDisabled(final ThrowableRunnable r) throws T { final Throwable[] throwable = new Throwable[1]; - final PostprocessReformattingAspect component = getProject().getComponent(PostprocessReformattingAspect.class); - try { - ((FormatterImpl)FormatterEx.getInstance()).disableFormatting(); - component.disablePostprocessFormattingInside(new Computable() { - public Object compute() { - try { - r.run(); - } - catch (Throwable t) { - throwable[0] = t; - } - return null; + performActionWithFormatterDisabled(new Computable() { + @Override + public Object compute() { + try { + r.run(); } - }); - } - finally { - ((FormatterImpl)FormatterEx.getInstance()).enableFormatting(); - } + catch (Throwable t) { + throwable[0] = t; + } + return null; + } + }); - if (throwable[0] != null) //noinspection unchecked + if (throwable[0] != null) { + //noinspection unchecked throw (T)throwable[0]; + } } - public T performActionWithFormatterDisabled(Computable r) { - try { - final PostprocessReformattingAspect component = PostprocessReformattingAspect.getInstance(getProject()); - ((FormatterImpl)FormatterEx.getInstance()).disableFormatting(); - return component.disablePostprocessFormattingInside(r); - } - finally { - ((FormatterImpl)FormatterEx.getInstance()).enableFormatting(); - } + public T performActionWithFormatterDisabled(final Computable r) { + return ((FormatterImpl)FormatterEx.getInstance()).runWithFormattingDisabled(new Computable() { + @Override + public T compute() { + final PostprocessReformattingAspect component = PostprocessReformattingAspect.getInstance(getProject()); + return component.disablePostprocessFormattingInside(r); + } + }); } @NotNull @@ -436,7 +424,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { } public void beforeChildAddition(PsiTreeChangeEventImpl event) { - event.setCode(BEFORE_CHILD_ADDITION); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.BEFORE_CHILD_ADDITION); if (LOG.isDebugEnabled()) { LOG.debug( "beforeChildAddition: parent = " + event.getParent() @@ -446,7 +434,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { } public void beforeChildRemoval(@NotNull PsiTreeChangeEventImpl event) { - event.setCode(BEFORE_CHILD_REMOVAL); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.BEFORE_CHILD_REMOVAL); if (LOG.isDebugEnabled()) { LOG.debug( "beforeChildRemoval: child = " + event.getChild() @@ -457,7 +445,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { } public void beforeChildReplacement(@NotNull PsiTreeChangeEventImpl event) { - event.setCode(BEFORE_CHILD_REPLACEMENT); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.BEFORE_CHILD_REPLACEMENT); if (LOG.isDebugEnabled()) { LOG.debug( "beforeChildReplacement: oldChild = " + event.getOldChild() @@ -468,7 +456,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { } public void beforeChildrenChange(PsiTreeChangeEventImpl event) { - event.setCode(BEFORE_CHILDREN_CHANGE); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.BEFORE_CHILDREN_CHANGE); if (LOG.isDebugEnabled()) { LOG.debug("beforeChildrenChange: parent = " + event.getParent()); } @@ -476,7 +464,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { } public void beforeChildMovement(PsiTreeChangeEventImpl event) { - event.setCode(BEFORE_CHILD_MOVEMENT); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.BEFORE_CHILD_MOVEMENT); if (LOG.isDebugEnabled()) { LOG.debug( "beforeChildMovement: child = " + event.getChild() @@ -488,7 +476,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { } public void beforePropertyChange(PsiTreeChangeEventImpl event) { - event.setCode(BEFORE_PROPERTY_CHANGE); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.BEFORE_PROPERTY_CHANGE); if (LOG.isDebugEnabled()) { LOG.debug( "beforePropertyChange: element = " + event.getElement() @@ -501,7 +489,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { public void childAdded(PsiTreeChangeEventImpl event) { beforeChange(true); - event.setCode(CHILD_ADDED); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.CHILD_ADDED); if (LOG.isDebugEnabled()) { LOG.debug( "childAdded: child = " + event.getChild() @@ -514,7 +502,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { public void childRemoved(PsiTreeChangeEventImpl event) { beforeChange(true); - event.setCode(CHILD_REMOVED); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.CHILD_REMOVED); if (LOG.isDebugEnabled()) { LOG.debug( "childRemoved: child = " + event.getChild() + ", parent = " + event.getParent() @@ -526,7 +514,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { public void childReplaced(PsiTreeChangeEventImpl event) { beforeChange(true); - event.setCode(CHILD_REPLACED); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.CHILD_REPLACED); if (LOG.isDebugEnabled()) { LOG.debug( "childReplaced: oldChild = " + event.getOldChild() @@ -540,7 +528,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { public void childMoved(PsiTreeChangeEventImpl event) { beforeChange(true); - event.setCode(CHILD_MOVED); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.CHILD_MOVED); if (LOG.isDebugEnabled()) { LOG.debug( "childMoved: child = " + event.getChild() @@ -554,7 +542,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { public void childrenChanged(PsiTreeChangeEventImpl event) { beforeChange(true); - event.setCode(CHILDREN_CHANGED); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.CHILDREN_CHANGED); if (LOG.isDebugEnabled()) { LOG.debug( "childrenChanged: parent = " + event.getParent() @@ -566,7 +554,7 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { public void propertyChanged(PsiTreeChangeEventImpl event) { beforeChange(true); - event.setCode(PROPERTY_CHANGED); + event.setCode(PsiTreeChangeEventImpl.PsiEventType.PROPERTY_CHANGED); if (LOG.isDebugEnabled()) { LOG.debug( "propertyChanged: element = " + event.getElement() @@ -584,7 +572,8 @@ public class PsiManagerImpl extends PsiManagerEx implements ProjectComponent { } private void fireEvent(PsiTreeChangeEventImpl event) { - boolean isRealTreeChange = event.getCode() != PROPERTY_CHANGED && event.getCode() != BEFORE_PROPERTY_CHANGE; + boolean isRealTreeChange = event.getCode() != PsiTreeChangeEventImpl.PsiEventType.PROPERTY_CHANGED + && event.getCode() != PsiTreeChangeEventImpl.PsiEventType.BEFORE_PROPERTY_CHANGE; PsiFile file = event.getFile(); if (file == null || file.isPhysical()) { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/Places.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/Places.java deleted file mode 100644 index ffd5095f90ef..000000000000 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/Places.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2000-2009 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.intellij.psi.impl.source.tree.injected; - -import com.intellij.util.SmartList; - -/** - * @author cdr - */ -class Places extends SmartList { - public boolean isValid() { - for (Place place : this) { - if (!place.isValid()) return false; - } - return true; - } -} \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java index a5e457bff1e0..8c95e0081e23 100644 --- a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java +++ b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java @@ -249,7 +249,7 @@ public class BrowserUtil { String previousTimestamp = null; if (timestampFile.exists()) { - previousTimestamp = new String(FileUtil.loadFileText(timestampFile)); + previousTimestamp = FileUtil.loadFile(timestampFile); } if (!currentTimestamp.equals(previousTimestamp)) { diff --git a/platform/platform-api/src/com/intellij/ide/plugins/PluginManager.java b/platform/platform-api/src/com/intellij/ide/plugins/PluginManager.java index f6efc8a9f457..44a670805a56 100644 --- a/platform/platform-api/src/com/intellij/ide/plugins/PluginManager.java +++ b/platform/platform-api/src/com/intellij/ide/plugins/PluginManager.java @@ -757,7 +757,7 @@ public class PluginManager { FileUtil.findFirstThatExist(PathManager.getHomePath() + "/build.txt", PathManager.getHomePath() + "/community/build.txt"); if (buildTxtFile != null) { - ourBuildNumber = BuildNumber.fromString(new String(FileUtil.loadFileText(buildTxtFile)).trim()); + ourBuildNumber = BuildNumber.fromString(FileUtil.loadFile(buildTxtFile).trim()); } else { ourBuildNumber = BuildNumber.fromString("106.SNAPSHOT"); diff --git a/platform/platform-impl/src/com/intellij/diagnostic/VMOptions.java b/platform/platform-impl/src/com/intellij/diagnostic/VMOptions.java index 00f4cb9ea63d..3aea8f0fd3e8 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/VMOptions.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/VMOptions.java @@ -76,7 +76,7 @@ public class VMOptions { private static int readOption(Pattern pattern) { try { - String content = new String(FileUtil.loadFileText(getFile())); + String content = FileUtil.loadFile(getFile()); if (isMacOs()) { content = extractMacOsVMOptionsSection(content); @@ -115,7 +115,7 @@ public class VMOptions { private static void writeOption(String option, int value, Pattern pattern) { try { String optionValue = option + value + "m"; - String content = new String(FileUtil.loadFileText(getFile())); + String content = FileUtil.loadFile(getFile()); String vmOptions; if (isMacOs()) { diff --git a/platform/platform-impl/src/com/intellij/idea/LoggerFactory.java b/platform/platform-impl/src/com/intellij/idea/LoggerFactory.java index eda1fa84d720..11d6a1843479 100644 --- a/platform/platform-impl/src/com/intellij/idea/LoggerFactory.java +++ b/platform/platform-impl/src/com/intellij/idea/LoggerFactory.java @@ -76,7 +76,7 @@ public class LoggerFactory implements Logger.Factory { throw new RuntimeException("log.xml file does not exist! Path: [ $home/bin/log.xml]"); } - String text = new String(FileUtil.loadFileText(logXmlFile)); + String text = FileUtil.loadFile(logXmlFile); text = StringUtil.replace(text, SYSTEM_MACRO, StringUtil.replace(PathManager.getSystemPath(), "\\", "\\\\")); text = StringUtil.replace(text, APPLICATION_MACRO, StringUtil.replace(PathManager.getHomePath(), "\\", "\\\\")); text = StringUtil.replace(text, LOGDIR_MACRO, StringUtil.replace(PathManager.getLogPath(), "\\", "\\\\")); diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index 863c7aa05387..6416ec90bc51 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -521,7 +521,7 @@ public final class UpdateChecker { try { final File file = new File(PathManager.getConfigPath(), DISABLED_UPDATE); if (file.isFile()) { - final String[] ids = new String(FileUtil.loadFileText(file)).split("[\\s]"); + final String[] ids = FileUtil.loadFile(file).split("[\\s]"); for (String id : ids) { if (id != null && id.trim().length() > 0) { ourDisabledToUpdatePlugins.add(id.trim()); diff --git a/platform/testFramework/src/com/intellij/FileSetTestCase.java b/platform/testFramework/src/com/intellij/FileSetTestCase.java index 9f0cc3bd614a..ee6196de4104 100644 --- a/platform/testFramework/src/com/intellij/FileSetTestCase.java +++ b/platform/testFramework/src/com/intellij/FileSetTestCase.java @@ -110,7 +110,7 @@ public abstract class FileSetTestCase extends TestSuite { @Override protected void runTest() throws Throwable { - String content = new String(FileUtil.loadFileText(myTestFile)); + String content = FileUtil.loadFile(myTestFile); assertNotNull(content); List input = new ArrayList(); diff --git a/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java index 61807d650577..2167ee325863 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java @@ -93,7 +93,7 @@ public abstract class LexerTestCase extends UsefulTestCase { String fileName = PathManager.getHomePath() + "/" + getDirPath() + "/" + getTestName(true) + "." + fileExt; String text = ""; try { - text = StringUtil.convertLineSeparators(new String(FileUtil.loadFileText(new File(fileName))).trim()); + text = StringUtil.convertLineSeparators(FileUtil.loadFile(new File(fileName)).trim()); } catch (IOException e) { fail("can't load file " + fileName + ": " + e.getMessage()); diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index 9f8487354b82..5ce206cad3d7 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -105,7 +105,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest String fullPath = getTestDataPath() + filePath; final File ioFile = new File(fullPath); - String fileText = new String(FileUtil.loadFileText(ioFile, CharsetToolkit.UTF8)); + String fileText = FileUtil.loadFile(ioFile, CharsetToolkit.UTF8); fileText = StringUtil.convertLineSeparators(fileText); configureFromFileText(ioFile.getName(), fileText); @@ -280,7 +280,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest assertTrue(getMessage("Cannot find file " + fullPath, message), ioFile.exists()); String fileText = null; try { - fileText = new String(FileUtil.loadFileText(ioFile, CharsetToolkit.UTF8)); + fileText = FileUtil.loadFile(ioFile, CharsetToolkit.UTF8); } catch (IOException e) { LOG.error(e); } diff --git a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java index a8ae528855fd..bdde15051217 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java @@ -135,7 +135,7 @@ public abstract class ParsingTestCase extends LightPlatformTestCase { private static String doLoadFile(String myFullDataPath, String name) throws IOException { String fullName = myFullDataPath + File.separatorChar + name; - String text = new String(FileUtil.loadFileText(new File(fullName))).trim(); + String text = FileUtil.loadFile(new File(fullName)).trim(); text = StringUtil.convertLineSeparators(text); return text; } diff --git a/platform/testFramework/src/com/intellij/testFramework/TestLoggerFactory.java b/platform/testFramework/src/com/intellij/testFramework/TestLoggerFactory.java index 6e2f0f488dee..7ad886df983a 100644 --- a/platform/testFramework/src/com/intellij/testFramework/TestLoggerFactory.java +++ b/platform/testFramework/src/com/intellij/testFramework/TestLoggerFactory.java @@ -60,7 +60,7 @@ public class TestLoggerFactory implements Logger.Factory { } final String logDir = PathManager.getSystemPath() + "/" + LOG_DIR; - String text = new String(FileUtil.loadFileText(logXmlFile)); + String text = FileUtil.loadFile(logXmlFile); text = StringUtil.replace(text, SYSTEM_MACRO, StringUtil.replace(PathManager.getSystemPath(), "\\", "\\\\")); text = StringUtil.replace(text, APPLICATION_MACRO, StringUtil.replace(PathManager.getHomePath(), "\\", "\\\\")); text = StringUtil.replace(text, LOG_DIR_MACRO, StringUtil.replace(logDir, "\\", "\\\\")); diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 4ab574926e63..7321b2b2631b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -506,8 +506,7 @@ public abstract class UsefulTestCase extends TestCase { protected static void assertSameLinesWithFile(final String filePath, final String actualText) { String fileText; try { - final FileReader reader = new FileReader(filePath); - fileText = FileUtil.loadTextAndClose(reader); + fileText = FileUtil.loadFile(new File(filePath)); } catch (IOException e) { throw new RuntimeException(e); diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index f05a51388470..0d6ed9bf36a2 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -168,12 +168,20 @@ public class FileUtil { } @NotNull - public static char[] loadFileText(File file) throws IOException { + public static String loadFile(@NotNull File file) throws IOException { + return loadFile(file, null); + } + @NotNull + public static String loadFile(@NotNull File file, String encoding) throws IOException { + return new String(loadFileText(file, encoding)); + } + @NotNull + public static char[] loadFileText(@NotNull File file) throws IOException { return loadFileText(file, null); } @NotNull - public static char[] loadFileText(File file, @NonNls String encoding) throws IOException{ + public static char[] loadFileText(@NotNull File file, @NonNls String encoding) throws IOException{ InputStream stream = new FileInputStream(file); Reader reader = encoding == null ? new InputStreamReader(stream) : new InputStreamReader(stream, encoding); try{ diff --git a/platform/util/src/com/intellij/util/io/zip/ReorderJarsMain.java b/platform/util/src/com/intellij/util/io/zip/ReorderJarsMain.java index 9df7a6854fdb..cefdcd360bec 100644 --- a/platform/util/src/com/intellij/util/io/zip/ReorderJarsMain.java +++ b/platform/util/src/com/intellij/util/io/zip/ReorderJarsMain.java @@ -91,13 +91,13 @@ public class ReorderJarsMain { private static Set loadIgnoredJars(String libPath) throws IOException { final File ignoredJarsFile = new File(libPath, "required_for_dist.txt"); final Set ignoredJars = new HashSet(); - ContainerUtil.addAll(ignoredJars, new String(FileUtil.loadFileText(ignoredJarsFile)).split("\r\n")); + ContainerUtil.addAll(ignoredJars, FileUtil.loadFile(ignoredJarsFile).split("\r\n")); return ignoredJars; } private static Map> getOrder(final File loadingFile) throws IOException { final Map> entriesOrder = new HashMap>(); - final String[] lines = new String(FileUtil.loadFileText(loadingFile)).split("\r\n"); + final String[] lines = FileUtil.loadFile(loadingFile).split("\r\n"); for (String line : lines) { final int i = line.indexOf(":"); if (i != -1) { diff --git a/platform/util/src/com/intellij/util/properties/EncodingAwareProperties.java b/platform/util/src/com/intellij/util/properties/EncodingAwareProperties.java index 064833aee51a..65b8bcb90040 100644 --- a/platform/util/src/com/intellij/util/properties/EncodingAwareProperties.java +++ b/platform/util/src/com/intellij/util/properties/EncodingAwareProperties.java @@ -29,7 +29,7 @@ import java.io.IOException; */ public class EncodingAwareProperties extends java.util.Properties{ public void load(File file, String encoding) throws IOException{ - String propText = new String(FileUtil.loadFileText(file, encoding)); + String propText = FileUtil.loadFile(file, encoding); propText = StringUtil.convertLineSeparators(propText); StringTokenizer stringTokenizer = new StringTokenizer(propText, "\n"); while (stringTokenizer.hasMoreElements()){ diff --git a/plugins/ant/tests/src/com/intellij/lang/ant/CustomTypesTest.java b/plugins/ant/tests/src/com/intellij/lang/ant/CustomTypesTest.java index e9c1ceb20ca3..f7db59fbe095 100644 --- a/plugins/ant/tests/src/com/intellij/lang/ant/CustomTypesTest.java +++ b/plugins/ant/tests/src/com/intellij/lang/ant/CustomTypesTest.java @@ -80,7 +80,7 @@ public class CustomTypesTest extends ParsingTestCase { @Override protected String loadFile(String name) throws IOException { String fullName = getTestDataPath() + File.separatorChar + name; - String text = new String(FileUtil.loadFileText(new File(fullName))).trim(); + String text = FileUtil.loadFile(new File(fullName)).trim(); text = StringUtil.convertLineSeparators(text); final String root = PathUtil.getJarPathForClass(this.getClass()); final String placeholder = "<_classpath_>"; diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsUtil.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsUtil.java index 5a4232c5b7ca..26a9a076a802 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsUtil.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsUtil.java @@ -279,7 +279,7 @@ public class CvsUtil { File file = getFileInTheAdminDir(directory, fileName); if (!file.isFile()) return null; try { - String result = new String(FileUtil.loadFileText(file)); + String result = FileUtil.loadFile(file); if (trimContent) { return result.trim(); } diff --git a/plugins/devkit/src/projectRoots/IdeaJdk.java b/plugins/devkit/src/projectRoots/IdeaJdk.java index e99615bc92b6..454b02ce02c5 100644 --- a/plugins/devkit/src/projectRoots/IdeaJdk.java +++ b/plugins/devkit/src/projectRoots/IdeaJdk.java @@ -162,7 +162,7 @@ public class IdeaJdk extends SdkType implements JavaSdkType { private static String getBuildNumber(String ideaHome) { try { @NonNls final String buildTxt = "/build.txt"; - return new String(FileUtil.loadFileText(new File(ideaHome + buildTxt))).trim(); + return FileUtil.loadFile(new File(ideaHome + buildTxt)).trim(); } catch (IOException e) { return null; diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseClasspathTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseClasspathTest.java index 4a7e67856713..1024906fff36 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseClasspathTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseClasspathTest.java @@ -74,7 +74,7 @@ public class EclipseClasspathTest extends IdeaTestCase { static Module setUpModule(final String path, final Project project) throws IOException, JDOMException, ConversionException { final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT); - String fileText = new String(FileUtil.loadFileText(classpathFile)).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath()); + String fileText = FileUtil.loadFile(classpathFile).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath()); if (!SystemInfo.isWindows) { fileText = fileText.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL); } @@ -104,7 +104,7 @@ public class EclipseClasspathTest extends IdeaTestCase { static void checkModule(String path, Module module) throws IOException, JDOMException, ConversionException { final File classpathFile1 = new File(path, EclipseXml.DOT_CLASSPATH_EXT); if (!classpathFile1.exists()) return; - String fileText1 = new String(FileUtil.loadFileText(classpathFile1)).replaceAll("\\$ROOT\\$", module.getProject().getBaseDir().getPath()); + String fileText1 = FileUtil.loadFile(classpathFile1).replaceAll("\\$ROOT\\$", module.getProject().getBaseDir().getPath()); if (!SystemInfo.isWindows) { fileText1 = fileText1.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL); } diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseEmlTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseEmlTest.java index f8711a2032f0..a8a7c69e5b56 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseEmlTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseEmlTest.java @@ -80,7 +80,7 @@ public class EclipseEmlTest extends IdeaTestCase { new EclipseClasspathStorageProvider.EclipseClasspathConverter(module); final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); - final Element classpathElement = JDOMUtil.loadDocument(new String(FileUtil.loadFileText(new File(path, EclipseXml.DOT_CLASSPATH_EXT)))).getRootElement(); + final Element classpathElement = JDOMUtil.loadDocument(FileUtil.loadFile(new File(path, EclipseXml.DOT_CLASSPATH_EXT))).getRootElement(); converter.getClasspath(rootModel, classpathElement); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { @@ -103,12 +103,12 @@ public class EclipseEmlTest extends IdeaTestCase { final File emlFile = new File(path, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX); Assert.assertTrue(resulted.replaceAll(StringUtil.escapeToRegexp(module.getProject().getBaseDir().getPath()), "\\$ROOT\\$"), - JDOMUtil.areElementsEqual(root, JDOMUtil.loadDocument(new String(FileUtil.loadFileText(emlFile))).getRootElement())); + JDOMUtil.areElementsEqual(root, JDOMUtil.loadDocument(FileUtil.loadFile(emlFile)).getRootElement())); } private static void replaceRoot(String path, final String child, final Project project) throws IOException, JDOMException { final File emlFile = new File(path, child); - String fileText = new String(FileUtil.loadFileText(emlFile)).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath()); + String fileText = FileUtil.loadFile(emlFile).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath()); if (!SystemInfo.isWindows) { fileText = fileText.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL); } diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java index 0707ba46dda5..0ffc332cc99d 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java @@ -73,7 +73,7 @@ public class EclipseImlTest extends IdeaTestCase { final String path = project.getBaseDir().getPath() + relativePath; final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT); - String fileText = new String(FileUtil.loadFileText(classpathFile)).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath()); + String fileText = FileUtil.loadFile(classpathFile).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath()); if (!SystemInfo.isWindows) { fileText = fileText.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL); } diff --git a/plugins/git4idea/src/git4idea/GitBranch.java b/plugins/git4idea/src/git4idea/GitBranch.java index f957ccf23011..130ea4ba7b24 100644 --- a/plugins/git4idea/src/git4idea/GitBranch.java +++ b/plugins/git4idea/src/git4idea/GitBranch.java @@ -158,7 +158,7 @@ public class GitBranch extends GitReference { // the case after git init and before first commit - there is no branch and no output, and we'll take refs/heads/master String head; try { - head = new String(FileUtil.loadFileText(new File(root.getPath(), ".git/HEAD"), GitUtil.UTF8_ENCODING)).trim(); + head = FileUtil.loadFile(new File(root.getPath(), ".git/HEAD"), GitUtil.UTF8_ENCODING).trim(); final String prefix = "ref: refs/heads/"; return head.startsWith(prefix) ? new GitBranch(head.substring(prefix.length()), true, false) : null; } catch (IOException e) { diff --git a/plugins/git4idea/src/git4idea/GitRemote.java b/plugins/git4idea/src/git4idea/GitRemote.java index 94f7dcab0f05..a4734dd291c4 100644 --- a/plugins/git4idea/src/git4idea/GitRemote.java +++ b/plugins/git4idea/src/git4idea/GitRemote.java @@ -31,9 +31,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -363,7 +361,7 @@ public final class GitRemote { // try remotes file try { //noinspection IOResourceOpenedButNotSafelyClosed - String text = FileUtil.loadTextAndClose(new InputStreamReader(new FileInputStream(remotesFile), US_ASCII_ENCODING)); + String text = FileUtil.loadFile(remotesFile, US_ASCII_ENCODING); @NonNls String pullPrefix = "Pull:"; for (StringScanner s = new StringScanner(text); s.hasMoreData();) { String line = s.line(); diff --git a/plugins/git4idea/src/git4idea/checkin/GitPushRebaseProcess.java b/plugins/git4idea/src/git4idea/checkin/GitPushRebaseProcess.java index 1c29040f5e6c..20a0ef6cd0d0 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitPushRebaseProcess.java +++ b/plugins/git4idea/src/git4idea/checkin/GitPushRebaseProcess.java @@ -198,7 +198,7 @@ public class GitPushRebaseProcess extends GitBaseRebaseProcess { } try { TreeMap pickLines = new TreeMap(); - StringScanner s = new StringScanner(new String(FileUtil.loadFileText(new File(path), GitUtil.UTF8_ENCODING))); + StringScanner s = new StringScanner(FileUtil.loadFile(new File(path), GitUtil.UTF8_ENCODING)); while (s.hasMoreData()) { if (!s.tryConsume("pick ")) { s.line(); diff --git a/plugins/git4idea/src/git4idea/checkout/branches/GitSwitchBranchesDialog.java b/plugins/git4idea/src/git4idea/checkout/branches/GitSwitchBranchesDialog.java index 1ed152da7ebb..d46a96b94d8e 100644 --- a/plugins/git4idea/src/git4idea/checkout/branches/GitSwitchBranchesDialog.java +++ b/plugins/git4idea/src/git4idea/checkout/branches/GitSwitchBranchesDialog.java @@ -476,7 +476,7 @@ public class GitSwitchBranchesDialog extends DialogWrapper { String newRef; try { final String refText = - new String(FileUtil.loadFileText(new File(rootPath, ".git/refs/" + value), GitUtil.UTF8_ENCODING)).trim(); + FileUtil.loadFile(new File(rootPath, ".git/refs/" + value), GitUtil.UTF8_ENCODING).trim(); String refsPrefix = "ref: refs/"; if (refText.endsWith("/HEAD") || !refText.startsWith(refsPrefix)) { newRef = null; diff --git a/plugins/git4idea/src/git4idea/merge/MergeChangeCollector.java b/plugins/git4idea/src/git4idea/merge/MergeChangeCollector.java index fdff0690303f..adba4f19979c 100644 --- a/plugins/git4idea/src/git4idea/merge/MergeChangeCollector.java +++ b/plugins/git4idea/src/git4idea/merge/MergeChangeCollector.java @@ -116,7 +116,7 @@ public class MergeChangeCollector { File mergeHeadsFile = new File(root, ".git/MERGE_HEAD"); try { if (mergeHeadsFile.exists()) { - String mergeHeads = new String(FileUtil.loadFileText(mergeHeadsFile, GitUtil.UTF8_ENCODING)); + String mergeHeads = FileUtil.loadFile(mergeHeadsFile, GitUtil.UTF8_ENCODING); for (StringScanner s = new StringScanner(mergeHeads); s.hasMoreData();) { String head = s.line(); if (head.length() == 0) { diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java index 78433f72b7d7..675f6eefb157 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java @@ -338,7 +338,7 @@ public class GitRebaseEditor extends DialogWrapper { */ public void load(final String file) throws IOException { String encoding = GitConfigUtil.getLogEncoding(myProject, myGitRoot); - final StringScanner s = new StringScanner(new String(FileUtil.loadFileText(new File(file), encoding))); + final StringScanner s = new StringScanner(FileUtil.loadFile(new File(file), encoding)); while (s.hasMoreData()) { if (s.isEol() || s.startsWith('#') || s.startsWith("noop")) { s.nextLine(); diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseUnstructuredEditor.java b/plugins/git4idea/src/git4idea/rebase/GitRebaseUnstructuredEditor.java index f00cd81e8f07..76f1a0ccd026 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseUnstructuredEditor.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseUnstructuredEditor.java @@ -66,7 +66,7 @@ public class GitRebaseUnstructuredEditor extends DialogWrapper { myGitRootLabel.setText(root.getPresentableUrl()); encoding = GitConfigUtil.getCommitEncoding(project, root); myFile = new File(path); - myTextArea.setText(new String(FileUtil.loadFileText(myFile, encoding))); + myTextArea.setText(FileUtil.loadFile(myFile, encoding)); init(); } diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseUtils.java b/plugins/git4idea/src/git4idea/rebase/GitRebaseUtils.java index 8c91b239707e..15ed73f19629 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseUtils.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseUtils.java @@ -91,7 +91,7 @@ public class GitRebaseUtils { File nextFile = new File(rebaseDir, "next"); int next; try { - next = Integer.parseInt(new String(FileUtil.loadFileText(nextFile, GitUtil.UTF8_ENCODING)).trim()); + next = Integer.parseInt(FileUtil.loadFile(nextFile, GitUtil.UTF8_ENCODING).trim()); } catch (Exception e) { if (LOG.isDebugEnabled()) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/extensions/GroovyNamedArgumentProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/extensions/GroovyNamedArgumentProvider.java index 8efd918823f4..ab62b7009c16 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/extensions/GroovyNamedArgumentProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/extensions/GroovyNamedArgumentProvider.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.extensions; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.util.Condition; +import com.intellij.psi.CommonClassNames; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiType; import com.intellij.psi.util.InheritanceUtil; @@ -48,6 +49,12 @@ public abstract class GroovyNamedArgumentProvider { return namedArguments; } + public static final StringTypeCondition TYPE_STRING = new StringTypeCondition(CommonClassNames.JAVA_LANG_STRING); + public static final StringTypeCondition TYPE_MAP = new StringTypeCondition(CommonClassNames.JAVA_UTIL_MAP); + public static final StringTypeCondition TYPE_BOOL = new StringTypeCondition(CommonClassNames.JAVA_LANG_BOOLEAN); + public static final StringTypeCondition TYPE_INTEGER = new StringTypeCondition(CommonClassNames.JAVA_LANG_INTEGER); + public static final Condition TYPE_ANY = Condition.TRUE; + protected static class StringTypeCondition implements Condition { private final String myTypeName; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/GroovySourceCodeNamedArgumentProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/GroovySourceCodeNamedArgumentProvider.java index faa0467936b1..38116accec69 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/GroovySourceCodeNamedArgumentProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/GroovySourceCodeNamedArgumentProvider.java @@ -18,7 +18,6 @@ package org.jetbrains.plugins.groovy.lang; import com.intellij.openapi.util.Condition; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiType; -import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.extensions.GroovyNamedArgumentProvider; @@ -35,7 +34,7 @@ public class GroovySourceCodeNamedArgumentProvider extends GroovyNamedArgumentPr public void getNamedArguments(@Nullable GrCall call, @NotNull PsiMethod method, Map> result) { if (method instanceof GrMethod) { for (String parameter : ((GrMethod)method).getNamedParametersArray()) { - result.put(parameter, Condition.TRUE); + result.put(parameter, TYPE_ANY); } } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/TestUtils.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/TestUtils.java index 3e222f3fcbdd..086beabbf8eb 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/TestUtils.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/TestUtils.java @@ -105,7 +105,7 @@ public abstract class TestUtils { public static List readInput(String filePath) { String content; try { - content = new String(FileUtil.loadFileText(new File(filePath))); + content = FileUtil.loadFile(new File(filePath)); } catch (IOException e) { throw new RuntimeException(e); diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java index a0c44d748bb2..fb525e325f21 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java @@ -310,8 +310,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { myAuthenticationManager.addListener(savedOnceListener); final File config = new File(myConfiguration.getConfigurationDirectory(), "config"); - final char[] chars = FileUtil.loadFileText(config); - final String contents = String.valueOf(chars); + final String contents = FileUtil.loadFile(config); final String auth = "[auth]"; final int idx = contents.indexOf(auth); Assert.assertTrue(idx != -1); @@ -439,8 +438,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { myAuthenticationManager.addListener(savedOnceListener); final File config = new File(myConfiguration.getConfigurationDirectory(), "config"); - final char[] chars = FileUtil.loadFileText(config); - final String contents = String.valueOf(chars); + final String contents = FileUtil.loadFile(config); final String auth = "[auth]"; final int idx = contents.indexOf(auth); Assert.assertTrue(idx != -1); @@ -572,8 +570,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { myAuthenticationManager.addListener(savedOnceListener); final File servers = new File(myConfiguration.getConfigurationDirectory(), "servers"); - final char[] chars = FileUtil.loadFileText(servers); - final String contents = String.valueOf(chars); + final String contents = FileUtil.loadFile(servers); final String groups = "[groups]"; final int idx = contents.indexOf(groups); Assert.assertTrue(idx != -1); diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java index 974741fb3d4f..9b7d7c4443e5 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java @@ -93,7 +93,7 @@ public class AsmCodeGeneratorTest extends TestCase { } private LwRootContainer loadFormData(final String formPath) throws Exception { - String formData = new String(FileUtil.loadFileText(new File(formPath))); + String formData = FileUtil.loadFile(new File(formPath)); final CompiledClassPropertiesProvider provider = new CompiledClassPropertiesProvider(getClass().getClassLoader()); return Utils.getRootContainer(formData, provider); } diff --git a/xml/impl/src/com/intellij/application/options/editor/WebEditorOptions.java b/xml/impl/src/com/intellij/application/options/editor/WebEditorOptions.java index db77e6e25d76..06befebee8ca 100644 --- a/xml/impl/src/com/intellij/application/options/editor/WebEditorOptions.java +++ b/xml/impl/src/com/intellij/application/options/editor/WebEditorOptions.java @@ -16,7 +16,9 @@ package com.intellij.application.options.editor; import com.intellij.codeInsight.template.impl.TemplateSettings; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.components.*; import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.xml.XmlBundle; @@ -55,6 +57,10 @@ public class WebEditorOptions implements PersistentStateComponent