From 7a6ea4065f2a263a5bd1e845b501dc01cc46b860 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 23 Mar 2018 15:24:24 +0300 Subject: [PATCH 01/23] unused classes removed --- .../injected/editor/DocumentWindowImpl.java | 14 -------------- .../intellij/injected/editor/EditorWindowImpl.java | 6 ++++-- .../injected/editor/VirtualFileWindowImpl.java | 4 +++- .../source/tree/injected/DocumentWindowImpl.java | 8 ++++---- 4 files changed, 11 insertions(+), 21 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/injected/editor/DocumentWindowImpl.java diff --git a/platform/lang-impl/src/com/intellij/injected/editor/DocumentWindowImpl.java b/platform/lang-impl/src/com/intellij/injected/editor/DocumentWindowImpl.java deleted file mode 100644 index 8e365b538dde..000000000000 --- a/platform/lang-impl/src/com/intellij/injected/editor/DocumentWindowImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ -package com.intellij.injected.editor; - -import com.intellij.openapi.util.UserDataHolderBase; - -/** - * @deprecated use {@link DocumentWindow} instead - */ -@Deprecated -public abstract class DocumentWindowImpl extends UserDataHolderBase implements DocumentWindow { - public abstract int hostToInjectedUnescaped(int hostOffset); -} diff --git a/platform/lang-impl/src/com/intellij/injected/editor/EditorWindowImpl.java b/platform/lang-impl/src/com/intellij/injected/editor/EditorWindowImpl.java index a43a39308575..1bcd012bccbe 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/EditorWindowImpl.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/EditorWindowImpl.java @@ -6,12 +6,14 @@ import com.intellij.openapi.util.UserDataHolderBase; import org.jetbrains.annotations.NotNull; /** - * @deprecated Use {@link EditorWindow} instead. to be removed in IDEA 2018.1 + * @deprecated Use {@link EditorWindow} instead. To be removed in IDEA 2018.1 */ +@Deprecated public abstract class EditorWindowImpl extends UserDataHolderBase implements EditorWindow { /** - * @deprecated Use {@link EditorWindow#getDelegate()} instead. to be removed in IDEA 2018.1 + * @deprecated Use {@link EditorWindow#getDelegate()} instead. To be removed in IDEA 2018.1 */ + @Deprecated @NotNull @Override public Editor getDelegate() { diff --git a/platform/lang-impl/src/com/intellij/injected/editor/VirtualFileWindowImpl.java b/platform/lang-impl/src/com/intellij/injected/editor/VirtualFileWindowImpl.java index cf1b5af6bc00..95bb27d3190f 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/VirtualFileWindowImpl.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/VirtualFileWindowImpl.java @@ -7,8 +7,9 @@ import com.intellij.testFramework.LightVirtualFile; import org.jetbrains.annotations.NotNull; /** - * @deprecated Use {@link VirtualFileWindow} instead. to be removed in IDEA 2018.1 + * @deprecated Use {@link VirtualFileWindow} instead. To be removed in IDEA 2018.1 */ +@Deprecated public abstract class VirtualFileWindowImpl extends LightVirtualFile implements VirtualFileWindow { public VirtualFileWindowImpl(@NotNull String name, Language language, @@ -19,6 +20,7 @@ public abstract class VirtualFileWindowImpl extends LightVirtualFile implements /** * @deprecated Use {@link VirtualFileWindow#getDelegate()} instead. to be removed in IDEA 2018.1 */ + @Deprecated @NotNull @Override public VirtualFile getDelegate() { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/DocumentWindowImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/DocumentWindowImpl.java index a2cadd5f1aee..9567c76dcafc 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/DocumentWindowImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/DocumentWindowImpl.java @@ -29,7 +29,7 @@ import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; -class DocumentWindowImpl extends com.intellij.injected.editor.DocumentWindowImpl implements Disposable, DocumentWindow, DocumentEx { +class DocumentWindowImpl extends UserDataHolderBase implements Disposable, DocumentWindow, DocumentEx { private static final Logger LOG = Logger.getInstance("#com.intellij.injected.editor.DocumentWindowImpl"); private final DocumentEx myDelegate; private final boolean myOneLine; @@ -775,7 +775,7 @@ class DocumentWindowImpl extends com.intellij.injected.editor.DocumentWindowImpl // result[i] == "" means delete // result[i] == string means replace @NotNull - public String[] calculateMinEditSequence(String newText) { + String[] calculateMinEditSequence(String newText) { synchronized (myLock) { String[] result = new String[myShreds.size()]; String hostText = myDelegate.getText(); @@ -915,7 +915,7 @@ class DocumentWindowImpl extends com.intellij.injected.editor.DocumentWindowImpl } } - public void setShreds(@NotNull Place shreds) { + void setShreds(@NotNull Place shreds) { synchronized (myLock) { myShreds.dispose(); myShreds = shreds; @@ -923,7 +923,7 @@ class DocumentWindowImpl extends com.intellij.injected.editor.DocumentWindowImpl } @NotNull - public Place getShreds() { + Place getShreds() { synchronized (myLock) { return myShreds; } From 9c388b92a951c125649746983daff1cd6019ea91 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 23 Mar 2018 15:24:46 +0300 Subject: [PATCH 02/23] cleanup --- .../miscGenerics/RedundantTypeArgsInspection.java | 6 +++--- .../src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RedundantTypeArgsInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RedundantTypeArgsInspection.java index 51e264b2a21c..1c0fabf20c50 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RedundantTypeArgsInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RedundantTypeArgsInspection.java @@ -33,7 +33,7 @@ import java.util.List; public class RedundantTypeArgsInspection extends GenericsInspectionToolBase { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.miscGenerics.RedundantTypeArgsInspection"); - private final static LocalQuickFix ourQuickFixAction = new MyQuickFixAction(); + private static final LocalQuickFix ourQuickFixAction = new MyQuickFixAction(); public static final String SHORT_NAME = "RedundantTypeArguments"; @Override @@ -136,7 +136,7 @@ public class RedundantTypeArgsInspection extends GenericsInspectionToolBase { final PsiTypeElement qualifierTypeElement = expression.getQualifierType(); if (qualifierTypeElement != null) { final PsiType psiType = qualifierTypeElement.getType(); - if (psiType instanceof PsiClassType && !(((PsiClassType)psiType).isRaw())) { + if (psiType instanceof PsiClassType && !((PsiClassType)psiType).isRaw()) { PsiClass aClass = ((PsiClassType)psiType).resolve(); if (aClass == null) return; final JavaResolveResult result = expression.advancedResolve(false); @@ -164,7 +164,7 @@ public class RedundantTypeArgsInspection extends GenericsInspectionToolBase { PsiTypeParameter[] typeParameters = resolve instanceof PsiClass ? PsiTypeParameter.EMPTY_ARRAY : ((PsiMethod)resolve).getTypeParameters(); if (typeParameters.length == 0 || typeParameters.length == typeArguments.length && - PsiDiamondTypeUtil.areTypeArgumentsRedundant(typeArguments, expression, false, ((PsiMethod)resolve), typeParameters)) { + PsiDiamondTypeUtil.areTypeArgumentsRedundant(typeArguments, expression, false, (PsiMethod)resolve, typeParameters)) { String key = typeParameters.length == 0 ? "inspection.redundant.type.no.generics.method.reference.problem.descriptor" : "inspection.redundant.type.problem.descriptor"; final ProblemDescriptor descriptor = diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java index 526b01412c04..dcd8adb9c768 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/NewVirtualFile.java @@ -77,9 +77,6 @@ public abstract class NewVirtualFile extends VirtualFile implements VirtualFileW @Nullable @Deprecated public NewVirtualFile findChildById(int id) {return null;} - @Nullable @Deprecated - public NewVirtualFile findChildByIdIfCached(int id) {return null;} - @Override public void refresh(final boolean asynchronous, final boolean recursive, final Runnable postRunnable) { RefreshQueue.getInstance().refresh(asynchronous, recursive, postRunnable, this); From 10281db5302ccf13bee0fba142bf592168889f86 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 23 Mar 2018 18:39:22 +0300 Subject: [PATCH 03/23] format leaked project info properly --- .../testFramework/PlatformTestCase.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 68cc57deb24b..1d41be0671a7 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -91,8 +91,6 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; -import static com.intellij.testFramework.TemporaryDirectoryKt.generateTemporaryPath; - /** * @author yole */ @@ -308,7 +306,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro int hashCode = System.identityHashCode(leaked); leakers.append("Leaked project found:").append(leaked).append("; hash: ").append(hashCode).append("; place: ") .append(getCreationPlace(leaked)).append("\n"); - leakers.append(backLink+"\n"); + leakers.append(backLink).append("\n"); leakers.append(";-----\n"); hashCodes.remove(hashCode); @@ -324,7 +322,6 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro @NotNull @TestOnly public static String getCreationPlace(@NotNull Project project) { - String place = project.getUserData(CREATION_PLACE); Object base; try { base = project.isDisposed() ? "" : project.getBaseDir(); @@ -332,7 +329,8 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro catch (Exception e) { base = " (" + e + " while getting base dir)"; } - return project + (place != null ? place : "") + base; + String place = project.getUserData(CREATION_PLACE); + return project + " " +(place == null ? "" : place) + base; } protected void runStartupActivities() { @@ -364,7 +362,8 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro } } - Path tempFile = generateTemporaryPath(FileUtil.sanitizeFileName(getName(), false) + (isDirectoryBasedProject ? "" : ProjectFileType.DOT_DEFAULT_EXTENSION)); + Path tempFile = TemporaryDirectoryKt + .generateTemporaryPath(FileUtil.sanitizeFileName(getName(), false) + (isDirectoryBasedProject ? "" : ProjectFileType.DOT_DEFAULT_EXTENSION)); myFilesToDelete.add(tempFile.toFile()); return tempFile; } @@ -601,14 +600,8 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro resetClassFields(aClass.getSuperclass()); } - private String getFullName() { - return getClass().getName() + "." + getName(); - } - protected void setUpJdk() { - //final ProjectJdkEx jdk = ProjectJdkUtil.getDefaultJdk("java 1.4"); final Sdk jdk = getTestProjectJdk(); -// ProjectJdkImpl jdk = ProjectJdkTable.getInstance().addJdk(defaultJdk); Module[] modules = ModuleManager.getInstance(myProject).getModules(); for (Module module : modules) { ModuleRootModificationUtil.setModuleSdk(module, jdk); @@ -635,8 +628,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro resetAllFields(); }); } - catch (Throwable e) { - // Ignore + catch (Throwable ignored) { } } } From 13a00272c3a55fb1046aa250bec199119c81ba91 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 23 Mar 2018 18:42:38 +0300 Subject: [PATCH 04/23] moved parseFile() outside injection lock because just calculating substituted language could potentially cause crazy method inheritors search in Spring/Hibernate shtuff: IDEA-188783 Intellij IDEA 2018.1RC#IU-181.4203.519 freezes frequently on start and during project build --- .../tree/injected/InjectionRegistrarImpl.java | 123 +++++++++--------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectionRegistrarImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectionRegistrarImpl.java index 7fc8d23c761c..a4e9175b1f7e 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectionRegistrarImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectionRegistrarImpl.java @@ -267,16 +267,15 @@ class InjectionRegistrarImpl extends MultiHostRegistrarImpl implements MultiHost place.add(shred); info.newInjectionHostRange = shred.getSmartPointer().getRange(); } + DocumentWindowImpl documentWindow = new DocumentWindowImpl(hostDocument, place); + String fileName = PathUtil.makeFileName(hostVirtualFile.getName(), injectedFileExtension); + + ASTNode parsedNode = + parseFile(language, forcedLanguage, documentWindow, hostVirtualFile, hostDocument, hostPsiFile, project, documentWindow.getText(), + placeInfos, decodedChars, fileName); + PsiFile psiFile = (PsiFile)parsedNode.getPsi(); + InjectedFileViewProvider viewProvider = (InjectedFileViewProvider)psiFile.getViewProvider(); synchronized (InjectedLanguageManagerImpl.ourInjectionPsiLock) { - DocumentWindowImpl documentWindow = new DocumentWindowImpl(hostDocument, place); - String fileName = PathUtil.makeFileName(hostVirtualFile.getName(), injectedFileExtension); - - ASTNode parsedNode = - parseFile(language, forcedLanguage, documentWindow, hostVirtualFile, hostDocument, hostPsiFile, project, documentWindow.getText(), - placeInfos, decodedChars, fileName); - PsiFile psiFile = (PsiFile)parsedNode.getPsi(); - InjectedFileViewProvider viewProvider = (InjectedFileViewProvider)psiFile.getViewProvider(); - cacheEverything(place, documentWindow, viewProvider, psiFile); PsiFile cachedPsiFile = documentManager.getCachedPsiFile(documentWindow); @@ -551,65 +550,64 @@ class InjectionRegistrarImpl extends MultiHostRegistrarImpl implements MultiHost @NotNull PsiFile hostPsiFile, @NotNull ProgressIndicator indicator, @NotNull ASTNode oldRoot, @NotNull ASTNode newRoot) { - synchronized (InjectedLanguageManagerImpl.ourInjectionPsiLock) { - Project project = hostPsiFile.getProject(); - String newText = oldDocumentWindow.getText(); - FileASTNode oldNode = oldInjectedPsi.getNode(); - InjectedFileViewProvider oldInjectedPsiViewProvider = (InjectedFileViewProvider)oldInjectedPsi.getViewProvider(); - String oldPsiText = oldNode.getText(); - if (newText.equals(oldPsiText)) return ()->true; - if (oldDocumentWindow.isOneLine() && newText.contains("\n") != oldPsiText.contains("\n")) { - // one-lineness changed, e.g. when enter pressed in the middle of a string literal + Project project = hostPsiFile.getProject(); + String newText = oldDocumentWindow.getText(); + FileASTNode oldNode = oldInjectedPsi.getNode(); + InjectedFileViewProvider oldInjectedPsiViewProvider = (InjectedFileViewProvider)oldInjectedPsi.getViewProvider(); + String oldPsiText = oldNode.getText(); + if (newText.equals(oldPsiText)) return ()->true; + if (oldDocumentWindow.isOneLine() && newText.contains("\n") != oldPsiText.contains("\n")) { + // one-lineness changed, e.g. when enter pressed in the middle of a string literal + return null; + } + Place oldPlace = oldDocumentWindow.getShreds(); + // can be different from newText if decode fails in the middle and we'll have to shrink the document + StringBuilder newDocumentText = new StringBuilder(newText.length()); + // we need escaper but it only works with committed PSI, + // so we get the committed (but not yet applied) PSI from the commit-document-in-the-background process + // and find the corresponding injection host there + // and create literal escaper from that new (dummy) psi + List placeInfos = new SmartList<>(); + StringBuilder chars = new StringBuilder(); + for (PsiLanguageInjectionHost.Shred shred : oldPlace) { + PsiLanguageInjectionHost oldHost = shred.getHost(); + if (oldHost == null) return null; + SmartPsiElementPointer hostPointer = ((ShredImpl)shred).getSmartPointer(); + Segment newInjectionHostRange = calcActualRange(hostPsiFile, oldDocumentWindow.getDelegate(), hostPointer.getPsiRange()); + if (newInjectionHostRange == null) return null; + PsiLanguageInjectionHost newDummyInjectionHost = findNewInjectionHost(hostPsiFile, oldRoot, newRoot, oldHost, newInjectionHostRange); + if (newDummyInjectionHost == null) { return null; } - Place oldPlace = oldDocumentWindow.getShreds(); - // can be different from newText if decode fails in the middle and we'll have to shrink the document - StringBuilder newDocumentText = new StringBuilder(newText.length()); - // we need escaper but it only works with committed PSI, - // so we get the committed (but not yet applied) PSI from the commit-document-in-the-background process - // and find the corresponding injection host there - // and create literal escaper from that new (dummy) psi - List placeInfos = new SmartList<>(); - StringBuilder chars = new StringBuilder(); - for (PsiLanguageInjectionHost.Shred shred : oldPlace) { - PsiLanguageInjectionHost oldHost = shred.getHost(); - if (oldHost == null) return null; - SmartPsiElementPointer hostPointer = ((ShredImpl)shred).getSmartPointer(); - Segment newInjectionHostRange = calcActualRange(hostPsiFile, oldDocumentWindow.getDelegate(), hostPointer.getPsiRange()); - if (newInjectionHostRange == null) return null; - PsiLanguageInjectionHost newDummyInjectionHost = findNewInjectionHost(hostPsiFile, oldRoot, newRoot, oldHost, newInjectionHostRange); - if (newDummyInjectionHost == null) { - return null; - } - newInjectionHostRange = newDummyInjectionHost.getTextRange().shiftRight(oldRoot.getTextRange().getStartOffset()); - Segment hostInjectionRange = shred.getHostRangeMarker(); // in the new document - if (hostInjectionRange == null) return null; - TextRange rangeInsideHost = TextRange.create(hostInjectionRange).shiftLeft(newInjectionHostRange.getStartOffset()); + newInjectionHostRange = newDummyInjectionHost.getTextRange().shiftRight(oldRoot.getTextRange().getStartOffset()); + Segment hostInjectionRange = shred.getHostRangeMarker(); // in the new document + if (hostInjectionRange == null) return null; + TextRange rangeInsideHost = TextRange.create(hostInjectionRange).shiftLeft(newInjectionHostRange.getStartOffset()); - PlaceInfo info = new PlaceInfo(shred.getPrefix(), shred.getSuffix(), newDummyInjectionHost, rangeInsideHost); - placeInfos.add(info); - info.newInjectionHostRange = newInjectionHostRange; + PlaceInfo info = new PlaceInfo(shred.getPrefix(), shred.getSuffix(), newDummyInjectionHost, rangeInsideHost); + placeInfos.add(info); + info.newInjectionHostRange = newInjectionHostRange; - decode(info, chars); + decode(info, chars); - // pass the old pointers because their offsets will be adjusted automatically (SmartPsiElementPointer does that) - TextRange rangeInHostElementPSI = info.rangeInHostElement; + // pass the old pointers because their offsets will be adjusted automatically (SmartPsiElementPointer does that) + TextRange rangeInHostElementPSI = info.rangeInHostElement; - newDocumentText.append(shred.getPrefix()); - newDocumentText.append(newDummyInjectionHost.getText(), rangeInHostElementPSI.getStartOffset(), rangeInHostElementPSI.getEndOffset()); - newDocumentText.append(shred.getSuffix()); - } - // newDocumentText can be shorter if decode failed - //assert newText.equals(newDocumentText.toString()) : "-\n"+newText+"\n--\n"+newDocumentText+"\n---\n"; - - PsiDocumentManagerBase documentManager = (PsiDocumentManagerBase)PsiDocumentManager.getInstance(project); - DocumentEx hostDocument = oldDocumentWindow.getDelegate(); - assert documentManager.isUncommited(hostDocument); - String fileName = ((VirtualFileWindowImpl)oldInjectedVirtualFile).getName(); - ASTNode parsedNode = parseFile(language, language, oldDocumentWindow, - hostVirtualFile, hostDocument, hostPsiFile, project, newDocumentText, placeInfos, chars, - fileName); + newDocumentText.append(shred.getPrefix()); + newDocumentText.append(newDummyInjectionHost.getText(), rangeInHostElementPSI.getStartOffset(), rangeInHostElementPSI.getEndOffset()); + newDocumentText.append(shred.getSuffix()); + } + // newDocumentText can be shorter if decode failed + //assert newText.equals(newDocumentText.toString()) : "-\n"+newText+"\n--\n"+newDocumentText+"\n---\n"; + PsiDocumentManagerBase documentManager = (PsiDocumentManagerBase)PsiDocumentManager.getInstance(project); + DocumentEx hostDocument = oldDocumentWindow.getDelegate(); + assert documentManager.isUncommited(hostDocument); + String fileName = ((VirtualFileWindowImpl)oldInjectedVirtualFile).getName(); + ASTNode parsedNode = parseFile(language, language, oldDocumentWindow, + hostVirtualFile, hostDocument, hostPsiFile, project, newDocumentText, placeInfos, chars, + fileName); + synchronized (InjectedLanguageManagerImpl.ourInjectionPsiLock) { DiffLog diffLog = BlockSupportImpl.mergeTrees((PsiFileImpl)oldInjectedPsi, oldNode, parsedNode, indicator, oldPsiText); return () -> { @@ -682,7 +680,6 @@ class InjectionRegistrarImpl extends MultiHostRegistrarImpl implements MultiHost virtualFile.setContent(null, decodedChars, false); virtualFile.setWritable(virtualFile.getDelegate().isWritable()); - try { List tokens = obtainHighlightTokensFromLexer(language, decodedChars, virtualFile, project, placeInfos); InjectedLanguageUtil.setHighlightTokens(psiFile, tokens); @@ -774,7 +771,7 @@ class InjectionRegistrarImpl extends MultiHostRegistrarImpl implements MultiHost int suffixLength = 0; TextRange rangeInsideHost = null; int shredEndOffset = -1; - List tokens = new ArrayList<>(10); + List tokens = new ArrayList<>(outChars.length()/5); // avg. token per 5 chars for (IElementType tokenType = lexer.getTokenType(); tokenType != null; lexer.advance(), tokenType = lexer.getTokenType()) { TextRange range = new ProperTextRange(lexer.getTokenStart(), lexer.getTokenEnd()); while (range != null && !range.isEmpty()) { From b733a8fb65c2c778191f73db225de55fe6420dfd Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 23 Mar 2018 18:44:05 +0300 Subject: [PATCH 05/23] removed unused ctr --- .../codeStyle/CodeStyleSettingsManager.java | 3 -- .../ProjectCodeStyleSettingsManager.java | 40 +++++++------------ 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsManager.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsManager.java index a76cd191b018..3ffaafd60826 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsManager.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsManager.java @@ -67,9 +67,6 @@ public class CodeStyleSettingsManager implements PersistentStateComponent mySettingsMap = ContainerUtil.newHashMap(); - private final static NotificationGroup NOTIFICATION_GROUP = + private static final NotificationGroup NOTIFICATION_GROUP = new NotificationGroup("Code style settings migration", NotificationDisplayType.STICKY_BALLOON, true); - @SuppressWarnings("unused") - public ProjectCodeStyleSettingsManager(Project project) { - this(); - } - public ProjectCodeStyleSettingsManager() { setMainProjectCodeStyle(null); } @@ -89,7 +80,6 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { @Override public void setMainProjectCodeStyle(@Nullable CodeStyleSettings settings) { // TODO: Remove the assignment below when there are no direct usages of PER_PROJECT_SETTINGS. - //noinspection deprecation PER_PROJECT_SETTINGS = settings; mySettingsMap.put(MAIN_PROJECT_CODE_STYLE_NAME, settings != null ? settings : new CodeStyleSettings()); } @@ -101,13 +91,12 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { } private void initDefaults() { - @SuppressWarnings("deprecation") CodeStyleSettingsManager appCodeStyleSettingsManager = CodeStyleSettingsManager.getInstance(); if (appCodeStyleSettingsManager != null) { CodeStyleSettings defaultProjectSettings = appCodeStyleSettingsManager.getMainProjectCodeStyle(); setMainProjectCodeStyle(defaultProjectSettings != null ? defaultProjectSettings.clone() : null); - this.USE_PER_PROJECT_SETTINGS = appCodeStyleSettingsManager.USE_PER_PROJECT_SETTINGS; - this.PREFERRED_PROJECT_CODE_STYLE = appCodeStyleSettingsManager.PREFERRED_PROJECT_CODE_STYLE; + USE_PER_PROJECT_SETTINGS = appCodeStyleSettingsManager.USE_PER_PROJECT_SETTINGS; + PREFERRED_PROJECT_CODE_STYLE = appCodeStyleSettingsManager.PREFERRED_PROJECT_CODE_STYLE; } myIsLoaded = true; } @@ -116,8 +105,8 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { public void loadState(@NotNull Element state) { super.loadState(state); updateFromOldProjectSettings(); - for (Element subStyle : state.getChildren(CODE_STYLE_TAG_NAME)) { - String name = subStyle.getAttributeValue(CODE_STYLE_NAME_ATTR); + for (Element subStyle : state.getChildren(CodeStyleScheme.CODE_STYLE_TAG_NAME)) { + String name = subStyle.getAttributeValue(CodeStyleScheme.CODE_STYLE_NAME_ATTR); CodeStyleSettings settings = new CodeStyleSettings(); settings.readExternal(subStyle); if (MAIN_PROJECT_CODE_STYLE_NAME.equals(name)) { @@ -130,7 +119,6 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { myIsLoaded = true; } - @SuppressWarnings("deprecation") private void updateFromOldProjectSettings() { CodeStyleSettings oldProjectSettings = PER_PROJECT_SETTINGS; if (oldProjectSettings != null) oldProjectSettings.resetDeprecatedFields(); @@ -143,8 +131,8 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { if (e != null) { for (String name : mySettingsMap.keySet()) { CodeStyleSettings settings = mySettingsMap.get(name); - Element codeStyle = new Element(CODE_STYLE_TAG_NAME); - codeStyle.setAttribute(CODE_STYLE_NAME_ATTR, name); + Element codeStyle = new Element(CodeStyleScheme.CODE_STYLE_TAG_NAME); + codeStyle.setAttribute(CodeStyleScheme.CODE_STYLE_NAME_ATTR, name); settings.writeExternal(codeStyle); if (!codeStyle.getContent().isEmpty()) { e.addContent(codeStyle); @@ -155,7 +143,7 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { } private static class CodeStyleMigrationNotification extends Notification { - public CodeStyleMigrationNotification(@NotNull String projectName) { + CodeStyleMigrationNotification(@NotNull String projectName) { super(NOTIFICATION_GROUP.getDisplayId(), ApplicationBundle.message("project.code.style.migration.title"), ApplicationBundle.message("project.code.style.migration.message", projectName), @@ -165,7 +153,7 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { } private static class ShowMoreInfoAction extends DumbAwareAction { - public ShowMoreInfoAction() { + ShowMoreInfoAction() { super("More info"); } @@ -190,13 +178,13 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { @NotNull @Override protected String getSubStateTagName() { - return CODE_STYLE_TAG_NAME; + return CodeStyleScheme.CODE_STYLE_TAG_NAME; } @NotNull @Override protected String getSubStateFileName(@NotNull Element element) { - return element.getAttributeValue(CODE_STYLE_NAME_ATTR); + return element.getAttributeValue(CodeStyleScheme.CODE_STYLE_NAME_ATTR); } } } From 1979558fc818bfb9f834f833dbc5837ce54a0765 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 23 Mar 2018 18:47:22 +0300 Subject: [PATCH 06/23] removed usages of deprecated method --- .../completion/JavadocCompletionTest.groovy | 3 ++- .../completion/WordCompletionTest.java | 5 ++-- .../reference/PsiReferenceRegistrarImpl.java | 23 ++----------------- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/JavadocCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/JavadocCompletionTest.groovy index 64835dfe866b..9b3cb3684b36 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/JavadocCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/JavadocCompletionTest.groovy @@ -22,6 +22,7 @@ import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection import com.intellij.lang.java.JavaLanguage +import com.intellij.patterns.PlatformPatterns import com.intellij.psi.PsiElement import com.intellij.psi.PsiReference import com.intellij.psi.PsiReferenceBase @@ -610,7 +611,7 @@ class Foo { } } try { - registrar.registerReferenceProvider(PsiDocTag.class, provider) + registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiDocTag.class), provider) configureByFile("ReferenceProvider.java") assertStringItems("1", "2", "3") } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/WordCompletionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/WordCompletionTest.java index f8a9db8762f4..fe7fb0fbc396 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/WordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/WordCompletionTest.java @@ -18,6 +18,7 @@ package com.intellij.java.codeInsight.completion; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.completion.CompletionTestCase; import com.intellij.lang.StdLanguages; +import com.intellij.patterns.PlatformPatterns; import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl; import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; @@ -89,8 +90,8 @@ public class WordCompletionTest extends CompletionTestCase { PsiReferenceRegistrarImpl registrar = (PsiReferenceRegistrarImpl)ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA); try { - registrar.registerReferenceProvider(PsiLiteralExpression.class, softProvider); - registrar.registerReferenceProvider(PsiLiteralExpression.class, hardProvider); + registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), softProvider); + registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), hardProvider); configureByFile(BASE_PATH + "3.java"); checkResultByFile(BASE_PATH + "3_after.java"); diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java index 38324dfc7475..71c5e862eb78 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.source.resolve.reference; -import com.intellij.lang.Language; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.patterns.*; @@ -46,15 +45,6 @@ public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { private final ConcurrentMap myBindingCache; private boolean myInitialized; - /** - * @deprecated To be removed in 2018.2 - */ - @Deprecated - @SuppressWarnings("unused") - public PsiReferenceRegistrarImpl(final Language language) { - this(); - } - PsiReferenceRegistrarImpl() { myBindingCache = ConcurrentFactoryMap.createMap(key-> { List result = ContainerUtil.newSmartList(); @@ -74,7 +64,7 @@ public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { ); } - public void markInitialized() { + void markInitialized() { myInitialized = true; } @@ -143,18 +133,9 @@ public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { providerBinding.registerProvider(names, pattern, caseSensitive, provider, priority); } - /** - * @see com.intellij.psi.PsiReferenceContributor - * @deprecated - */ - public void registerReferenceProvider(@NotNull Class scope, @NotNull PsiReferenceProvider provider) { - registerReferenceProvider(PlatformPatterns.psiElement(scope), provider, DEFAULT_PRIORITY); - } - @NotNull List> getPairsByElement(@NotNull PsiElement element, - @NotNull PsiReferenceService.Hints hints) { - + @NotNull PsiReferenceService.Hints hints) { final ProviderBinding[] bindings = myBindingCache.get(element.getClass()); if (bindings.length == 0) return Collections.emptyList(); From 7041a9a83ebc9120fbb68b3282dcc2a8ed26517b Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 23 Mar 2018 16:15:13 +0100 Subject: [PATCH 07/23] UI DSL: use V/H GAP consts from UIUtil --- .../src/com/intellij/ui/layout/layoutImpl.kt | 3 --- .../intellij/ui/layout/migLayout/MigLayoutBuilder.kt | 11 ++++++----- .../com/intellij/ui/layout/migLayout/MigLayoutRow.kt | 7 ++++--- .../ui/layout/align fields in the nested grid.yml | 4 ++-- .../testData/ui/layout/align fields.yml | 2 +- .../testData/ui/layout/note row in the dialog.yml | 12 ++++++------ .../testSrc/com/intellij/ui/layout/UiDslTest.kt | 10 ++++++---- .../projectModel-api/src/com/intellij/util/jdom.kt | 6 +++--- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/layout/layoutImpl.kt b/platform/platform-impl/src/com/intellij/ui/layout/layoutImpl.kt index b001ef1e9e13..a0d4ce9b42c7 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/layoutImpl.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/layoutImpl.kt @@ -9,9 +9,6 @@ import javax.swing.JLabel // see com.intellij.uiDesigner.core.AbstractLayout.DEFAULT_HGAP and DEFAULT_VGAP // https://docs.google.com/document/d/1DKnLkO-7_onA7_NCw669aeMH5ltNvw-QMiQHnXu8k_Y/edit -internal const val HORIZONTAL_GAP = 10 -internal const val VERTICAL_GAP = 5 - @PublishedApi internal fun createLayoutBuilder() = LayoutBuilder(MigLayoutBuilder()) diff --git a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutBuilder.kt b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutBuilder.kt index dcb086ff5372..d784fedc86e1 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutBuilder.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutBuilder.kt @@ -5,6 +5,7 @@ import com.intellij.icons.AllIcons import com.intellij.ui.components.noteComponent import com.intellij.ui.layout.* import com.intellij.util.containers.ContainerUtil +import com.intellij.util.ui.UIUtil import net.miginfocom.layout.* import net.miginfocom.swing.MigLayout import java.awt.Component @@ -32,8 +33,8 @@ internal class MigLayoutBuilder : LayoutBuilderImpl { newRow() val cc = CC() - cc.vertical.gapBefore = gapToBoundSize(VERTICAL_GAP, false) - cc.vertical.gapAfter = gapToBoundSize(VERTICAL_GAP * 2, false) + cc.vertical.gapBefore = gapToBoundSize(UIUtil.DEFAULT_VGAP, false) + cc.vertical.gapAfter = gapToBoundSize(UIUtil.DEFAULT_VGAP * 2, false) val row = rootRow.createChildRow(label = null, noGrid = true) row.apply { @@ -78,7 +79,7 @@ internal class MigLayoutBuilder : LayoutBuilderImpl { // https://goo.gl/LDylKm // gap = 10u where u = 4px - gapTop = VERTICAL_GAP * 3 + gapTop = UIUtil.DEFAULT_VGAP * 3 } var isSplitRequired = true @@ -140,7 +141,7 @@ internal class MigLayoutBuilder : LayoutBuilderImpl { // do not add gap if next component is gear action button if (component !== lastComponent && !row.components.get(index + 1).let { it is JLabel && it.icon === AllIcons.General.Gear }) { - cc.horizontal.gapAfter = gapToBoundSize(HORIZONTAL_GAP * 2, true) + cc.horizontal.gapAfter = gapToBoundSize(UIUtil.DEFAULT_HGAP * 2, true) } } } @@ -190,7 +191,7 @@ internal fun gapToBoundSize(value: Int, isHorizontal: Boolean): BoundSize { // default values differs to MigLayout - IntelliJ Platform defaults are used // see com.intellij.uiDesigner.core.AbstractLayout.DEFAULT_HGAP and DEFAULT_VGAP (multiplied by 2 to achieve the same look (it seems in terms of MigLayout gap is both left and right space)) -private fun createLayoutConstraints(gridGapX: Int = HORIZONTAL_GAP * 2, gridGapY: Int = VERTICAL_GAP): LC { +private fun createLayoutConstraints(gridGapX: Int = UIUtil.DEFAULT_HGAP * 2, gridGapY: Int = UIUtil.DEFAULT_VGAP): LC { // no setter for gap, so, create string to parse val lc = LC() lc.gridGapX = gapToBoundSize(gridGapX, true) diff --git a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt index 05723cb37c0a..5236d7c0f78a 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt @@ -12,6 +12,7 @@ import com.intellij.ui.components.Label import com.intellij.ui.layout.* import com.intellij.util.SmartList import com.intellij.util.ui.JBUI +import com.intellij.util.ui.UIUtil import net.miginfocom.layout.BoundSize import net.miginfocom.layout.CC import net.miginfocom.layout.ConstraintParser @@ -53,8 +54,8 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?, row.apply { val separatorComponent = SeparatorComponent(0, OnePixelDivider.BACKGROUND, null) val cc = CC() - cc.vertical.gapBefore = gapToBoundSize(VERTICAL_GAP * 3, false) - cc.vertical.gapAfter = gapToBoundSize(VERTICAL_GAP * 2, false) + cc.vertical.gapBefore = gapToBoundSize(UIUtil.LARGE_VGAP, false) + cc.vertical.gapAfter = gapToBoundSize(UIUtil.DEFAULT_VGAP * 2, false) componentConstraints.put(separatorComponent, cc) separatorComponent() } @@ -80,7 +81,7 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?, return ComponentPanelBuilder.computeCommentInsets(firstComponent, true).left } else { - return HORIZONTAL_GAP * 3 + return UIUtil.DEFAULT_HGAP * 3 } } } diff --git a/platform/platform-tests/testData/ui/layout/align fields in the nested grid.yml b/platform/platform-tests/testData/ui/layout/align fields in the nested grid.yml index 26070d23fad1..163ece913059 100644 --- a/platform/platform-tests/testData/ui/layout/align fields in the nested grid.yml +++ b/platform/platform-tests/testData/ui/layout/align fields in the nested grid.yml @@ -39,5 +39,5 @@ componentConstrains: skip: 1 spanX: 2097051 wrap: true -rectangles: '[0, 0, 512, 23], [0, 28, 132, 26], [152, 28, 360, 26], [152, 28, 360, - 26], [0, 59, 132, 26], [152, 59, 360, 26], [152, 85, 360, 14]' +rectangles: '[0, 0, 512, 23], [0, 27, 132, 26], [152, 27, 360, 26], [152, 27, 360, + 26], [0, 57, 132, 26], [152, 57, 360, 26], [152, 83, 360, 14]' diff --git a/platform/platform-tests/testData/ui/layout/align fields.yml b/platform/platform-tests/testData/ui/layout/align fields.yml index 808858c8f111..2be01b43f3c1 100644 --- a/platform/platform-tests/testData/ui/layout/align fields.yml +++ b/platform/platform-tests/testData/ui/layout/align fields.yml @@ -14,5 +14,5 @@ componentConstrains: 'JTextField #3': horizontal: {grow: 100.0} wrap: true -rectangles: '[0, 0, 145, 23], [165, 0, 347, 23], [0, 28, 145, 26], [165, 28, 347, +rectangles: '[0, 0, 145, 23], [165, 0, 347, 23], [0, 27, 145, 26], [165, 27, 347, 26]' diff --git a/platform/platform-tests/testData/ui/layout/note row in the dialog.yml b/platform/platform-tests/testData/ui/layout/note row in the dialog.yml index 5eb0d37cd428..7fe4c32beb3e 100644 --- a/platform/platform-tests/testData/ui/layout/note row in the dialog.yml +++ b/platform/platform-tests/testData/ui/layout/note row in the dialog.yml @@ -12,10 +12,10 @@ componentConstrains: spanX: 2097051 vertical: gapAfter: - min: &id001 {horizontal: false, operation: 100, unit: 0, unitString: px, value: 10.0} + min: &id001 {horizontal: false, operation: 100, unit: 0, unitString: px, value: 8.0} preferred: *id001 gapBefore: - min: &id002 {horizontal: false, operation: 100, unit: 0, unitString: px, value: 5.0} + min: &id002 {horizontal: false, operation: 100, unit: 0, unitString: px, value: 4.0} preferred: *id002 wrap: true 'JLabel #1': {} @@ -25,11 +25,11 @@ componentConstrains: spanX: 2097051 vertical: gapAfter: - min: &id003 {horizontal: false, operation: 100, unit: 0, unitString: px, value: 10.0} + min: &id003 {horizontal: false, operation: 100, unit: 0, unitString: px, value: 8.0} preferred: *id003 gapBefore: - min: &id004 {horizontal: false, operation: 100, unit: 0, unitString: px, value: 15.0} + min: &id004 {horizontal: false, operation: 100, unit: 0, unitString: px, value: 12.0} preferred: *id004 wrap: true -rectangles: '[0, 0, 512, 47], [0, 52, 99, 26], [119, 52, 393, 26], [119, 83, 393, - 23], [0, 111, 512, 41]' +rectangles: '[0, 0, 512, 44], [0, 48, 99, 26], [119, 48, 393, 26], [119, 78, 393, + 23], [0, 105, 512, 36]' diff --git a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt index 9c47094bd74e..cdd867ce9d89 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt @@ -14,6 +14,7 @@ import com.intellij.util.io.exists import com.intellij.util.io.outputStream import com.intellij.util.io.sanitizeFileName import com.intellij.util.io.write +import io.netty.util.internal.SystemPropertyUtil import net.miginfocom.layout.Grid import net.miginfocom.layout.LayoutUtil import net.miginfocom.swing.MigLayout @@ -139,11 +140,12 @@ class UiDslTest { val actualLayoutJson = configurationToJson(component, component.layout as MigLayout, false, rectangles.joinToString(", ") { "[${it.joinToString(", ")}]" }) try { val expectedLayoutDataFile = Paths.get(PlatformTestUtil.getPlatformTestDataPath(), "ui", "layout", "$imageName.yml") - if (expectedLayoutDataFile.exists()) { - Assertions.assertThat(actualLayoutJson).isEqualTo(expectedLayoutDataFile) + val isUpdateSnapshots = SystemPropertyUtil.getBoolean("test.update.snapshots", false) + if (!expectedLayoutDataFile.exists() || isUpdateSnapshots) { + expectedLayoutDataFile.write(actualLayoutJson) } else { - expectedLayoutDataFile.write(actualLayoutJson) + Assertions.assertThat(actualLayoutJson).isEqualTo(expectedLayoutDataFile) } if (imageDir.isNullOrEmpty()) { @@ -151,7 +153,7 @@ class UiDslTest { } val imagePath = Paths.get(imageDir, "$imageName.png") - if (!imagePath.exists()) { + if (!imagePath.exists() || isUpdateSnapshots) { System.out.println("Write a new snapshot image ${imagePath.fileName}") saveImage(imagePath) return diff --git a/platform/projectModel-api/src/com/intellij/util/jdom.kt b/platform/projectModel-api/src/com/intellij/util/jdom.kt index 711ad514e8d5..ab965e697b49 100644 --- a/platform/projectModel-api/src/com/intellij/util/jdom.kt +++ b/platform/projectModel-api/src/com/intellij/util/jdom.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util import com.intellij.openapi.util.JDOMUtil @@ -39,8 +39,8 @@ private fun getSaxBuilder(): SAXBuilder { } saxBuilder.ignoringBoundaryWhitespace = true saxBuilder.ignoringElementContentWhitespace = true - saxBuilder.entityResolver = EntityResolver { publicId, systemId -> InputSource(CharArrayReader(ArrayUtil.EMPTY_CHAR_ARRAY)) } - cachedSaxBuilder.set(SoftReference(saxBuilder)) + saxBuilder.entityResolver = EntityResolver { _, _ -> InputSource(CharArrayReader(ArrayUtil.EMPTY_CHAR_ARRAY)) } + cachedSaxBuilder.set(SoftReference(saxBuilder)) } return saxBuilder } From 99cbb28191fefc4ddcf85262a421cc3aff0ff194 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 23 Mar 2018 17:42:20 +0100 Subject: [PATCH 08/23] revert to use encodeHexString (Guava also has difference, so, revert as before) --- .../facet/impl/ui/libraries/RequiredLibrariesInfo.java | 4 ++-- plugins/hg4idea/intellij.vcs.hg.iml | 1 + .../hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java index c8e23e374026..cf4a865ad493 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java @@ -8,13 +8,13 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; +import org.apache.commons.codec.binary.Hex; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Arrays; -import java.util.Base64; import java.util.List; /** @@ -76,7 +76,7 @@ public class RequiredLibrariesInfo { md5.update(file.contentsToByteArray()); final byte[] digest = md5.digest(); - return Base64.getEncoder().encodeToString(digest); + return new String(Hex.encodeHex(digest)); } catch (Exception e) { return null; diff --git a/plugins/hg4idea/intellij.vcs.hg.iml b/plugins/hg4idea/intellij.vcs.hg.iml index 5c6520e0ac30..ec254ed1bb80 100644 --- a/plugins/hg4idea/intellij.vcs.hg.iml +++ b/plugins/hg4idea/intellij.vcs.hg.iml @@ -24,5 +24,6 @@ + \ No newline at end of file diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java index 77ddd182cd36..8fb1d813e29f 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java @@ -11,6 +11,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.vcs.log.Hash; import com.intellij.vcs.log.VcsLogObjectsFactory; +import org.apache.commons.codec.binary.Hex; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgNameWithHashInfo; @@ -104,7 +105,7 @@ public class HgRepositoryReader { public String readCurrentRevision() { if (!isDirStateInfoAvailable()) return null; try { - return Base64.getEncoder().encodeToString(readHashBytesFromFile(myDirStateFile)); + return Hex.encodeHexString(readHashBytesFromFile(myDirStateFile)); } catch (IOException e) { // dirState exists if not fresh, if we could not load dirState info repository must be corrupted From d40652358651ed673a65ce217a92bdcb7b6722b9 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 23 Mar 2018 17:48:37 +0100 Subject: [PATCH 09/23] since Guava already in the deps, use BaseEncoding instead of commons-codec --- .../facet/impl/ui/libraries/RequiredLibrariesInfo.java | 4 ++-- plugins/hg4idea/intellij.vcs.hg.iml | 1 - .../hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java index cf4a865ad493..7ece39597eb6 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java @@ -2,13 +2,13 @@ package com.intellij.facet.impl.ui.libraries; +import com.google.common.io.BaseEncoding; import com.intellij.facet.ui.libraries.LibraryInfo; import com.intellij.openapi.roots.libraries.LibraryUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; -import org.apache.commons.codec.binary.Hex; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -76,7 +76,7 @@ public class RequiredLibrariesInfo { md5.update(file.contentsToByteArray()); final byte[] digest = md5.digest(); - return new String(Hex.encodeHex(digest)); + return BaseEncoding.base16().lowerCase().encode(digest); } catch (Exception e) { return null; diff --git a/plugins/hg4idea/intellij.vcs.hg.iml b/plugins/hg4idea/intellij.vcs.hg.iml index ec254ed1bb80..5c6520e0ac30 100644 --- a/plugins/hg4idea/intellij.vcs.hg.iml +++ b/plugins/hg4idea/intellij.vcs.hg.iml @@ -24,6 +24,5 @@ - \ No newline at end of file diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java index 8fb1d813e29f..d9924bab68cc 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java @@ -1,6 +1,7 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.zmlx.hg4idea.repo; +import com.google.common.io.BaseEncoding; import com.intellij.dvcs.DvcsUtil; import com.intellij.dvcs.repo.RepoStateException; import com.intellij.dvcs.repo.Repository; @@ -11,7 +12,6 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.vcs.log.Hash; import com.intellij.vcs.log.VcsLogObjectsFactory; -import org.apache.commons.codec.binary.Hex; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgNameWithHashInfo; @@ -105,7 +105,7 @@ public class HgRepositoryReader { public String readCurrentRevision() { if (!isDirStateInfoAvailable()) return null; try { - return Hex.encodeHexString(readHashBytesFromFile(myDirStateFile)); + return BaseEncoding.base16().lowerCase().encode(readHashBytesFromFile(myDirStateFile)); } catch (IOException e) { // dirState exists if not fresh, if we could not load dirState info repository must be corrupted From 960710e3765f984c97ff24b448dc64a856dffdbe Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 23 Mar 2018 19:48:09 +0300 Subject: [PATCH 10/23] one line less & use preprocessed

instead of generic
--- .../codeInsight/documentation/DocumentationManager.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java index 09961941952f..7938d2c6ab27 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java @@ -1215,11 +1215,10 @@ public class DocumentationManager extends DockablePopupManager"); + return StringUtil.replace(StringUtil.escapeXml(text) + " ", "\n", "

"); } } From 909a324e8ee8129a520a9fa1e56947fcc327b714 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 23 Mar 2018 19:50:43 +0300 Subject: [PATCH 11/23] use ImageIO in image index --- .../impl/ImageFileTypeManagerImpl.java | 3 +- .../intellij/images/index/ImageInfoIndex.java | 18 +- .../intellij/images/util/ImageInfoReader.java | 213 ++---------------- .../util/resources/misc/registry.properties | 2 + .../src/com/intellij/util/ImageLoader.java | 5 +- 5 files changed, 32 insertions(+), 209 deletions(-) diff --git a/images/src/org/intellij/images/fileTypes/impl/ImageFileTypeManagerImpl.java b/images/src/org/intellij/images/fileTypes/impl/ImageFileTypeManagerImpl.java index 3dca4014d13a..c7f603957f4b 100644 --- a/images/src/org/intellij/images/fileTypes/impl/ImageFileTypeManagerImpl.java +++ b/images/src/org/intellij/images/fileTypes/impl/ImageFileTypeManagerImpl.java @@ -26,7 +26,6 @@ import icons.ImagesIcons; import org.intellij.images.ImagesBundle; import org.intellij.images.fileTypes.ImageFileTypeManager; import org.intellij.images.vfs.IfsUtil; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import javax.imageio.ImageIO; @@ -39,7 +38,7 @@ import java.util.Set; */ final class ImageFileTypeManagerImpl extends ImageFileTypeManager { - @NonNls private static final String IMAGE_FILE_TYPE_NAME = "Images"; + private static final String IMAGE_FILE_TYPE_NAME = "Image"; private static final String IMAGE_FILE_TYPE_DESCRIPTION = ImagesBundle.message("images.filetype.description"); private static final UserFileType imageFileType; diff --git a/images/src/org/intellij/images/index/ImageInfoIndex.java b/images/src/org/intellij/images/index/ImageInfoIndex.java index f2db1b48fc33..90131f92f6c5 100644 --- a/images/src/org/intellij/images/index/ImageInfoIndex.java +++ b/images/src/org/intellij/images/index/ImageInfoIndex.java @@ -16,6 +16,7 @@ package org.intellij.images.index; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.indexing.*; @@ -33,14 +34,7 @@ import java.io.IOException; * @author spleaner */ public class ImageInfoIndex extends SingleEntryFileBasedIndexExtension { - private static final int ourMaxImageSize; - static { - int maxImageSize = 200; - try { - maxImageSize = Integer.parseInt(System.getProperty("idea.max.image.filesize", Integer.toString(maxImageSize)), 10); - } catch (NumberFormatException ex) {} - ourMaxImageSize = maxImageSize; - } + private static final long ourMaxImageSize = (long)(Registry.get("ide.index.image.max.size").asDouble() * 1024 * 1024); public static final ID INDEX_ID = ID.create("ImageFileInfoIndex"); @@ -94,17 +88,15 @@ public class ImageInfoIndex extends SingleEntryFileBasedIndexExtension it = ImageIO.getImageReaders(iis); + ImageReader reader = it.hasNext() ? it.next() : null; + if (reader != null) { + reader.setInput(iis, true); + int w = reader.getWidth(0); + int h = reader.getHeight(0); + int bpp = reader.getRawImageType(0).getColorModel().getPixelSize(); + return new Info(w, h, bpp); } } catch (IOException e) { - return null; + LOG.warn(e); } - } - - @Nullable - private static Info read(@NotNull final byte[] data) { - final DataInputStream is = new DataInputStream(new UnsyncByteArrayInputStream(data)); - try { - return readFileData(is); - } - catch (IOException e) { - return null; - } - finally { - try { - is.close(); - } - catch (IOException e) { - // nothing - } - } - } - - - @Nullable - private static Info readFileData(@NotNull final DataInput di) throws IOException { - final int b1 = di.readUnsignedByte(); - final int b2 = di.readUnsignedByte(); - - if (b1 == 0x47 && b2 == 0x49) { - return readGif(di); - } - - if (b1 == 0x89 && b2 == 0x50) { - return readPng(di); - } - - if (b1 == 0xff && b2 == 0xd8) { - return readJpeg(di); - } - - //if (b1 == 0x42 && b2 == 0x4d) { - // return readBmp(raf); - //} - return null; } - @Nullable - private static Info readGif(DataInput di) throws IOException { - final byte[] GIF_MAGIC_87A = {0x46, 0x38, 0x37, 0x61}; - final byte[] GIF_MAGIC_89A = {0x46, 0x38, 0x39, 0x61}; - byte[] a = new byte[11]; // 4 from the GIF signature + 7 from the global header - - di.readFully(a); - if ((!eq(a, 0, GIF_MAGIC_89A, 0, 4)) && (!eq(a, 0, GIF_MAGIC_87A, 0, 4))) { - return null; - } - - final int width = getShortLittleEndian(a, 4); - final int height = getShortLittleEndian(a, 6); - - int flags = a[8] & 0xff; - final int bpp = ((flags >> 4) & 0x07) + 1; - - return new Info(width, height, bpp); - } - - private static Info readBmp(RandomAccessFile raf) throws IOException { - byte[] a = new byte[44]; - if (raf.read(a) != a.length) { - return null; - } - - final int width = getIntLittleEndian(a, 16); - final int height = getIntLittleEndian(a, 20); - - if (width < 1 || height < 1) { - return null; - } - - final int bpp = getShortLittleEndian(a, 26); - if (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 & bpp != 32) { - return null; - } - - return new Info(width, height, bpp); - } - - @Nullable - private static Info readJpeg(DataInput di) throws IOException { - byte[] a = new byte[13]; - while (true) { - di.readFully(a, 0, 4); - - int marker = getShortBigEndian(a, 0); - final int size = getShortBigEndian(a, 2); - - if ((marker & 0xff00) != 0xff00) { - return null; - } - - if (marker == 0xffe0) { - if (size < 14) { - di.skipBytes(size - 2); - continue; - } - - di.readFully(a, 0, 12); - di.skipBytes(size - 14); - } - else if (marker >= 0xffc0 && marker <= 0xffcf && marker != 0xffc4 && marker != 0xffc8) { - di.readFully(a, 0, 6); - - final int bpp = (a[0] & 0xff) * (a[5] & 0xff); - final int width = getShortBigEndian(a, 3); - final int height = getShortBigEndian(a, 1); - - return new Info(width, height, bpp); - } - else { - di.skipBytes(size - 2); - } - } - } - - @Nullable - private static Info readPng(DataInput di) throws IOException { - final byte[] PNG_MAGIC = {0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}; - byte[] a = new byte[27]; - - di.readFully(a); - if (!eq(a, 0, PNG_MAGIC, 0, 6)) { - return null; - } - - final int width = getIntBigEndian(a, 14); - final int height = getIntBigEndian(a, 18); - int bpp = a[22] & 0xff; - int colorType = a[23] & 0xff; - if (colorType == 2 || colorType == 6) { - bpp *= 3; - } - - return new Info(width, height, bpp); - } - - private static int getShortBigEndian(byte[] a, int offset) { - return (a[offset] & 0xff) << 8 | (a[offset + 1] & 0xff); - } - - private static boolean eq(byte[] a1, int offset1, byte[] a2, int offset2, int num) { - while (num-- > 0) { - if (a1[offset1++] != a2[offset2++]) { - return false; - } - } - - return true; - } - - private static int getIntBigEndian(byte[] a, int offset) { - return (a[offset] & 0xff) << 24 | (a[offset + 1] & 0xff) << 16 | (a[offset + 2] & 0xff) << 8 | a[offset + 3] & 0xff; - } - - private static int getIntLittleEndian(byte[] a, int offset) { - return (a[offset + 3] & 0xff) << 24 | (a[offset + 2] & 0xff) << 16 | (a[offset + 1] & 0xff) << 8 | a[offset] & 0xff; - } - - private static int getShortLittleEndian(byte[] a, int offset) { - return (a[offset] & 0xff) | (a[offset + 1] & 0xff) << 8; - } - public static class Info { public int width; public int height; diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 86c899dfbe48..034ee7f554d6 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -97,6 +97,8 @@ ide.javafx.tips.description=(Experimental) Use JavaFX Browser for 'Tips of the D ide.svg.icon=true ide.svg.icon.description=Load & auto-scale svg version of an icon if present +ide.index.image.max.size=10 +ide.index.image.max.size.description=Max size of an image to index, in megabytes ide.cached.image.max.size=1.5 ide.cached.image.max.size.description=Max size of an image to cache, in megabytes diff --git a/platform/util/src/com/intellij/util/ImageLoader.java b/platform/util/src/com/intellij/util/ImageLoader.java index 2760a8f010dd..5c3020602c4e 100644 --- a/platform/util/src/com/intellij/util/ImageLoader.java +++ b/platform/util/src/com/intellij/util/ImageLoader.java @@ -46,12 +46,13 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentMap; -import static com.intellij.util.ui.JBUI.ScaleType.*; +import static com.intellij.util.ui.JBUI.ScaleType.PIX_SCALE; +import static com.intellij.util.ui.JBUI.ScaleType.SYS_SCALE; public class ImageLoader implements Serializable { private static final Logger LOG = Logger.getInstance("#com.intellij.util.ImageLoader"); - public static final int CACHED_IMAGE_MAX_SIZE = (int)Math.round(Registry.doubleValue("ide.cached.image.max.size") * 1024 * 1024); + public static final long CACHED_IMAGE_MAX_SIZE = (long)(Registry.doubleValue("ide.cached.image.max.size") * 1024 * 1024); private static final ConcurrentMap ourCache = ContainerUtil.createConcurrentSoftValueMap(); @SuppressWarnings({"UnusedDeclaration"}) // set from com.intellij.internal.IconsLoadTime From b4c98de7b02af12571ee6a016ceb87094fdd3b49 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 23 Mar 2018 17:53:14 +0100 Subject: [PATCH 12/23] =?UTF-8?q?set=20KEEP=5FFIRST=5FCOLUMN=5FCOMMENT=20f?= =?UTF-8?q?or=20kotlin=20to=20false=20=E2=80=94=20it=20is=20logical/conven?= =?UTF-8?q?ient=20and=20enabled=20for=20ages=20for=20Java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/codeStyles/Project.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 7a5179bf7916..248156378878 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -471,6 +471,7 @@ +