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-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java index 79fe32f1e62b..ed3c07767a2d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java @@ -7,6 +7,7 @@ import com.intellij.codeInsight.generation.PsiMethodMember; import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElementDecorator; import com.intellij.codeInsight.lookup.LookupItem; +import com.intellij.codeInsight.lookup.PsiTypeLookupItem; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.util.MemberChooser; import com.intellij.openapi.application.ApplicationManager; @@ -16,6 +17,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.source.PostprocessReformattingAspect; @@ -63,38 +65,67 @@ class ConstructorInsertHandler implements InsertHandler 0) { + TextRange range = paramList.getTextRange(); + context.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), "<>"); + editor.getCaretModel().moveToOffset(range.getStartOffset() + 1); + } + return; + } + } } } - if (mySmart) { - FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW); + } + + context.setLaterRunnable(generateAnonymousBody(editor, context.getFile())); + } + else { + final PsiNewExpression newExpression = + PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiNewExpression.class, false); + if (newExpression != null) { + final PsiJavaCodeReferenceElement classReference = newExpression.getClassOrAnonymousClassReference(); + if (classReference != null) { + CodeStyleManager.getInstance(context.getProject()).reformat(classReference); } } + if (mySmart) { + FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW); + } } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java index c446d083b469..76b14c447fa6 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java @@ -37,6 +37,7 @@ import com.intellij.find.impl.FindManagerImpl; import com.intellij.ide.util.SuperMethodWarningUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.undo.UndoUtil; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; @@ -68,6 +69,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction { private final boolean myChangeAllUsages; private final int myMinUsagesNumberToShowDialog; private ParameterInfoImpl[] myNewParametersInfo; + private static final Logger LOG = Logger.getInstance("#" + ChangeMethodSignatureFromUsageFix.class.getName()); ChangeMethodSignatureFromUsageFix(@NotNull PsiMethod targetMethod, @NotNull PsiExpression[] expressions, @@ -99,6 +101,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction { if (result.length() != 0) { result += ", "; } + LOG.assertTrue(type != null, "old idx: " + info.getOldIndex() + "; " + info.getClass().getName()); result += type.getPresentableText(); } } diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java index 9e8f2a32fabd..6f657eecc649 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java @@ -678,9 +678,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr PsiParameter[] parameters = list.getParameters(); final JavaParameterInfo[] parameterInfos = changeInfo.getNewParameters(); - PsiParameter[] newParms = new PsiParameter[parameterInfos.length - - (baseMethod != null ? baseMethod.getParameterList().getParametersCount() - - method.getParameterList().getParametersCount() : 0)]; + final int delta = baseMethod != null ? baseMethod.getParameterList().getParametersCount() - method.getParameterList().getParametersCount() : 0; + PsiParameter[] newParms = new PsiParameter[Math.max(parameterInfos.length - delta, 0)]; final String[] oldParameterNames = changeInfo.getOldParameterNames(); final String[] oldParameterTypes = changeInfo.getOldParameterTypes(); for (int i = 0; i < newParms.length; i++) { @@ -865,6 +864,20 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr } } + for (UsageInfo usageInfo : usagesSet) { + if (usageInfo instanceof OverriderUsageInfo) { + final PsiMethod method = (PsiMethod)usageInfo.getElement(); + final PsiMethod baseMethod = ((OverriderUsageInfo)usageInfo).getBaseMethod(); + final int delta = baseMethod.getParameterList().getParametersCount() - method.getParameterList().getParametersCount(); + if (delta > 0) { + final boolean[] toRemove = myChangeInfo.toRemoveParm(); + if (toRemove[toRemove.length - 1]) { //todo check if implicit parameter is not the last one + conflictDescriptions.putValue(baseMethod, "Implicit last parameter should not be deleted"); + } + } + } + } + return conflictDescriptions; } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index 02b38d7eb026..1254d9567356 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -89,7 +89,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { myMethodToSearchFor = methodToSearchFor; myOccurrences = occurrences; myMustBeFinal = mustBeFinal; - myExprMarker = expr != null ? myEditor.getDocument().createRangeMarker(expr.getTextRange()) : null; + myExprMarker = expr != null && expr.isPhysical() ? myEditor.getDocument().createRangeMarker(expr.getTextRange()) : null; myExprText = myExpr != null ? myExpr.getText() : null; myWholePanel = new JPanel(new GridBagLayout()); @@ -202,7 +202,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { @Override protected PsiExpression getExpr() { - return myExpr; + return myExpr != null && myExpr.isValid() && myExpr.isPhysical() ? myExpr : null; } @Override @@ -301,9 +301,11 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { public void run() { final PsiFile containingFile = myMethod.getContainingFile(); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myProject); - myExpr = restoreExpression(containingFile, psiParameter, elementFactory, myExprMarker, myExprText); - if (myExpr != null) { - myExprMarker = myEditor.getDocument().createRangeMarker(myExpr.getTextRange()); + if (myExprMarker != null) { + myExpr = restoreExpression(containingFile, psiParameter, elementFactory, myExprMarker, myExprText); + if (myExpr != null) { + myExprMarker = myEditor.getDocument().createRangeMarker(myExpr.getTextRange()); + } } final List occurrenceMarkers = getOccurrenceMarkers(); for (int i = 0, occurrenceMarkersSize = occurrenceMarkers.size(); i < occurrenceMarkersSize; i++) { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java index 5da76bbd8561..9ae8973f4744 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java @@ -75,7 +75,7 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { private final SmartPsiElementPointer myPointer; private final RangeMarker myExprMarker; private final List myOccurrenceMarkers; - private final PsiType myDefaultType; + private final SmartTypePointer myDefaultType; protected JCheckBox myCanBeFinal; private Balloon myBalloon; @@ -97,14 +97,15 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { myExprMarker = exprMarker; myOccurrenceMarkers = occurrenceMarkers; - myDefaultType = elementToRename.getType(); + final PsiType defaultType = elementToRename.getType(); + myDefaultType = SmartTypePointerManager.getInstance(project).createSmartTypePointer(defaultType); final PsiDeclarationStatement declarationStatement = PsiTreeUtil.getParentOfType(elementToRename, PsiDeclarationStatement.class); myPointer = declarationStatement != null ? SmartPointerManager.getInstance(project).createSmartPsiElementPointer(declarationStatement) : null; editor.putUserData(ReassignVariableUtil.DECLARATION_KEY, myPointer); editor.putUserData(ReassignVariableUtil.OCCURRENCES_KEY, occurrenceMarkers.toArray(new RangeMarker[occurrenceMarkers.size()])); - setAdvertisementText(getAdvertisementText(declarationStatement, myDefaultType, hasTypeSuggestion)); + setAdvertisementText(getAdvertisementText(declarationStatement, defaultType, hasTypeSuggestion)); if (!cantChangeFinalModifier) { myCanBeFinal = new NonFocusableCheckBox("Declare final"); myCanBeFinal.setSelected(createFinals()); @@ -221,7 +222,7 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { protected void saveSettings(PsiVariable psiVariable) { JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_FINALS = psiVariable.hasModifierProperty(PsiModifier.FINAL); - TypeSelectorManagerImpl.typeSelected(psiVariable.getType(), myDefaultType); + TypeSelectorManagerImpl.typeSelected(psiVariable.getType(), myDefaultType.getType()); } diff --git a/java/java-impl/src/com/intellij/refactoring/util/CanonicalTypes.java b/java/java-impl/src/com/intellij/refactoring/util/CanonicalTypes.java index ea47fb2c9e12..b86d99362340 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/CanonicalTypes.java +++ b/java/java-impl/src/com/intellij/refactoring/util/CanonicalTypes.java @@ -24,6 +24,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.List; @@ -38,6 +39,7 @@ public class CanonicalTypes { private CanonicalTypes() { } public abstract static class Type { + @NotNull public abstract PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException; @NonNls @@ -53,6 +55,7 @@ public class CanonicalTypes { myType = type; } + @NotNull public PsiType getType(PsiElement context, final PsiManager manager) { return myType; } @@ -71,6 +74,7 @@ public class CanonicalTypes { myComponentType = componentType; } + @NotNull public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException { return myComponentType.getType(context, manager).createArrayType(); } @@ -91,6 +95,7 @@ public class CanonicalTypes { myComponentType = componentType; } + @NotNull public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException { return new PsiEllipsisType(myComponentType.getType(context, manager)); } @@ -113,6 +118,7 @@ public class CanonicalTypes { myBound = bound; } + @NotNull public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException { if(myBound == null) return PsiWildcardType.createUnbounded(context.getManager()); if (myIsExtending) { @@ -140,6 +146,7 @@ public class CanonicalTypes { myText = text; } + @NotNull public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException { return JavaPsiFacade.getInstance(context.getProject()).getElementFactory().createTypeFromText(myText, context); } @@ -162,6 +169,7 @@ public class CanonicalTypes { mySubstitutor = substitutor; } + @NotNull public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException { final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject()); final PsiElementFactory factory = facade.getElementFactory(); @@ -205,6 +213,7 @@ public class CanonicalTypes { myTypes = types; } + @NotNull @Override public PsiType getType(final PsiElement context, final PsiManager manager) throws IncorrectOperationException { final List types = ContainerUtil.map(myTypes, new Function() { diff --git a/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs-out.java b/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs-out.java new file mode 100644 index 000000000000..e0f7ba5fcded --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs-out.java @@ -0,0 +1,10 @@ +interface Foo {} +interface FooEx extends Foo { + T foo(); +} + +class Bar { + { + Foo f = new FooEx<>() {}; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs.java b/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs.java new file mode 100644 index 000000000000..aa2333d3906c --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs.java @@ -0,0 +1,10 @@ +interface Foo {} +interface FooEx extends Foo { + T foo(); +} + +class Bar { + { + Foo f = new FE + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index b32fd98fe38c..8f90525530a4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -861,6 +861,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { doTest(); } + public void testUnboundTypeArgs() throws Exception { doTest(); } + public void testIDEADEV2668() throws Exception { doTest(); } 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/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 5a8433feca8c..50b649715a8a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -669,6 +669,9 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { finally { myChangeGuard = false; } + if (isVisible()) { + updateLookupBounds(); + } LOG.assertTrue(!myDisposed, disposeTrace); } @@ -1135,8 +1138,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { } updateScrollbarVisibility(); - HintManagerImpl.adjustEditorHintPosition(this, myEditor, calculatePosition(getComponent())); - layoutStatusIcons(); + updateLookupBounds(); if (reused) { ensureSelectionVisible(); @@ -1144,6 +1146,11 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { } } + private void updateLookupBounds() { + HintManagerImpl.adjustEditorHintPosition(this, myEditor, calculatePosition(getComponent())); + layoutStatusIcons(); + } + private void layoutStatusIcons() { final JLayeredPane layeredPane = getComponent().getRootPane().getLayeredPane(); 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/execution/impl/RunConfigurable.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java index 34d483c74600..1b65e18ea94a 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java @@ -295,11 +295,12 @@ class RunConfigurable extends BaseConfigurable { public void stateChanged(final SettingsEditor editor) { update(); final RunConfiguration configuration = info.getConfiguration(); - if (configuration instanceof RuntimeConfiguration) { - final RuntimeConfiguration runtimeConfiguration = (RuntimeConfiguration)configuration; + if (configuration instanceof LocatableConfiguration) { + final LocatableConfiguration runtimeConfiguration = (LocatableConfiguration)configuration; if (runtimeConfiguration.isGeneratedName()) { try { - final String generatedName = ((RuntimeConfiguration)editor.getSnapshot().getConfiguration()).getGeneratedName(); + final LocatableConfiguration snapshot = (LocatableConfiguration)editor.getSnapshot().getConfiguration(); + final String generatedName = snapshot instanceof RuntimeConfiguration? ((RuntimeConfiguration)snapshot).getGeneratedName() : snapshot.suggestedName(); if (generatedName != null && generatedName.length() > 0) { info.setNameText(generatedName); } 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-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index 9b159b26218c..18e210767567 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -3338,11 +3338,6 @@ public class AbstractTreeUi { notified = true; } } - - if (!notified) { - myTreeModel.nodeChanged(node); - } - } public DefaultTreeModel getTreeModel() { 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/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index c3fc74bea79a..a75f44f3e3fb 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -87,6 +87,8 @@ + + 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/platform/util/src/com/intellij/util/xmlb/BeanBinding.java b/platform/util/src/com/intellij/util/xmlb/BeanBinding.java index f0a16c3f4270..34c5cf6c3323 100644 --- a/platform/util/src/com/intellij/util/xmlb/BeanBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/BeanBinding.java @@ -279,7 +279,8 @@ class BeanBinding implements Binding { return new AccessorBindingWrapper(accessor, binding); } - return new OptionTagBinding(accessor, xmlSerializer); + OptionTag optionTag = XmlSerializerImpl.findAnnotation(accessor.getAnnotations(), OptionTag.class); + return new OptionTagBinding(accessor, xmlSerializer, optionTag); } } diff --git a/platform/util/src/com/intellij/util/xmlb/OptionTagBinding.java b/platform/util/src/com/intellij/util/xmlb/OptionTagBinding.java index dd3216ab4a72..06f1f369bbea 100644 --- a/platform/util/src/com/intellij/util/xmlb/OptionTagBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/OptionTagBinding.java @@ -19,42 +19,57 @@ package com.intellij.util.xmlb; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.JDOMUtil; import com.intellij.util.ArrayUtil; +import com.intellij.util.xmlb.annotations.OptionTag; import org.jdom.Attribute; import org.jdom.Content; import org.jdom.Element; import org.jdom.Text; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -//todo: use TagBinding class OptionTagBinding implements Binding { - private final static Logger LOG = Logger.getInstance("#" + OptionTagBinding.class.getName()); private final Accessor accessor; private final String myName; private final Binding myBinding; + private final String myTagName; + private final String myNameAttribute; + private final String myValueAttribute; - public OptionTagBinding(Accessor accessor, XmlSerializerImpl xmlSerializer) { + public OptionTagBinding(Accessor accessor, XmlSerializerImpl xmlSerializer, @Nullable OptionTag optionTag) { this.accessor = accessor; - myName = accessor.getName(); myBinding = xmlSerializer.getBinding(accessor); + if (optionTag != null) { + String name = optionTag.value(); + myName = name.isEmpty() ? accessor.getName() : name; + myTagName = optionTag.tag(); + myNameAttribute = optionTag.nameAttribute(); + myValueAttribute = optionTag.valueAttribute(); + } + else { + myName = accessor.getName(); + myTagName = Constants.OPTION; + myNameAttribute = Constants.NAME; + myValueAttribute = Constants.VALUE; + } } public Object serialize(Object o, Object context) { - Element targetElement = new Element(Constants.OPTION); + Element targetElement = new Element(myTagName); Object value = accessor.read(o); - targetElement.setAttribute(Constants.NAME, myName); + targetElement.setAttribute(myNameAttribute, myName); if (value == null) return targetElement; Object node = myBinding.serialize(value, targetElement); if (node instanceof Text) { Text text = (Text)node; - targetElement.setAttribute(Constants.VALUE, text.getText()); + targetElement.setAttribute(myValueAttribute, text.getText()); } else { if (targetElement != node) { @@ -72,7 +87,7 @@ class OptionTagBinding implements Binding { assert nodes.length != 0 : "Empty nodes passed to: " + this; Element element = ((Element)nodes[0]); - Attribute valueAttr = element.getAttribute(Constants.VALUE); + Attribute valueAttr = element.getAttribute(myValueAttribute); if (valueAttr != null) { Object value = myBinding.deserialize(o, valueAttr); @@ -102,8 +117,8 @@ class OptionTagBinding implements Binding { public boolean isBoundTo(Object node) { if (!(node instanceof Element)) return false; Element e = (Element)node; - if (!e.getName().equals(Constants.OPTION)) return false; - String name = e.getAttributeValue(Constants.NAME); + if (!e.getName().equals(myTagName)) return false; + String name = e.getAttributeValue(myNameAttribute); return name != null && name.equals(myName); } diff --git a/platform/util/src/com/intellij/util/xmlb/annotations/OptionTag.java b/platform/util/src/com/intellij/util/xmlb/annotations/OptionTag.java new file mode 100644 index 000000000000..3f921b3ed206 --- /dev/null +++ b/platform/util/src/com/intellij/util/xmlb/annotations/OptionTag.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2011 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.util.xmlb.annotations; + +import com.intellij.util.xmlb.Constants; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Store value in tag like <option name="optionName" value="optionValue"/> + * + * @author nik + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.METHOD}) +public @interface OptionTag { + String value() default ""; + String tag() default Constants.OPTION; + String nameAttribute() default Constants.NAME; + String valueAttribute() default Constants.VALUE; +} diff --git a/platform/util/testSrc/com/intellij/util/xmlb/XmlSerializerTest.java b/platform/util/testSrc/com/intellij/util/xmlb/XmlSerializerTest.java index ec4b0dd6aceb..5879e223de30 100644 --- a/platform/util/testSrc/com/intellij/util/xmlb/XmlSerializerTest.java +++ b/platform/util/testSrc/com/intellij/util/xmlb/XmlSerializerTest.java @@ -21,9 +21,6 @@ import com.intellij.util.xmlb.annotations.*; import junit.framework.TestCase; import org.jdom.Element; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; -import java.io.IOException; import java.util.*; import java.util.Collection; @@ -36,7 +33,7 @@ public class XmlSerializerTest extends TestCase { public static class EmptyBean { } - public void testEmptyBeanSerialization() throws Exception { + public void testEmptyBeanSerialization() { doSerializerTest("", new EmptyBean()); } @@ -44,7 +41,7 @@ public class XmlSerializerTest extends TestCase { public static class EmptyBeanWithCustomName { } - public void testEmptyBeanSerializationWithCustomName() throws Exception { + public void testEmptyBeanSerializationWithCustomName() { doSerializerTest("", new EmptyBeanWithCustomName()); } @@ -67,7 +64,7 @@ public class XmlSerializerTest extends TestCase { } } - public void testPublicFieldSerialization() throws Exception { + public void testPublicFieldSerialization() { BeanWithPublicFields bean = new BeanWithPublicFields(); doSerializerTest( @@ -91,7 +88,7 @@ public class XmlSerializerTest extends TestCase { public String NEW_S = "foo"; } - public void testPublicFieldSerializationWithInheritance() throws Exception { + public void testPublicFieldSerializationWithInheritance() { BeanWithPublicFieldsDescendant bean = new BeanWithPublicFieldsDescendant(); doSerializerTest( @@ -120,7 +117,7 @@ public class XmlSerializerTest extends TestCase { public BeanWithPublicFields BEAN2 = new BeanWithPublicFields(); } - public void testSubBeanSerialization() throws Exception { + public void testSubBeanSerialization() { BeanWithSubBean bean = new BeanWithSubBean(); doSerializerTest( "\n" + @@ -153,7 +150,7 @@ public class XmlSerializerTest extends TestCase { bean); } - public void testNullFieldValue() throws Exception { + public void testNullFieldValue() { BeanWithPublicFields bean1 = new BeanWithPublicFields(); doSerializerTest( @@ -187,7 +184,7 @@ public class XmlSerializerTest extends TestCase { public List VALUES = new ArrayList(Arrays.asList("a", "b", "c")); } - public void testListSerialization() throws Exception { + public void testListSerialization() { BeanWithList bean = new BeanWithList(); doSerializerTest( @@ -221,7 +218,7 @@ public class XmlSerializerTest extends TestCase { public Set VALUES = new LinkedHashSet(Arrays.asList("a", "b", "w")); } - public void testSetSerialization() throws Exception { + public void testSetSerialization() { BeanWithSet bean = new BeanWithSet(); doSerializerTest( "\n" + @@ -259,7 +256,7 @@ public class XmlSerializerTest extends TestCase { } } - public void testMapSerialization() throws Exception { + public void testMapSerialization() { BeanWithMap bean = new BeanWithMap(); doSerializerTest( "\n" + @@ -307,7 +304,7 @@ public class XmlSerializerTest extends TestCase { } } - public void testMapSerializationWithAnnotations() throws Exception { + public void testMapSerializationWithAnnotations() { BeanWithMapWithAnnotations bean = new BeanWithMapWithAnnotations(); doSerializerTest( "\n" + @@ -335,7 +332,7 @@ public class XmlSerializerTest extends TestCase { public Map VALUES = new HashMap(); } - public void testMapWithBeanValue() throws Exception { + public void testMapWithBeanValue() { BeanWithMapWithBeanValue bean = new BeanWithMapWithBeanValue(); bean.VALUES.put("a", new BeanWithProperty("James")); @@ -372,6 +369,33 @@ public class XmlSerializerTest extends TestCase { "", bean); } + + public static class BeanWithOption { + @OptionTag("path") + public String PATH; + } + + public void testOptionTag() { + BeanWithOption bean = new BeanWithOption(); + bean.PATH = "123"; + doSerializerTest("\n" + + " ", bean); + } + + public static class BeanWithCustomizedOption { + @OptionTag(tag = "setting", nameAttribute = "key", valueAttribute = "saved") + public String PATH; + } + + public void testCustomizedOptionTag() { + BeanWithCustomizedOption bean = new BeanWithCustomizedOption(); + bean.PATH = "123"; + doSerializerTest("\n" + + " \n" + + "", bean); + } + public static class BeanWithProperty { private String name = "James"; @@ -392,7 +416,7 @@ public class XmlSerializerTest extends TestCase { } } - public void testPropertySerialization() throws Exception { + public void testPropertySerialization() { BeanWithProperty bean = new BeanWithProperty(); doSerializerTest( @@ -414,7 +438,7 @@ public class XmlSerializerTest extends TestCase { public String STRING_V = "hello"; } - public void testFieldWithTagAnnotation() throws Exception { + public void testFieldWithTagAnnotation() { BeanWithFieldWithTagAnnotation bean = new BeanWithFieldWithTagAnnotation(); doSerializerTest( @@ -431,7 +455,7 @@ public class XmlSerializerTest extends TestCase { "", bean); } - public void testShuffledDeserialize() throws Exception { + public void testShuffledDeserialize() { BeanWithPublicFields bean = new BeanWithPublicFields(); bean.INT_V = 987; bean.STRING_V = "1234"; @@ -448,7 +472,7 @@ public class XmlSerializerTest extends TestCase { assertEquals("1234", bean.STRING_V); } - public void testFilterSerializer() throws Exception { + public void testFilterSerializer() { BeanWithPublicFields bean = new BeanWithPublicFields(); assertSerializer(bean, "\n" + @@ -465,7 +489,7 @@ public class XmlSerializerTest extends TestCase { public static class BeanWithArray { public String[] ARRAY_V = new String[] {"a", "b"}; } - public void testArray() throws Exception { + public void testArray() { final BeanWithArray bean = new BeanWithArray(); doSerializerTest( "\n" + @@ -498,7 +522,7 @@ public class XmlSerializerTest extends TestCase { return "foo"; } } - public void testTransient() throws Exception { + public void testTransient() { final BeanWithTransient bean = new BeanWithTransient(); doSerializerTest("", bean); } @@ -507,7 +531,7 @@ public class XmlSerializerTest extends TestCase { @com.intellij.util.xmlb.annotations.AbstractCollection(surroundWithTag = false) public String[] V = new String[]{"a"}; } - public void testArrayAnnotationWithoutTagNAmeGivesError() throws Exception { + public void testArrayAnnotationWithoutTagNAmeGivesError() { final BeanWithArrayWithoutTagName bean = new BeanWithArrayWithoutTagName(); try { @@ -524,7 +548,7 @@ public class XmlSerializerTest extends TestCase { @com.intellij.util.xmlb.annotations.AbstractCollection(elementTag = "vvalue", elementValueAttribute = "v") public String[] V = new String[]{"a", "b"}; } - public void testArrayAnnotationWithElementTag() throws Exception { + public void testArrayAnnotationWithElementTag() { final BeanWithArrayWithElementTagName bean = new BeanWithArrayWithElementTagName(); doSerializerTest( @@ -557,7 +581,7 @@ public class XmlSerializerTest extends TestCase { public String[] V = new String[]{"a", "b"}; public int INT_V = 1; } - public void testArrayWithoutTag() throws Exception { + public void testArrayWithoutTag() { final BeanWithArrayWithoutTag bean = new BeanWithArrayWithoutTag(); doSerializerTest( @@ -587,7 +611,7 @@ public class XmlSerializerTest extends TestCase { @Property(surroundWithTag = false) public int INT_V = 1; } - public void testPropertyWithoutTagWithPrimitiveType() throws Exception { + public void testPropertyWithoutTagWithPrimitiveType() { final BeanWithPropertyWithoutTagOnPrimitiveValue bean = new BeanWithPropertyWithoutTagOnPrimitiveValue(); try { @@ -605,7 +629,7 @@ public class XmlSerializerTest extends TestCase { public BeanWithPublicFields BEAN1 = new BeanWithPublicFields(); public int INT_V = 1; } - public void testPropertyWithoutTag() throws Exception { + public void testPropertyWithoutTag() { final BeanWithPropertyWithoutTag bean = new BeanWithPropertyWithoutTag(); doSerializerTest( @@ -638,7 +662,7 @@ public class XmlSerializerTest extends TestCase { public String[] V = new String[]{"a", "b"}; public int INT_V = 1; } - public void testArrayWithoutAllTags() throws Exception { + public void testArrayWithoutAllTags() { final BeanWithArrayWithoutAllsTag bean = new BeanWithArrayWithoutAllsTag(); doSerializerTest( @@ -666,7 +690,7 @@ public class XmlSerializerTest extends TestCase { public String[] V = new String[]{"a", "b"}; public int INT_V = 1; } - public void testArrayWithoutAllTags2() throws Exception { + public void testArrayWithoutAllTags2() { final BeanWithArrayWithoutAllsTag2 bean = new BeanWithArrayWithoutAllsTag2(); doSerializerTest( @@ -706,7 +730,7 @@ public class XmlSerializerTest extends TestCase { public BeanWithPublicFields[] V = new BeanWithPublicFields[] {}; } - public void testPolymorphicArray() throws Exception { + public void testPolymorphicArray() { final BeanWithPolymorphicArray bean = new BeanWithPolymorphicArray(); doSerializerTest( @@ -747,7 +771,7 @@ public class XmlSerializerTest extends TestCase { @Attribute("name") public String name = "James"; } - public void testBeanWithPrimitivePropertyBoundToAttribute() throws Exception { + public void testBeanWithPrimitivePropertyBoundToAttribute() { final BeanWithPropertiesBoundToAttribute bean = new BeanWithPropertiesBoundToAttribute(); doSerializerTest("", bean); @@ -771,7 +795,7 @@ public class XmlSerializerTest extends TestCase { return !accessor.read(bean).equals("skip"); } } - public void testPropertyFilter() throws Exception { + public void testPropertyFilter() { BeanWithPropertyFilter bean = new BeanWithPropertyFilter(); doSerializerTest( @@ -797,7 +821,7 @@ public class XmlSerializerTest extends TestCase { public org.jdom.Element actions; } - public void testSerializeJDOMElementField() throws Exception { + public void testSerializeJDOMElementField() { BeanWithJDOMElement element = new BeanWithJDOMElement(); element.STRING_V = "a"; element.actions = new Element("x").addContent(new Element("a")).addContent(new Element("b")); @@ -881,7 +905,7 @@ public class XmlSerializerTest extends TestCase { } } - public void testTextAnnotation() throws Exception { + public void testTextAnnotation() { BeanWithTextAnnotation bean = new BeanWithTextAnnotation(); doSerializerTest( @@ -911,7 +935,7 @@ public class XmlSerializerTest extends TestCase { public TestEnum FLD = TestEnum.VALUE_1; } - public void testEnums() throws Exception { + public void testEnums() { BeanWithEnum bean = new BeanWithEnum(); doSerializerTest( @@ -927,7 +951,7 @@ public class XmlSerializerTest extends TestCase { public Map, String> myMap = new HashMap, String>(); } - public void testSetKeysInMap() throws Exception { + public void testSetKeysInMap() { final BeanWithSetKeysInMap bean = new BeanWithSetKeysInMap(); bean.myMap.put(new HashSet(Arrays.asList("1", "2", "3")), "numbers"); bean.myMap.put(new HashSet(Arrays.asList("a", "b", "c")), "letters"); @@ -982,7 +1006,7 @@ public class XmlSerializerTest extends TestCase { public Map MAP = new HashMap(); } - public void testMapWithNotSurroundingKeyAndValue() throws Exception { + public void testMapWithNotSurroundingKeyAndValue() { BeanWithMapWithoutSurround bean = new BeanWithMapWithoutSurround(); bean.MAP.put(new BeanWithPublicFields(1, "a"), new BeanWithTextAnnotation(2, "b")); @@ -1028,24 +1052,29 @@ public class XmlSerializerTest extends TestCase { //--------------------------------------------------------------------------------------------------- - private void assertSerializer(Object bean, String expected, SerializationFilter filter) - throws TransformerException, ParserConfigurationException, IOException { + private static void assertSerializer(Object bean, String expected, SerializationFilter filter) { assertSerializer(bean, expected, "Serialization failure", filter); } - private Object doSerializerTest(String expectedText, Object bean) - throws ParserConfigurationException, TransformerException, XmlSerializationException, IOException { - Element element = assertSerializer(bean, expectedText, "Serialization failure", null); + private static Object doSerializerTest(String expectedText, Object bean) { + try { + Element element = assertSerializer(bean, expectedText, "Serialization failure", null); - //test deserializer + //test deserializer - Object o = XmlSerializer.deserialize(element, bean.getClass()); - assertSerializer(o, expectedText, "Deserialization failure", null); - return o; + Object o = XmlSerializer.deserialize(element, bean.getClass()); + assertSerializer(o, expectedText, "Deserialization failure", null); + return o; + } + catch (XmlSerializationException e) { + throw e; + } + catch (Exception e) { + throw new RuntimeException(e); + } } - private Element assertSerializer(Object bean, String expectedText, String message, SerializationFilter filter) - throws ParserConfigurationException, XmlSerializationException, TransformerException, IOException { + private static Element assertSerializer(Object bean, String expectedText, String message, SerializationFilter filter) throws XmlSerializationException { Element element = serialize(bean, filter); @@ -1060,7 +1089,7 @@ public class XmlSerializerTest extends TestCase { return element; } - private Element serialize(Object bean, SerializationFilter filter) throws ParserConfigurationException { + private static Element serialize(Object bean, SerializationFilter filter) { return XmlSerializer.serialize(bean, filter); } } diff --git a/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java b/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java index 07371c692732..3414508a63c4 100644 --- a/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java +++ b/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java @@ -123,7 +123,7 @@ public class AndroidUtils { public static final String EXT_NATIVE_LIB = "so"; @NonNls public static final String RES_OVERLAY_DIR_NAME = "res-overlay"; - public static final int TIMEOUT = 60000; + public static final int TIMEOUT = 300000; private AndroidUtils() { } 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/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java b/plugins/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java index e0783eb7fefa..f5f971a37abe 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/options/ExternalOptionHelper.java @@ -17,6 +17,7 @@ package com.maddyhome.idea.copyright.options; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.JDOMUtil; import com.maddyhome.idea.copyright.CopyrightProfile; import org.jdom.Document; @@ -54,10 +55,11 @@ public class ExternalOptionHelper { } } } - return profiles.isEmpty() ? null : profiles; + return profiles; } catch (Exception e) { - logger.error(e); + logger.info(e); + Messages.showErrorDialog(e.getMessage(), "Import Failure"); return null; } } diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java index 1eebcd37f55a..21d3c270e204 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java @@ -201,7 +201,8 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se if (files.length != 1) return; final List copyrightProfiles = ExternalOptionHelper.loadOptions(VfsUtil.virtualToIoFile(files[0])); - if (copyrightProfiles != null) { + if (copyrightProfiles == null) return; + if (!copyrightProfiles.isEmpty()) { if (copyrightProfiles.size() == 1) { importProfile(copyrightProfiles.get(0)); } else { @@ -224,7 +225,7 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se } } else { - Messages.showWarningDialog(myProject, "The selected file did not contain any copyright settings.", "Import Failure"); + Messages.showWarningDialog(myProject, "The selected file does not contain any copyright settings.", "Import Failure"); } } 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/github/src/org/jetbrains/plugins/github/GithubCheckoutProvider.java b/plugins/github/src/org/jetbrains/plugins/github/GithubCheckoutProvider.java index d1d7e4a877fc..a1157119cba0 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubCheckoutProvider.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubCheckoutProvider.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2011 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 org.jetbrains.plugins.github; import com.intellij.ide.GeneralSettings; @@ -72,6 +87,7 @@ public class GithubCheckoutProvider implements CheckoutProvider { if (!writeAccessAllowed){ Messages.showErrorDialog(project, "It seems that you have only read access to the selected repository.\n" + "GitHub supports only https protocol for readonly access, which is not supported yet.\n" + + "As a workaround, please fork it and clone your forked repository instead.\n" + "More details are available here: http://youtrack.jetbrains.net/issue/IDEA-55298", "Cannot clone this repository"); return; } diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubSettings.java b/plugins/github/src/org/jetbrains/plugins/github/GithubSettings.java index b58f576dfa66..40ea647de790 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubSettings.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubSettings.java @@ -1,10 +1,27 @@ +/* + * Copyright 2000-2011 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 org.jetbrains.plugins.github; +import com.intellij.ide.passwordSafe.PasswordSafe; +import com.intellij.ide.passwordSafe.PasswordSafeException; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; -import com.intellij.openapi.util.PasswordUtil; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -24,13 +41,14 @@ public class GithubSettings implements PersistentStateComponent { private static final String GITHUB_SETTINGS_TAG = "GithubSettings"; private static final String LOGIN = "Login"; - private static final String PASSWORD = "Password"; private static final String HOST = "Host"; private static final String GITHUB = "github.com"; + private static final String GITHUB_SETTINGS_PASSWORD_KEY = "GITHUB_SETTINGS_PASSWORD_KEY"; private String myLogin; private String myPassword; private String myHost; + private static final Logger LOG = Logger.getInstance(GithubSettings.class.getName()); public static GithubSettings getInstance(){ return ServiceManager.getService(GithubSettings.class); @@ -40,31 +58,23 @@ public class GithubSettings implements PersistentStateComponent { if (StringUtil.isEmptyOrSpaces(myLogin) && StringUtil.isEmptyOrSpaces(myPassword) && StringUtil.isEmptyOrSpaces(myHost)) { return null; } + try { + PasswordSafe.getInstance().storePassword(null, GithubSettings.class, GITHUB_SETTINGS_PASSWORD_KEY, myPassword); + } + catch (PasswordSafeException e) { + LOG.error(e); + } final Element element = new Element(GITHUB_SETTINGS_TAG); element.setAttribute(LOGIN, getLogin()); - element.setAttribute(PASSWORD, getEncodedPassword()); element.setAttribute(HOST, getHost()); return element; } - public String getEncodedPassword() { - return PasswordUtil.encodePassword(getPassword()); - } - - public void setEncodedPassword(final String password) { - try { - setPassword(PasswordUtil.decodePassword(password)); - } - catch (NumberFormatException e) { - // do nothing - } - } - public void loadState(@NotNull final Element element) { try { setLogin(element.getAttributeValue(LOGIN)); - setEncodedPassword(element.getAttributeValue(PASSWORD)); setHost(element.getAttributeValue(HOST)); + setPassword(PasswordSafe.getInstance().getPassword(null, GithubSettings.class, GITHUB_SETTINGS_PASSWORD_KEY)); } catch (Exception e) { // ignore diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java index ce4b8a94e456..fec480c3eb79 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2011 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 org.jetbrains.plugins.github; import com.intellij.openapi.diagnostic.Logger; @@ -141,6 +156,10 @@ public class GithubUtil { public static boolean isPushableRepo(final String url, final String login, final String password, final RepositoryInfo repositoryInfo) { try { + // Github API doesn't list your own repos among pushable repos. Fail! + if (login.equals(repositoryInfo.getOwner())){ + return true; + } final HttpMethod method = doREST(url, login, password, "/repos/pushable", false); final InputStream stream = method.getResponseBodyAsStream(); final Element element = new SAXBuilder(false).build(stream).getRootElement(); 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/WebEditorAppearanceConfigurable.java b/xml/impl/src/com/intellij/application/options/editor/WebEditorAppearanceConfigurable.java index 6818b852adf0..4f68031c75f2 100644 --- a/xml/impl/src/com/intellij/application/options/editor/WebEditorAppearanceConfigurable.java +++ b/xml/impl/src/com/intellij/application/options/editor/WebEditorAppearanceConfigurable.java @@ -28,6 +28,5 @@ public class WebEditorAppearanceConfigurable extends BeanConfigurable +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingConfigurable.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingConfigurable.java new file mode 100644 index 000000000000..0b15e38f5eb1 --- /dev/null +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingConfigurable.java @@ -0,0 +1,112 @@ +/* + * Copyright 2000-2011 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.codeInsight.daemon.impl.tagTreeHighlighting; + +import com.intellij.application.options.editor.WebEditorOptions; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileEditor; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.TextEditor; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.options.UnnamedConfigurable; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.util.ui.UIUtil; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author Eugene.Kudelevsky + */ +public class HtmlTagTreeHighlightingConfigurable implements UnnamedConfigurable { + private JCheckBox myEnableTagTreeHighlightingCheckBox; + private JSpinner myLevelsSpinner; + private JPanel myLevelsPanel; + private JPanel myContentPanel; + + public HtmlTagTreeHighlightingConfigurable() { + myLevelsSpinner.setModel(new SpinnerNumberModel(1, 1, 50, 1)); + + myEnableTagTreeHighlightingCheckBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final boolean enabled = myEnableTagTreeHighlightingCheckBox.isSelected(); + UIUtil.setEnabled(myLevelsPanel, enabled, true); + } + }); + } + + @Override + public JComponent createComponent() { + return myContentPanel; + } + + @Override + public boolean isModified() { + final WebEditorOptions options = WebEditorOptions.getInstance(); + + if (myEnableTagTreeHighlightingCheckBox.isSelected() != options.isTagTreeHighlightingEnabled()) { + return true; + } + + if (getLevelCount() != options.getTagTreeHighlightingLevelCount()) { + return true; + } + + return false; + } + + @Override + public void apply() throws ConfigurationException { + final WebEditorOptions options = WebEditorOptions.getInstance(); + + options.setTagTreeHighlightingEnabled(myEnableTagTreeHighlightingCheckBox.isSelected()); + options.setTagTreeHighlightingLevelCount(getLevelCount()); + + clearTagTreeHighlighting(); + } + + private int getLevelCount() { + return ((Integer)myLevelsSpinner.getValue()).intValue(); + } + + private static void clearTagTreeHighlighting() { + for (Project project : ProjectManager.getInstance().getOpenProjects()) { + for (FileEditor fileEditor : FileEditorManager.getInstance(project).getAllEditors()) { + if (fileEditor instanceof TextEditor) { + final Editor editor = ((TextEditor)fileEditor).getEditor(); + HtmlTagTreeHighlightingPass.clearHighlightingAndLineMarkers(editor, project); + } + } + } + } + + @Override + public void reset() { + final WebEditorOptions options = WebEditorOptions.getInstance(); + final boolean enabled = options.isTagTreeHighlightingEnabled(); + + myEnableTagTreeHighlightingCheckBox.setSelected(enabled); + myLevelsSpinner.setValue(options.getTagTreeHighlightingLevelCount()); + UIUtil.setEnabled(myLevelsPanel, enabled, true); + } + + @Override + public void disposeUIResources() { + } +} diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingPass.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingPass.java index f99cc91b34e7..e43b19e9205e 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingPass.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingPass.java @@ -31,8 +31,11 @@ import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.editor.ex.MarkupModelEx; +import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.psi.FileViewProvider; @@ -52,6 +55,8 @@ import java.util.List; * @author Eugene.Kudelevsky */ public class HtmlTagTreeHighlightingPass extends TextEditorHighlightingPass { + private static final Key> TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY = Key.create("TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY"); + private static final HighlightInfoType TYPE = new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, TextAttributesKey .createTextAttributesKey("TAG_TREE_HIGHLIGHTING_KEY")); @@ -154,24 +159,28 @@ public class HtmlTagTreeHighlightingPass extends TextEditorHighlightingPass { } public List getHighlights() { + clearLineMarkers(myEditor); + final int count = myPairsToHighlight.size(); final List highlightInfos = new ArrayList(count * 2); + final MarkupModel markupModel = myEditor.getMarkupModel(); - final Color[] colors = getColors(); + final Color[] baseColors = getBaseColors(); + final Color[] colorsForEditor = toColorsForEditor(baseColors); + final Color[] colorsForLineMarkers = toColorsForLineMarkers(baseColors); - assert colors.length > 0; + final List newHighlighters = new ArrayList(); - int colorIndex = 0; + assert colorsForEditor.length > 0; + + for (int i = 0, n = myPairsToHighlight.size(); i < n && i < baseColors.length; i++) { + Pair pair = myPairsToHighlight.get(i); - for (Pair pair : myPairsToHighlight) { if (pair == null || (pair.first == null && pair.second == null)) { continue; } - if (colorIndex >= colors.length) { - colorIndex = 0; - } - Color color = colors[colorIndex]; + Color color = colorsForEditor[i]; if (pair.first != null) { highlightInfos.add(createHighlightInfo(color, pair.first)); @@ -181,30 +190,100 @@ public class HtmlTagTreeHighlightingPass extends TextEditorHighlightingPass { highlightInfos.add(createHighlightInfo(color, pair.second)); } - colorIndex++; + final int start = pair.first != null ? pair.first.getStartOffset() : pair.second.getStartOffset(); + final int end = pair.second != null ? pair.second.getEndOffset() : pair.first.getEndOffset(); + + final RangeHighlighter highlighter = createHighlighter(markupModel, new TextRange(start, end), colorsForLineMarkers[i]); + newHighlighters.add(highlighter); } + myEditor.putUserData(TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY, newHighlighters); + return highlightInfos; } + private static void clearLineMarkers(Editor editor) { + final List oldHighlighters = editor.getUserData(TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY); + + if (oldHighlighters != null) { + final MarkupModelEx markupModel = (MarkupModelEx)editor.getMarkupModel(); + + for (RangeHighlighter highlighter : oldHighlighters) { + if (markupModel.containsHighlighter(highlighter)) { + highlighter.dispose(); + } + } + editor.putUserData(TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY, null); + } + } + @NotNull private static HighlightInfo createHighlightInfo(Color color, @NotNull TextRange range) { return new HighlightInfo(new TextAttributes(null, color, null, null, Font.PLAIN), TYPE, range.getStartOffset(), range.getEndOffset(), null, null, HighlightSeverity.INFORMATION, false, null, false); } - private Color[] getColors() { - final ColorKey[] colorKeys = HtmlTagTreeHighlightingColors.COLOR_KEYS; + @NotNull + private static RangeHighlighter createHighlighter(final MarkupModel mm, final @NotNull TextRange range, final Color color) { + final RangeHighlighter highlighter = + mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.LINES_IN_RANGE); + + highlighter.setLineMarkerRenderer(new LineMarkerRenderer() { + public void paint(Editor editor, Graphics g, Rectangle r) { + int height = r.height + editor.getLineHeight(); + g.setColor(color); + g.fillRect(r.x, r.y, 2, height); + } + }); + return highlighter; + } + + + private static Color[] getBaseColors() { + final ColorKey[] colorKeys = HtmlTagTreeHighlightingColors.getColorKeys(); final Color[] colors = new Color[colorKeys.length]; + + final EditorColorsScheme colorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); + + for (int i = 0; i < colors.length; i++) { + colors[i] = colorsScheme.getColor(colorKeys[i]); + } + + return colors; + } + + private static Color[] toColorsForLineMarkers(Color[] baseColors) { + final Color[] colors = new Color[baseColors.length]; + final Color tagBackground = new Color(239, 239, 239); + final double transparency = 0.4; + final double factor = 0.8; + + for (int i = 0; i < colors.length; i++) { + final Color color = baseColors[i]; + + int r = (int)(color.getRed() * factor); + int g = (int)(color.getGreen() * factor); + int b = (int)(color.getBlue() * factor); + + r = (int)(tagBackground.getRed() * (1 - transparency) + r * transparency); + g = (int)(tagBackground.getGreen() * (1 - transparency) + g * transparency); + b = (int)(tagBackground.getBlue() * (1 - transparency) + b * transparency); + + colors[i] = new Color(r, g, b); + } + + return colors; + } + + private Color[] toColorsForEditor(Color[] baseColors) { + final Color[] colors = new Color[baseColors.length]; final Color tagBackground = myEditor instanceof EditorEx ? ((EditorEx)myEditor).getBackgroundColor() : null; // todo: make configurable final double transparency = 0.1; - final EditorColorsScheme colorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); - for (int i = 0; i < colors.length; i++) { - Color color = colorsScheme.getColor(colorKeys[i]); + final Color color = baseColors[i]; if (tagBackground == null) { colors[i] = color; @@ -220,4 +299,22 @@ public class HtmlTagTreeHighlightingPass extends TextEditorHighlightingPass { return colors; } + + public static void clearHighlightingAndLineMarkers(final Editor editor, @NotNull Project project) { + final MarkupModel markupModel = editor.getDocument().getMarkupModel(project); + + for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) { + Object tooltip = highlighter.getErrorStripeTooltip(); + + if (!(tooltip instanceof HighlightInfo)) { + continue; + } + + if (((HighlightInfo)tooltip).type == TYPE) { + highlighter.dispose(); + } + } + + clearLineMarkers(editor); + } } diff --git a/xml/impl/src/com/intellij/lang/xml/XmlUnwrapDescriptor.java b/xml/impl/src/com/intellij/lang/xml/XmlUnwrapDescriptor.java index 539e29d6c9c9..ca2d4ed07fae 100644 --- a/xml/impl/src/com/intellij/lang/xml/XmlUnwrapDescriptor.java +++ b/xml/impl/src/com/intellij/lang/xml/XmlUnwrapDescriptor.java @@ -22,6 +22,7 @@ import com.intellij.lang.Language; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; +import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; @@ -29,32 +30,51 @@ import com.intellij.psi.xml.XmlChildRole; import com.intellij.psi.xml.XmlTag; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; public class XmlUnwrapDescriptor implements UnwrapDescriptor { public List> collectUnwrappers(Project project, Editor editor, PsiFile file) { - List> result = new ArrayList>(); - int offset = editor.getCaretModel().getOffset(); + PsiElement e1 = file.findElementAt(offset); if (e1 != null) { Language language = e1.getParent().getLanguage(); if (language != file.getLanguage()) { UnwrapDescriptor unwrapDescriptor = LanguageUnwrappers.INSTANCE.forLanguage(language); if (unwrapDescriptor != null && !(unwrapDescriptor instanceof XmlUnwrapDescriptor)) { - result.addAll(unwrapDescriptor.collectUnwrappers(project, editor, file)); + return unwrapDescriptor.collectUnwrappers(project, editor, file); } } } - PsiElement tag = PsiTreeUtil.getParentOfType(e1, XmlTag.class); - while (tag != null) { - if (XmlChildRole.START_TAG_END_FINDER.findChild(tag.getNode()) != null) { // Exclude implicit tags suck as 'jsp:root' - result.add(new Pair(tag, new XmlEnclosingTagUnwrapper())); + List> result = new ArrayList>(); + + FileViewProvider viewProvider = file.getViewProvider(); + + for (Language language : viewProvider.getLanguages()) { + UnwrapDescriptor unwrapDescriptor = LanguageUnwrappers.INSTANCE.forLanguage(language); + if (unwrapDescriptor instanceof XmlUnwrapDescriptor) { + PsiElement e = viewProvider.findElementAt(offset, language); + + PsiElement tag = PsiTreeUtil.getParentOfType(e, XmlTag.class); + while (tag != null) { + if (XmlChildRole.START_TAG_END_FINDER.findChild(tag.getNode()) != null) { // Exclude implicit tags suck as 'jsp:root' + result.add(new Pair(tag, new XmlEnclosingTagUnwrapper())); + } + tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class); + } } - tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class); } + Collections.sort(result, new Comparator>() { + @Override + public int compare(Pair o1, Pair o2) { + return o2.first.getTextOffset() - o1.first.getTextOffset(); + } + }); + return result; } diff --git a/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java b/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java index b7e035101ac2..c5e5ce97780d 100644 --- a/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java +++ b/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java @@ -19,6 +19,7 @@ import com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.HtmlTagTreeHighl import com.intellij.ide.highlighter.HtmlFileHighlighter; import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.editor.XmlHighlighterColors; +import com.intellij.openapi.editor.colors.ColorKey; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.fileTypes.SyntaxHighlighter; @@ -42,19 +43,6 @@ public class HTMLColorsPage implements ColorSettingsPage { }; private static final String FULL_PRODUCT_NAME = ApplicationNamesInfo.getInstance().getFullProductName(); - private static final ColorDescriptor[] COLOR_DESCRIPTORS; - - static { - COLOR_DESCRIPTORS = new ColorDescriptor[HtmlTagTreeHighlightingColors.COLOR_KEYS.length]; - - for (int i = 0; i < COLOR_DESCRIPTORS.length; i++) { - COLOR_DESCRIPTORS[i] = new ColorDescriptor(OptionsBundle.message("options.html.attribute.descriptor.tag.tree", i + 1), - HtmlTagTreeHighlightingColors.COLOR_KEYS[i], ColorDescriptor.Kind.BACKGROUND); - } - - // todo: make preview for it - } - @NotNull public String getDisplayName() { return OptionsBundle.message("options.html.display.name"); @@ -71,7 +59,17 @@ public class HTMLColorsPage implements ColorSettingsPage { @NotNull public ColorDescriptor[] getColorDescriptors() { - return COLOR_DESCRIPTORS; + // todo: make preview for it + + final ColorKey[] colorKeys = HtmlTagTreeHighlightingColors.getColorKeys(); + final ColorDescriptor[] colorDescriptors = new ColorDescriptor[colorKeys.length]; + + for (int i = 0; i < colorDescriptors.length; i++) { + colorDescriptors[i] = new ColorDescriptor(OptionsBundle.message("options.html.attribute.descriptor.tag.tree", i + 1), + colorKeys[i], ColorDescriptor.Kind.BACKGROUND); + } + + return colorDescriptors; } @NotNull diff --git a/xml/impl/src/com/intellij/xml/util/documentation/html5table.xml b/xml/impl/src/com/intellij/xml/util/documentation/html5table.xml index eabb39f455c8..94c2e45589a6 100644 --- a/xml/impl/src/com/intellij/xml/util/documentation/html5table.xml +++ b/xml/impl/src/com/intellij/xml/util/documentation/html5table.xml @@ -471,4 +471,52 @@ type = "string" default = "true" /> + + + + + + \ No newline at end of file