Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2018-03-08 13:33:57 +01:00
120 changed files with 843 additions and 1279 deletions
@@ -23,7 +23,10 @@ import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
import com.intellij.testFramework.*;
import com.intellij.testFramework.ModuleTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.VfsTestUtil;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.io.TestFileSystemBuilder;
import com.intellij.util.ui.UIUtil;
@@ -304,7 +307,7 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase {
//todo[nik] reuse code from PlatformTestCase
final VirtualFile baseDir = getOrCreateProjectBaseDir();
final File moduleFile = new File(baseDir.getPath().replace('/', File.separatorChar), moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
PlatformTestCase.myFilesToDelete.add(moduleFile);
myFilesToDelete.add(moduleFile);
return WriteAction.computeAndWait(() -> {
Module module = ModuleManager.getInstance(myProject)
.newModule(FileUtil.toSystemIndependentName(moduleFile.getAbsolutePath()), getModuleType().getId());
@@ -34,7 +34,6 @@ import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.SmartList;
import com.intellij.util.io.StringRef;
import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -210,7 +209,7 @@ public class TypeInfo {
boolean hasEllipsis = isSet(flags, HAS_ELLIPSIS);
int frequentIndex = FREQUENT_INDEX_MASK & flags;
String text = frequentIndex == 0 ? StringRef.toString(record.readName()) : ourIndexFrequentType[frequentIndex];
String text = frequentIndex == 0 ? record.readNameString() : ourIndexFrequentType[frequentIndex];
return new TypeInfo(text, arrayCount, hasEllipsis, PsiAnnotationStub.EMPTY_ARRAY);
}
@@ -40,7 +40,7 @@ public abstract class FunctionalExpressionElementType<T extends PsiFunctionalExp
@NotNull
@Override
public FunctionalExpressionStub<T> deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new FunctionalExpressionStub<>(parentStub, this, StringRef.toString(dataStream.readName()));
return new FunctionalExpressionStub<>(parentStub, this, dataStream.readNameString());
}
@Override
@@ -167,16 +167,16 @@ public abstract class JavaClassElementType extends JavaStubElementType<PsiClassS
JavaClassElementType type = typeForClass(isAnonymous, isEnumConst);
if (!isAnonymous) {
StringRef name = dataStream.readName();
StringRef qname = dataStream.readName();
StringRef sourceFileName = dataStream.readName();
PsiClassStubImpl classStub = new PsiClassStubImpl(type, parentStub, StringRef.toString(qname), StringRef.toString(name), null, flags);
classStub.setSourceFileName(StringRef.toString(sourceFileName));
String name = dataStream.readNameString();
String qname = dataStream.readNameString();
String sourceFileName = dataStream.readNameString();
PsiClassStubImpl classStub = new PsiClassStubImpl(type, parentStub, qname, name, null, flags);
classStub.setSourceFileName(sourceFileName);
return classStub;
}
else {
StringRef baseRef = dataStream.readName();
return new PsiClassStubImpl(type, parentStub, null, null, StringRef.toString(baseRef), flags);
String baseRef = dataStream.readNameString();
return new PsiClassStubImpl(type, parentStub, null, null, baseRef, flags);
}
}
@@ -32,7 +32,6 @@ import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.ArrayUtil;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -87,7 +86,7 @@ public abstract class JavaClassReferenceListElementType extends JavaStubElementT
int len = dataStream.readVarInt();
String[] names = ArrayUtil.newStringArray(len);
for (int i = 0; i < names.length; i++) {
names[i] = StringRef.toString(dataStream.readName());
names[i] = dataStream.readNameString();
}
return new PsiClassReferenceListStubImpl(this, parentStub, names);
}
@@ -36,7 +36,6 @@ import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -128,11 +127,11 @@ public abstract class JavaFieldStubElementType extends JavaStubElementType<PsiFi
@NotNull
@Override
public PsiFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef name = dataStream.readName();
String name = dataStream.readNameString();
TypeInfo type = TypeInfo.readTYPE(dataStream);
StringRef initializerText = dataStream.readName();
String initializerText = dataStream.readNameString();
byte flags = dataStream.readByte();
return new PsiFieldStubImpl(parentStub, StringRef.toString(name), type, StringRef.toString(initializerText), flags);
return new PsiFieldStubImpl(parentStub, name, type, initializerText, flags);
}
@Override
@@ -88,9 +88,9 @@ public abstract class JavaImportStatementElementType extends JavaStubElementType
@NotNull
@Override
public PsiImportStatementStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException {
final byte flags = dataStream.readByte();
final StringRef refText = dataStream.readName();
return new PsiImportStatementStubImpl(parentStub, StringRef.toString(refText), flags);
byte flags = dataStream.readByte();
String refText = dataStream.readNameString();
return new PsiImportStatementStubImpl(parentStub, refText, flags);
}
@Override
@@ -138,11 +138,11 @@ public abstract class JavaMethodElementType extends JavaStubElementType<PsiMetho
@NotNull
@Override
public PsiMethodStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException {
StringRef name = dataStream.readName();
String name = dataStream.readNameString();
final TypeInfo type = TypeInfo.readTYPE(dataStream);
byte flags = dataStream.readByte();
final StringRef defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readName() : null;
return new PsiMethodStubImpl(parentStub, StringRef.toString(name), type, flags, StringRef.toString(defaultMethodValue));
String defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readNameString() : null;
return new PsiMethodStubImpl(parentStub, name, type, flags, defaultMethodValue);
}
@Override
@@ -30,7 +30,6 @@ import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -70,8 +69,7 @@ public class JavaModuleElementType extends JavaStubElementType<PsiJavaModuleStub
@NotNull
@Override
public PsiJavaModuleStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = StringRef.toString(dataStream.readName());
return new PsiJavaModuleStubImpl(parentStub, name);
return new PsiJavaModuleStubImpl(parentStub, dataStream.readNameString());
}
@Override
@@ -30,7 +30,6 @@ import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -92,7 +91,7 @@ public class JavaNameValuePairType extends JavaStubElementType<PsiNameValuePairS
@NotNull
@Override
public PsiNameValuePairStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = StringRef.toString(dataStream.readName());
String name = dataStream.readNameString();
boolean hasValue = dataStream.readBoolean();
return new PsiNameValuePairStubImpl(parentStub, name, hasValue ? dataStream.readUTFFast() : null);
}
@@ -31,7 +31,6 @@ import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -81,7 +80,7 @@ public class JavaPackageAccessibilityStatementElementType extends JavaStubElemen
@NotNull
@Override
public PsiPackageAccessibilityStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String packageName = StringRef.toString(dataStream.readName());
String packageName = dataStream.readNameString();
List<String> targets = StringUtil.split(dataStream.readUTFFast(), "/");
return new PsiPackageAccessibilityStatementStubImpl(parentStub, this, packageName, targets);
}
@@ -78,11 +78,11 @@ public class JavaParameterElementType extends JavaStubElementType<PsiParameterSt
@NotNull
@Override
public PsiParameterStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef name = dataStream.readName();
String name = dataStream.readNameString();
if (name == null) throw new IOException("corrupted indices");
TypeInfo type = TypeInfo.readTYPE(dataStream);
byte flags = dataStream.readByte();
return new PsiParameterStubImpl(parentStub, name.toString(), type, flags);
return new PsiParameterStubImpl(parentStub, name, type, flags);
}
@Override
@@ -70,7 +70,7 @@ public class JavaProvidesStatementElementType extends JavaStubElementType<PsiPro
@NotNull
@Override
public PsiProvidesStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiProvidesStatementStubImpl(parentStub, StringRef.toString(dataStream.readName()));
return new PsiProvidesStatementStubImpl(parentStub, dataStream.readNameString());
}
@Override
@@ -70,7 +70,7 @@ public class JavaRequiresStatementElementType extends JavaStubElementType<PsiReq
@NotNull
@Override
public PsiRequiresStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiRequiresStatementStubImpl(parentStub, StringRef.toString(dataStream.readName()));
return new PsiRequiresStatementStubImpl(parentStub, dataStream.readNameString());
}
@Override
@@ -29,7 +29,6 @@ import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -74,8 +73,7 @@ public class JavaTypeParameterElementType extends JavaStubElementType<PsiTypePar
@NotNull
@Override
public PsiTypeParameterStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException {
StringRef name = dataStream.readName();
return new PsiTypeParameterStubImpl(parentStub, StringRef.toString(name));
return new PsiTypeParameterStubImpl(parentStub, dataStream.readNameString());
}
@Override
@@ -29,7 +29,6 @@ import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -70,7 +69,7 @@ public class JavaUsesStatementElementType extends JavaStubElementType<PsiUsesSta
@NotNull
@Override
public PsiUsesStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiUsesStatementStubImpl(parentStub, StringRef.toString(dataStream.readName()));
return new PsiUsesStatementStubImpl(parentStub, dataStream.readNameString());
}
@Override
@@ -108,8 +108,8 @@ public class JavaFileElementType extends ILightStubFileElementType<PsiJavaFileSt
public PsiJavaFileStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
boolean compiled = dataStream.readBoolean();
int level = dataStream.readByte();
StringRef packageName = dataStream.readName();
return new PsiJavaFileStubImpl(null, StringRef.toString(packageName), level >= 0 ? LanguageLevel.values()[level] : null, compiled);
String packageName = dataStream.readNameString();
return new PsiJavaFileStubImpl(null, packageName, level >= 0 ? LanguageLevel.values()[level] : null, compiled);
}
@Override
@@ -501,7 +501,7 @@ public class InferenceSession {
boolean addConstraint,
PsiSubstitutor initialSubstitutor) {
final PsiType interfaceReturnType = LambdaUtil.getFunctionalInterfaceReturnType(parameterType);
if (interfaceReturnType != null) {
if (interfaceReturnType != null && !PsiType.VOID.equals(interfaceReturnType)) {
final List<PsiExpression> returnExpressions = LambdaUtil.getReturnExpressions(lambdaExpression);
for (PsiExpression returnExpression : returnExpressions) {
processReturnExpression(additionalConstraints, ignoredConstraints, returnExpression, interfaceReturnType, addConstraint, initialSubstitutor);
@@ -0,0 +1,56 @@
import java.io.IOException;
class Test {
interface ThrowableRunnable<T extends Throwable> {
void run() throws T;
}
interface ThrowableComputable<R, E extends Throwable> {
R compute() throws E;
}
private <D extends Throwable> void doTest(ThrowableRunnable<D> action) { }
public void testNoNotificationForWorkspace() {
doTest(() -> computeAndWait(() -> foo()));
}
private String foo() throws IOException {
return null;
}
public static <R, E extends Throwable> R computeAndWait(ThrowableComputable<R, E> action) throws E {
return null;
}
}
class TestWithImplicitLambda {
interface ThrowableRunnable<T extends Throwable> {
void run(int k) throws T;
}
interface ThrowableComputable<R, E extends Throwable> {
R compute() throws E;
}
private <D extends Throwable> void doTest(ThrowableRunnable<D> action) { }
public void testNoNotificationForWorkspace() {
doTest((k) -> computeAndWait(() -> foo()));
}
private String foo() throws IOException {
return null;
}
public static <R, E extends Throwable> R computeAndWait(ThrowableComputable<R, E> action) throws E {
return null;
}
}
@@ -2293,8 +2293,9 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
// it must be either hidden or not have that error anymore
if (lastHintAfterDeletion != null) {
assertFalse(lastHintBeforeDeletion.getCachedIntentions().toString(), lastHintBeforeDeletion.getCachedIntentions().getErrorFixes().stream().anyMatch(e -> e.getText().equals("Initialize variable 'var'")));
} else {
assertEmpty(visibleHints);
}
assertEmpty(visibleHints);
}
public void testCodeFoldingPassRestartsOnRegionUnfolding() {
@@ -164,6 +164,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testVoidValueCompatibilityWithBreakInSwitch() { doTest(); }
public void testExceptionInferenceForVarargMethods() { doTest(); }
public void testConditionalBooleanAsFunctionalInterfaceType() { doTest(); }
public void testUnhandledExceptionInLambdaChain() { doTest(); }
private void doTest() {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
@@ -1,6 +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.java.codeInsight.javadoc;
import com.intellij.JavaTestUtil;
@@ -31,6 +29,7 @@ import org.intellij.lang.annotations.Flow;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
@@ -271,7 +270,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
public void testPackageInfo() throws Exception {
final String path = JavaTestUtil.getJavaTestDataPath() + TEST_DATA_FOLDER;
final String packageInfo = path + getTestName(true);
PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete);
createTestProjectStructure(path);
PsiPackage psiPackage = JavaPsiFacade.getInstance(getProject()).findPackage(getTestName(true));
final String info = JavaDocumentationProvider.generateExternalJavadoc(psiPackage, (List<String>)null);
String htmlText = FileUtil.loadFile(new File(packageInfo + File.separator + "packageInfo.html"));
@@ -323,7 +322,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
PsiDirectory dir = (PsiDirectory)psiClass.getParent().getParent();
PsiFile htmlFile = dir.findFile(psiClass.getName() + ".html");
assertNotNull(htmlFile);
assertEquals(StringUtil.convertLineSeparators(new String(htmlFile.getVirtualFile().contentsToByteArray(), "UTF-8").trim()),
assertEquals(StringUtil.convertLineSeparators(new String(htmlFile.getVirtualFile().contentsToByteArray(), StandardCharsets.UTF_8).trim()),
replaceEnvironmentDependentContent(doc));
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.dependencies;
import com.intellij.JavaTestUtil;
@@ -34,7 +20,7 @@ public class CyclicDependenciesTest extends PsiTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/dependencies/cycle/" + getTestName(true);
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure(root);
}
public void testT1() {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.dependencies;
import com.intellij.JavaTestUtil;
@@ -48,7 +34,7 @@ public class UsagesInAnalyzingDependenciesTest extends PsiTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/dependencies/search/" + getTestName(true);
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure( root);
}
@SuppressWarnings("ConstantConditions")
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.execution;
import com.intellij.execution.Location;
@@ -51,19 +37,16 @@ import java.util.ArrayList;
import java.util.List;
public abstract class BaseConfigurationTestCase extends IdeaTestCase {
protected TempFiles myTempFiles;
private final List<Module> myModulesToDispose = new ArrayList<>();
@Override
protected void setUp() throws Exception {
super.setUp();
myTempFiles = new TempFiles(myFilesToDelete);
}
@Override
protected void tearDown() throws Exception {
myModulesToDispose.clear();
super.tearDown();
try {
myModulesToDispose.clear();
}
finally {
super.tearDown();
}
}
protected void addModule(String path) {
@@ -101,7 +84,7 @@ public abstract class BaseConfigurationTestCase extends IdeaTestCase {
}
private Module createTempModule() {
return createTempModule(myTempFiles, myProject);
return createTempModule(getTempDir(), myProject);
}
@NotNull
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.ide.fileTemplates.impl
import com.intellij.ide.fileTemplates.FileTemplate
@@ -141,9 +127,7 @@ class FileTemplatesTest extends IdeaTestCase {
String name = "my_class"
FileTemplate template = addTestTemplate(name, 'package ${PACKAGE_NAME}; public class ${NAME} {}')
File temp = FileUtil.createTempDirectory(getTestName(true), "")
myFilesToDelete.add(temp)
File temp = createTempDirectory(false)
VirtualFile tempDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp)
PsiTestUtil.addSourceRoot(getModule(), tempDir)
@@ -204,7 +188,6 @@ class FileTemplatesTest extends IdeaTestCase {
//noinspection GroovyAccessibility
String name = FTManager.encodeFileName("test", "ext.has.dots")
File file = createTempFile(name, "test")
myFilesToDelete.add(file)
FileUtil.loadFile(new File(file.getAbsolutePath()), CharsetToolkit.UTF8_CHARSET)
LOG.debug("File loaded: " + file.getAbsolutePath())
File dir = new File(file.getParent())
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi;
import com.intellij.ide.highlighter.JavaFileType;
@@ -30,7 +16,7 @@ import com.intellij.testFramework.PsiTestUtil;
@PlatformTestCase.WrapInCommand
public class AddClassToFileTest extends PsiTestCase{
public void test() throws Exception {
VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete);
VirtualFile root = createTestProjectStructure();
PsiDirectory dir = myPsiManager.findDirectory(root);
assertNotNull(dir);
PsiFile file = WriteAction.compute(() -> dir.createFile("AAA.java"));
@@ -44,7 +30,7 @@ public class AddClassToFileTest extends PsiTestCase{
}
public void testFileModified() throws Exception {
VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete);
VirtualFile root = createTestProjectStructure();
VirtualFile pkg = createChildDirectory(root, "foo");
PsiDirectory dir = myPsiManager.findDirectory(pkg);
assertNotNull(dir);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi;
import com.intellij.JavaTestUtil;
@@ -49,7 +35,7 @@ public class ArrayIndexOutOfBoundsTest extends PsiTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/arrayIndexOutOfBounds/src";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
myProjectRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
myProjectRoot = createTestProjectStructure(root);
}
public void testSCR10930() {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi;
import com.intellij.core.CoreJavaFileManager;
@@ -25,7 +11,6 @@ import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PsiTestCase;
import com.intellij.testFramework.PsiTestUtil;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
@@ -189,7 +174,7 @@ public class CoreJavaFileManagerTest extends PsiTestCase {
@NotNull
private CoreJavaFileManager configureManager(@Language("JAVA") @NotNull String text, @NotNull String className) throws Exception {
VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete);
VirtualFile root = createTestProjectStructure();
VirtualFile pkg = createChildDirectory(root, "foo");
PsiDirectory dir = myPsiManager.findDirectory(pkg);
assertNotNull(dir);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi;
import com.intellij.JavaTestUtil;
@@ -38,7 +24,7 @@ public class ModifyAnnotationsTest extends PsiTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/repositoryUse/modifyAnnotations";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure( root);
}
public void testReplaceAnnotation() {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.
/*
* @author max
@@ -24,7 +10,6 @@ import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator;
import com.intellij.codeInsight.daemon.impl.HighlightVisitor;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
@@ -61,7 +46,7 @@ public class PsiConcurrencyStressTest extends DaemonAnalyzerTestCase {
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure( root);
}
@Override
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi;
import com.intellij.openapi.application.ex.PathManagerEx;
@@ -50,7 +36,7 @@ public class Src15RepositoryUseTest extends PsiTestCase {
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src15";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure( root);
}
@Override
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi;
import com.intellij.openapi.application.ApplicationManager;
@@ -60,7 +46,7 @@ public class SrcRepositoryUseTest extends PsiTestCase{
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure( root);
}
public void testGetClasses(){
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi.impl.cache.impl;
import com.intellij.JavaTestUtil;
@@ -49,7 +35,7 @@ public class IdCacheTest extends CodeInsightTestCase{
String root = JavaTestUtil.getJavaTestDataPath()+ "/psi/impl/cache/";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
myRootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
myRootDir = createTestProjectStructure(root);
myCacheFile = FileUtil.createTempFile("cache", "");
myCacheFile.delete();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi.impl.file.impl;
import com.intellij.openapi.application.ApplicationManager;
@@ -578,7 +564,6 @@ public class PsiEventsTest extends PsiTestCase {
rename(virtualFile, "b.xml");
}
private String newText;
private String original;
private String eventsFired = "";
private PsiTreeChangeListener listener;
@@ -691,7 +676,6 @@ public class PsiEventsTest extends PsiTestCase {
try {
getPsiManager().addPsiTreeChangeListener(listener);
eventsFired = "";
this.newText = newText;
original = getFile().getText();
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(getFile());
ApplicationManager.getApplication().runWriteAction(() -> document.setText(newText));
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi.search;
import com.intellij.JavaTestUtil;
@@ -37,7 +23,7 @@ public class FindUsages15Test extends PsiTestCase{
LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/search/findUsages15/" + getTestName(true);
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure(root);
}
public void testEnumConstructor() {
@@ -1,24 +1,9 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.psi.search;
import com.intellij.JavaTestUtil;
import com.intellij.find.findUsages.JavaFindUsagesHandler;
import com.intellij.find.findUsages.JavaFindUsagesHandlerFactory;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.ModifiableModuleModel;
@@ -40,7 +25,6 @@ import com.intellij.testFramework.fixtures.TempDirTestFixture;
import com.intellij.usageView.UsageInfo;
import com.intellij.util.Processor;
import com.intellij.util.containers.IntArrayList;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
@@ -54,7 +38,7 @@ public class FindUsagesTest extends PsiTestCase{
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/search/findUsages/" + getTestName(true);
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure(root);
}
public void testOverloadConstructors() {
@@ -27,7 +27,7 @@ public class PlainTextUsagesTest extends PsiTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/search/plainTextUsages/" + getTestName(true);
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure( root);
}
public void testSimple() {
@@ -58,7 +58,7 @@ public class UpdateCacheTest extends PsiTestCase {
setUpModule();
final String root = JavaTestUtil.getJavaTestDataPath() + "/psi/search/updateCache";
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
createTestProjectStructure( root);
setUpJdk();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.refactoring;
import com.intellij.JavaTestUtil;
@@ -68,7 +54,7 @@ public class CopyClassTest extends CodeInsightTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/" + getTestName(true);
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
myRootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
myRootDir = createTestProjectStructure(root);
performAction(oldName, copyName);
@@ -107,7 +93,7 @@ public class CopyClassTest extends CodeInsightTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
String rootBefore = root + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
VirtualFile rootDir = createTestProjectStructure(rootBefore);
final HashMap<PsiFile, PsiClass[]> map = new HashMap<>();
final VirtualFile sourceDir = rootDir.findChild("p1");
@@ -143,7 +129,7 @@ public class CopyClassTest extends CodeInsightTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
String rootBefore = root + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
VirtualFile rootDir = createTestProjectStructure(rootBefore);
final VirtualFile targetVDir = rootDir.findChild("p2");
final PsiDirectory sourceP1Dir = myPsiManager.findDirectory(rootDir.findChild("p1"));
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.refactoring;
import com.intellij.JavaTestUtil;
@@ -41,7 +27,7 @@ public class CopyTest extends CodeInsightTestCase {
private void doTest() throws Exception {
String rootBefore = getRoot();
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
createTestProjectStructure(rootBefore);
PsiPackage pack1 = myJavaFacade.findPackage("pack1");
PsiPackage pack2 = myJavaFacade.findPackage("pack2");
assertTrue(CopyHandler.canCopy(new PsiElement[]{pack1.getDirectories()[0], pack2.getDirectories()[0]}));
@@ -50,7 +36,7 @@ public class CopyTest extends CodeInsightTestCase {
public void testMultipleClasses() throws Exception {
String rootBefore = getRoot();
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile root = createTestProjectStructure(rootBefore);
final PsiClass aClass = myJavaFacade.findClass("pack1.Klass");
assertNotNull(aClass);
@@ -72,7 +58,7 @@ public class CopyTest extends CodeInsightTestCase {
public void testMultipleFiles() throws Exception {
String rootBefore = getRoot();
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile root = createTestProjectStructure(rootBefore);
final VirtualFile first = root.findFileByRelativePath("from/1.txt");
assertNotNull(first);
@@ -97,7 +83,7 @@ public class CopyTest extends CodeInsightTestCase {
public void testPackageInfo() throws Exception {
String rootBefore = getRoot();
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile root = createTestProjectStructure(rootBefore);
final VirtualFile first = root.findFileByRelativePath("from/package-info.java");
assertNotNull(first);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.refactoring;
import com.intellij.JavaTestUtil;
@@ -34,7 +20,6 @@ import com.intellij.refactoring.util.DocCommentPolicy;
import com.intellij.refactoring.util.classMembers.MemberInfo;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.PsiTestUtil;
import java.util.HashSet;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NonNls;
@@ -42,6 +27,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
/**
* @author yole
@@ -139,7 +125,7 @@ public class ExtractSuperClassTest extends RefactoringTestCase {
public void testAnonymClass() throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk14());
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile rootDir = createTestProjectStructure(rootBefore);
PsiClass psiClass = myJavaFacade.findClass("Test", ProjectScope.getAllScope(myProject));
assertNotNull(psiClass);
final PsiField[] fields = psiClass.getFields();
@@ -192,7 +178,7 @@ public class ExtractSuperClassTest extends RefactoringTestCase {
RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk14());
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile rootDir = createTestProjectStructure(rootBefore);
PsiClass psiClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
assertNotNull(psiClass);
final MemberInfo[] members = RefactoringTestUtil.findMembers(psiClass, membersToFind);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.refactoring;
import com.intellij.JavaTestUtil;
@@ -53,7 +39,7 @@ public class MoveClassAndFileTest extends RefactoringTestCase {
String rootBefore = root + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
VirtualFile rootDir = createTestProjectStructure(rootBefore);
performAction(newPackageName, fileNameNearFirstClass, classNames);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.refactoring;
import com.intellij.JavaTestUtil;
@@ -106,7 +92,7 @@ public class MoveClassTest extends RefactoringTestCase {
String rootBefore = root + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
VirtualFile rootDir = createTestProjectStructure(rootBefore);
performAction(classNames, newPackageName);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.refactoring;
import com.intellij.JavaTestUtil;
@@ -146,7 +132,7 @@ public class MoveClassToInnerTest extends RefactoringTestCase {
private VirtualFile prepareTest() throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
return PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
return createTestProjectStructure(rootBefore);
}
private String getRoot() {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.refactoring.inline;
import com.intellij.JavaTestUtil;
@@ -55,7 +41,7 @@ public class InlineMethodMultifileTest extends RefactoringTestCase {
private void doTest(String className, String methodName) throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile rootDir = createTestProjectStructure(rootBefore);
PsiClass aClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
assertTrue(aClass != null);
PsiElement element = aClass.findMethodsByName(methodName, false)[0];
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.java.refactoring.inline;
import com.intellij.JavaTestUtil;
@@ -66,7 +52,7 @@ public class InlineToAnonymousClassMultifileTest extends RefactoringTestCase {
private void doTest(String className) throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
final VirtualFile rootDir = createTestProjectStructure(rootBefore);
String path = getRoot() + "/lib/simple.jar";
VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
if (libJarLocal != null) {
@@ -1,6 +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.psi.impl.smartPointers;
import com.intellij.JavaTestUtil;
@@ -68,7 +66,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase {
String root = JavaTestUtil.getJavaTestDataPath() + "/codeEditor/smartPsiElementPointers";
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
myRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
myRoot = createTestProjectStructure( root);
}
public void testChangeInDocument() {
@@ -13,7 +13,6 @@ import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.ModuleRootManagerImpl;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.IdeaTestUtil;
@@ -47,7 +46,7 @@ public class ModuleRootsExternalizationTest extends ModuleTestCase {
}
private ModuleRootManagerImpl createTempModuleRootManager() throws IOException {
File tmpModule = FileUtil.createTempFile("tst", ModuleFileType.DOT_DEFAULT_EXTENSION);
File tmpModule = getTempDir().createTempFile("tst", ModuleFileType.DOT_DEFAULT_EXTENSION, false);
myFilesToDelete.add(tmpModule);
final Module module = createModule(tmpModule);
return (ModuleRootManagerImpl)ModuleRootManager.getInstance(module);
@@ -14,7 +14,6 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.jetbrains.jsonSchema.ide.JsonSchemaService;
import com.jetbrains.jsonSchema.impl.JsonSchemaAnnotator;
@@ -593,8 +592,8 @@ public class JsonSchemaHighlightingTest extends DaemonAnalyzerTestCase {
doTest(file.getVirtualFile(), true, false);
}
public static void registerProvider(Project project, @NotNull String schema) throws IOException {
File dir = PlatformTestCase.createTempDir("json_schema_test", true);
public void registerProvider(Project project, @NotNull String schema) throws IOException {
File dir = createTempDir("json_schema_test", true);
File child = new File(dir, "schema.json");
//noinspection ResultOfMethodCallIgnored
child.createNewFile();
@@ -79,13 +79,6 @@ open class FileBasedStorage(file: Path,
storage.lineSeparator = lineSeparator
}
// only app level components do not use xml prolog
if (storage.roamingType == RoamingType.DISABLED && storage.isUseXmlProlog) {
if (element == null) {
}
}
val isUseVfs = storage.isUseVfsForWrite
val virtualFile = if (isUseVfs) storage.virtualFile else null
if (element == null) {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2015 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.
*/
// 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.configurationStore
import com.intellij.openapi.application.ApplicationManager
@@ -93,7 +79,7 @@ private class StateGetterImpl<S : Any, T : Any>(private val component: Persisten
if (ApplicationManager.getApplication().isUnitTestMode &&
serializedState != serializedStateAfterLoad &&
(serializedStateAfterLoad == null || !JDOMUtil.areElementsEqual(serializedState, serializedStateAfterLoad))) {
LOG.warn("$componentName (from ${component.javaClass.name}) state changed after load. \nOld: ${JDOMUtil.writeElement(serializedState!!)}\n\nNew: ${serializedStateAfterLoad?.let { JDOMUtil.writeElement(it) } ?: "null"}\n")
LOG.debug("$componentName (from ${component.javaClass.name}) state changed after load. \nOld: ${JDOMUtil.writeElement(serializedState!!)}\n\nNew: ${serializedStateAfterLoad?.let { JDOMUtil.writeElement(it) } ?: "null"}\n")
}
storage.archiveState(storageData, componentName, serializedStateAfterLoad)
@@ -43,14 +43,16 @@ public class StubInputStream extends DataInputStream {
@Nullable
public StringRef readName() throws IOException {
return DataInputOutputUtil.readNAME(this, myNameStorage);
return StringRef.fromStream(this, myNameStorage);
}
@Nullable
public String readNameString() throws IOException {
return StringRef.stringFromStream(this, myNameStorage);
}
public int readVarInt() throws IOException {
return DataInputOutputUtil.readINT(this);
}
public String stringFromId(int id) throws IOException {
return myNameStorage.valueOf(id);
}
}
@@ -42,14 +42,12 @@ public class StubOutputStream extends DataOutputStream {
}
public void writeName(@Nullable final String arg) throws IOException {
DataInputOutputUtil.writeNAME(this, arg, myNameStorage);
final int nameId = arg != null ? myNameStorage.enumerate(arg) : 0;
DataInputOutputUtil.writeINT(this, nameId);
}
public void writeVarInt(final int value) throws IOException {
DataInputOutputUtil.writeINT(this, value);
}
public int getStringId(final String value) throws IOException {
return myNameStorage.enumerate(value);
}
}
@@ -18,7 +18,6 @@ package com.intellij.psi.util;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -158,8 +157,7 @@ public class QualifiedName implements Comparable<QualifiedName> {
else {
qName = new QualifiedName(size);
for (int i = 0; i < size; i++) {
final StringRef name = dataStream.readName();
qName.myComponents.add(name == null ? null : name.getString());
qName.myComponents.add(dataStream.readNameString());
}
}
return qName;
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.actionSystem;
import com.intellij.ide.DataManager;
@@ -119,7 +105,7 @@ public class AnActionEvent implements PlaceProvider<String> {
@NotNull
public static AnActionEvent createFromInputEvent(@Nullable InputEvent event,
@NotNull String place,
@NotNull Presentation presentation,
@Nullable Presentation presentation,
@NotNull DataContext dataContext) {
return createFromInputEvent(event, place, presentation, dataContext, false, false);
}
@@ -127,11 +113,11 @@ public class AnActionEvent implements PlaceProvider<String> {
@NotNull
public static AnActionEvent createFromInputEvent(@Nullable InputEvent event,
@NotNull String place,
@NotNull Presentation presentation,
@Nullable Presentation presentation,
@NotNull DataContext dataContext,
boolean isContextMenuAction,
boolean isToolbarAction) {
return new AnActionEvent(event, dataContext, place, presentation, ActionManager.getInstance(),
return new AnActionEvent(event, dataContext, place, presentation == null ? new Presentation() : presentation, ActionManager.getInstance(),
event == null ? 0 : event.getModifiers(), isContextMenuAction, isToolbarAction);
}
@@ -1,23 +1,12 @@
/*
* 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.
*/
// 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.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.psi.Weigher;
import com.intellij.util.Consumer;
@@ -62,6 +51,20 @@ public abstract class CompletionService {
*/
public abstract void setAdvertisementText(@Nullable String text);
/**
* Creates the completion parameters for the given context.
*
* @param caret the selected caret in the given editor
* @param invocationCount the number of times the user has pressed the code completion shortcut (0 if autopopup)
* @return the completion parameters instance
*/
@SuppressWarnings("unused")
public abstract CompletionParameters createCompletionParameters(@NotNull Project project,
@NotNull Editor editor,
@NotNull Caret caret,
int invocationCount,
CompletionType completionType);
/**
* Run all contributors until any of them returns false or the list is exhausted. If from parameter is not null, contributors
* will be run starting from the next one after that.
@@ -11,7 +11,6 @@ import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.editor.markup.SeparatorPlacement;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -26,7 +25,6 @@ import java.awt.*;
public class LineMarkerInfo<T extends PsiElement> {
private static final Logger LOG = Logger.getInstance(LineMarkerInfo.class);
public static final Key<LineMarkerInfo> LINE_MARKER_INFO = Key.create("LINE_MARKER_INFO");
protected final Icon myIcon;
private final SmartPsiElementPointer<T> elementRef;
@@ -146,11 +144,6 @@ public class LineMarkerInfo<T extends PsiElement> {
return myNavigationHandler;
}
@SuppressWarnings({"unused", "unchecked"})
public static <T extends PsiElement> LineMarkerInfo<T> fromRangeHighlighter(RangeHighlighter rangeHighlighter) {
return (LineMarkerInfo<T>) rangeHighlighter.getUserData(LINE_MARKER_INFO);
}
public static class LineMarkerGutterIconRenderer<T extends PsiElement> extends GutterIconRenderer {
private final LineMarkerInfo<T> myInfo;
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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.
*/
// 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.codeInsight.completion;
@@ -26,7 +12,6 @@ import com.intellij.codeInsight.lookup.*;
import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.ide.DataManager;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.lang.Language;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.actionSystem.ActionManager;
@@ -37,29 +22,25 @@ import com.intellij.openapi.application.TransactionGuard;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.CaretAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorModificationUtil;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
import com.intellij.openapi.editor.ex.DocumentEx;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.PsiFileEx;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.reference.SoftReference;
import com.intellij.util.ThreeState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -166,18 +147,8 @@ public class CodeCompletionHandlerBase {
}
Runnable initCmd = () -> {
CompletionInitializationContext context = WriteAction.compute(() -> {
EditorUtil.fillVirtualSpaceUntilCaret(editor);
PsiDocumentManager.getInstance(project).commitAllDocuments();
CompletionAssertions.checkEditorValid(editor);
final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(caret, project);
assert psiFile != null : "no PSI file: " + FileDocumentManager.getInstance().getFile(editor.getDocument());
psiFile.putUserData(PsiFileEx.BATCH_REFERENCE_PROCESSING, Boolean.TRUE);
CompletionAssertions.assertCommitSuccessful(editor, psiFile);
return runContributorsBeforeCompletion(editor, psiFile, invocationCount, caret);
});
CompletionInitializationContextImpl context = CompletionInitializationUtil.createCompletionInitializationContext(project, editor, caret,
invocationCount, completionType);
doComplete(context, hasModifiers);
};
if (autopopup) {
@@ -187,31 +158,6 @@ public class CodeCompletionHandlerBase {
}
}
private CompletionInitializationContext runContributorsBeforeCompletion(Editor editor, PsiFile psiFile, int invocationCount, @NotNull Caret caret) {
final Ref<CompletionContributor> current = Ref.create(null);
CompletionInitializationContext context = new CompletionInitializationContext(editor, caret, psiFile, completionType, invocationCount) {
CompletionContributor dummyIdentifierChanger;
@Override
public void setDummyIdentifier(@NotNull String dummyIdentifier) {
super.setDummyIdentifier(dummyIdentifier);
if (dummyIdentifierChanger != null) {
LOG.error("Changing the dummy identifier twice, already changed by " + dummyIdentifierChanger);
}
dummyIdentifierChanger = current.get();
}
};
Project project = psiFile.getProject();
for (final CompletionContributor contributor : CompletionContributor.forLanguageHonorDumbness(context.getPositionLanguage(), project)) {
current.set(contributor);
contributor.beforeCompletion(context);
CompletionAssertions.checkEditorValid(editor);
assert !PsiDocumentManager.getInstance(project).isUncommited(editor.getDocument()) : "Contributor " + contributor + " left the document uncommitted";
}
return context;
}
private static void checkNoWriteAccess() {
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
@@ -264,11 +210,10 @@ public class CodeCompletionHandlerBase {
return lookup;
}
private void doComplete(CompletionInitializationContext initContext, boolean hasModifiers) {
private void doComplete(CompletionInitializationContextImpl initContext, boolean hasModifiers) {
final Editor editor = initContext.getEditor();
CompletionAssertions.checkEditorValid(editor);
OffsetsInFile hostOffsets = new OffsetsInFile(initContext.getFile(), initContext.getOffsetMap()).toTopLevelFile();
LookupImpl lookup = obtainLookup(editor, initContext.getProject());
CompletionPhase phase = CompletionServiceImpl.getCompletionPhase();
@@ -283,7 +228,9 @@ public class CodeCompletionHandlerBase {
CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, initContext.getCaret(),
initContext.getInvocationCount(), this,
initContext.getOffsetMap(), hostOffsets, hasModifiers, lookup);
initContext.getOffsetMap(),
initContext.getHostOffsets(),
hasModifiers, lookup);
CompletionServiceImpl.setCompletionPhase(synchronous ? new CompletionPhase.Synchronous(indicator) : new CompletionPhase.BgCalculation(indicator));
@@ -323,36 +270,7 @@ public class CodeCompletionHandlerBase {
if (autopopup && shouldSkipAutoPopup(initContext.getEditor(), initContext.getFile())) {
return null;
}
OffsetsInFile hostCopyOffsets = insertDummyIdentifier(initContext, indicator, indicator.getHostOffsets());
if (hostCopyOffsets == null) {
return null;
}
indicator.registerChildDisposable(hostCopyOffsets::getOffsets);
OffsetsInFile finalOffsets = toInjectedIfAny(initContext.getFile(), hostCopyOffsets);
indicator.registerChildDisposable(finalOffsets::getOffsets);
return createCompletionParameters(initContext, indicator, finalOffsets);
}
@NotNull
private CompletionParameters createCompletionParameters(CompletionInitializationContext initContext,
CompletionProgressIndicator indicator, OffsetsInFile finalOffsets) {
int offset = finalOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET);
PsiFile fileCopy = finalOffsets.getFile();
PsiFile originalFile = fileCopy.getOriginalFile();
PsiElement insertedElement = findCompletionPositionLeaf(finalOffsets, offset, originalFile);
insertedElement.putUserData(CompletionContext.COMPLETION_CONTEXT_KEY, new CompletionContext(fileCopy, finalOffsets.getOffsets()));
return new CompletionParameters(insertedElement, originalFile, completionType, offset, initContext.getInvocationCount(),
initContext.getEditor(), indicator);
}
@NotNull
private static PsiElement findCompletionPositionLeaf(OffsetsInFile offsets, int offset, PsiFile originalFile) {
PsiElement insertedElement = offsets.getFile().findElementAt(offset);
CompletionAssertions.assertCompletionPositionPsiConsistent(offsets, offset, originalFile, insertedElement);
return insertedElement;
return CompletionInitializationUtil.prepareCompletionParameters(initContext, indicator);
}
private static void checkNotSync(CompletionProgressIndicator indicator, List<LookupElement> allItems) {
@@ -460,49 +378,6 @@ public class CodeCompletionHandlerBase {
}
}
private static OffsetsInFile insertDummyIdentifier(CompletionInitializationContext initContext,
CompletionProgressIndicator indicator,
OffsetsInFile topLevelOffsets) {
CompletionAssertions.checkEditorValid(initContext.getEditor());
Editor hostEditor = InjectedLanguageUtil.getTopLevelEditor(initContext.getEditor());
OffsetMap hostMap = topLevelOffsets.getOffsets();
PsiFile hostCopy = obtainFileCopy(topLevelOffsets.getFile());
Document copyDocument = Objects.requireNonNull(hostCopy.getViewProvider().getDocument());
String dummyIdentifier = initContext.getDummyIdentifier();
int startOffset = hostMap.getOffset(CompletionInitializationContext.START_OFFSET);
int endOffset = hostMap.getOffset(CompletionInitializationContext.SELECTION_END_OFFSET);
indicator.registerChildDisposable(
() -> new OffsetTranslator(hostEditor.getDocument(), initContext.getFile(), copyDocument, startOffset, endOffset, dummyIdentifier));
OffsetsInFile copyOffsets = topLevelOffsets.replaceInCopy(hostCopy, startOffset, endOffset, dummyIdentifier);
return hostCopy.isValid() ? copyOffsets : null;
}
private static OffsetsInFile toInjectedIfAny(PsiFile originalFile, OffsetsInFile hostCopyOffsets) {
CompletionAssertions.assertHostInfo(hostCopyOffsets.getFile(), hostCopyOffsets.getOffsets());
int hostStartOffset = hostCopyOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET);
OffsetsInFile translatedOffsets = hostCopyOffsets.toInjectedIfAny(hostStartOffset);
if (translatedOffsets != hostCopyOffsets) {
PsiFile injected = translatedOffsets.getFile();
if (injected instanceof PsiFileImpl) {
((PsiFileImpl)injected).setOriginalFile(originalFile);
}
DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injected);
CompletionAssertions.assertInjectedOffsets(hostStartOffset, injected, documentWindow);
if (injected.getTextRange().contains(translatedOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET))) {
return translatedOffsets;
}
}
return hostCopyOffsets;
}
protected void lookupItemSelected(final CompletionProgressIndicator indicator, @NotNull final LookupElement item, final char completionChar,
final List<LookupElement> items) {
if (indicator.isAutopopupCompletion()) {
@@ -666,57 +541,6 @@ public class CodeCompletionHandlerBase {
}
}
private static final Key<SoftReference<Pair<PsiFile, Document>>> FILE_COPY_KEY = Key.create("CompletionFileCopy");
private static boolean isCopyUpToDate(Document document, @NotNull PsiFile copyFile, @NotNull PsiFile originalFile) {
if (!copyFile.getClass().equals(originalFile.getClass()) ||
!copyFile.isValid() ||
!copyFile.getName().equals(originalFile.getName())) {
return false;
}
// the psi file cache might have been cleared by some external activity,
// in which case PSI-document sync may stop working
PsiFile current = PsiDocumentManager.getInstance(copyFile.getProject()).getPsiFile(document);
return current != null && current.getViewProvider().getPsi(copyFile.getLanguage()) == copyFile;
}
private static PsiFile obtainFileCopy(PsiFile file) {
final VirtualFile virtualFile = file.getVirtualFile();
boolean mayCacheCopy = file.isPhysical() &&
// we don't want to cache code fragment copies even if they appear to be physical
virtualFile != null && virtualFile.isInLocalFileSystem();
if (mayCacheCopy) {
final Pair<PsiFile, Document> cached = SoftReference.dereference(file.getUserData(FILE_COPY_KEY));
if (cached != null && isCopyUpToDate(cached.second, cached.first, file)) {
PsiFile copy = cached.first;
CompletionAssertions.assertCorrectOriginalFile("Cached", file, copy);
return copy;
}
}
final PsiFile copy = (PsiFile)file.copy();
if (copy.isPhysical() || copy.getViewProvider().isEventSystemEnabled()) {
LOG.error("File copy should be non-physical and non-event-system-enabled! Language=" + file.getLanguage() + "; file=" + file + " of " + file.getClass());
}
CompletionAssertions.assertCorrectOriginalFile("New", file, copy);
if (mayCacheCopy) {
final Document document = copy.getViewProvider().getDocument();
assert document != null;
syncAcceptSlashR(file.getViewProvider().getDocument(), document);
file.putUserData(FILE_COPY_KEY, new SoftReference<>(Pair.create(copy, document)));
}
return copy;
}
private static void syncAcceptSlashR(Document originalDocument, Document documentCopy) {
if (!(originalDocument instanceof DocumentImpl) || !(documentCopy instanceof DocumentImpl)) {
return;
}
((DocumentImpl) documentCopy).setAcceptSlashR(((DocumentImpl) originalDocument).acceptsSlashR());
}
private static boolean isAutocompleteOnInvocation(final CompletionType type) {
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
if (type == CompletionType.SMART) {
@@ -0,0 +1,26 @@
// 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.codeInsight.completion;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
class CompletionInitializationContextImpl extends CompletionInitializationContext {
private final OffsetsInFile myHostOffsets;
CompletionInitializationContextImpl(Editor editor,
@NotNull Caret caret,
PsiFile file,
CompletionType completionType, int invocationCount) {
super(editor, caret, file, completionType, invocationCount);
myHostOffsets = new OffsetsInFile(file, getOffsetMap()).toTopLevelFile();
}
OffsetsInFile getHostOffsets() {
return myHostOffsets;
}
}
@@ -0,0 +1,213 @@
// 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.codeInsight.completion;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.PsiFileEx;
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.reference.SoftReference;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/**
* @author yole
*/
public class CompletionInitializationUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.CompletionServiceUtil");
public static CompletionInitializationContextImpl createCompletionInitializationContext(@NotNull Project project,
@NotNull Editor editor,
@NotNull Caret caret,
int invocationCount,
CompletionType completionType) {
return WriteAction.compute(() -> {
EditorUtil.fillVirtualSpaceUntilCaret(editor);
PsiDocumentManager.getInstance(project).commitAllDocuments();
CompletionAssertions.checkEditorValid(editor);
final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(caret, project);
assert psiFile != null : "no PSI file: " + FileDocumentManager.getInstance().getFile(editor.getDocument());
psiFile.putUserData(PsiFileEx.BATCH_REFERENCE_PROCESSING, Boolean.TRUE);
CompletionAssertions.assertCommitSuccessful(editor, psiFile);
return runContributorsBeforeCompletion(editor, psiFile, invocationCount, caret, completionType);
});
}
private static CompletionInitializationContextImpl runContributorsBeforeCompletion(Editor editor,
PsiFile psiFile,
int invocationCount,
@NotNull Caret caret,
CompletionType completionType) {
final Ref<CompletionContributor> current = Ref.create(null);
CompletionInitializationContextImpl context = new CompletionInitializationContextImpl(editor, caret, psiFile, completionType, invocationCount) {
CompletionContributor dummyIdentifierChanger;
@Override
public void setDummyIdentifier(@NotNull String dummyIdentifier) {
super.setDummyIdentifier(dummyIdentifier);
if (dummyIdentifierChanger != null) {
LOG.error("Changing the dummy identifier twice, already changed by " + dummyIdentifierChanger);
}
dummyIdentifierChanger = current.get();
}
};
Project project = psiFile.getProject();
for (final CompletionContributor contributor : CompletionContributor.forLanguageHonorDumbness(context.getPositionLanguage(), project)) {
current.set(contributor);
contributor.beforeCompletion(context);
CompletionAssertions.checkEditorValid(editor);
assert !PsiDocumentManager.getInstance(project).isUncommited(editor.getDocument()) : "Contributor " + contributor + " left the document uncommitted";
}
return context;
}
public static CompletionParameters prepareCompletionParameters(CompletionInitializationContext initContext,
CompletionProcessEx process) {
CompletionProcessEx indicator = (CompletionProcessEx) process;
OffsetsInFile hostCopyOffsets = insertDummyIdentifier(initContext, indicator, indicator.getHostOffsets());
if (hostCopyOffsets == null) {
return null;
}
indicator.registerChildDisposable(hostCopyOffsets::getOffsets);
OffsetsInFile finalOffsets = toInjectedIfAny(initContext.getFile(), hostCopyOffsets);
indicator.registerChildDisposable(finalOffsets::getOffsets);
return createCompletionParameters(initContext, indicator, finalOffsets);
}
@NotNull
private static CompletionParameters createCompletionParameters(CompletionInitializationContext initContext,
CompletionProcessEx indicator, OffsetsInFile finalOffsets) {
int offset = finalOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET);
PsiFile fileCopy = finalOffsets.getFile();
PsiFile originalFile = fileCopy.getOriginalFile();
PsiElement insertedElement = findCompletionPositionLeaf(finalOffsets, offset, originalFile);
insertedElement.putUserData(CompletionContext.COMPLETION_CONTEXT_KEY, new CompletionContext(fileCopy, finalOffsets.getOffsets()));
return new CompletionParameters(insertedElement, originalFile, initContext.getCompletionType(), offset, initContext.getInvocationCount(),
initContext.getEditor(), indicator);
}
private static OffsetsInFile insertDummyIdentifier(CompletionInitializationContext initContext,
CompletionProcessEx indicator,
OffsetsInFile topLevelOffsets) {
CompletionAssertions.checkEditorValid(initContext.getEditor());
Editor hostEditor = InjectedLanguageUtil.getTopLevelEditor(initContext.getEditor());
OffsetMap hostMap = topLevelOffsets.getOffsets();
PsiFile hostCopy = obtainFileCopy(topLevelOffsets.getFile());
Document copyDocument = Objects.requireNonNull(hostCopy.getViewProvider().getDocument());
String dummyIdentifier = initContext.getDummyIdentifier();
int startOffset = hostMap.getOffset(CompletionInitializationContext.START_OFFSET);
int endOffset = hostMap.getOffset(CompletionInitializationContext.SELECTION_END_OFFSET);
indicator.registerChildDisposable(
() -> new OffsetTranslator(hostEditor.getDocument(), initContext.getFile(), copyDocument, startOffset, endOffset, dummyIdentifier));
OffsetsInFile copyOffsets = topLevelOffsets.replaceInCopy(hostCopy, startOffset, endOffset, dummyIdentifier);
return hostCopy.isValid() ? copyOffsets : null;
}
private static OffsetsInFile toInjectedIfAny(PsiFile originalFile, OffsetsInFile hostCopyOffsets) {
CompletionAssertions.assertHostInfo(hostCopyOffsets.getFile(), hostCopyOffsets.getOffsets());
int hostStartOffset = hostCopyOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET);
OffsetsInFile translatedOffsets = hostCopyOffsets.toInjectedIfAny(hostStartOffset);
if (translatedOffsets != hostCopyOffsets) {
PsiFile injected = translatedOffsets.getFile();
if (injected instanceof PsiFileImpl) {
((PsiFileImpl)injected).setOriginalFile(originalFile);
}
DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injected);
CompletionAssertions.assertInjectedOffsets(hostStartOffset, injected, documentWindow);
if (injected.getTextRange().contains(translatedOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET))) {
return translatedOffsets;
}
}
return hostCopyOffsets;
}
@NotNull
private static PsiElement findCompletionPositionLeaf(OffsetsInFile offsets, int offset, PsiFile originalFile) {
PsiElement insertedElement = offsets.getFile().findElementAt(offset);
CompletionAssertions.assertCompletionPositionPsiConsistent(offsets, offset, originalFile, insertedElement);
return insertedElement;
}
private static PsiFile obtainFileCopy(PsiFile file) {
final VirtualFile virtualFile = file.getVirtualFile();
boolean mayCacheCopy = file.isPhysical() &&
// we don't want to cache code fragment copies even if they appear to be physical
virtualFile != null && virtualFile.isInLocalFileSystem();
if (mayCacheCopy) {
final Pair<PsiFile, Document> cached = SoftReference.dereference(file.getUserData(FILE_COPY_KEY));
if (cached != null && isCopyUpToDate(cached.second, cached.first, file)) {
PsiFile copy = cached.first;
CompletionAssertions.assertCorrectOriginalFile("Cached", file, copy);
return copy;
}
}
final PsiFile copy = (PsiFile)file.copy();
if (copy.isPhysical() || copy.getViewProvider().isEventSystemEnabled()) {
LOG.error("File copy should be non-physical and non-event-system-enabled! Language=" + file.getLanguage() + "; file=" + file + " of " + file.getClass());
}
CompletionAssertions.assertCorrectOriginalFile("New", file, copy);
if (mayCacheCopy) {
final Document document = copy.getViewProvider().getDocument();
assert document != null;
syncAcceptSlashR(file.getViewProvider().getDocument(), document);
file.putUserData(FILE_COPY_KEY, new SoftReference<>(Pair.create(copy, document)));
}
return copy;
}
private static final Key<SoftReference<Pair<PsiFile, Document>>> FILE_COPY_KEY = Key.create("CompletionFileCopy");
private static boolean isCopyUpToDate(Document document, @NotNull PsiFile copyFile, @NotNull PsiFile originalFile) {
if (!copyFile.getClass().equals(originalFile.getClass()) ||
!copyFile.isValid() ||
!copyFile.getName().equals(originalFile.getName())) {
return false;
}
// the psi file cache might have been cleared by some external activity,
// in which case PSI-document sync may stop working
PsiFile current = PsiDocumentManager.getInstance(copyFile.getProject()).getPsiFile(document);
return current != null && current.getViewProvider().getPsi(copyFile.getLanguage()) == copyFile;
}
private static void syncAcceptSlashR(Document originalDocument, Document documentCopy) {
if (!(originalDocument instanceof DocumentImpl) || !(documentCopy instanceof DocumentImpl)) {
return;
}
((DocumentImpl) documentCopy).setAcceptSlashR(((DocumentImpl) originalDocument).acceptsSlashR());
}
}
@@ -0,0 +1,44 @@
// 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.codeInsight.completion;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
/**
* @author yole
*/
public class CompletionProcessBase implements CompletionProcessEx, Disposable {
protected final int myInvocationCount;
protected final Object myLock = new String("CompletionProgressIndicator");
protected OffsetsInFile myHostOffsets;
public CompletionProcessBase(CompletionInitializationContext context) {
myInvocationCount = context.getInvocationCount();
myHostOffsets = ((CompletionInitializationContextImpl) context).getHostOffsets();
}
@Override
public boolean isAutopopupCompletion() {
return myInvocationCount == 0;
}
@Override
public OffsetsInFile getHostOffsets() {
return myHostOffsets;
}
@Override
public void registerChildDisposable(@NotNull Supplier<Disposable> child) {
synchronized (myLock) {
// avoid registering stuff on an indicator being disposed concurrently
Disposer.register(this, child.get());
}
}
@Override
public void dispose() {
}
}
@@ -0,0 +1,15 @@
// 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.codeInsight.completion;
import com.intellij.openapi.Disposable;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
/**
* @author yole
*/
interface CompletionProcessEx extends CompletionProcess {
OffsetsInFile getHostOffsets();
void registerChildDisposable(@NotNull Supplier<Disposable> child);
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 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.codeInsight.completion;
@@ -90,7 +76,7 @@ import java.util.function.Supplier;
*/
@SuppressWarnings("deprecation")
@Deprecated
public class CompletionProgressIndicator extends ProgressIndicatorBase implements CompletionProcess, Disposable {
public class CompletionProgressIndicator extends ProgressIndicatorBase implements CompletionProcessEx, Disposable {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.CompletionProgressIndicator");
private final Editor myEditor;
@NotNull
@@ -193,7 +179,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
return myOffsetMap;
}
OffsetsInFile getHostOffsets() {
@Override
public OffsetsInFile getHostOffsets() {
return myHostOffsets;
}
@@ -215,9 +202,9 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
if (reference != null) {
final int replacementOffset = findReplacementOffset(selectionEndOffset, reference);
if (replacementOffset > document.getTextLength()) {
LOG.error("Invalid replacementOffset: " + replacementOffset + " returned by reference " + reference + " of " + reference.getClass() +
"; doc=" + document +
"; doc actual=" + (document == initContext.getFile().getViewProvider().getDocument()) +
LOG.error("Invalid replacementOffset: " + replacementOffset + " returned by reference " + reference + " of " + reference.getClass() +
"; doc=" + document +
"; doc actual=" + (document == initContext.getFile().getViewProvider().getDocument()) +
"; doc committed=" + PsiDocumentManager.getInstance(getProject()).isCommitted(document));
} else {
initContext.setReplacementOffset(replacementOffset);
@@ -236,14 +223,14 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
myHostOffsets = new OffsetsInFile(initContext.getFile(), initContext.getOffsetMap()).toTopLevelFile();
}
}
private void addDefaultAdvertisements(CompletionParameters parameters) {
if (DumbService.isDumb(getProject())) {
addAdvertisement("The results might be incomplete while indexing is in progress", MessageType.WARNING.getPopupBackground());
return;
}
advertiseTabReplacement(parameters);
if (isAutopopupCompletion()) {
if (shouldPreselectFirstSuggestion(parameters) && !CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS) {
@@ -513,7 +500,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
}
void registerChildDisposable(@NotNull Supplier<Disposable> child) {
@Override
public void registerChildDisposable(@NotNull Supplier<Disposable> child) {
synchronized (myLock) {
// avoid registering stuff on an indicator being disposed concurrently
checkCanceled();
@@ -1,24 +1,12 @@
/*
* Copyright 2000-2017 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.
*/
// 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.codeInsight.completion.impl;
import com.intellij.codeInsight.completion.*;
import com.intellij.codeInsight.lookup.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
@@ -80,6 +68,18 @@ public final class CompletionServiceImpl extends CompletionService {
}
}
@Override
public CompletionParameters createCompletionParameters(@NotNull Project project,
@NotNull Editor editor,
@NotNull Caret caret,
int invocationCount,
CompletionType completionType) {
CompletionInitializationContext context = CompletionInitializationUtil.createCompletionInitializationContext(project, editor, caret,
invocationCount, completionType);
CompletionProcessBase progress = new CompletionProcessBase(context);
return CompletionInitializationUtil.prepareCompletionParameters(context, progress);
}
@Override
public CompletionResultSet createResultSet(final CompletionParameters parameters, final Consumer<CompletionResult> consumer,
@NotNull final CompletionContributor contributor) {
@@ -12,6 +12,7 @@ import com.intellij.openapi.editor.impl.DocumentMarkupModel;
import com.intellij.openapi.editor.markup.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
@@ -97,7 +98,7 @@ class LineMarkersUtil {
markerEx.setLineSeparatorColor(info.separatorColor);
markerEx.setLineSeparatorPlacement(info.separatorPlacement);
markerEx.putUserData(LineMarkerInfo.LINE_MARKER_INFO, info);
markerEx.putUserData(LINE_MARKER_INFO, info);
});
MarkupEditorFilter editorFilter = info.getEditorFilter();
@@ -107,7 +108,7 @@ class LineMarkersUtil {
}
if (!newHighlighter) {
highlighter.putUserData(LineMarkerInfo.LINE_MARKER_INFO, info);
highlighter.putUserData(LINE_MARKER_INFO, info);
LineMarkerInfo.LineMarkerGutterIconRenderer oldRenderer = highlighter.getGutterIconRenderer() instanceof LineMarkerInfo.LineMarkerGutterIconRenderer ? (LineMarkerInfo.LineMarkerGutterIconRenderer)highlighter.getGutterIconRenderer() : null;
boolean rendererChanged = oldRenderer == null || newRenderer == null || !newRenderer.equals(oldRenderer);
@@ -150,6 +151,8 @@ class LineMarkersUtil {
}
private static LineMarkerInfo getLineMarkerInfo(@NotNull RangeHighlighter highlighter) {
return highlighter.getUserData(LineMarkerInfo.LINE_MARKER_INFO);
return highlighter.getUserData(LINE_MARKER_INFO);
}
private static final Key<LineMarkerInfo> LINE_MARKER_INFO = Key.create("LINE_MARKER_INFO");
}
@@ -241,7 +241,6 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
if (aw.isAvailable()) {
String id = ActionManager.getInstance().getId(aw.getAction());
KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), activeKeymap, component);
popup.repaintListImmediate();
}
}
}
@@ -2,13 +2,13 @@
package com.intellij.openapi.ui;
public interface TestDialog {
TestDialog DEFAULT = new TestDialog() {
public int show(String message) {
throw new RuntimeException(message);
}
};
TestDialog OK = new TestDialog() {
@Override
public int show(String message) {
return 0;
}
@@ -1249,12 +1249,11 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Persis
@Override
@NotNull
public FileEditor[] getSelectedEditors() {
Set<FileEditor> selectedEditors = new LinkedHashSet<>();
EditorComposite selected = getLastSelected();
if (selected != null) selectedEditors.add(selected.getSelectedEditor());
Set<FileEditor> selectedEditors = new HashSet<>();
for (EditorsSplitters each : getAllSplitters()) {
ContainerUtil.addAll(selectedEditors, each.getSelectedEditors());
}
return selectedEditors.toArray(new FileEditor[0]);
}
@@ -491,7 +491,7 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene
boolean enabledFocus = getFocusManager().isFocusTransferEnabled();
if (focused || requestFocus) {
if (enabledFocus) {
return getFocusManager().requestFocus(myComponent, true).doWhenProcessed(() -> selection.run().notify(result));
return getFocusManager().requestFocus(getComponent(), true).doWhenProcessed(() -> selection.run().notify(result));
}
}
return selection.run().notify(result);
@@ -1,6 +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.framework.detection;
import com.intellij.framework.detection.impl.exclude.DetectionExcludesConfigurationImpl;
@@ -12,7 +10,6 @@ import com.intellij.framework.detection.impl.exclude.old.OldFacetDetectionExclud
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.TempFiles;
import static com.intellij.testFramework.assertions.Assertions.assertThat;
@@ -21,17 +18,10 @@ import static com.intellij.testFramework.assertions.Assertions.assertThat;
*/
public class ConvertingOldDetectionExcludesTest extends PlatformTestCase {
public static final String FRAMEWORK_ID = "my-framework";
private TempFiles myTempFiles;
@Override
protected void setUp() throws Exception {
super.setUp();
myTempFiles = new TempFiles(myFilesToDelete);
}
public void testUseOldConfiguration() {
final DisabledAutodetectionInfo state = new DisabledAutodetectionInfo();
final VirtualFile file = myTempFiles.createVFile("my-file", ".xml");
final VirtualFile file = getTempDir().createVFile("my-file", ".xml");
state.getElements().add(new DisabledAutodetectionByTypeElement(FRAMEWORK_ID, myModule.getName(), file.getUrl(), false));
getOldConfiguration().loadState(state);
@@ -42,9 +32,9 @@ public class ConvertingOldDetectionExcludesTest extends PlatformTestCase {
public void testExcludeModuleConfiguration() {
final DisabledAutodetectionInfo state = new DisabledAutodetectionInfo();
final VirtualFile dir = myTempFiles.createTempVDir();
final VirtualFile dir = getTempDir().createTempVDir();
PsiTestUtil.addContentRoot(myModule, dir);
final VirtualFile file = myTempFiles.createVFile(dir, "my-file", ".xml");
final VirtualFile file = getTempDir().createVFile(dir, "my-file", ".xml");
state.getElements().add(new DisabledAutodetectionByTypeElement(FRAMEWORK_ID, myModule.getName()));
getOldConfiguration().loadState(state);
@@ -55,7 +45,7 @@ public class ConvertingOldDetectionExcludesTest extends PlatformTestCase {
public void testExcludeFrameworkConfiguration() {
final DisabledAutodetectionInfo state = new DisabledAutodetectionInfo();
final VirtualFile file = myTempFiles.createVFile("my-file", ".xml");
final VirtualFile file = getTempDir().createVFile("my-file", ".xml");
state.getElements().add(new DisabledAutodetectionByTypeElement(FRAMEWORK_ID));
getOldConfiguration().loadState(state);
@@ -66,7 +56,7 @@ public class ConvertingOldDetectionExcludesTest extends PlatformTestCase {
public void testUseNewConfiguration() {
final ExcludesConfigurationState state = new ExcludesConfigurationState();
final VirtualFile file = myTempFiles.createVFile("xxx", ".xml");
final VirtualFile file = getTempDir().createVFile("xxx", ".xml");
state.getFiles().add(new ExcludedFileState(file.getUrl(), FRAMEWORK_ID));
getNewConfiguration().loadState(state);
@@ -83,7 +73,7 @@ public class ConvertingOldDetectionExcludesTest extends PlatformTestCase {
public void testConvert() {
final DisabledAutodetectionInfo state = new DisabledAutodetectionInfo();
final VirtualFile file = myTempFiles.createVFile("my-file", ".xml");
final VirtualFile file = getTempDir().createVFile("my-file", ".xml");
state.getElements().add(new DisabledAutodetectionByTypeElement(FRAMEWORK_ID, myModule.getName(), file.getUrl(), false));
getOldConfiguration().loadState(state);
@@ -11,8 +11,8 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.ArrayUtil;
import org.jdom.Element;
@@ -87,7 +87,7 @@ public class LightFileTemplatesTest extends LightPlatformTestCase {
myTemplateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(myTemplateManager.getAllTemplates()));
assertNotNull(myTemplateManager.getTemplate("foo.txt"));
File foo = PlatformTestCase.createTempDir("foo");
File foo = FileUtilRt.createTempDirectory("foo", null, false);
final Project project = ProjectManager.getInstance().createProject("foo", foo.getPath());
try {
assertNotNull(project);
@@ -95,11 +95,12 @@ public class LightFileTemplatesTest extends LightPlatformTestCase {
}
finally {
closeProject(project);
FileUtilRt.delete(foo);
}
}
public void testSurviveOnProjectReopen() throws Exception {
File foo = PlatformTestCase.createTempDir("foo");
File foo = FileUtilRt.createTempDirectory("foo", null, false);
Project reloaded = null;
final Project project = ProjectManager.getInstance().createProject("foo", foo.getPath());
try {
@@ -127,11 +128,12 @@ public class LightFileTemplatesTest extends LightPlatformTestCase {
finally {
closeProject(project);
closeProject(reloaded);
FileUtilRt.delete(foo);
}
}
public void testAddRemoveShared() throws Exception {
File foo = PlatformTestCase.createTempDir("foo");
File foo = FileUtilRt.createTempDirectory("foo", null, false);
final Project project = ProjectManager.getInstance().createProject("foo", foo.getPath());
try {
assertThat(project).isNotNull();
@@ -169,6 +171,7 @@ public class LightFileTemplatesTest extends LightPlatformTestCase {
}
finally {
closeProject(project);
FileUtilRt.delete(foo);
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.diff.impl.mergeTool;
import com.intellij.openapi.diff.ActionButtonPresentation;
@@ -21,13 +7,10 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.TempFiles;
public class MergeDataTest extends BaseDiffTestCase {
private TempFiles myTempFiles;
public void testWorkingDocument() {
VirtualFile file = myTempFiles.createVFile("merge", ".txt");
VirtualFile file = getTempDir().createVFile("merge", ".txt");
assertNotNull(file);
assertEquals("txt", file.getExtension());
Document document = FileDocumentManager.getInstance().getDocument(file);
@@ -44,17 +27,4 @@ public class MergeDataTest extends BaseDiffTestCase {
mergeData.setResult(DialogWrapper.OK_EXIT_CODE);
assertEquals("corrected", document.getText());
}
@Override
protected void setUp() throws Exception {
super.setUp();
myTempFiles = new TempFiles(myFilesToDelete);
}
@Override
protected void tearDown() throws Exception {
myTempFiles.deleteAll();
myTempFiles = null;
super.tearDown();
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.diff.impl.patch;
@@ -27,7 +13,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileFilter;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.PsiTestUtil;
import java.io.File;
import java.util.ArrayList;
@@ -200,7 +185,7 @@ public class ApplyPatchTest extends PlatformTestCase {
String afterPath = testDataPath + "/after";
VirtualFile afterDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(afterPath.replace(File.separatorChar, '/'));
VirtualFile patchedDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, beforePath, myFilesToDelete);
VirtualFile patchedDir = createTestProjectStructure(beforePath);
String patchPath = testDataPath + "/apply.patch";
VirtualFile patchFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(patchPath.replace(File.separatorChar, '/'));
@@ -1,31 +1,15 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.diff.impl.patch
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.testFramework.PlatformTestCase
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.PsiTestUtil
import com.intellij.vcs.log.impl.VcsUserImpl
import junit.framework.TestCase
import java.io.File
class PatchReaderTest : PlatformTestCase() {
private val author = VcsUserImpl("D D", "aaaa@gmail.com")
private val doubleSurname = VcsUserImpl("D D-D", "aaaa@gmail.com")
private val longName = VcsUserImpl("very long author-surname", "aaaa@gmail.com")
@@ -99,8 +83,8 @@ class PatchReaderTest : PlatformTestCase() {
private fun read(): PatchReader {
val testDataPath = PlatformTestUtil.getPlatformTestDataPath() + "diff/patchReader/" + getTestName(true)
PsiTestUtil.createTestProjectStructure(myProject, myModule, testDataPath, PlatformTestCase.myFilesToDelete)
val patchPath = testDataPath + "/test.patch"
createTestProjectStructure(testDataPath)
val patchPath = "$testDataPath/test.patch"
val patchFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(patchPath.replace(File.separatorChar, '/'))
val patchContents = patchFile!!.contentsToByteArray()
@@ -1,29 +1,13 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.diff.impl.patch
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.testFramework.PlatformTestCase
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.PsiTestUtil
import java.io.File
class PatchTextDetectionTest : PlatformTestCase() {
fun testClassicalContextDiff() {
doTest(true)
}
@@ -48,16 +32,14 @@ class PatchTextDetectionTest : PlatformTestCase() {
doTest(false)
}
private fun doTest(expected: Boolean) {
val testDataPath = PlatformTestUtil.getPlatformTestDataPath() + "diff/patchTextDetection/" + getTestName(true)
PsiTestUtil.createTestProjectStructure(myProject, myModule, testDataPath, PlatformTestCase.myFilesToDelete)
val patchPath = testDataPath + "/test.patch"
createTestProjectStructure(testDataPath)
val patchPath = "$testDataPath/test.patch"
val patchFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(patchPath.replace(File.separatorChar, '/'))
val patchContents = patchFile!!.contentsToByteArray()
val patchText = LoadTextUtil.getTextByBinaryPresentation(patchContents, patchFile);
assertEquals(expected, PatchReader.isPatchContent((patchText.toString())));
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.project.impl;
import com.intellij.ide.impl.ProjectUtil;
@@ -40,7 +26,7 @@ import static com.intellij.openapi.startup.StartupActivity.POST_STARTUP_ACTIVITY
public class ProjectOpeningTest extends PlatformTestCase {
public void testOpenProjectCancelling() throws Exception {
File foo = PlatformTestCase.createTempDir("foo");
File foo = createTempDir("foo");
Project project = null;
MyStartupActivity activity = new MyStartupActivity();
PlatformTestUtil.registerExtension(POST_STARTUP_ACTIVITY, activity, getTestRootDisposable());
@@ -58,7 +44,7 @@ public class ProjectOpeningTest extends PlatformTestCase {
}
public void testCancelOnLoadingModules() throws Exception {
File foo = PlatformTestCase.createTempDir("foo");
File foo = createTempDir("foo");
Project project = null;
try {
ProjectManagerEx manager = ProjectManagerEx.getInstanceEx();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.project.impl;
import com.intellij.ide.ProjectGroup;
@@ -76,7 +62,7 @@ public class RecentProjectsTest extends PlatformTestCase {
public void testTimestampForOpenProjectUpdatesWhenGetStateCalled() throws Exception {
Project project = null;
try {
File path = PlatformTestCase.createTempDir("z1");
File path = createTempDir("z1");
ProjectManagerEx manager = ProjectManagerEx.getInstanceEx();
project = manager.createProject(null, path.getPath());
project.save();
@@ -129,10 +115,10 @@ public class RecentProjectsTest extends PlatformTestCase {
Assert.assertEquals(Arrays.toString(groups), Arrays.toString(recentGroups.toArray()));
}
private static String createAndOpenProject(String name) throws IOException, JDOMException {
private String createAndOpenProject(String name) throws IOException, JDOMException {
Project project = null;
try {
File path = PlatformTestCase.createTempDir(name);
File path = createTempDir(name);
ProjectManagerEx manager = ProjectManagerEx.getInstanceEx();
project = manager.createProject(null, path.getPath());
project.save();
@@ -46,6 +46,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
@@ -64,6 +65,11 @@ public class FileEncodingTest extends PlatformTestCase implements TestDialog {
private static final String THREE_RUSSIAN_LETTERS = "\u0416\u041e\u041f";
private TestDialog myOldTestDialogValue;
@Override
public int show(String message) {
return 0;
}
private static String prolog(Charset charset) {
return "<?xml version=\"1.0\" encoding=\"" + charset.name() + "\"?>\n";
}
@@ -84,15 +90,10 @@ public class FileEncodingTest extends PlatformTestCase implements TestDialog {
}
}
@Override
public int show(String message) {
return 0;
}
private static Document getDocument(VirtualFile file) {
return FileDocumentManager.getInstance().getDocument(file);
}
public void testWin1251() {
VirtualFile vTestRoot = getTestRoot();
VirtualFile xml = vTestRoot.findChild("xWin1251.xml");
@@ -159,7 +160,7 @@ public class FileEncodingTest extends PlatformTestCase implements TestDialog {
FileDocumentManager.getInstance().saveAllDocuments();
byte[] savedBytes = FileUtil.loadFileBytes(file);
String saved = new String(savedBytes, CharsetToolkit.UTF8).replace("\r\n", "\n");
String saved = new String(savedBytes, StandardCharsets.UTF_8).replace("\r\n", "\n");
String expected = (UTF8_XML_PROLOG + XML_TEST_BODY).replace("\r\n", "\n");
assertEquals(expected, saved);
@@ -214,8 +215,7 @@ public class FileEncodingTest extends PlatformTestCase implements TestDialog {
String text = document.getText();
assertEquals("\u041f\u0440\u0438", text);
File copy = FileUtil.createTempFile("copy", ".txt");
myFilesToDelete.add(copy);
File copy = getTempDir().createTempFile("copy", ".txt", false);
FileUtil.copy(source, copy);
VirtualFile fileCopy = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(copy);
document = getDocument(fileCopy);
@@ -238,15 +238,13 @@ public class FileEncodingTest extends PlatformTestCase implements TestDialog {
"<meta charset =\"utf-8\">");
}
private static void doHtmlTest(final String metaWithWindowsEncoding, final String metaWithUtf8Encoding) throws IOException {
File temp = FileUtil.createTempFile("copy", ".html");
private void doHtmlTest(final String metaWithWindowsEncoding, final String metaWithUtf8Encoding) throws IOException {
File temp = getTempDir().createTempFile("copy", ".html", false);
setContentOnDisk(temp, NO_BOM,
"<html><head>" + metaWithWindowsEncoding + "</head>" +
THREE_RUSSIAN_LETTERS +
"</html>",
WINDOWS_1252);
myFilesToDelete.add(temp);
VirtualFile file = ObjectUtils.assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp));
assertEquals(WINDOWS_1252, file.getCharset());
@@ -703,7 +701,7 @@ public class FileEncodingTest extends PlatformTestCase implements TestDialog {
VirtualFile file = createTempFile("txt", CharsetToolkit.UTF8_BOM, text, CharsetToolkit.UTF8_CHARSET);
file.contentsToByteArray();
Document document = ObjectUtils.assertNotNull(FileDocumentManager.getInstance().getDocument(file));
assertEquals(text, document.getText());
assertEquals(CharsetToolkit.UTF8_CHARSET, file.getCharset());
assertArrayEquals(CharsetToolkit.UTF8_BOM, file.getBOM());
@@ -1,25 +1,10 @@
/*
* Copyright 2000-2015 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.
*/
// 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.psi.search;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.TempFiles;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -62,7 +47,7 @@ public class GlobalSearchScopeTest extends PlatformTestCase {
}
public void testNotScope() {
VirtualFile moduleRoot = new TempFiles(myFilesToDelete).createTempVDir();
VirtualFile moduleRoot = getTempDir().createTempVDir();
ModuleRootModificationUtil.addContentRoot(getModule(), moduleRoot.getPath());
GlobalSearchScope projectScope = GlobalSearchScope.projectScope(getProject());
@@ -101,7 +101,10 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
protected ProjectManagerEx myProjectManager;
protected Project myProject;
protected Module myModule;
protected static final Collection<File> myFilesToDelete = new THashSet<>();
protected final Collection<File> myFilesToDelete = new THashSet<>();
private final TempFiles myTempFiles = new TempFiles(myFilesToDelete);
protected boolean myAssertionsInTestDetected;
public static Thread ourTestThread;
private static TestCase ourTestCase;
@@ -115,6 +118,20 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
private SdkLeakTracker myOldSdks;
private VirtualFilePointerTracker myVirtualFilePointerTracker;
@NotNull
public TempFiles getTempDir() {
return myTempFiles;
}
protected final VirtualFile createTestProjectStructure() throws IOException {
return PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete);
}
protected final VirtualFile createTestProjectStructure(String rootPath) throws Exception {
return PsiTestUtil.createTestProjectStructure(myProject, myModule, rootPath, myFilesToDelete);
}
/**
* If a temp directory is reused from some previous test run, there might be cached children in its VFS.
* Ensure they're removed
@@ -500,10 +517,8 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
})
.append(() -> {
((JarFileSystemImpl)JarFileSystem.getInstance()).cleanupForNextTest();
for (final File fileToDelete : myFilesToDelete) {
delete(fileToDelete);
}
getTempDir().deleteAll();
LocalFileSystem.getInstance().refreshIoFiles(myFilesToDelete);
})
.append(() -> {
@@ -586,13 +601,6 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
return getClass().getName() + "." + getName();
}
private void delete(File file) {
boolean b = FileUtil.delete(file);
if (!b && file.exists() && !myAssertionsInTestDetected) {
fail("Can't delete " + file.getAbsolutePath() + " in " + getFullName());
}
}
protected void setUpJdk() {
//final ProjectJdkEx jdk = ProjectJdkUtil.getDefaultJdk("java 1.4");
final Sdk jdk = getTestProjectJdk();
@@ -745,12 +753,12 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
}
@NotNull
public static File createTempDir(@NonNls final String prefix) throws IOException {
public File createTempDir(@NonNls @NotNull String prefix) throws IOException {
return createTempDir(prefix, true);
}
@NotNull
public static File createTempDir(@NonNls final String prefix, final boolean refresh) throws IOException {
public File createTempDir(@NonNls @NotNull String prefix, final boolean refresh) throws IOException {
final File tempDirectory = FileUtilRt.createTempDirectory("idea_test_" + prefix, null, false);
myFilesToDelete.add(tempDirectory);
if (refresh) {
@@ -797,7 +805,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
}
@NotNull
public static VirtualFile createTempFile(@NonNls @NotNull String ext, @Nullable byte[] bom, @NonNls @NotNull String content, @NotNull Charset charset) throws IOException {
public VirtualFile createTempFile(@NonNls @NotNull String ext, @Nullable byte[] bom, @NonNls @NotNull String content, @NotNull Charset charset) throws IOException {
File temp = FileUtil.createTempFile("copy", "." + ext);
setContentOnDisk(temp, bom, content, charset);
@@ -35,6 +35,7 @@ import com.intellij.openapi.project.ex.ProjectManagerEx;
import com.intellij.openapi.ui.Queryable;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -771,27 +772,33 @@ public class PlatformTestUtil {
}
public static void assertJarFilesEqual(File file1, File file2) throws IOException {
final File tempDirectory1;
final File tempDirectory2;
final File tempDir = FileUtilRt.createTempDirectory("assert_jar_tmp", null, false);
try {
final File tempDirectory1 = new File(tempDir, "tmp1");
final File tempDirectory2 = new File(tempDir, "tmp2");
FileUtilRt.createDirectory(tempDirectory1);
FileUtilRt.createDirectory(tempDirectory2);
try (JarFile jarFile1 = new JarFile(file1)) {
try (JarFile jarFile2 = new JarFile(file2)) {
tempDirectory1 = PlatformTestCase.createTempDir("tmp1");
tempDirectory2 = PlatformTestCase.createTempDir("tmp2");
ZipUtil.extract(jarFile1, tempDirectory1, null);
ZipUtil.extract(jarFile2, tempDirectory2, null);
try (JarFile jarFile1 = new JarFile(file1)) {
try (JarFile jarFile2 = new JarFile(file2)) {
ZipUtil.extract(jarFile1, tempDirectory1, null);
ZipUtil.extract(jarFile2, tempDirectory2, null);
}
}
}
final VirtualFile dirAfter = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory1);
Assert.assertNotNull(tempDirectory1.toString(), dirAfter);
final VirtualFile dirBefore = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory2);
Assert.assertNotNull(tempDirectory2.toString(), dirBefore);
getApplication().runWriteAction(() -> {
dirAfter.refresh(false, true);
dirBefore.refresh(false, true);
});
assertDirectoriesEqual(dirAfter, dirBefore);
final VirtualFile dirAfter = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory1);
Assert.assertNotNull(tempDirectory1.toString(), dirAfter);
final VirtualFile dirBefore = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory2);
Assert.assertNotNull(tempDirectory2.toString(), dirBefore);
getApplication().runWriteAction(() -> {
dirAfter.refresh(false, true);
dirBefore.refresh(false, true);
});
assertDirectoriesEqual(dirAfter, dirBefore);
}
finally {
FileUtilRt.delete(tempDir);
}
}
/**
@@ -1,23 +1,10 @@
/*
* Copyright 2000-2015 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.
*/
// 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.testFramework;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -52,10 +39,17 @@ public class TempFiles {
@NotNull
public File createTempFile(@NotNull String prefix, String suffix) {
return createTempFile(prefix, suffix, true);
}
@NotNull
public File createTempFile(@NotNull String prefix, String suffix, boolean isRefreshVfs) {
try {
File tempFile = FileUtil.createTempFile(prefix, suffix);
File tempFile = FileUtilRt.createTempFile(prefix, suffix, false);
tempFileCreated(tempFile);
getVFileByFile(tempFile);
if (isRefreshVfs) {
getVFileByFile(tempFile);
}
return tempFile;
}
catch (IOException e) {
@@ -103,6 +97,7 @@ public class TempFiles {
public void deleteAll() {
for (File file : myFilesToDelete) {
if (!FileUtil.delete(file)) {
//noinspection SSBasedInspection
file.deleteOnExit();
}
}
@@ -42,16 +42,6 @@ public class DataInputOutputUtil extends DataInputOutputUtilRt {
DataInputOutputUtilRt.writeINT(record, val);
}
@Nullable
public static StringRef readNAME(@NotNull DataInput record, @NotNull AbstractStringEnumerator nameStore) throws IOException {
return StringRef.fromStream(record, nameStore);
}
public static void writeNAME(@NotNull DataOutput record, @Nullable String name, @NotNull AbstractStringEnumerator nameStore) throws IOException {
final int nameId = name != null ? nameStore.enumerate(name) : 0;
writeINT(record, nameId);
}
public static long readLONG(@NotNull DataInput record) throws IOException {
final int val = record.readUnsignedByte();
if (val < 192) {
@@ -115,6 +115,12 @@ public class StringRef {
return nameId != 0 ? new StringRef(nameId, store) : null;
}
@Nullable
public static String stringFromStream(@NotNull DataInput in, @NotNull AbstractStringEnumerator store) throws IOException {
final int nameId = DataInputOutputUtil.readINT(in);
return nameId != 0 ? store.valueOf(nameId) : null;
}
@NotNull
public static StringRef[] createArray(int count) {
return count == 0 ? EMPTY_ARRAY : new StringRef[count];
@@ -23,8 +23,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
/**
* @author Sergey Karashevich
@@ -34,17 +34,16 @@ public class ExecutableHelper {
private static final Logger LOG = Logger.getInstance(ExecutableHelper.class);
private static final String GIT_EXECUTABLE_ENV = "IDEA_TEST_GIT_EXECUTABLE";
private static final String TEAMCITY_GIT_EXECUTABLE_ENV = "TEAMCITY_GIT_PATH";
public static String findGitExecutable() {
return findExecutable("Git", "git", "git.exe", Arrays.asList(GIT_EXECUTABLE_ENV, TEAMCITY_GIT_EXECUTABLE_ENV));
return findExecutable("Git", "git", "git.exe", Collections.singletonList(GIT_EXECUTABLE_ENV));
}
@NotNull
public static String findExecutable(@NotNull String programName,
@NotNull String unixExec,
@NotNull String winExec,
@NotNull Collection<String> envs) {
@NotNull String unixExec,
@NotNull String winExec,
@NotNull Collection<String> envs) {
String exec = findEnvValue(programName, envs);
if (exec != null) {
return exec;
@@ -78,5 +77,4 @@ public class ExecutableHelper {
LOG.info(msg);
}
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.vcs;
import com.intellij.ide.startup.impl.StartupManagerImpl;
@@ -31,7 +17,6 @@ import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.vcsUtil.VcsUtil;
import junit.framework.Assert;
import org.jetbrains.annotations.NonNls;
import java.io.File;
@@ -73,10 +58,13 @@ public class DirectoryMappingListTest extends PlatformTestCase {
@Override
protected void tearDown() throws Exception {
myMappings.disposeMe();
((AllVcses) myVcses).dispose();
super.tearDown();
try {
myMappings.disposeMe();
((AllVcses)myVcses).dispose();
}
finally {
super.tearDown();
}
}
public void testMappingsFilter() {
@@ -139,12 +127,12 @@ public class DirectoryMappingListTest extends PlatformTestCase {
for (String child : children) {
myMappings.setMapping(child, "CVS");
myMappings.cleanupMappings();
Assert.assertEquals("cleanup failed: " + child, 1, myMappings.getDirectoryMappings().size());
assertEquals("cleanup failed: " + child, 1, myMappings.getDirectoryMappings().size());
}
for (String child : children) {
myMappings.setMapping(child, "CVS");
Assert.assertEquals("cleanup failed: " + child, 1, myMappings.getDirectoryMappings().size());
assertEquals("cleanup failed: " + child, 1, myMappings.getDirectoryMappings().size());
}
}
@@ -160,7 +148,7 @@ public class DirectoryMappingListTest extends PlatformTestCase {
for (String child : children) {
myMappings.setMapping(child, "CVS");
myMappings.cleanupMappings();
Assert.assertEquals("cleanup failed: " + child, 1, myMappings.getDirectoryMappings().size());
assertEquals("cleanup failed: " + child, 1, myMappings.getDirectoryMappings().size());
}
}
@@ -180,14 +168,14 @@ public class DirectoryMappingListTest extends PlatformTestCase {
for (int i = 0; i < children.length; i++) {
String child = children[i];
final VirtualFile vf = lfs.refreshAndFindFileByIoFile(new File(child));
Assert.assertNotNull(vf);
assertNotNull(vf);
final VcsDirectoryMapping mapping = myMappings.getMappingFor(vf);
Assert.assertNotNull(mapping);
Assert.assertEquals(awaitedVcsNames[i], mapping.getVcs());
assertNotNull(mapping);
assertEquals(awaitedVcsNames[i], mapping.getVcs());
}
}
private static void createFiles(final String[] paths) {
private void createFiles(final String[] paths) {
for (String path : paths) {
final File file = new File(FileUtil.toSystemDependentName(path));
assert file.mkdirs() || file.isDirectory() : file;
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.openapi.vcs.changes.committed;
import com.intellij.openapi.application.ApplicationManager;
@@ -325,7 +311,6 @@ public class CommittedChangesCacheTest extends PlatformTestCase {
private File createTestFile(final String fileName) throws IOException {
final File testFile = new File(myTempDir, fileName);
testFile.createNewFile();
myFilesToDelete.add(testFile);
ApplicationManager.getApplication().runWriteAction(() -> {
VirtualFileManager.getInstance().syncRefresh();
});
@@ -35,7 +35,6 @@ import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
abstract class VcsPlatformTest : PlatformTestCase() {
protected lateinit var testRoot: File
protected lateinit var testRootFile: VirtualFile
protected lateinit var projectRoot: VirtualFile
@@ -50,8 +49,7 @@ abstract class VcsPlatformTest : PlatformTestCase() {
@Throws(Exception::class)
override fun setUp() {
testRoot = File(FileUtil.getTempDirectory(), "root-${Integer.toHexString(Random().nextInt())}")
PlatformTestCase.myFilesToDelete.add(testRoot)
testRoot = createTempDir("root-${Integer.toHexString(Random().nextInt())}", false)
checkTestRootIsEmpty(testRoot)
runInEdtAndWait { super@VcsPlatformTest.setUp() }
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// 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.xdebugger;
import com.intellij.openapi.application.WriteAction;
@@ -57,7 +43,7 @@ public class UpdateBreakpointsAfterRenameTest extends XBreakpointsTestCase {
}
private VirtualFile createFile(String path) {
final File ioFile = new File(myTempFiles.createTempDir(), FileUtil.toSystemDependentName(path));
final File ioFile = new File(getTempDir().createTempDir(), FileUtil.toSystemDependentName(path));
FileUtil.createIfDoesntExist(ioFile);
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile);
assertNotNull(virtualFile);
@@ -1,6 +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.xdebugger;
import com.intellij.openapi.vfs.VirtualFile;
@@ -136,7 +134,7 @@ public class XBreakpointManagerTest extends XBreakpointsTestCase {
}
public void testRemoveFile() {
final VirtualFile file = myTempFiles.createVFile("breakpoint", ".txt");
final VirtualFile file = getTempDir().createVFile("breakpoint", ".txt");
addLineBreakpoint(myBreakpointManager, file.getUrl(), 0, null);
assertOneElement(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE));
delete(file);
@@ -1,11 +1,8 @@
/*
* 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.xdebugger;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.TempFiles;
import com.intellij.xdebugger.breakpoints.XBreakpoint;
import com.intellij.xdebugger.breakpoints.XBreakpointType;
import com.intellij.xdebugger.impl.BreakpointManagerState;
@@ -25,13 +22,11 @@ import static com.intellij.configurationStore.XmlSerializer.serialize;
*/
public abstract class XBreakpointsTestCase extends XDebuggerTestCase {
protected XBreakpointManagerImpl myBreakpointManager;
protected TempFiles myTempFiles;
@Override
protected void setUp() throws Exception {
super.setUp();
myBreakpointManager = (XBreakpointManagerImpl)XDebuggerManager.getInstance(myProject).getBreakpointManager();
myTempFiles = new TempFiles(myFilesToDelete);
}
@Override
@@ -7,7 +7,6 @@ import com.intellij.execution.impl.ConsoleViewImpl;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
@@ -31,15 +30,16 @@ import com.intellij.xdebugger.impl.frame.XStackFrameContainerEx;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.concurrency.Promise;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.junit.Assert.*;
@@ -65,15 +65,13 @@ public class XDebuggerTestUtil {
@Nullable
public static XLineBreakpoint toggleBreakpoint(Project project, VirtualFile file, int line) {
return new WriteAction<XLineBreakpoint>() {
@Override
protected void run(@NotNull Result<XLineBreakpoint> result) {
Promise<XLineBreakpoint> promise =
((XDebuggerUtilImpl)XDebuggerUtil.getInstance()).toggleAndReturnLineBreakpoint(project, file, line, false);
promise.done(result::setResult);
}
}.execute().getResultObject();
try {
return WriteAction.computeAndWait(() -> ((XDebuggerUtilImpl)XDebuggerUtil.getInstance())
.toggleAndReturnLineBreakpoint(project, file, line, false)).blockingGet(TIMEOUT_MS);
}
catch (TimeoutException | ExecutionException e) {
return null;
}
}
public static <P extends XBreakpointProperties> XBreakpoint<P> insertBreakpoint(final Project project,
@@ -12,7 +12,6 @@ import com.intellij.psi.util.CachedValuesManager;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.io.DataInputOutputUtil;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
@@ -42,7 +41,7 @@ public class GrStubUtils {
@NotNull
public static String[] readStringArray(@NotNull StubInputStream dataStream) throws IOException {
return ArrayUtil.toStringArray(readSeq(dataStream, () -> StringRef.toString(dataStream.readName())));
return ArrayUtil.toStringArray(readSeq(dataStream, () -> dataStream.readNameString()));
}
public static void writeNullableString(StubOutputStream dataStream, @Nullable String typeText) throws IOException {
@@ -50,7 +50,7 @@ public class GrNameValuePairElementType extends GrStubElementType<GrNameValuePai
public GrNameValuePairStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new GrNameValuePairStub(
parentStub,
StringRef.toString(dataStream.readName()),
dataStream.readNameString(),
dataStream.readBoolean() ? dataStream.readUTFFast() : null
);
}
@@ -56,10 +56,10 @@ public abstract class GrTypeDefinitionElementType<TypeDef extends GrTypeDefiniti
@Override
@NotNull
public GrTypeDefinitionStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = StringRef.toString(dataStream.readName());
String qname = StringRef.toString(dataStream.readName());
String name = dataStream.readNameString();
String qname = dataStream.readNameString();
byte flags = dataStream.readByte();
String baseClassName = StringRef.toString(dataStream.readName());
String baseClassName = dataStream.readNameString();
String[] annos = readStringArray(dataStream);
return new GrTypeDefinitionStub(parentStub, name, baseClassName, this, qname, annos, flags);
}
@@ -6,7 +6,6 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.scope.ElementClassHint;
import com.intellij.psi.scope.ElementClassHint.DeclarationKind;
@@ -63,8 +62,6 @@ import org.jetbrains.plugins.groovy.lang.resolve.processors.*;
import java.util.*;
import static com.intellij.util.containers.ContainerUtil.count;
import static com.intellij.util.containers.ContainerUtil.filter;
import static org.jetbrains.plugins.groovy.lang.psi.impl.GrAnnotationUtilKt.hasAnnotation;
import static org.jetbrains.plugins.groovy.lang.psi.util.PsiTreeUtilKt.treeWalkUpAndGetSingleElement;
import static org.jetbrains.plugins.groovy.lang.resolve.ResolveUtilKt.getDefaultConstructor;
@@ -1080,19 +1077,6 @@ public class ResolveUtil {
return true;
}
public static boolean isMethodCallRef(@NotNull GrReferenceExpression ref) {
final PsiElement element = PsiTreeUtil.skipParentsOfType(ref, GrReferenceExpression.class);
return element instanceof GrMethodCall;
}
public static boolean isPartOfFQN(@NotNull GrReferenceExpression ref) {
if (ref.hasAt()) return false;
final String name = ref.getReferenceName();
if (StringUtil.isEmpty(name)) return false;
return Character.isUpperCase(name.charAt(0)) && !isMethodCallRef(ref) ||
ref.getParent() instanceof GrReferenceExpression && isPartOfFQN((GrReferenceExpression)ref.getParent());
}
public static boolean canResolveToMethod(@NotNull GrReferenceExpression ref) {
return ref.hasMemberPointer() || ref.getParent() instanceof GrMethodCall;
}
@@ -1107,25 +1091,6 @@ public class ResolveUtil {
return true;
}
@NotNull
public static List<GroovyResolveResult> filterAccessorMethods(@NotNull List<GroovyResolveResult> candidates) {
return filter(candidates, it -> !(it.getElement() instanceof GrAccessorMethod));
}
@NotNull
public static List<GroovyResolveResult> collapseReflectedMethodsSimple(@NotNull List<GroovyResolveResult> candidates) {
if (count(candidates, it -> it.getElement() instanceof GrReflectedMethod) < 2) return candidates;
final Set<GrMethod> visited = ContainerUtil.newHashSet();
return ContainerUtil.mapNotNull(candidates, result -> {
final PsiElement element = result.getElement();
if (!(element instanceof GrReflectedMethod)) return result;
final GrMethod baseMethod = ((GrReflectedMethod)element).getBaseMethod();
if (!visited.add(baseMethod)) return null;
return new ElementGroovyResult<>(baseMethod);
});
}
@NotNull
public static List<GroovyResolveResult> collapseReflectedMethods(Collection<GroovyResolveResult> candidates) {
Set<GrMethod> visited = ContainerUtil.newHashSet();
@@ -18,11 +18,8 @@ import static org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil.collapseRefl
class GroovyResolverProcessorImpl extends GroovyResolverProcessor implements GrMethodComparator.Context {
private final boolean myIsPartOfFqn;
GroovyResolverProcessorImpl(@NotNull final GrReferenceExpression ref, @NotNull EnumSet<GroovyResolveKind> kinds, boolean forceRValue) {
super(ref, kinds, null, forceRValue);
myIsPartOfFqn = ResolveUtil.isPartOfFQN(ref);
}
@NotNull
@@ -45,13 +42,6 @@ class GroovyResolverProcessorImpl extends GroovyResolverProcessor implements GrM
return candidates;
}
if (myIsPartOfFqn) {
candidates = getCandidates(GroovyResolveKind.PACKAGE, GroovyResolveKind.CLASS);
if (!candidates.isEmpty()) {
return candidates;
}
}
candidates = getCandidates(GroovyResolveKind.PROPERTY);
if (!candidates.isEmpty()) {
return candidates.size() <= 1 ? candidates : ContainerUtil.newSmartList(candidates.get(0));
@@ -30,7 +30,6 @@ import com.intellij.lang.properties.psi.impl.PropertyStubImpl;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.*;
import com.intellij.util.CharTable;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -60,8 +59,7 @@ public class PropertyStubElementType extends ILightStubElementType<PropertyStub,
@NotNull
public PropertyStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException {
final StringRef ref = dataStream.readName();
return new PropertyStubImpl(parentStub, ref.getString());
return new PropertyStubImpl(parentStub, dataStream.readNameString());
}
public void indexStub(@NotNull final PropertyStub stub, @NotNull final IndexSink sink) {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2012 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.
*/
// 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.uiDesigner.binding;
@@ -40,7 +26,7 @@ public class FormEnumUsageTest extends PsiTestCase {
String root = PluginPathManager.getPluginHomePath("ui-designer") + "/testData/binding/" + getTestName(true);
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
myTestProjectRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
myTestProjectRoot = createTestProjectStructure(root);
}
@Override protected void tearDown() throws Exception {

Some files were not shown because too many files have changed in this diff Show More