diff --git a/.idea/libraries/asm5.xml b/.idea/libraries/ASM.xml similarity index 68% rename from .idea/libraries/asm5.xml rename to .idea/libraries/ASM.xml index e4873676bb75..7ed029a31507 100644 --- a/.idea/libraries/asm5.xml +++ b/.idea/libraries/ASM.xml @@ -1,11 +1,11 @@ - + - + \ No newline at end of file diff --git a/build/asm/1_version_check.patch b/build/asm/1_version_check.patch index 63ec6e0278f8..45eb8373f4c7 100644 --- a/build/asm/1_version_check.patch +++ b/build/asm/1_version_check.patch @@ -5,7 +5,7 @@ Index: org/objectweb/asm/ClassReader.java @@ -167,7 +167,7 @@ this.b = b; // checks the class version - if (readShort(off + 6) > Opcodes.V1_8) { + if (readShort(off + 6) > Opcodes.V1_9) { - throw new IllegalArgumentException(); + //[JB: accept any version] throw new IllegalArgumentException(); } diff --git a/build/asm/repackage.xml b/build/asm/repackage.xml index 75336cfbe16b..6d72c6d4c53a 100644 --- a/build/asm/repackage.xml +++ b/build/asm/repackage.xml @@ -19,7 +19,7 @@ - + @@ -41,6 +41,7 @@ + diff --git a/build/build.iml b/build/build.iml index 9eb5b9dfb1fb..71b5f94898ed 100644 --- a/build/build.iml +++ b/build/build.iml @@ -13,7 +13,7 @@ - + diff --git a/build/scripts/libLicenses.gant b/build/scripts/libLicenses.gant index 88f3bf933756..a673f8f7cd9d 100644 --- a/build/scripts/libLicenses.gant +++ b/build/scripts/libLicenses.gant @@ -171,11 +171,7 @@ libraryLicense(name: "Apache Commons Net", libraryName: "commons-net", version: libraryLicense(name: "Apache Lucene", libraryName: "lucene-core-2.4.1.jar", version: "2.4.1", license: "Apache 2.0", url: "http://lucene.apache.org/java") libraryLicense(name: "Apache Sanselan", libraryName: "Sanselan", version: "0.98", license: "Apache 2.0", url: "https://commons.apache.org/proper/commons-imaging/") libraryLicense(name: "Apache XML Graphics Commons", libraryName: "xmlgraphics-commons-1.3.1.jar", version: "1.3.1", license: "Apache 2.0", url: "http://xmlgraphics.apache.org/commons/", licenseUrl:"http://www.apache.org/licenses/LICENSE-2.0") -libraryLicense(name: "asm-4.0-all", libraryName: "asm-4.0-all", version: "4.0", attachedTo: "ByteCodeViewer", license: "BSD", url: "http://asm.objectweb.org/", licenseUrl: "http://asm.objectweb.org/license.html") -libraryLicense(name: "ASM Bytecode Manipulation Framework", libraryName: "asm-tools", version: "4.0", license: "BSD", url: "http://asm.objectweb.org/", licenseUrl: "http://asm.objectweb.org/license.html") -libraryLicense(name: "ASM Bytecode Manipulation Framework", libraryName: "asm", version: "3.3", license: "BSD", url: "http://asm.objectweb.org/", licenseUrl: "http://asm.objectweb.org/license.html") -libraryLicense(name: "ASM Bytecode Manipulation Framework", libraryName: "asm4", version: "4.0", license: "BSD", url: "http://asm.objectweb.org/", licenseUrl: "http://asm.objectweb.org/license.html") -libraryLicense(name: "ASM Bytecode Manipulation Framework", libraryName: "asm5", version: "5.0.3 (with patches by JetBrains)", license: "BSD", url: "http://asm.objectweb.org/", licenseUrl: "http://asm.objectweb.org/license.html") +libraryLicense(name: "ASM Bytecode Manipulation Framework", libraryName: "ASM", version: "6.0-ALPHA (with patches by JetBrains)", license: "BSD", url: "http://asm.objectweb.org/", licenseUrl: "http://asm.objectweb.org/license.html") libraryLicense(name: "assertJ", version: "3", license: "Apache 2.0", url: "https://github.com/joel-costigliola/assertj-core") libraryLicense(name: "Automaton", libraryName: "automaton.jar", version: "1.11", license: "BSD", url: "http://www.brics.dk/automaton/", licenseUrl: "http://www.opensource.org/licenses/bsd-license.php") libraryLicense(name: "Axis", libraryName: "axis-1.4", version: "1.4", license: "Apache 2.0", url: "http://ws.apache.org/axis/", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.html") diff --git a/images/src/org/intellij/images/editor/impl/ImageEditorUI.java b/images/src/org/intellij/images/editor/impl/ImageEditorUI.java index c5c48b96cfd6..62948cb62279 100644 --- a/images/src/org/intellij/images/editor/impl/ImageEditorUI.java +++ b/images/src/org/intellij/images/editor/impl/ImageEditorUI.java @@ -466,14 +466,14 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider, } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) { return editor != null ? editor.getFile() : null; } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) { - return editor != null ? new VirtualFile[]{editor.getFile()} : new VirtualFile[]{}; + return editor != null ? new VirtualFile[]{editor.getFile()} : VirtualFile.EMPTY_ARRAY; } else if (CommonDataKeys.PSI_FILE.is(dataId)) { return getData(CommonDataKeys.PSI_ELEMENT.getName()); } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) { VirtualFile file = editor != null ? editor.getFile() : null; return file != null && file.isValid() ? PsiManager.getInstance(editor.getProject()).findFile(file) : null; } else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) { - return editor != null ? new PsiElement[]{(PsiElement)getData(CommonDataKeys.PSI_ELEMENT.getName())} : new PsiElement[]{} ; + return editor != null ? new PsiElement[]{(PsiElement)getData(CommonDataKeys.PSI_ELEMENT.getName())} : PsiElement.EMPTY_ARRAY; } else if (PlatformDataKeys.COPY_PROVIDER.is(dataId) && copyPasteSupport != null) { return this; } else if (PlatformDataKeys.CUT_PROVIDER.is(dataId) && copyPasteSupport != null) { diff --git a/java/compiler/forms-compiler/forms-compiler.iml b/java/compiler/forms-compiler/forms-compiler.iml index 111123aaf886..9eec06a77713 100644 --- a/java/compiler/forms-compiler/forms-compiler.iml +++ b/java/compiler/forms-compiler/forms-compiler.iml @@ -10,7 +10,7 @@ - + diff --git a/java/compiler/impl/compiler-impl.iml b/java/compiler/impl/compiler-impl.iml index 481598a0c7ae..73e40393577b 100644 --- a/java/compiler/impl/compiler-impl.iml +++ b/java/compiler/impl/compiler-impl.iml @@ -16,7 +16,7 @@ - + diff --git a/java/compiler/instrumentation-util/instrumentation-util.iml b/java/compiler/instrumentation-util/instrumentation-util.iml index 293410b8d23a..eb96516e2f04 100644 --- a/java/compiler/instrumentation-util/instrumentation-util.iml +++ b/java/compiler/instrumentation-util/instrumentation-util.iml @@ -7,7 +7,6 @@ - + - - + \ No newline at end of file diff --git a/java/compiler/javac2/javac2.iml b/java/compiler/javac2/javac2.iml index 986d88e635fd..5376b3eff57f 100644 --- a/java/compiler/javac2/javac2.iml +++ b/java/compiler/javac2/javac2.iml @@ -10,7 +10,7 @@ - + @@ -165,5 +165,4 @@ - - + \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ClassRenderer.java b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ClassRenderer.java index 2cfe619026e0..f7e96758b2bf 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ClassRenderer.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ClassRenderer.java @@ -244,7 +244,7 @@ public class ClassRenderer extends NodeRendererImpl{ PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory(); try { - return elementFactory.createExpressionFromText(fieldDescriptor.getField().name(), DebuggerUtils.findClass( + return elementFactory.createExpressionFromText("this." + fieldDescriptor.getField().name(), DebuggerUtils.findClass( fieldDescriptor.getObject().referenceType().name(), context.getProject(), context.getDebugProcess().getSearchScope()) ); } diff --git a/java/execution/impl/src/com/intellij/execution/testframework/AbstractPatternBasedConfigurationProducer.java b/java/execution/impl/src/com/intellij/execution/testframework/AbstractPatternBasedConfigurationProducer.java index 76058aabeaa9..00a684da7cd9 100644 --- a/java/execution/impl/src/com/intellij/execution/testframework/AbstractPatternBasedConfigurationProducer.java +++ b/java/execution/impl/src/com/intellij/execution/testframework/AbstractPatternBasedConfigurationProducer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -31,7 +31,6 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.search.PsiElementProcessor; @@ -176,7 +175,7 @@ public abstract class AbstractPatternBasedConfigurationProducer - + - - + \ No newline at end of file diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/ModuleHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/ModuleHighlightUtil.java index 078e2fdff13d..d59741e42020 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/ModuleHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/ModuleHighlightUtil.java @@ -29,7 +29,6 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiJavaModule; -import com.intellij.psi.PsiJavaModuleReference; import com.intellij.psi.search.FilenameIndex; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,15 +36,15 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; -public class ModuleHighlightUtil { - private static final String MODULE_FILE_NAME = "module-info.java"; +import static com.intellij.psi.PsiJavaModule.MODULE_INFO_FILE; +public class ModuleHighlightUtil { @Nullable static HighlightInfo checkFileName(@NotNull PsiJavaModule element, @NotNull PsiFile file) { - if (!MODULE_FILE_NAME.equals(file.getName())) { + if (!MODULE_INFO_FILE.equals(file.getName())) { String message = JavaErrorMessages.message("module.file.wrong.name"); HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range(element)).description(message).create(); - QuickFixAction.registerQuickFixAction(info, factory().createRenameFileFix(MODULE_FILE_NAME)); + QuickFixAction.registerQuickFixAction(info, factory().createRenameFileFix(MODULE_INFO_FILE)); return info; } @@ -60,7 +59,7 @@ public class ModuleHighlightUtil { Module module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(vFile); if (module != null) { Collection others = - FilenameIndex.getVirtualFilesByName(project, MODULE_FILE_NAME, new ModulesScope(Collections.singleton(module), project)); + FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, new ModulesScope(Collections.singleton(module), project)); if (others.size() > 1) { String message = JavaErrorMessages.message("module.file.duplicate"); return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range(element)).description(message).create(); @@ -93,7 +92,6 @@ public class ModuleHighlightUtil { } private static TextRange range(PsiJavaModule module) { - PsiJavaModuleReference name = module.getNameElement(); - return name != null ? new TextRange(module.getTextOffset(), name.getTextRange().getEndOffset()) : module.getTextRange(); + return new TextRange(module.getTextOffset(), module.getNameElement().getTextRange().getEndOffset()); } } \ No newline at end of file diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java index ea4c4bceb032..df1fe781baa1 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java @@ -224,7 +224,28 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { descriptors = new ArrayList(); globalContext.getRefManager().iterate(new RefVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { - CommonProblemDescriptor[] descriptors1 = global.getTool().checkElement(refEntity, scope, manager, globalContext, new ProblemDescriptionsProcessor() { + CommonProblemDescriptor[] + descriptors1 = global.getTool().checkElement(refEntity, scope, manager, globalContext, new ProblemDescriptionsProcessor() { + @Nullable + @Override + public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) { + return CommonProblemDescriptor.EMPTY_ARRAY; + } + + @Override + public void ignoreElement(@NotNull RefEntity refEntity) { + + } + + @Override + public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) { + int i =0; + } + + @Override + public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) { + return null; + } }); if (descriptors1 != null) { ContainerUtil.addAll(descriptors, descriptors1); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/concurrencyAnnotations/JCiPUtil.java b/java/java-analysis-impl/src/com/intellij/codeInspection/concurrencyAnnotations/JCiPUtil.java index 9300b954c488..624659f1c90a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/concurrencyAnnotations/JCiPUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/concurrencyAnnotations/JCiPUtil.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; -class JCiPUtil { +public class JCiPUtil { static boolean isJCiPAnnotation(String ref) { return "Immutable".equals(ref) || "GuardedBy".equals(ref) || "ThreadSafe".equals(ref) || "NotThreadSafe".equals(ref); } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/concurrencyAnnotations/NonFinalFieldInImmutableInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/concurrencyAnnotations/NonFinalFieldInImmutableInspection.java index d3bcce5c3671..e1aefce0e557 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/concurrencyAnnotations/NonFinalFieldInImmutableInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/concurrencyAnnotations/NonFinalFieldInImmutableInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -59,7 +59,7 @@ public class NonFinalFieldInImmutableInspection extends BaseJavaBatchLocalInspec if (!JCiPUtil.isImmutable(containingClass)) { return; } - holder.registerProblem(field, "Non-final field #ref in @Immutable class #loc"); + holder.registerProblem(field.getNameIdentifier(), "Non-final field #ref in @Immutable class #loc"); } } }; diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java index 36c8ea3485f6..198e462b1e77 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java @@ -92,7 +92,7 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { List deadCodeAddIns = new ArrayList(extensions.length); for (EntryPoint entryPoint : extensions) { try { - deadCodeAddIns.add(entryPoint); + deadCodeAddIns.add(entryPoint.clone()); } catch (Exception e) { LOG.error(e); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefPackageImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefPackageImpl.java index 1f26717ad3d6..4abc755982e3 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefPackageImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefPackageImpl.java @@ -32,26 +32,10 @@ import javax.swing.*; public class RefPackageImpl extends RefEntityImpl implements RefPackage { - private final String myQualifiedName; - public RefPackageImpl(@NotNull String name, @NotNull RefManager refManager) { - super(getPackageSuffix(name), refManager); - myQualifiedName = name; + super(name, refManager); } - @NotNull - @Override - public String getQualifiedName() { - return myQualifiedName; - } - - @NotNull - private static String getPackageSuffix(@NotNull String fullName) { - int dotIndex = fullName.lastIndexOf('.'); - return (dotIndex >= 0) ? fullName.substring(dotIndex + 1) : fullName; - } - - @Override public void accept(@NotNull final RefVisitor visitor) { if (visitor instanceof RefJavaVisitor) { @@ -61,11 +45,6 @@ public class RefPackageImpl extends RefEntityImpl implements RefPackage { } } - @Override - public String getExternalName() { - return getQualifiedName(); - } - public static RefEntity packageFromFQName(final RefManager manager, final String name) { return manager.getExtension(RefJavaManager.MANAGER).getPackage(name); } diff --git a/java/java-impl/java-impl.iml b/java/java-impl/java-impl.iml index 1be708c7149c..1f9fd8301eef 100644 --- a/java/java-impl/java-impl.iml +++ b/java/java-impl/java-impl.iml @@ -42,7 +42,7 @@ - + diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/FunctionalExpressionCompletionProvider.java b/java/java-impl/src/com/intellij/codeInsight/completion/FunctionalExpressionCompletionProvider.java index 6400dfc9e12a..8f4a6348b099 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/FunctionalExpressionCompletionProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/FunctionalExpressionCompletionProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -80,7 +80,7 @@ public class FunctionalExpressionCompletionProvider extends CompletionProvider result = new ArrayList(); for (final PsiReference ref : methodReferences) { final PsiElement element = ref.getElement(); diff --git a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseProcessor.java b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseProcessor.java index 75c965f45ba2..ddf5952ca961 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -104,7 +104,8 @@ public abstract class ExtractSuperBaseProcessor extends TurnRefsToSuperProcessor @NotNull protected UsageInfo[] findUsages() { - PsiReference[] refs = ReferencesSearch.search(myClass, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); + PsiReference[] refs = ReferencesSearch.search(myClass, GlobalSearchScope.projectScope(myProject), false).toArray( + PsiReference.EMPTY_ARRAY); final ArrayList result = new ArrayList(); detectTurnToSuperRefs(refs, result); final PsiPackage originalPackage = JavaDirectoryService.getInstance().getPackage(myClass.getContainingFile().getContainingDirectory()); diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java index 78844ee81153..2ac01c3cbad9 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -55,7 +55,6 @@ import com.intellij.refactoring.rename.RenameJavaVariableProcessor; import com.intellij.refactoring.util.*; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewDescriptor; -import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.HashMap; import com.intellij.util.containers.MultiMap; @@ -1108,7 +1107,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { if (isAccessedForWriting) { if (refVar.hasModifierProperty(PsiModifier.FINAL) || shouldBeFinal) return false; PsiReference[] refs = - ReferencesSearch.search(refVar, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); + ReferencesSearch.search(refVar, GlobalSearchScope.projectScope(myProject), false).toArray(PsiReference.EMPTY_ARRAY); return refs.length == 1; //TODO: control flow } else { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/LocalToFieldHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/LocalToFieldHandler.java index 5d5f0f012f18..9060a78310c3 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/LocalToFieldHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/LocalToFieldHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -31,6 +31,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiElementProcessor; import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.FileTypeUtils; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.HelpID; import com.intellij.refactoring.RefactoringBundle; @@ -40,7 +41,6 @@ import com.intellij.refactoring.util.EnumConstantsUtil; import com.intellij.refactoring.util.RefactoringUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.VisibilityUtil; -import com.intellij.psi.util.FileTypeUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -295,7 +295,7 @@ public abstract class LocalToFieldHandler { final boolean rebindNeeded2 = !myVariableName.equals(myFieldName) || myRebindNeeded; final PsiReference[] refs; if (rebindNeeded2) { - refs = ReferencesSearch.search(myLocal, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); + refs = ReferencesSearch.search(myLocal, GlobalSearchScope.projectScope(myProject), false).toArray(PsiReference.EMPTY_ARRAY); } else { refs = null; diff --git a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodStaticProcessor.java b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodStaticProcessor.java index 906b809af879..bee75c86f492 100644 --- a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodStaticProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodStaticProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -35,7 +35,6 @@ import com.intellij.refactoring.util.CanonicalTypes; import com.intellij.refactoring.util.RefactoringUtil; import com.intellij.refactoring.util.javadoc.MethodJavaDocHelper; import com.intellij.usageView.UsageInfo; -import com.intellij.util.Consumer; import com.intellij.util.IncorrectOperationException; import com.intellij.util.VisibilityUtil; import com.intellij.util.containers.MultiMap; @@ -304,7 +303,7 @@ public class MakeMethodStaticProcessor extends MakeMethodOrClassStaticProcessor< PsiElement anchor = null; PsiExpressionList argList = null; - PsiExpression[] exprs = new PsiExpression[0]; + PsiExpression[] exprs = PsiExpression.EMPTY_ARRAY; if (parent instanceof PsiMethodCallExpression) { argList = ((PsiMethodCallExpression)parent).getArgumentList(); exprs = argList.getExpressions(); diff --git a/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHelper.java b/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHelper.java index bc16d1e24792..c913417dfc3b 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHelper.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHelper.java @@ -22,7 +22,6 @@ import com.intellij.codeInsight.intention.AddAnnotationFix; import com.intellij.lang.Language; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Key; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleSettings; @@ -552,7 +551,7 @@ public class JavaPullUpHelper implements PullUpHelper { } if (doLookup) { final PsiReference[] references = - ReferencesSearch.search(field, new LocalSearchScope(statement), false).toArray(new PsiReference[0]); + ReferencesSearch.search(field, new LocalSearchScope(statement), false).toArray(PsiReference.EMPTY_ARRAY); if (commonInitializerCandidate == null && references.length > 0) { return null; } diff --git a/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java b/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java index e36d976d0e07..9661961a1197 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -155,7 +155,7 @@ public class PullUpConflictsUtil { ContainerUtil.addIfNotNull(checkModuleConflictsList, method.getTypeParameterList()); } RefactoringConflictsUtil.analyzeModuleConflicts(subclass.getProject(), checkModuleConflictsList, - new UsageInfo[0], targetRepresentativeElement, conflicts); + UsageInfo.EMPTY_ARRAY, targetRepresentativeElement, conflicts); final PsiFile psiFile = PsiTreeUtil.getParentOfType(subclass, PsiClassOwner.class); final boolean toDifferentPackage = !Comparing.strEqual(targetPackage.getQualifiedName(), diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/JavaMoveClassesOrPackagesHandler.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/JavaMoveClassesOrPackagesHandler.java index d114f9687745..18051c1aee3e 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/JavaMoveClassesOrPackagesHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/JavaMoveClassesOrPackagesHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -211,7 +211,7 @@ public class JavaMoveClassesOrPackagesHandler extends MoveHandlerDelegate { return; } final MoveClassesOrPackagesToNewDirectoryDialog dlg = - new MoveClassesOrPackagesToNewDirectoryDialog(directories[0], new PsiElement[0], false, callback) { + new MoveClassesOrPackagesToNewDirectoryDialog(directories[0], PsiElement.EMPTY_ARRAY, false, callback) { @Override protected BaseRefactoringProcessor createRefactoringProcessor(Project project, final PsiDirectory targetDirectory, diff --git a/java/java-impl/src/com/intellij/refactoring/psi/SearchUtils.java b/java/java-impl/src/com/intellij/refactoring/psi/SearchUtils.java index a5c73ca58fe2..570835ea90a8 100644 --- a/java/java-impl/src/com/intellij/refactoring/psi/SearchUtils.java +++ b/java/java-impl/src/com/intellij/refactoring/psi/SearchUtils.java @@ -31,7 +31,7 @@ public class SearchUtils{ public static Iterable findAllReferences(PsiElement element, SearchScope scope){ - return new ArrayIterable(ReferencesSearch.search(element, scope, true).toArray(new PsiReference[0])); + return new ArrayIterable(ReferencesSearch.search(element, scope, true).toArray(PsiReference.EMPTY_ARRAY)); /* try { Class searchClass = Class.forName("com.intellij.psi.search.searches.ReferencesSearch"); @@ -59,12 +59,12 @@ public class SearchUtils{ } public static Iterable findOverridingMethods(PsiMethod method){ - return new ArrayIterable(OverridingMethodsSearch.search(method).toArray(new PsiMethod[0])); + return new ArrayIterable(OverridingMethodsSearch.search(method).toArray(PsiMethod.EMPTY_ARRAY)); // return OverridingMethodsSearch.search(method, method.getUseScope(), true).findAll(); } public static Iterable findClassInheritors(PsiClass aClass, boolean deep){ - return new ArrayIterable(ClassInheritorsSearch.search(aClass, deep).toArray(new PsiClass[0])); + return new ArrayIterable(ClassInheritorsSearch.search(aClass, deep).toArray(PsiClass.EMPTY_ARRAY)); // return ClassInheritorsSearch.search(aClass, deep); } diff --git a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderViewDescriptor.java b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderViewDescriptor.java index e58a9df62bc0..a593a37b86ca 100644 --- a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderViewDescriptor.java +++ b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderViewDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -28,7 +28,7 @@ public class ReplaceConstructorWithBuilderViewDescriptor extends UsageViewDescri @NotNull public PsiElement[] getElements() { - return new PsiElement[0]; + return PsiElement.EMPTY_ARRAY; } public String getProcessedElementsHeader() { diff --git a/java/java-impl/src/com/intellij/refactoring/tempWithQuery/TempWithQueryHandler.java b/java/java-impl/src/com/intellij/refactoring/tempWithQuery/TempWithQueryHandler.java index 9a3f209ed2dd..c13857137bc2 100644 --- a/java/java-impl/src/com/intellij/refactoring/tempWithQuery/TempWithQueryHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/tempWithQuery/TempWithQueryHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -79,7 +79,8 @@ public class TempWithQueryHandler implements RefactoringActionHandler { return; } - final PsiReference[] refs = ReferencesSearch.search(local, GlobalSearchScope.projectScope(project), false).toArray(new PsiReference[0]); + final PsiReference[] refs = ReferencesSearch.search(local, GlobalSearchScope.projectScope(project), false).toArray( + PsiReference.EMPTY_ARRAY); if (refs.length == 0) { String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.never.used", localName)); diff --git a/java/java-impl/src/com/intellij/refactoring/turnRefsToSuper/TurnRefsToSuperProcessor.java b/java/java-impl/src/com/intellij/refactoring/turnRefsToSuper/TurnRefsToSuperProcessor.java index 44eed8588c59..6e43ed29c005 100644 --- a/java/java-impl/src/com/intellij/refactoring/turnRefsToSuper/TurnRefsToSuperProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/turnRefsToSuper/TurnRefsToSuperProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -68,7 +68,8 @@ public class TurnRefsToSuperProcessor extends TurnRefsToSuperProcessorBase { @NotNull protected UsageInfo[] findUsages() { - final PsiReference[] refs = ReferencesSearch.search(myClass, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); + final PsiReference[] refs = ReferencesSearch.search(myClass, GlobalSearchScope.projectScope(myProject), false).toArray( + PsiReference.EMPTY_ARRAY); final ArrayList result = detectTurnToSuperRefs(refs, new ArrayList()); diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java index 3016555b1e95..ec9dd94b0e43 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java @@ -823,7 +823,8 @@ public class TypeMigrationLabeler { } public PsiReference[] markRootUsages(final PsiElement element, final PsiType migrationType) { - return markRootUsages(element, migrationType, ReferencesSearch.search(element, myRules.getSearchScope(), false).toArray(new PsiReference[0])); + return markRootUsages(element, migrationType, ReferencesSearch.search(element, myRules.getSearchScope(), false).toArray( + PsiReference.EMPTY_ARRAY)); } PsiReference[] markRootUsages(final PsiElement element, final PsiType migrationType, final PsiReference[] refs) { diff --git a/java/java-impl/src/com/intellij/refactoring/util/classRefs/ClassReferenceSearchingScanner.java b/java/java-impl/src/com/intellij/refactoring/util/classRefs/ClassReferenceSearchingScanner.java index 866198e009c7..5ab6fd5d69ae 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/classRefs/ClassReferenceSearchingScanner.java +++ b/java/java-impl/src/com/intellij/refactoring/util/classRefs/ClassReferenceSearchingScanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -30,7 +30,7 @@ public class ClassReferenceSearchingScanner extends ClassReferenceScanner { public PsiReference[] findReferences() { GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myClass.getProject()); - return ReferencesSearch.search(myClass, projectScope, false).toArray(new PsiReference[0]); + return ReferencesSearch.search(myClass, projectScope, false).toArray(PsiReference.EMPTY_ARRAY); } } diff --git a/java/java-impl/src/com/intellij/slicer/SliceUtil.java b/java/java-impl/src/com/intellij/slicer/SliceUtil.java index 9f46cf8e0a22..a1a1785608cd 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceUtil.java +++ b/java/java-impl/src/com/intellij/slicer/SliceUtil.java @@ -440,7 +440,7 @@ class SliceUtil { // for erased method calls for which we cannot determine target substitutor, // rely on call argument types. I.e. new Pair(1,2) -> Pair if (element instanceof PsiTypeParameterListOwner && PsiUtil.isRawSubstitutor((PsiTypeParameterListOwner)element, substitutor)) { - PsiTypeParameter[] typeParameters = substitutor.getSubstitutionMap().keySet().toArray(new PsiTypeParameter[0]); + PsiTypeParameter[] typeParameters = substitutor.getSubstitutionMap().keySet().toArray(PsiTypeParameter.EMPTY_ARRAY); PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(project).getResolveHelper(); substitutor = resolveHelper.inferTypeArguments(typeParameters, actualParameters, expressions, parentSubstitutor, argumentList, diff --git a/java/java-psi-api/src/com/intellij/psi/PsiJavaModule.java b/java/java-psi-api/src/com/intellij/psi/PsiJavaModule.java index 974e9af8e9cb..3656ce32aba5 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiJavaModule.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiJavaModule.java @@ -15,7 +15,7 @@ */ package com.intellij.psi; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; /** * Represents a Java module declaration. @@ -23,6 +23,9 @@ import org.jetbrains.annotations.Nullable; * @since 2016.3 */ public interface PsiJavaModule extends PsiElement { - @Nullable PsiJavaModuleReference getNameElement(); - @Nullable String getModuleName(); + String MODULE_INFO_CLASS = "module-info"; + String MODULE_INFO_FILE = MODULE_INFO_CLASS + ".java"; + + @NotNull PsiJavaModuleReference getNameElement(); + @NotNull String getModuleName(); } \ No newline at end of file diff --git a/java/java-psi-impl/java-psi-impl.iml b/java/java-psi-impl/java-psi-impl.iml index 40064b497c8b..3efdb8fa9616 100644 --- a/java/java-psi-impl/java-psi-impl.iml +++ b/java/java-psi-impl/java-psi-impl.iml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImportListImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImportListImpl.java index a996bb88c5d6..43bf3349a17e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImportListImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImportListImpl.java @@ -32,7 +32,7 @@ public class PsiImportListImpl extends JavaStubPsiElement imp private volatile Map myClassNameToImportMap; private volatile Map myPackageNameToImportMap; private volatile Map myNameToSingleImportMap; - private static final PsiImportStatementBase[] EMPTY_ARRAY = new PsiImportStatementBase[0]; + private static final PsiImportStatementBase[] EMPTY_ARRAY = PsiImportStatementBase.EMPTY_ARRAY; private static final ArrayFactory ARRAY_FACTORY = new ArrayFactory() { @NotNull @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleImpl.java index 4905a52c18c4..fccb8b1202ad 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleImpl.java @@ -15,29 +15,30 @@ */ package com.intellij.psi.impl.source; -import com.intellij.psi.*; +import com.intellij.psi.JavaElementVisitor; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.PsiJavaModule; +import com.intellij.psi.PsiJavaModuleReference; import com.intellij.psi.impl.source.tree.CompositePsiElement; import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class PsiJavaModuleImpl extends CompositePsiElement implements PsiJavaModule { public PsiJavaModuleImpl() { super(JavaElementType.MODULE); } - @Nullable + @NotNull @Override public PsiJavaModuleReference getNameElement() { - return PsiTreeUtil.getChildOfType(this, PsiJavaModuleReference.class); + return PsiTreeUtil.getRequiredChildOfType(this, PsiJavaModuleReference.class); } - @Nullable + @NotNull @Override public String getModuleName() { - PsiJavaModuleReference nameElement = getNameElement(); - return nameElement != null ? nameElement.getReferenceText() : null; + return getNameElement().getReferenceText(); } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 25f9e47a4a89..bac588d7ce9e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -771,7 +771,7 @@ public class InferenceSession { restParamSubstitution = restParamSubstitution.put(typeParameters[i], parameter); } } - return initBounds(null, restParamSubstitution, capturedParams.toArray(new PsiTypeParameter[0])); + return initBounds(null, restParamSubstitution, capturedParams.toArray(PsiTypeParameter.EMPTY_ARRAY)); } return initBounds(null, typeParameters); } diff --git a/java/java-tests/java-tests.iml b/java/java-tests/java-tests.iml index 1f39eba6946c..3edaf9d0e1fc 100644 --- a/java/java-tests/java-tests.iml +++ b/java/java-tests/java-tests.iml @@ -25,7 +25,7 @@ - + diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateEquals15Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateEquals15Test.java index 8ea66c9fe7a2..be02e9c483c4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateEquals15Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateEquals15Test.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.intellij.codeInsight; import com.intellij.codeInsight.generation.EqualsHashCodeTemplatesManager; @@ -13,12 +28,12 @@ public class GenerateEquals15Test extends GenerateEqualsTestCase { } public void testDifferentTypes() throws Exception { - doTest(Function.ID, Function.ID, fields -> new PsiField[0], true + doTest(Function.ID, Function.ID, fields -> PsiField.EMPTY_ARRAY, true ); } public void testDifferentTypesGetters() throws Exception { - doTest(Function.ID, Function.ID, fields -> new PsiField[0], true, true); + doTest(Function.ID, Function.ID, fields -> PsiField.EMPTY_ARRAY, true, true); } public void testDifferentTypesAllNotNull() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/find/findUsages/FindParameterTest.java b/java/java-tests/testSrc/com/intellij/find/findUsages/FindParameterTest.java index 3113d8c096ae..350b887aad3e 100644 --- a/java/java-tests/testSrc/com/intellij/find/findUsages/FindParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/find/findUsages/FindParameterTest.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.intellij.find.findUsages; import com.intellij.psi.*; @@ -25,7 +40,7 @@ public class FindParameterTest extends PsiTestCase { final PsiMethod methodFromText = elementFactory.createMethodFromText(text, null); final PsiParameter[] parameters = methodFromText.getParameterList().getParameters(); final PsiReference[] references = - ReferencesSearch.search(parameters[0], new LocalSearchScope(methodFromText), false).toArray(new PsiReference[0]); + ReferencesSearch.search(parameters[0], new LocalSearchScope(methodFromText), false).toArray(PsiReference.EMPTY_ARRAY); Assert.assertEquals(references.length, 2); } } diff --git a/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java b/java/java-tests/testSrc/com/intellij/psi/ClsStubBuilderTest.java similarity index 98% rename from java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java rename to java/java-tests/testSrc/com/intellij/psi/ClsStubBuilderTest.java index 471f5e0ed630..d1d2f08d4559 100644 --- a/java/java-tests/testSrc/com/intellij/psi/ClsBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/ClsStubBuilderTest.java @@ -31,7 +31,7 @@ import java.io.File; /** * @author max */ -public class ClsBuilderTest extends LightIdeaTestCase { +public class ClsStubBuilderTest extends LightIdeaTestCase { public void testUtilList() { doTest("java/util/List.class"); } public void testNullable() { doTest("org/jetbrains/annotations/Nullable.class"); } public void testUtilCollections() { doTest("java/util/Collections.class"); } diff --git a/java/java-tests/testSrc/com/intellij/psi/search/FindUsages15Test.java b/java/java-tests/testSrc/com/intellij/psi/search/FindUsages15Test.java index 45923fa78402..5e13cf868023 100644 --- a/java/java-tests/testSrc/com/intellij/psi/search/FindUsages15Test.java +++ b/java/java-tests/testSrc/com/intellij/psi/search/FindUsages15Test.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * 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. @@ -16,7 +16,6 @@ package com.intellij.psi.search; import com.intellij.JavaTestUtil; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; @@ -47,12 +46,12 @@ public class FindUsages15Test extends PsiTestCase{ PsiMethod[] constructors = enumClass.getConstructors(); assertEquals(2, constructors.length); PsiReference[] references0 = - ReferencesSearch.search(constructors[0], GlobalSearchScope.moduleScope(myModule), false).toArray(new PsiReference[0]); + ReferencesSearch.search(constructors[0], GlobalSearchScope.moduleScope(myModule), false).toArray(PsiReference.EMPTY_ARRAY); assertEquals(2, references0.length); assertTrue(references0[0].getElement() instanceof PsiEnumConstant); assertTrue(references0[1].getElement() instanceof PsiEnumConstant); PsiReference[] references1 = - ReferencesSearch.search(constructors[1], GlobalSearchScope.moduleScope(myModule), false).toArray(new PsiReference[0]); + ReferencesSearch.search(constructors[1], GlobalSearchScope.moduleScope(myModule), false).toArray(PsiReference.EMPTY_ARRAY); assertEquals(1, references1.length); assertTrue(references1[0].getElement() instanceof PsiEnumConstant); } diff --git a/java/java-tests/testSrc/com/intellij/psi/search/SearchInLibsTest.java b/java/java-tests/testSrc/com/intellij/psi/search/SearchInLibsTest.java index f21cac838046..8dcb983beb9f 100644 --- a/java/java-tests/testSrc/com/intellij/psi/search/SearchInLibsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/search/SearchInLibsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -148,7 +148,7 @@ public class SearchInLibsTest extends PsiTestCase { final PsiClass aClass = myJavaFacade.findClass(classNameToSearch); assertNotNull(aClass); - PsiReference[] refs = ReferencesSearch.search(aClass, scope, false).toArray(new PsiReference[0]); + PsiReference[] refs = ReferencesSearch.search(aClass, scope, false).toArray(PsiReference.EMPTY_ARRAY); ArrayList files = new ArrayList<>(); for (PsiReference ref : refs) { diff --git a/java/java-tests/testSrc/com/intellij/psi/search/UpdateCacheTest.java b/java/java-tests/testSrc/com/intellij/psi/search/UpdateCacheTest.java index 602d42e50bcb..be33b6f07a5c 100644 --- a/java/java-tests/testSrc/com/intellij/psi/search/UpdateCacheTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/search/UpdateCacheTest.java @@ -45,13 +45,15 @@ import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.PsiTestCase; import com.intellij.testFramework.PsiTestUtil; import com.intellij.util.ArrayUtil; -import com.intellij.util.Processor; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; @PlatformTestCase.WrapInCommand public class UpdateCacheTest extends PsiTestCase { @@ -406,7 +408,8 @@ public class UpdateCacheTest extends PsiTestCase { } private void checkUsages(PsiElement element, @NonNls String[] expectedFiles){ - PsiReference[] refs = ReferencesSearch.search(element, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); + PsiReference[] refs = ReferencesSearch.search(element, GlobalSearchScope.projectScope(myProject), false).toArray( + PsiReference.EMPTY_ARRAY); List files = new ArrayList(); for (PsiReference ref : refs) { diff --git a/java/typeMigration/src/META-INF/TypeMigration.xml b/java/typeMigration/src/META-INF/TypeMigration.xml index c27c63eb1afc..46042d875b03 100644 --- a/java/typeMigration/src/META-INF/TypeMigration.xml +++ b/java/typeMigration/src/META-INF/TypeMigration.xml @@ -8,6 +8,7 @@ + diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/VoidConversionRule.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/VoidConversionRule.java new file mode 100644 index 000000000000..27fe8801bec4 --- /dev/null +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/VoidConversionRule.java @@ -0,0 +1,84 @@ +/* + * 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. + */ +package com.intellij.refactoring.typeMigration.rules; + +import com.intellij.codeInspection.dataFlow.ControlFlowAnalyzer; +import com.intellij.psi.*; +import com.intellij.psi.search.PsiElementProcessor; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.refactoring.typeMigration.TypeConversionDescriptorBase; +import com.intellij.refactoring.typeMigration.TypeEvaluator; +import com.intellij.refactoring.typeMigration.TypeMigrationLabeler; +import com.intellij.util.IncorrectOperationException; +import com.siyeh.ig.controlflow.UnnecessaryReturnInspection; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Dmitry Batkovich + */ +public class VoidConversionRule extends TypeConversionRule { + @Nullable + @Override + public TypeConversionDescriptorBase findConversion(PsiType from, + PsiType to, + PsiMember member, + PsiExpression context, + TypeMigrationLabeler labeler) { + if (PsiType.VOID.equals(to) && context.getParent() instanceof PsiReturnStatement) { + final boolean isPure = PsiTreeUtil.processElements(context, new PsiElementProcessor() { + @Override + public boolean execute(@NotNull PsiElement element) { + if (element instanceof PsiPrefixExpression) { + return analyzeUnaryExpressionOperand(((PsiPrefixExpression)element).getOperand()); + } + if (element instanceof PsiPostfixExpression) { + return analyzeUnaryExpressionOperand(((PsiPostfixExpression)element).getOperand()); + } + if (element instanceof PsiMethodCallExpression) { + final PsiMethod method = ((PsiMethodCallExpression)element).resolveMethod(); + return method != null && ControlFlowAnalyzer.isPure(method); + } + return true; + } + + private boolean analyzeUnaryExpressionOperand(PsiExpression operand) { + if (!(operand instanceof PsiReferenceExpression)) return false; + final PsiElement resolved = ((PsiReferenceExpression)operand).resolve(); + return !(resolved instanceof PsiField); + } + }); + if (isPure) { + return new TypeConversionDescriptorBase() { + @Override + public PsiExpression replace(PsiExpression expression, @NotNull TypeEvaluator evaluator) throws IncorrectOperationException { + final PsiElement parent = expression.getParent(); + if (parent instanceof PsiReturnStatement) { + expression.delete(); + if (UnnecessaryReturnInspection.isReturnRedundant((PsiReturnStatement)parent, false, null)) { + parent.delete(); + } + } + return null; + } + }; + } else { + return null; + } + } + return null; + } +} diff --git a/java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java b/java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java index 2d999892902a..e91b68c1ff1d 100644 --- a/java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java +++ b/java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java @@ -826,6 +826,10 @@ public class TypeMigrationTest extends TypeMigrationTestBase { doTestFieldType("fooDontMigrateName", PsiType.BOOLEAN); } + public void testMethodMigrationToVoidWithUnusedReturns() { + doTestMethodType("toVoidMethod", PsiType.VOID); + } + public void testMigrationToSuper() { doTestFieldType("b", myJavaFacade.getElementFactory().createTypeFromText("Test.A", null)); } diff --git a/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/after/Test.items b/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/after/Test.items new file mode 100644 index 000000000000..af6da3191a83 --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/after/Test.items @@ -0,0 +1,9 @@ +Types: +PsiMethod:toVoidMethod : void +PsiMethodCallExpression:toVoidMethod() : void + +Conversions: + +New expression type changes: +Fails: +"" + String.valueOf(999)->void diff --git a/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/after/test.java b/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/after/test.java new file mode 100644 index 000000000000..9a41034f67a0 --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/after/test.java @@ -0,0 +1,11 @@ +class Test { + + public void toVoidMethod() { + int j = 0; + return "" + String.valueOf(999); + } + + public void main(String[] args) { + toVoidMethod(); + } +} diff --git a/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/before/test.java b/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/before/test.java new file mode 100644 index 000000000000..dc030e222267 --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigration/methodMigrationToVoidWithUnusedReturns/before/test.java @@ -0,0 +1,11 @@ +class Test { + + public String toVoidMethod() { + int j = 0; + return "" + String.valueOf(999); + } + + public void main(String[] args) { + toVoidMethod(); + } +} diff --git a/jps/jps-builders/jps-builders.iml b/jps/jps-builders/jps-builders.iml index be7df797f0bb..f876b2a7e3cc 100644 --- a/jps/jps-builders/jps-builders.iml +++ b/jps/jps-builders/jps-builders.iml @@ -12,7 +12,7 @@ - + diff --git a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaDefinitionResolver.java b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaDefinitionResolver.java new file mode 100644 index 000000000000..c8a74030ad49 --- /dev/null +++ b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaDefinitionResolver.java @@ -0,0 +1,184 @@ +/* + * 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. + */ +package com.jetbrains.jsonSchema.extension.schema; + +import com.intellij.json.psi.JsonObject; +import com.intellij.json.psi.JsonProperty; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.indexing.FileBasedIndex; +import com.jetbrains.jsonSchema.ide.JsonSchemaService; +import com.jetbrains.jsonSchema.impl.JsonSchemaObject; +import com.jetbrains.jsonSchema.impl.JsonSchemaResourcesRootsProvider; +import com.jetbrains.jsonSchema.impl.JsonSchemaWalker; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author Irina.Chernushina on 7/7/2016. + */ +public class JsonSchemaDefinitionResolver { + @Nullable private String myRef; + @Nullable JsonSchemaObject mySchemaObject; + + @NotNull private final PsiElement myElement; + @Nullable final String mySchemaId; + private boolean myInCurrentFile; + + public JsonSchemaDefinitionResolver(@NotNull PsiElement element, @Nullable String schemaId) { + myElement = element; + mySchemaId = schemaId; + } + + public JsonSchemaDefinitionResolver setSchemaObject(@NotNull final JsonSchemaObject value) { + mySchemaObject = value; + return this; + } + + public JsonSchemaDefinitionResolver setRef(@NotNull final String value) { + myRef = value; + return this; + } + + @Nullable + public PsiElement doResolve() { + PsiElement result = tryResolveByName(); + if (result != null) return result; + if (mySchemaId == null) { + return tryResolveBySchemaObject(); + } + return null; + } + + private PsiElement tryResolveBySchemaObject() { + if (!(myElement.getParent() instanceof JsonProperty)) return null; + final Ref ref = new Ref<>(); + + final String propertyName = ((JsonProperty)myElement.getParent()).getName(); + + JsonSchemaService.Impl.getEx(myElement.getProject()).iterateSchemaObjects( + myElement.getContainingFile().getVirtualFile(), + object -> { + final JsonSchemaWalker.CompletionSchemesConsumer consumer = new JsonSchemaWalker.CompletionSchemesConsumer() { + @Override + public void consume(boolean isName, @NotNull JsonSchemaObject schema) { + if (!ref.isNull()) return; + + String definitionAddress = schema.getDefinitionAddress(); + if (!StringUtil.isEmptyOrSpaces(definitionAddress) && definitionAddress.startsWith("#")) { + definitionAddress = definitionAddress.substring(1) + "/properties/" + propertyName; + ref.set(resolveByPath(definitionAddress)); + if (!ref.isNull()) return; + } + List list = new ArrayList(); + if (schema.getAllOf() != null) list.addAll(schema.getAllOf()); + if (schema.getAnyOf() != null) list.addAll(schema.getAnyOf()); + if (schema.getOneOf() != null) list.addAll(schema.getOneOf()); + for (JsonSchemaObject schemaObject : list) { + definitionAddress = schemaObject.getDefinitionAddress(); + if (!StringUtil.isEmptyOrSpaces(definitionAddress) && definitionAddress.startsWith("#")) { + definitionAddress = definitionAddress.substring(1) + "/properties/" + propertyName; + ref.set(resolveByPath(definitionAddress)); + if (!ref.isNull()) return; + } + } + } + }; + + final List position = JsonSchemaWalker.findPosition(((JsonProperty)myElement.getParent()).getNameElement(), true); + if (position == null || position.isEmpty()) return true; // to continue iteration + JsonSchemaWalker.extractSchemaVariants(consumer, object, true, position); + return ref.isNull(); + }); + return ref.get(); + } + + private PsiElement tryResolveByName() { + if (myRef == null) initializeName(); + if (myRef == null) return null; + + return resolveByPath(myRef); + } + + @Nullable + private PsiElement resolveByPath(String referenceName) { + final Project project = myElement.getProject(); + final FileBasedIndex index = FileBasedIndex.getInstance(); + final Ref> reference = new Ref<>(); + GlobalSearchScope filter = mySchemaId != null && myInCurrentFile ? GlobalSearchScope.fileScope(myElement.getContainingFile()) : + GlobalSearchScope.allScope(project); + filter = JsonSchemaResourcesRootsProvider.enlarge(project, filter); + + index.processValues(JsonSchemaFileIndex.PROPERTIES_INDEX, referenceName, null, new FileBasedIndex.ValueProcessor() { + @Override + public boolean process(VirtualFile file, Integer value) { + if (mySchemaId != null) { + if (!JsonSchemaService.Impl.getEx(project).checkFileForId(mySchemaId, file)) { + return true; + } + } + reference.set(Pair.create(file, value)); + return false; + } + }, filter); + + if (!reference.isNull()) { + final Pair pair = reference.get(); + final PsiFile file = myElement.getManager().findFile(pair.getFirst()); + if (file != null) { + return file.findElementAt(pair.getSecond()); + } + } + return null; + } + + private void initializeName() { + final List names = new ArrayList<>(); + final PsiElement parent = myElement.getParent(); + if (!(parent instanceof JsonProperty)) return; + JsonProperty element = (JsonProperty)parent; + while (true) { + names.add(StringUtil.unquoteString(element.getName())); + if (!(element.getParent() instanceof JsonObject)) break; + final PsiElement grand = element.getParent().getParent(); + if (grand instanceof JsonProperty && ((JsonProperty)grand).getValue() != null && + ((JsonProperty)grand).getValue().equals(element.getParent())) { + element = (JsonProperty) grand; + } else break; + } + final StringBuilder path = new StringBuilder(); + Collections.reverse(names); + for (String name : names) { + path.append("/properties/").append(name); + } + myRef = path.toString(); + } + + public JsonSchemaDefinitionResolver setInCurrentFile(boolean inCurrentFile) { + myInCurrentFile = inCurrentFile; + return this; + } +} diff --git a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java index bab4ee9b59d9..848f43739271 100644 --- a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java +++ b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java @@ -35,7 +35,7 @@ import java.util.Map; */ public class JsonSchemaFileIndex extends FileBasedIndexExtension { public static final ID PROPERTIES_INDEX = ID.create("json.schema.properties.index"); - public static final int VERSION = 1; + public static final int VERSION = 2; private IntInlineKeyDescriptor myKeyDescriptor = new IntInlineKeyDescriptor(); @NotNull diff --git a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaRefReferenceProvider.java b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaRefReferenceProvider.java index 68ad9aa5e5d8..55c9ca9c642d 100644 --- a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaRefReferenceProvider.java +++ b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaRefReferenceProvider.java @@ -16,17 +16,12 @@ package com.jetbrains.jsonSchema.extension.schema; import com.intellij.json.psi.JsonValue; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.ElementManipulators; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReference; +import com.intellij.psi.PsiReferenceProvider; import com.intellij.util.ProcessingContext; -import com.intellij.util.indexing.FileBasedIndex; -import com.jetbrains.jsonSchema.ide.JsonSchemaService; -import com.jetbrains.jsonSchema.impl.JsonSchemaResourcesRootsProvider; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -57,44 +52,15 @@ public class JsonSchemaRefReferenceProvider extends PsiReferenceProvider { final String text = getCanonicalText(); String id = null; String ref = text.substring(1); - if (!text.startsWith("#")) { + final boolean isGlobal = !text.startsWith("#"); + if (isGlobal) { final int idx = text.indexOf("#"); if (idx <= 0) return null; id = text.substring(0, idx); ref = text.substring(idx + 1); } - return resolveSchemaProperty(getElement(), id, ref); + return new JsonSchemaDefinitionResolver(getElement(), id).setRef(ref).setInCurrentFile(!isGlobal).doResolve(); } } - - @Nullable - public static PsiElement resolveSchemaProperty(PsiElement baseElement, @Nullable final String schemaId, String ref) { - final Project project = baseElement.getProject(); - final FileBasedIndex index = FileBasedIndex.getInstance(); - final Ref> reference = new Ref<>(); - final GlobalSearchScope filter = schemaId == null ? GlobalSearchScope.fileScope(baseElement.getContainingFile()) : - JsonSchemaResourcesRootsProvider.enlarge(project, GlobalSearchScope.allScope(project)); - index.processValues(JsonSchemaFileIndex.PROPERTIES_INDEX, ref, null, new FileBasedIndex.ValueProcessor() { - @Override - public boolean process(VirtualFile file, Integer value) { - if (schemaId != null) { - if (!JsonSchemaService.Impl.getEx(project).checkFileForId(schemaId, file)) { - return true; - } - } - reference.set(Pair.create(file, value)); - return false; - } - }, filter); - - if (!reference.isNull()) { - final Pair pair = reference.get(); - final PsiFile file = baseElement.getManager().findFile(pair.getFirst()); - if (file != null) { - return file.findElementAt(pair.getSecond()); - } - } - return null; - } } diff --git a/json/src/com/jetbrains/jsonSchema/ide/JsonSchemaService.java b/json/src/com/jetbrains/jsonSchema/ide/JsonSchemaService.java index 29e91a4116e5..ac00f5257e45 100644 --- a/json/src/com/jetbrains/jsonSchema/ide/JsonSchemaService.java +++ b/json/src/com/jetbrains/jsonSchema/ide/JsonSchemaService.java @@ -8,9 +8,9 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiElement; import com.intellij.util.Consumer; -import com.intellij.util.containers.Convertor; +import com.intellij.util.Processor; +import com.jetbrains.jsonSchema.impl.JsonSchemaObject; import com.jetbrains.jsonSchema.impl.JsonSchemaServiceEx; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,8 +41,7 @@ public interface JsonSchemaService { @Nullable DocumentationProvider getDocumentationProvider(@Nullable VirtualFile file); - @Nullable - Convertor getToPropertyResolver(@Nullable VirtualFile file); + void iterateSchemaObjects(VirtualFile file, @NotNull final Processor consumer); @Nullable List> getMatchingSchemaDescriptors(@Nullable VirtualFile file); diff --git a/json/src/com/jetbrains/jsonSchema/impl/CodeInsightProviders.java b/json/src/com/jetbrains/jsonSchema/impl/CodeInsightProviders.java index b4065d34bbb6..0699f90d5244 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/CodeInsightProviders.java +++ b/json/src/com/jetbrains/jsonSchema/impl/CodeInsightProviders.java @@ -18,8 +18,7 @@ package com.jetbrains.jsonSchema.impl; import com.intellij.codeInsight.completion.CompletionContributor; import com.intellij.lang.annotation.Annotator; import com.intellij.lang.documentation.DocumentationProvider; -import com.intellij.psi.PsiElement; -import com.intellij.util.containers.Convertor; +import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; /** @@ -35,6 +34,5 @@ public interface CodeInsightProviders { @NotNull DocumentationProvider getDocumentationProvider(); - @NotNull - Convertor getToPropertyResolver(); + boolean iterateSchemaObjects(@NotNull Processor consumer); } diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonPropertyName2SchemaDefinitionReferenceProvider.java b/json/src/com/jetbrains/jsonSchema/impl/JsonPropertyName2SchemaDefinitionReferenceProvider.java index 1d064b7ff47a..c99576fb5d40 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonPropertyName2SchemaDefinitionReferenceProvider.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonPropertyName2SchemaDefinitionReferenceProvider.java @@ -16,16 +16,13 @@ package com.jetbrains.jsonSchema.impl; import com.intellij.json.psi.JsonStringLiteral; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.ElementManipulators; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.PsiReferenceProvider; import com.intellij.util.ProcessingContext; -import com.intellij.util.containers.Convertor; import com.jetbrains.jsonSchema.extension.schema.JsonSchemaBaseReference; -import com.jetbrains.jsonSchema.ide.JsonSchemaService; +import com.jetbrains.jsonSchema.extension.schema.JsonSchemaDefinitionResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,11 +44,7 @@ public class JsonPropertyName2SchemaDefinitionReferenceProvider extends PsiRefer @Nullable @Override public PsiElement resolveInner() { - final Project project = getElement().getProject(); - final Convertor resolver = - JsonSchemaService.Impl.get(project).getToPropertyResolver(getElement().getContainingFile().getVirtualFile()); - if (resolver != null) return resolver.convert("/properties/" + StringUtil.unquoteString(getCanonicalText())); - return null; + return new JsonSchemaDefinitionResolver(getElement(), null).doResolve(); } } } diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java index f24ae17dfa61..8b25b52680ab 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java @@ -9,6 +9,7 @@ import java.util.Map; * @author Irina.Chernushina on 8/28/2015. */ public class JsonSchemaObject { + private String myDefinitionAddress; private Map myDefinitions; private Map myProperties; private Map myPatternProperties; @@ -108,6 +109,7 @@ public class JsonSchemaObject { myAnyOf = other.myAnyOf; myOneOf = other.myOneOf; myNot = other.myNot; + myDefinitionAddress = other.myDefinitionAddress; } public void mergeValues(JsonSchemaObject other) { @@ -480,4 +482,12 @@ public class JsonSchemaObject { public boolean hasSpecifiedType() { return myType != null || (myTypeVariants != null && !myTypeVariants.isEmpty()); } + + public String getDefinitionAddress() { + return myDefinitionAddress; + } + + public void setDefinitionAddress(String definitionAddress) { + myDefinitionAddress = definitionAddress; + } } diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObjectCodeInsightWrapper.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObjectCodeInsightWrapper.java index 9fcf2caab0b6..490316329b7e 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObjectCodeInsightWrapper.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObjectCodeInsightWrapper.java @@ -6,17 +6,14 @@ import com.intellij.lang.annotation.Annotator; import com.intellij.lang.documentation.DocumentationProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; -import com.intellij.util.containers.Convertor; +import com.intellij.util.Processor; import com.jetbrains.jsonSchema.extension.SchemaType; -import com.jetbrains.jsonSchema.extension.schema.JsonSchemaRefReferenceProvider; import org.jetbrains.annotations.NotNull; class JsonSchemaObjectCodeInsightWrapper implements CodeInsightProviders { @NotNull private final String myName; @NotNull private final SchemaType mySchemaType; + @NotNull private final JsonSchemaObject mySchemaObject; @NotNull private final CompletionContributor myContributor; @@ -25,7 +22,7 @@ class JsonSchemaObjectCodeInsightWrapper implements CodeInsightProviders { @NotNull private final DocumentationProvider myDocumentationProvider; - private Convertor my2SchemaResolver; + public JsonSchemaObjectCodeInsightWrapper(@NotNull Project project, @NotNull String name, @NotNull SchemaType type, @@ -33,17 +30,10 @@ class JsonSchemaObjectCodeInsightWrapper implements CodeInsightProviders { @NotNull JsonSchemaObject schemaObject) { myName = name; mySchemaType = type; + mySchemaObject = schemaObject; myContributor = new JsonBySchemaObjectCompletionContributor(type, schemaObject); myAnnotator = new JsonBySchemaObjectAnnotator(schemaObject); myDocumentationProvider = new JsonBySchemaDocumentationProvider(schemaObject); - my2SchemaResolver = new Convertor() { - @Override - public PsiElement convert(String key) { - final PsiFile psiFile = PsiManager.getInstance(project).findFile(schemaFile); - if (psiFile == null) return null; - return JsonSchemaRefReferenceProvider.resolveSchemaProperty(psiFile, null, key); - } - }; } @Override @@ -69,10 +59,9 @@ class JsonSchemaObjectCodeInsightWrapper implements CodeInsightProviders { return myDocumentationProvider; } - @NotNull @Override - public Convertor getToPropertyResolver() { - return my2SchemaResolver; + public boolean iterateSchemaObjects(@NotNull final Processor consumer) { + return consumer.process(mySchemaObject); } public boolean isUserSchema() { diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java index c77bfde24ea3..eeeba1384a49 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java @@ -147,6 +147,7 @@ public class JsonSchemaReader { } final JsonSchemaObject copy = new JsonSchemaObject(); + copy.setDefinitionAddress(current.getRef()); copy.mergeValues(definition); copy.mergeValues(current); current.copyValues(copy); diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java index 59bbe615c6ad..832ba47d0922 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java @@ -18,14 +18,15 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.NullableLazyValue; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.PsiElement; import com.intellij.util.Consumer; import com.intellij.util.NotNullFunction; import com.intellij.util.PairConsumer; +import com.intellij.util.Processor; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.Convertor; import com.jetbrains.jsonSchema.JsonSchemaFileTypeManager; import com.jetbrains.jsonSchema.JsonSchemaVfsListener; import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider; @@ -53,8 +54,7 @@ public class JsonSchemaServiceImpl implements JsonSchemaServiceEx { public JsonSchemaServiceImpl(@NotNull Project project) { myLock = new Object(); myProject = project; - myDefinitions = new JsonSchemaExportedDefinitions( - consumer -> iterateSchemas(consumer)); + myDefinitions = new JsonSchemaExportedDefinitions(this::iterateSchemas); ApplicationManager .getApplication().getMessageBus().connect(project).subscribe(VirtualFileManager.VFS_CHANGES, new JsonSchemaVfsListener(project, this)); ensureSchemaFiles(project); @@ -113,7 +113,7 @@ public class JsonSchemaServiceImpl implements JsonSchemaServiceEx { public boolean isSchemaFile(@NotNull VirtualFile file, @NotNull final Consumer errorConsumer) { final String text; try { - text = VfsUtil.loadText(file); + text = VfsUtilCore.loadText(file); } catch (IOException e) { errorConsumer.consume(e.getMessage()); @@ -145,11 +145,11 @@ public class JsonSchemaServiceImpl implements JsonSchemaServiceEx { return wrapper != null ? wrapper.getDocumentationProvider() : null; } - @Nullable @Override - public Convertor getToPropertyResolver(@Nullable VirtualFile file) { - CodeInsightProviders wrapper = getWrapper(file); - return wrapper != null ? wrapper.getToPropertyResolver() : null; + public void iterateSchemaObjects(VirtualFile file, @NotNull Processor consumer) { + final CodeInsightProviders wrapper = getWrapper(file); + if (wrapper == null) return; + wrapper.iterateSchemaObjects(consumer); } @Nullable @@ -286,13 +286,14 @@ public class JsonSchemaServiceImpl implements JsonSchemaServiceEx { public CompositeCodeInsightProviderWithWarning(List wrappers) { final List userSchemaWrappers = - ContainerUtil.filter(wrappers, wrapper -> wrapper.isUserSchema()); + ContainerUtil.filter(wrappers, JsonSchemaObjectCodeInsightWrapper::isUserSchema); // filter for the case when there are one system schema and one (several) user schemas // then do not use provided system schema: user schema will override it (maybe the user updated the version himself) // if there are 2 or more system schemas - just go the common way: it is unclear what happened and why if (!userSchemaWrappers.isEmpty() && ((userSchemaWrappers.size() + 1) == wrappers.size())) { myWrappers = userSchemaWrappers; - } else { + } + else { myWrappers = wrappers; } myContributor = new CompletionContributor() { @@ -336,19 +337,12 @@ public class JsonSchemaServiceImpl implements JsonSchemaServiceEx { return myDocumentationProvider; } - @NotNull @Override - public Convertor getToPropertyResolver() { - return new Convertor() { - @Override - public PsiElement convert(String key) { - for (JsonSchemaObjectCodeInsightWrapper wrapper : myWrappers) { - PsiElement element = wrapper.getToPropertyResolver().convert(key); - if (element != null) return element; - } - return null; - } - }; + public boolean iterateSchemaObjects(@NotNull Processor consumer) { + for (JsonSchemaObjectCodeInsightWrapper wrapper : myWrappers) { + if (!wrapper.iterateSchemaObjects(consumer)) return false; + } + return true; } } diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaWalker.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaWalker.java index 9babd682e4f2..ecc93865807c 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaWalker.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaWalker.java @@ -41,7 +41,7 @@ import java.util.List; * This will significantly simplify code, since we will not need to take the list of possible variants of children and grandchildren; * we will be able to iterate variants, not collections of variants */ -class JsonSchemaWalker { +public class JsonSchemaWalker { public interface CompletionSchemesConsumer { void consume(boolean isName, @NotNull JsonSchemaObject schema); } @@ -65,7 +65,7 @@ class JsonSchemaWalker { extractSchemaVariants(consumer, rootSchema, isName, position); } - private static void extractSchemaVariants(@NotNull CompletionSchemesConsumer consumer, + public static void extractSchemaVariants(@NotNull CompletionSchemesConsumer consumer, @NotNull JsonSchemaObject rootSchema, boolean isName, List position) { final ArrayDeque> queue = new ArrayDeque>(); queue.add(Pair.create(rootSchema, 0)); @@ -189,12 +189,12 @@ class JsonSchemaWalker { return steps; } - private static class Step { + public static class Step { private final StateType myType; @Nullable private final Transition myTransition; - public Step(StateType type, Transition transition) { + public Step(StateType type, @Nullable Transition transition) { myType = type; myTransition = transition; } @@ -282,7 +282,7 @@ class JsonSchemaWalker { @Nullable private final JsonSchemaType myCorrespondingJsonType; - StateType(JsonSchemaType correspondingJsonType) { + StateType(@Nullable JsonSchemaType correspondingJsonType) { myCorrespondingJsonType = correspondingJsonType; } diff --git a/lib/asm-all.jar b/lib/asm-all.jar index b2f2849bae45..12f25c2c4220 100644 Binary files a/lib/asm-all.jar and b/lib/asm-all.jar differ diff --git a/lib/src/asm5-src.zip b/lib/src/asm-src.zip similarity index 57% rename from lib/src/asm5-src.zip rename to lib/src/asm-src.zip index ad405c1ca3e2..26dd8efc7fef 100644 Binary files a/lib/src/asm5-src.zip and b/lib/src/asm-src.zip differ diff --git a/platform/core-impl/src/com/intellij/mock/MockFileDocumentManagerImpl.java b/platform/core-impl/src/com/intellij/mock/MockFileDocumentManagerImpl.java index 1d7e03624708..ecbb31c6f3b1 100644 --- a/platform/core-impl/src/com/intellij/mock/MockFileDocumentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/mock/MockFileDocumentManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -86,7 +86,7 @@ public class MockFileDocumentManagerImpl extends FileDocumentManager { @Override @NotNull public Document[] getUnsavedDocuments() { - return new Document[0]; + return Document.EMPTY_ARRAY; } @Override diff --git a/platform/lang-api/src/com/intellij/util/ActionRunner.java b/platform/lang-api/src/com/intellij/util/ActionRunner.java index 75e5179d522a..d1f662cab902 100644 --- a/platform/lang-api/src/com/intellij/util/ActionRunner.java +++ b/platform/lang-api/src/com/intellij/util/ActionRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -46,6 +46,7 @@ public abstract class ActionRunner { return result.throwException().getResultObject(); } + @Deprecated public static void runInsideReadAction(@NotNull final InterruptibleRunnable runnable) throws Exception { ApplicationManager.getApplication().runReadAction(new ThrowableComputable() { @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java index 310ff333b511..131813271daf 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -268,7 +268,7 @@ public class FoldingUpdate { ", PSI element range: " + psiElement.getTextRange() + "; " + DebugUtil.diagnosePsiDocumentInconsistency(psiElement, document); LOG.error(message, ApplicationManager.getApplication().isInternal() ? new Attachment[]{AttachmentFactory.createAttachment(document), new Attachment("psiTree.txt", DebugUtil.psiToString(file, false, true))} - : new Attachment[0]); + : Attachment.EMPTY_ARRAY); } public static class FoldingMap extends MultiMap{ diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java index 48665d43dc44..038a85eb921f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -153,7 +153,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { } String text = ""; - PsiElement[] impls = new PsiElement[0]; + PsiElement[] impls = PsiElement.EMPTY_ARRAY; if (element != null) { //if (element instanceof PsiPackage) return; diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index 83577c6b396d..ae51adce6318 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -733,6 +733,17 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp private ProblemDescriptionsProcessor getProblemDescriptionProcessor(@NotNull final GlobalInspectionToolWrapper toolWrapper, @NotNull final Map wrappersMap) { return new ProblemDescriptionsProcessor() { + @Nullable + @Override + public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) { + return CommonProblemDescriptor.EMPTY_ARRAY; + } + + @Override + public void ignoreElement(@NotNull RefEntity refEntity) { + + } + @Override public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) { for (CommonProblemDescriptor problemDescriptor : commonProblemDescriptors) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java index 8dba1efa5ec1..6e61c44978bc 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java @@ -415,7 +415,7 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro public void ignoreCurrentElementProblem(RefEntity refEntity, CommonProblemDescriptor descriptor) { CommonProblemDescriptor[] descriptors = getIgnoredElements().get(refEntity); if (descriptors == null) { - descriptors = new CommonProblemDescriptor[0]; + descriptors = CommonProblemDescriptor.EMPTY_ARRAY; } getIgnoredElements().put(refEntity, ArrayUtil.append(descriptors, descriptor)); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index cc7cfdcc337f..d953946471f5 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -722,7 +722,6 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren final HighlightDisplayKey key = HighlightDisplayKey.find(defaultToolWrapper.getShortName()); for (ScopeToolState state : myProvider.getTools(currentTools)) { InspectionToolWrapper toolWrapper = state.getTool(); - LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed()); ReadAction.run(() -> { if (myProvider.checkReportedProblems(myGlobalInspectionContext, toolWrapper)) { addTool(toolWrapper, diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java index 394c710de8eb..1735f08961d6 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java @@ -29,13 +29,14 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.MutableTreeNode; +import javax.swing.tree.TreeNode; /** * @author max */ public class RefElementNode extends SuppressableInspectionTreeNode { - private boolean myHasDescriptorsUnder = false; - private CommonProblemDescriptor mySingleDescriptor = null; + private volatile boolean myHasDescriptorsUnder; + private volatile CommonProblemDescriptor mySingleDescriptor; private final Icon myIcon; public RefElementNode(@Nullable RefEntity userObject, @NotNull InspectionToolPresentation presentation) { super(userObject, presentation); @@ -76,7 +77,6 @@ public class RefElementNode extends SuppressableInspectionTreeNode { @Override public void excludeElement(ExcludedInspectionTreeNodesManager excludedManager) { - myPresentation.ignoreCurrentElement(getElement()); super.excludeElement(excludedManager); } @@ -92,10 +92,14 @@ public class RefElementNode extends SuppressableInspectionTreeNode { @Override public void add(MutableTreeNode newChild) { + checkHasDescriptorUnder(newChild); super.add(newChild); - if (newChild instanceof ProblemDescriptionNode) { - myHasDescriptorsUnder = true; - } + } + + @Override + public InspectionTreeNode insertByOrder(InspectionTreeNode child, boolean allowDuplication) { + checkHasDescriptorUnder(child); + return super.insertByOrder(child, allowDuplication); } public void setProblem(@NotNull CommonProblemDescriptor descriptor) { @@ -142,4 +146,17 @@ public class RefElementNode extends SuppressableInspectionTreeNode { } return isLeaf() ? "" : null; } + + private void checkHasDescriptorUnder(MutableTreeNode newChild) { + if (myHasDescriptorsUnder) return; + if (newChild instanceof ProblemDescriptionNode || + newChild instanceof RefElementNode && ((RefElementNode)newChild).hasDescriptorsUnder()) { + myHasDescriptorsUnder = true; + TreeNode parent = getParent(); + while (parent instanceof RefElementNode) { + ((RefElementNode)parent).myHasDescriptorsUnder = true; + parent = parent.getParent(); + } + } + } } diff --git a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectDialog.java b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectDialog.java index a705cd062f3a..61ff94fe09c0 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectDialog.java @@ -93,7 +93,7 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper { @Override protected String getHelpId() { - return null; + return "create_new_project_dialog"; } @NotNull @@ -103,6 +103,6 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper { @Override public void show() { - DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> AbstractNewProjectDialog.super.show()); + DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, super::show); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java index f7e413fe010e..22c78ac45401 100644 --- a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java +++ b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -243,7 +243,7 @@ public class DefaultLanguageColorsPage implements ColorSettingsPage, DisplayPrio @NotNull @Override public ColorDescriptor[] getColorDescriptors() { - return new ColorDescriptor[0]; + return ColorDescriptor.EMPTY_ARRAY; } @NotNull diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/FindDependencyUtil.java b/platform/lang-impl/src/com/intellij/packageDependencies/FindDependencyUtil.java index 888fb38b1b3e..4cd358cc8ca1 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/FindDependencyUtil.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/FindDependencyUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -80,7 +80,7 @@ public class FindDependencyUtil { } } deps.retainAll(searchIn); - if (deps.isEmpty()) return new UsageInfo[0]; + if (deps.isEmpty()) return UsageInfo.EMPTY_ARRAY; int totalCount = deps.size(); int count = 0; diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesUsagesPanel.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesUsagesPanel.java index c2ee176db7a3..73fd993f4299 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesUsagesPanel.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesUsagesPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -32,9 +32,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiUtilCore; import com.intellij.usageView.UsageInfo; -import com.intellij.util.Consumer; -import javax.swing.*; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -68,7 +66,7 @@ public class DependenciesUsagesPanel extends UsagesPanel { myCurrentProgress = progress; ProgressManager.getInstance().runProcess(() -> { ApplicationManager.getApplication().runReadAction(() -> { - UsageInfo[] usages = new UsageInfo[0]; + UsageInfo[] usages = UsageInfo.EMPTY_ARRAY; Set elementsToSearch = null; try { diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java index fb20ebb3317b..593792436228 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java @@ -70,6 +70,8 @@ import java.io.File; import java.io.IOException; import java.util.*; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public abstract class InspectionToolsConfigurable extends BaseConfigurable implements ErrorsConfigurable, SearchableConfigurable, Configurable.NoScroll { @@ -78,7 +80,8 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable private static final String HEADER_TITLE = "Profile:"; private static final Logger LOG = Logger.getInstance(InspectionToolsConfigurable.class); - private static final String COPY_SUFFIX = "copy"; + private static final Pattern COPIED_PROFILE_SUFFIX_PATTERN = Pattern.compile("(.*\\s*copy)\\s*(\\d*)"); + protected final InspectionProfileManager myApplicationProfileManager; protected final ProjectInspectionProfileManager myProjectProfileManager; private final CardLayout myLayout = new CardLayout(); @@ -114,15 +117,21 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable LOG.assertTrue(modifyLevel || modifyName); String profileDefaultName = selectedProfile.getName(); if (modifyName) { - if (!profileDefaultName.endsWith(COPY_SUFFIX)) { - profileDefaultName += " " + COPY_SUFFIX; + final Matcher matcher = COPIED_PROFILE_SUFFIX_PATTERN.matcher(profileDefaultName); + int nextIdx; + if (matcher.matches()) { + profileDefaultName = matcher.group(1); + nextIdx = matcher.group(2).isEmpty() ? 1 : Integer.valueOf(matcher.group(2)); + } + else { + profileDefaultName += " copy"; + nextIdx = 1; } if (hasName(profileDefaultName, modifyLevel != myPanels.get(selectedProfile).isProjectLevel())) { - int idx = 0; String currentProfileDefaultName; do { - idx++; - currentProfileDefaultName = profileDefaultName + " " + String.valueOf(idx); + currentProfileDefaultName = profileDefaultName + " " + String.valueOf(nextIdx); + nextIdx++; } while (hasName(currentProfileDefaultName, modifyLevel != myPanels.get(selectedProfile).isProjectLevel())); profileDefaultName = currentProfileDefaultName; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiFileProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiFileProcessor.java index 678f3903b29d..527e33289838 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiFileProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiFileProcessor.java @@ -56,7 +56,7 @@ public class RenamePsiFileProcessor extends RenamePsiElementProcessor { return super.findReferences(element); } - protected static class PsiFileRenameDialog extends RenameWithOptionalReferencesDialog { + public static class PsiFileRenameDialog extends RenameWithOptionalReferencesDialog { public PsiFileRenameDialog(Project project, PsiElement element, PsiElement nameSuggestionContext, Editor editor) { super(project, element, nameSuggestionContext, editor); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index 1d3a8a7bc364..0be25906c1b2 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -2003,6 +2003,7 @@ public class FileBasedIndexImpl extends FileBasedIndex { private UnindexedFilesFinder(@Nullable ProgressIndicator indicator) { myProgressIndicator = indicator; + if (!myInitialized) waitUntilIndicesAreInitialized(); } @NotNull diff --git a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/FreezeLogger.java b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/FreezeLogger.java new file mode 100644 index 000000000000..f1da1fde7b2b --- /dev/null +++ b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/FreezeLogger.java @@ -0,0 +1,50 @@ +/* + * 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. + */ +package com.intellij.openapi.editor.actionSystem; + +import com.intellij.diagnostic.ThreadDumper; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.Alarm; + +public class FreezeLogger { + + private static final Logger LOG = Logger.getInstance(FreezeLogger.class); + private static final Alarm ALARM = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, ApplicationManager.getApplication()); + private static final int MAX_ALLOWED_TIME = 500; + + public static void runUnderPerformanceMonitor(Runnable action) { + ALARM.cancelAllRequests(); + ALARM.addRequest(FreezeLogger::dumpThreads, MAX_ALLOWED_TIME); + + try { + action.run(); + } + finally { + ALARM.cancelAllRequests(); + } + } + + private static void dumpThreads() { + String dumps = ThreadDumper.dumpThreadsToString(); + String msg = "Typing freeze report, thread dumps attached. EDT stacktrace:\n" + + ThreadDumper.dumpEdtStackTrace() + + "\n\n\n"; + + LOG.error(msg, dumps); + } + +} \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/TypedAction.java b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/TypedAction.java index 81376292aa63..4de77f5c449c 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/TypedAction.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/TypedAction.java @@ -15,18 +15,14 @@ */ package com.intellij.openapi.editor.actionSystem; -import com.intellij.diagnostic.ThreadDumper; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.UndoConfirmationPolicy; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.*; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.util.Disposer; -import com.intellij.util.Alarm; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -165,34 +161,4 @@ public class TypedAction { "", editor.getDocument(), UndoConfirmationPolicy.DEFAULT, editor.getDocument()); } } -} - - -class FreezeLogger { - - private static final Logger LOG = Logger.getInstance(FreezeLogger.class); - private static final Alarm ALARM = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, Disposer.newDisposable()); - private static final int MAX_ALLOWED_TIME = 500; - - public static void runUnderPerformanceMonitor(Runnable action) { - ALARM.cancelAllRequests(); - ALARM.addRequest(FreezeLogger::dumpThreads, MAX_ALLOWED_TIME); - - try { - action.run(); - } - finally { - ALARM.cancelAllRequests(); - } - } - - private static void dumpThreads() { - String dumps = ThreadDumper.dumpThreadsToString(); - String msg = "Typing freeze report, thread dumps attached. EDT stacktrace:\n" - + ThreadDumper.dumpEdtStackTrace() - + "\n\n\n"; - - LOG.error(msg, dumps); - } - } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/ui/EffectPainter.java b/platform/platform-api/src/com/intellij/ui/EffectPainter.java new file mode 100644 index 000000000000..050a4a73538d --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/EffectPainter.java @@ -0,0 +1,85 @@ +/* + * 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. + */ +package com.intellij.ui; + +import com.intellij.openapi.util.registry.Registry; +import com.intellij.util.ui.RegionPainter; + +import java.awt.*; +import java.awt.geom.*; + +/** + * @author Sergey.Malenkov + */ +public enum EffectPainter implements RegionPainter { + WAVE { + private final BasicStroke STROKE = new BasicStroke(.7f); + + @Override + public void paint(Graphics2D g, int x, int y, int width, int height, Paint paint) { + if (paint != null && width > 0 && height > 0) { + if (!Registry.is("ide.text.effect.wave.new.scale")) { + y += height - 3; + height = 3; + } + g = (Graphics2D)g.create(x, y, width, height); + g.clipRect(0, 0, width, height); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setPaint(paint); + + int length = 2 * height; + boolean simple = length < 5; + + double dx = -((x % length + length) % length); // normalize + double size = (double)length / 4; + + double upper = 0; + double lower = height - 1; + double center = lower / 2; + + Path2D path = new Path2D.Double(); + path.moveTo(dx, lower); + while (true) { + if (simple) { + dx += size + size; + path.lineTo(dx, upper); + if (dx > width) break; + dx += size + size; + path.lineTo(dx, lower); + if (dx > width) break; + } + else { + dx += size; + path.quadTo(dx - size / 2, lower, dx, center); + if (dx > width) break; + dx += size; + path.quadTo(dx - size / 2, upper, dx, upper); + if (dx > width) break; + dx += size; + path.quadTo(dx - size / 2, upper, dx, center); + if (dx > width) break; + dx += size; + path.quadTo(dx - size / 2, lower, dx, lower); + if (dx > width) break; + } + } + if (simple) g.setStroke(STROKE); + g.draw(path); + g.dispose(); + } + } + } +} diff --git a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java index 6d3e83afa1fe..f983834840fe 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java @@ -22,6 +22,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.JBUI; @@ -833,10 +834,15 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co } // 2. Waved effect if (attributes.isWaved()) { - if (attributes.getWaveColor() != null) { - g.setColor(attributes.getWaveColor()); + if (Registry.is("ide.text.effect.wave.new")) { + EffectPainter.WAVE.paint(g, offset, textBaseline + 1, fragmentWidth, Math.max(2, metrics.getDescent()), attributes.getWaveColor()); + } + else { + if (attributes.getWaveColor() != null) { + g.setColor(attributes.getWaveColor()); + } + UIUtil.drawWave(g, new Rectangle(offset, textBaseline + 1, fragmentWidth, Math.max(2, metrics.getDescent()))); } - UIUtil.drawWave(g, new Rectangle(offset, textBaseline + 1, fragmentWidth, Math.max(2, metrics.getDescent()))); } // 3. Underline if (attributes.isUnderline()) { diff --git a/platform/platform-api/src/com/intellij/util/config/ExternalizablePropertyContainer.java b/platform/platform-api/src/com/intellij/util/config/ExternalizablePropertyContainer.java index 25f3a173e45b..c1e1070bb2aa 100644 --- a/platform/platform-api/src/com/intellij/util/config/ExternalizablePropertyContainer.java +++ b/platform/platform-api/src/com/intellij/util/config/ExternalizablePropertyContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -79,6 +79,8 @@ public class ExternalizablePropertyContainer extends AbstractProperty.AbstractPr } public void readExternal(@NotNull Element element) { + myValues.clear(); + Map propertyByName = new THashMap(); for (AbstractProperty abstractProperty : myExternalizers.keySet()) { propertyByName.put(abstractProperty.getName(), abstractProperty); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java index 6220dbacb697..bfbfdc0f1ae0 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java @@ -425,7 +425,7 @@ public class Switcher extends AnAction implements DumbAware { filesData.add(info); if (!firstRecentMarked) { selectionIndex = filesData.size() - 1; - if (selectionIndex != 0 || UISettings.getInstance().EDITOR_TAB_PLACEMENT != UISettings.TABS_NONE) { + if (selectionIndex != 0 || UISettings.getInstance().EDITOR_TAB_PLACEMENT != UISettings.TABS_NONE || !isPinnedMode()) { firstRecentMarked = true; } } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java b/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java index 6961dc4f1166..61561edc4a0f 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java @@ -95,26 +95,14 @@ public class RepositoryHelper { @NotNull public static List loadPlugins(@Nullable String repositoryUrl, @Nullable ProgressIndicator indicator) throws IOException { - boolean forceHttps = repositoryUrl == null && IdeaApplication.isLoaded() && UpdateSettings.getInstance().canUseSecureConnection(); - return loadPlugins(repositoryUrl, null, forceHttps, indicator); + return loadPlugins(repositoryUrl, null, indicator); } - /** - * Loads list of plugins, compatible with a given build, from a given plugin repository (main repository if null). - */ @NotNull public static List loadPlugins(@Nullable String repositoryUrl, @Nullable BuildNumber buildnumber, @Nullable ProgressIndicator indicator) throws IOException { boolean forceHttps = repositoryUrl == null && IdeaApplication.isLoaded() && UpdateSettings.getInstance().canUseSecureConnection(); - return loadPlugins(repositoryUrl, buildnumber, forceHttps, indicator); - } - - @NotNull - public static List loadPlugins(@Nullable String repositoryUrl, - @Nullable BuildNumber buildnumber, - boolean forceHttps, - @Nullable ProgressIndicator indicator) throws IOException { return loadPlugins(repositoryUrl, buildnumber, null, forceHttps, indicator); } diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java index 51d3a12c183c..40667067921f 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java @@ -228,8 +228,11 @@ public class DarculaLaf extends BasicLookAndFeel { loadDefaults(defaults); defaults.put("Table.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] { "ctrl C", "copy", + "meta C", "copy", "ctrl V", "paste", + "meta V", "paste", "ctrl X", "cut", + "meta X", "cut", "COPY", "copy", "PASTE", "paste", "CUT", "cut", diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/DummyProject.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/DummyProject.java index 5f1e4ddc5c43..928b8cc55784 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/DummyProject.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/DummyProject.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -144,7 +144,7 @@ public class DummyProject extends UserDataHolderBase implements Project { @NotNull public ComponentConfig[] getComponentConfigurations() { - return new ComponentConfig[0]; + return ComponentConfig.EMPTY_ARRAY; } @Nullable diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 4124067ec1fb..2e56f175f983 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -2413,7 +2413,12 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int y = visibleLineToY(visibleStartLine) + getAscent() + 1; g.setColor(attributes.getEffectColor()); if (attributes.getEffectType() == EffectType.WAVE_UNDERSCORE) { - UIUtil.drawWave((Graphics2D)g, new Rectangle(end.x, y, charWidth - 1, getDescent()- 1)); + if (Registry.is("ide.text.effect.wave.new")) { + EffectPainter.WAVE.paint((Graphics2D)g, end.x, y, charWidth - 1, getDescent() - 1, attributes.getEffectColor()); + } + else { + UIUtil.drawWave((Graphics2D)g, new Rectangle(end.x, y, charWidth - 1, getDescent() - 1)); + } } else if (attributes.getEffectType() == EffectType.BOLD_DOTTED_LINE) { final int dottedAt = SystemInfo.isMac ? y - 1 : y; @@ -3562,8 +3567,13 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi g.setColor(savedColor); } else if (effectType == EffectType.WAVE_UNDERSCORE) { - g.setColor(effectColor); - UIUtil.drawWave((Graphics2D)g, new Rectangle(xStart, y+1, xEnd - xStart, getDescent() - 1)); + if (Registry.is("ide.text.effect.wave.new")) { + EffectPainter.WAVE.paint((Graphics2D)g, xStart, y + 1, xEnd - xStart, getDescent() - 1, effectColor); + } + else { + g.setColor(effectColor); + UIUtil.drawWave((Graphics2D)g, new Rectangle(xStart, y + 1, xEnd - xStart, getDescent() - 1)); + } g.setColor(savedColor); } else if (effectType == EffectType.BOLD_DOTTED_LINE) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java index 1de3624296ea..27a432411458 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java @@ -33,6 +33,7 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.impl.IdeBackgroundUtil; import com.intellij.ui.ColorUtil; +import com.intellij.ui.EffectPainter; import com.intellij.ui.Gray; import com.intellij.ui.JBColor; import com.intellij.util.ui.JBUI; @@ -439,7 +440,12 @@ class EditorPainter implements TextDrawingCallback { UIUtil.drawLine(g, xStart, y1, xEnd, y1); } else if (effectType == EffectType.WAVE_UNDERSCORE) { - UIUtil.drawWave(g, new Rectangle(xStart, y + 1, xEnd - xStart, myView.getDescent() - 1)); + if (Registry.is("ide.text.effect.wave.new")) { + EffectPainter.WAVE.paint(g, xStart, y + 1, xEnd - xStart, myView.getDescent() - 1, effectColor); + } + else { + UIUtil.drawWave(g, new Rectangle(xStart, y + 1, xEnd - xStart, myView.getDescent() - 1)); + } } else if (effectType == EffectType.BOLD_DOTTED_LINE) { UIUtil.drawBoldDottedLine(g, xStart, xEnd, SystemInfo.isMac ? y : y + 1, myEditor.getBackgroundColor(), g.getColor(), false); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java index 547c9ad38289..d3e8a467a1e8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java @@ -266,7 +266,7 @@ abstract class LineLayout { assert startOffset <= endOffset; final BidiRun[] runs; if (startOffset == endOffset) { - runs = new BidiRun[0]; + runs = BidiRun.EMPTY_ARRAY; } else { List runList = new ArrayList(); @@ -338,7 +338,7 @@ abstract class LineLayout { } private BidiRun[] createRuns() { - if (myChunk == null) return new BidiRun[0]; + if (myChunk == null) return BidiRun.EMPTY_ARRAY; BidiRun run = new BidiRun(myChunk.endOffset); run.chunks = new Chunk[] {myChunk}; return new BidiRun[] {run}; @@ -474,6 +474,7 @@ abstract class LineLayout { } private static class BidiRun { + public static final BidiRun[] EMPTY_ARRAY = new BidiRun[0]; private static final int CHUNK_CHARACTERS = 1024; private final byte level; diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/KeymapImpl.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/KeymapImpl.java index 484235dd097b..cc69281bfad9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/KeymapImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/KeymapImpl.java @@ -87,7 +87,7 @@ public class KeymapImpl extends ExternalizableSchemeAdapter implements Keymap { */ private Map> myMouseShortcut2ListOfIds = null; - private static final Shortcut[] ourEmptyShortcutsArray = new Shortcut[0]; + private static final Shortcut[] ourEmptyShortcutsArray = Shortcut.EMPTY_ARRAY; private final List myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); private KeymapManagerEx myKeymapManager; diff --git a/platform/platform-impl/src/com/intellij/openapi/options/SchemeImportUtil.java b/platform/platform-impl/src/com/intellij/openapi/options/SchemeImportUtil.java index 56dda7dc59f4..5775fe88c3b2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/SchemeImportUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/SchemeImportUtil.java @@ -58,7 +58,7 @@ public class SchemeImportUtil { preselectFiles[0] = preselect; } else { - preselectFiles = new VirtualFile[0]; + preselectFiles = VirtualFile.EMPTY_ARRAY; } final VirtualFile[] virtualFiles = fileChooser.choose(null, preselectFiles); //CodeStyleSchemesUIConfiguration.Util.getRecentImportFile()); diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java index 89653b9d4e67..76277dacad09 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java @@ -63,18 +63,20 @@ public class PluginDownloader { private String myDescription; private List myDepends; private IdeaPluginDescriptor myDescriptor; - private boolean myForceHttps; + private final boolean myForceHttps; private PluginDownloader(@NotNull String pluginId, @NotNull String pluginUrl, @Nullable String pluginName, @Nullable String pluginVersion, - @Nullable BuildNumber buildNumber) { + @Nullable BuildNumber buildNumber, + boolean forceHttps) { myPluginId = pluginId; myPluginUrl = pluginUrl; myPluginVersion = pluginVersion; myPluginName = pluginName; myBuildNumber = buildNumber; + myForceHttps = forceHttps; } public String getPluginId() { @@ -117,10 +119,6 @@ public class PluginDownloader { myDescriptor = descriptor; } - public void setForceHttps(boolean forceHttps) { - myForceHttps = forceHttps; - } - public boolean prepareToInstall(@NotNull ProgressIndicator indicator) throws IOException { if (myFile != null) { return true; @@ -295,10 +293,19 @@ public class PluginDownloader { public static PluginDownloader createDownloader(@NotNull IdeaPluginDescriptor descriptor, @Nullable String host, @Nullable BuildNumber buildNumber) throws IOException { + boolean forceHttps = host == null && UpdateSettings.getInstance().canUseSecureConnection(); + return createDownloader(descriptor, host, buildNumber, forceHttps); + } + + @NotNull + public static PluginDownloader createDownloader(@NotNull IdeaPluginDescriptor descriptor, + @Nullable String host, + @Nullable BuildNumber buildNumber, + boolean forceHttps) throws IOException { try { String url = getUrl(descriptor, host, buildNumber); String id = descriptor.getPluginId().getIdString(); - PluginDownloader downloader = new PluginDownloader(id, url, descriptor.getName(), descriptor.getVersion(), buildNumber); + PluginDownloader downloader = new PluginDownloader(id, url, descriptor.getName(), descriptor.getVersion(), buildNumber, forceHttps); downloader.setDescriptor(descriptor); downloader.setDescription(descriptor.getDescription()); List depends; diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.kt b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.kt index e1d36d9c5df9..c1a8a78819cf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.kt +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.kt @@ -222,14 +222,13 @@ object UpdateChecker { outer@ for (host in hosts) { try { val forceHttps = host == null && updateSettings.canUseSecureConnection() - val list = RepositoryHelper.loadPlugins(host, buildNumber, forceHttps, indicator) + val list = RepositoryHelper.loadPlugins(host, buildNumber, null, forceHttps, indicator) for (descriptor in list) { val id = descriptor.pluginId if (updateable.containsKey(id)) { updateable.remove(id) state.onDescriptorDownload(descriptor) - val downloader = PluginDownloader.createDownloader(descriptor, host, buildNumber) - downloader.setForceHttps(forceHttps) + val downloader = PluginDownloader.createDownloader(descriptor, host, buildNumber, forceHttps) checkAndPrepareToInstall(downloader, state, toUpdate, incompatiblePlugins, indicator) if (updateable.isEmpty()) { break@outer diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java index d687a206ccd4..dc2755d4cef9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -41,7 +41,6 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.reference.SoftReference; import com.intellij.ui.EditorNotifications; -import com.intellij.util.Function; import com.intellij.util.PlatformUtils; import com.intellij.util.containers.MultiMap; import com.intellij.util.io.HttpRequests; @@ -220,7 +219,7 @@ public class PluginsAdvertiser implements StartupActivity { } public static void installAndEnablePlugins(final @NotNull Set pluginIds, final @NotNull Runnable onSuccess) { - ProgressManager.getInstance().run(new Task.Modal(null, "Search for plugins in repository", true) { + ProgressManager.getInstance().run(new Task.Modal(null, "Search for Plugins in Repository", true) { private final Set myPlugins = new HashSet(); private List myAllPlugins; @@ -260,131 +259,139 @@ public class PluginsAdvertiser implements StartupActivity { } @Override - public void runActivity(@NotNull final Project project) { + public void runActivity(@NotNull Project project) { if (!UpdateSettings.getInstance().isCheckNeeded()) { return; } final UnknownFeaturesCollector collectorSuggester = UnknownFeaturesCollector.getInstance(project); final Set unknownFeatures = collectorSuggester.getUnknownFeatures(); final KnownExtensions extensions = loadExtensions(); - if (extensions != null && unknownFeatures.isEmpty()) return; - final Runnable runnable = () -> { - final Application application = ApplicationManager.getApplication(); - if (application.isUnitTestMode() || application.isHeadlessEnvironment()) return; - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - private final Set myPlugins = new HashSet(); - private List myAllPlugins; + if (extensions != null && unknownFeatures.isEmpty()) { + return; + } - private final Map myDisabledPlugins = new HashMap(); - private List myBundledPlugin; - private final MultiMap myFeatures = new MultiMap(); + final Application application = ApplicationManager.getApplication(); + if (application.isUnitTestMode() || application.isHeadlessEnvironment()) { + return; + } - @Override - public void run() { - try { - myAllPlugins = RepositoryHelper.loadPluginsFromAllRepositories(null); + //noinspection SSBasedInspection + SwingUtilities.invokeLater(() -> application.executeOnPooledThread(new Runnable() { + private final Set myPlugins = new HashSet(); + private List myAllPlugins; + + private final Map myDisabledPlugins = new HashMap(); + private List myBundledPlugin; + private final MultiMap myFeatures = new MultiMap(); + + @Override + public void run() { + if (project.isDisposed()) { + return; + } + + try { + myAllPlugins = RepositoryHelper.loadPluginsFromAllRepositories(null); + if (project.isDisposed()) { + return; + } + if (extensions == null) { + loadSupportedExtensions(myAllPlugins); if (project.isDisposed()) return; - if (extensions == null) { - loadSupportedExtensions(myAllPlugins); - if (project.isDisposed()) return; - EditorNotifications.getInstance(project).updateAllNotifications(); - } - final Map ids = new HashMap(); - for (UnknownFeature feature : unknownFeatures) { - ProgressManager.checkCanceled(); - final List pluginId = retrieve(feature); - if (pluginId != null) { - for (Plugin plugin : pluginId) { - ids.put(plugin.myPluginId, plugin); - myFeatures.putValue(plugin.myPluginId, feature); - } - } - } - - final List disabledPlugins = PluginManagerCore.getDisabledPlugins(); - //include disabled plugins - for (String id : ids.keySet()) { - Plugin plugin = ids.get(id); - if (disabledPlugins.contains(id)) { - final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(PluginId.getId(id)); - if (pluginDescriptor != null) { - myDisabledPlugins.put(plugin, pluginDescriptor); - } - } - } - - myBundledPlugin = hasBundledPluginToInstall(ids.values()); - - for (IdeaPluginDescriptor loadedPlugin : myAllPlugins) { - final PluginId pluginId = loadedPlugin.getPluginId(); - if (ids.containsKey(pluginId.getIdString()) && - !disabledPlugins.contains(pluginId.getIdString()) && - !PluginManagerCore.isBrokenPlugin(loadedPlugin)) { - myPlugins.add(PluginDownloader.createDownloader(loadedPlugin)); - } - } - - ApplicationManager.getApplication().invokeLater(() -> onSuccess(), ModalityState.NON_MODAL); - + EditorNotifications.getInstance(project).updateAllNotifications(); } - catch (Exception e) { - LOG.info(e); + final Map ids = new HashMap(); + for (UnknownFeature feature : unknownFeatures) { + ProgressManager.checkCanceled(); + final List pluginId = retrieve(feature); + if (pluginId != null) { + for (Plugin plugin : pluginId) { + ids.put(plugin.myPluginId, plugin); + myFeatures.putValue(plugin.myPluginId, feature); + } + } } + + final List disabledPlugins = PluginManagerCore.getDisabledPlugins(); + //include disabled plugins + for (String id : ids.keySet()) { + Plugin plugin = ids.get(id); + if (disabledPlugins.contains(id)) { + final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(PluginId.getId(id)); + if (pluginDescriptor != null) { + myDisabledPlugins.put(plugin, pluginDescriptor); + } + } + } + + myBundledPlugin = hasBundledPluginToInstall(ids.values()); + + for (IdeaPluginDescriptor loadedPlugin : myAllPlugins) { + final PluginId pluginId = loadedPlugin.getPluginId(); + if (ids.containsKey(pluginId.getIdString()) && + !disabledPlugins.contains(pluginId.getIdString()) && + !PluginManagerCore.isBrokenPlugin(loadedPlugin)) { + myPlugins.add(PluginDownloader.createDownloader(loadedPlugin)); + } + } + + ApplicationManager.getApplication().invokeLater(this::onSuccess, ModalityState.NON_MODAL); + } + catch (Exception e) { + LOG.info(e); + } + } + + private void onSuccess() { + String message = null; + if (!myPlugins.isEmpty() || !myDisabledPlugins.isEmpty()) { + message = getAddressedMessagePresentation(); + if (!myDisabledPlugins.isEmpty()) { + message += "Enable plugins...
"; + } + else { + message += "Configure plugins...
"; + } + + message += "Ignore Unknown Features"; + } + else if (myBundledPlugin != null && !PropertiesComponent.getInstance().isTrueValue(IGNORE_ULTIMATE_EDITION)) { + message = "Features covered by " + IDEA_ULTIMATE_EDITION + + " (" + StringUtil.join(myBundledPlugin, ", ") + ") are detected.
" + + "" + CHECK_ULTIMATE_EDITION_TITLE + "
" + + "" + ULTIMATE_EDITION_SUGGESTION + ""; } - private void onSuccess() { - String message = null; - if (!myPlugins.isEmpty() || !myDisabledPlugins.isEmpty()) { - message = getAddressedMessagePresentation(); - if (!myDisabledPlugins.isEmpty()) { - message += "Enable plugins...
"; - } - else { - message += "Configure plugins...
"; - } - - message += "Ignore Unknown Features"; - } - else if (myBundledPlugin != null && !PropertiesComponent.getInstance().isTrueValue(IGNORE_ULTIMATE_EDITION)) { - message = "Features covered by " + IDEA_ULTIMATE_EDITION + - " (" + StringUtil.join(myBundledPlugin, ", ") + ") are detected.
" + - "" + CHECK_ULTIMATE_EDITION_TITLE + "
" + - "" + ULTIMATE_EDITION_SUGGESTION + ""; - } - - if (message != null) { + if (message != null) { final ConfigurePluginsListener notificationListener = new ConfigurePluginsListener(unknownFeatures, project, PluginManagerMain.mapToPluginIds(myAllPlugins), myPlugins, myDisabledPlugins); - NOTIFICATION_GROUP.createNotification(DISPLAY_ID, message, NotificationType.INFORMATION, notificationListener).notify(project); + NOTIFICATION_GROUP.createNotification(DISPLAY_ID, message, NotificationType.INFORMATION, notificationListener).notify(project); + } + } + + @NotNull + private String getAddressedMessagePresentation() { + final MultiMap addressedFeatures = MultiMap.createSet(); + final Set ids = new LinkedHashSet(); + for (PluginDownloader plugin : myPlugins) { + ids.add(plugin.getPluginId()); + } + for (Plugin plugin : myDisabledPlugins.keySet()) { + ids.add(plugin.myPluginId); + } + for (String id : ids) { + for (UnknownFeature feature : myFeatures.get(id)) { + addressedFeatures.putValue(feature.getFeatureDisplayName(), feature.getImplementationName()); } } - - @NotNull - private String getAddressedMessagePresentation() { - final MultiMap addressedFeatures = MultiMap.createSet(); - final Set ids = new LinkedHashSet(); - for (PluginDownloader plugin : myPlugins) { - ids.add(plugin.getPluginId()); - } - for (Plugin plugin : myDisabledPlugins.keySet()) { - ids.add(plugin.myPluginId); - } - for (String id : ids) { - for (UnknownFeature feature : myFeatures.get(id)) { - addressedFeatures.putValue(feature.getFeatureDisplayName(), feature.getImplementationName()); - } - } - final String addressedFeaturesPresentation = StringUtil.join(addressedFeatures.entrySet(), - entry -> entry.getKey() + "[" + StringUtil.join(entry.getValue(), ", ") + "]", ", "); - final int addressedFeaturesNumber = addressedFeatures.keySet().size(); - final int pluginsNumber = ids.size(); - return "Unknown feature" + (addressedFeaturesNumber == 1 ? "" : "s") + - " (" + addressedFeaturesPresentation + ") covered by " + (myPlugins.isEmpty() ? "disabled" : "non-bundled") + " plugin" + (pluginsNumber == 1 ? "" : "s") + - " detected.
"; - } - }); - }; - - SwingUtilities.invokeLater(runnable); + final String addressedFeaturesPresentation = StringUtil.join(addressedFeatures.entrySet(), + entry -> entry.getKey() + "[" + StringUtil.join(entry.getValue(), ", ") + "]", ", "); + final int addressedFeaturesNumber = addressedFeatures.keySet().size(); + final int pluginsNumber = ids.size(); + return "Unknown feature" + (addressedFeaturesNumber == 1 ? "" : "s") + + " (" + addressedFeaturesPresentation + ") covered by " + (myPlugins.isEmpty() ? "disabled" : "non-bundled") + " plugin" + (pluginsNumber == 1 ? "" : "s") + + " detected.
"; + } + })); } @Tag("exts") diff --git a/platform/platform-tests/testSrc/com/intellij/psi/tree/IElementTypeTest.java b/platform/platform-tests/testSrc/com/intellij/psi/tree/IElementTypeTest.java index 333df7656066..79e3a5bf9661 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/tree/IElementTypeTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/tree/IElementTypeTest.java @@ -26,12 +26,14 @@ import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.impl.source.tree.CompositeElement; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; -import com.intellij.util.ThrowableRunnable; import com.intellij.util.containers.HashSet; import gnu.trove.THashMap; import gnu.trove.TObjectIntHashMap; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; /** * @author gregsh @@ -149,7 +151,7 @@ public class IElementTypeTest extends LightPlatformCodeInsightFixtureTestCase { public void testInitialRegisterPerformance() { PlatformTestUtil.startPerformanceTest("IElementType add", 100, () -> { Language language = Language.ANY; - IElementType[] old = IElementType.push(new IElementType[0]); + IElementType[] old = IElementType.push(IElementType.EMPTY_ARRAY); try { for (short i = 0; i < 15000; i++) { IElementType type = new IElementType("i " + i, language); diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageNodeTreeBuilderTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageNodeTreeBuilderTest.java index 11ec56ee91e2..97f24e7dd8c8 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageNodeTreeBuilderTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageNodeTreeBuilderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -22,7 +22,6 @@ import com.intellij.testFramework.LightPlatformTestCase; import com.intellij.usages.*; import com.intellij.usages.rules.UsageFilteringRule; import com.intellij.usages.rules.UsageGroupingRule; -import com.intellij.util.Consumer; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -261,7 +260,7 @@ public class UsageNodeTreeBuilderTest extends LightPlatformTestCase { @Override @NotNull public TextChunk[] getText() { - return new TextChunk[0]; + return TextChunk.EMPTY_ARRAY; } @Override diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexImpl.java index 02f43bc8ba3b..d669a2b870f9 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexImpl.java @@ -163,7 +163,7 @@ public class ProjectFileIndexImpl extends FileIndexBase implements ProjectFileIn @Override public String getPackageNameByDirectory(@NotNull VirtualFile dir) { - LOG.assertTrue(dir.isDirectory(), dir.getPresentableUrl()); + if (!dir.isDirectory()) LOG.error(dir.getPresentableUrl()); return myDirectoryIndex.getPackageName(dir); } diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/ServerType.java b/platform/remote-servers/api/src/com/intellij/remoteServer/ServerType.java index 3402920719ea..ea09f7f8bc66 100644 --- a/platform/remote-servers/api/src/com/intellij/remoteServer/ServerType.java +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/ServerType.java @@ -34,6 +34,11 @@ public abstract class ServerType { @NotNull public abstract String getPresentableName(); + @NotNull + public String getHelpTopic() { + return "reference.settings.clouds"; + } + @NotNull public abstract Icon getIcon(); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/SingleRemoteServerConfigurable.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/SingleRemoteServerConfigurable.java index 6031309cafd9..120db55c7726 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/SingleRemoteServerConfigurable.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/SingleRemoteServerConfigurable.java @@ -166,7 +166,7 @@ public class SingleRemoteServerConfigurable extends NamedConfigurable commands) { Collections.addAll(commands, String.valueOf(pid), String.valueOf(beforeRestart.length)); Collections.addAll(commands, beforeRestart); - Collections.addAll(commands, String.valueOf(argc.getValue())); + Collections.addAll(commands, String.valueOf(argv.length)); Collections.addAll(commands, argv); } }); @@ -147,11 +147,34 @@ public class Restarter { }); } + private static String[] getRestartArgv(String[] argv) { + int countArgs = argv.length; + for (int i = argv.length-1; i >=0; i--) { + if (argv[i].endsWith("com.intellij.idea.Main") || + argv[i].endsWith(".exe")) { + countArgs = i + 1; + if ("0".equals(argv[2])) { + // update number of args in according with removed cmd line args + argv[3] = String.valueOf(Integer.valueOf(argv[3]) - (argv.length - (i+1))); + } + if (argv[i].endsWith(".exe") && argv[i].indexOf(File.separator) < 0) { + //absolute path + argv[i] = new File(PathManager.getBinPath(), argv[i]).getPath(); + } + break; + } + } + String[] restartArg = new String[countArgs]; + System.arraycopy(argv, 0, restartArg, 0, countArgs); + return restartArg; + } + private static void doScheduleRestart(File restarterFile, Consumer> argumentsBuilder) throws IOException { List commands = new ArrayList(); commands.add(createTempExecutable(restarterFile).getPath()); argumentsBuilder.consume(commands); - Runtime.getRuntime().exec(ArrayUtil.toStringArray(commands)); + String[] argv = getRestartArgv(ArrayUtil.toStringArray(commands)); + Runtime.getRuntime().exec(argv); } public static String getRestarterDir() { diff --git a/platform/util/src/com/intellij/util/containers/JBIterable.java b/platform/util/src/com/intellij/util/containers/JBIterable.java index e7df7259c74e..92eb82980572 100644 --- a/platform/util/src/com/intellij/util/containers/JBIterable.java +++ b/platform/util/src/com/intellij/util/containers/JBIterable.java @@ -148,6 +148,14 @@ public abstract class JBIterable implements Iterable { }; } + /** + * Returns a {@code JBIterable} containing the one {@code element}. + */ + @NotNull + public static JBIterable of(@Nullable E element) { + return element == null ? JBIterable.empty() : from(Collections.singletonList(element)); + } + /** * Returns a {@code JBIterable} containing {@code elements} in the specified order. */ diff --git a/plugins/ByteCodeViewer/ByteCodeViewer.iml b/plugins/ByteCodeViewer/ByteCodeViewer.iml index 022e24d30dc9..ecf022c8422d 100644 --- a/plugins/ByteCodeViewer/ByteCodeViewer.iml +++ b/plugins/ByteCodeViewer/ByteCodeViewer.iml @@ -7,7 +7,7 @@ - + @@ -19,5 +19,4 @@ - - + \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml index a9f8456a52c1..4e3f8c6d86ee 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml @@ -1624,6 +1624,10 @@ bundle="com.siyeh.InspectionGadgetsBundle" key="array.allocation.zero.length.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.memory.issues" enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.memory.ZeroLengthArrayInitializationInspection"/> + #ref should not be called in production code #loc array.allocation.zero.length.display.name=Zero-length array allocation array.allocation.zero.length.problem.descriptor=Allocation of zero length array #loc +constant.for.zero.length.array.display.name=Unnecessary zero length array usage +constant.for.zero.length.array.problem.descriptor=Zero length array can be changed to constant #loc +constant.for.zero.length.array.quickfix.family=Replace with constant +replace.with=Replace with ''{0}'' multiple.loggers.display.name=Class with multiple loggers logger.name.option=Logger &class name: multiple.loggers.problem.descriptor=Class #ref declares multiple loggers #loc @@ -2051,6 +2055,7 @@ only.report.public.methods.option=Only report 'public' methods lambda.parameter.hides.member.variable.display.name=Lambda parameter hides field static.initializer.references.subclass.display.name=Static initializer references subclass lambda.parameter.hides.member.variable.problem.descriptor=Lambda parameter #ref hides field in class ''{0}'' #loc +lambda.parameter.hides.member.variable.ignore.invisible.option=Ignore fields not actually visible from the lambda shared.thread.local.random.display.name='ThreadLocalRandom' instance might be shared shared.thread.local.random.problem.descriptor='ThreadLocalRandom' instance might be shared between threads native.method.naming.convention.display.name='native' method naming convention diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CovariantEqualsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CovariantEqualsInspection.java index 5e89b0b9c519..9c4217f3c5bb 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CovariantEqualsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CovariantEqualsInspection.java @@ -55,9 +55,6 @@ public class CovariantEqualsInspection extends BaseInspection { if (!HardcodedMethodConstants.EQUALS.equals(name)) { return; } - if (!method.hasModifierProperty(PsiModifier.PUBLIC)) { - return; - } final PsiParameterList parameterList = method.getParameterList(); if (parameterList.getParametersCount() != 1) { return; @@ -71,7 +68,7 @@ public class CovariantEqualsInspection extends BaseInspection { if (aClass == null) { return; } - final PsiMethod[] methods = aClass.getMethods(); + final PsiMethod[] methods = aClass.findMethodsByName("equals", false); for (PsiMethod method1 : methods) { if (MethodUtils.isEquals(method1)) { return; diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/UnnecessaryReturnInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/UnnecessaryReturnInspection.java index 5a91e861441a..193be4ee448f 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/UnnecessaryReturnInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/UnnecessaryReturnInspection.java @@ -16,6 +16,7 @@ package com.siyeh.ig.controlflow; import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; +import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.util.FileTypeUtils; import com.intellij.psi.util.PsiTreeUtil; @@ -26,6 +27,7 @@ import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.fixes.DeleteUnnecessaryStatementFix; import com.siyeh.ig.psiutils.ControlFlowUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -85,48 +87,59 @@ public class UnnecessaryReturnInspection extends BaseInspection { @Override public void visitReturnStatement(@NotNull PsiReturnStatement statement) { super.visitReturnStatement(statement); - if (statement.getReturnValue() != null) { - return; + final Ref constructorRef = Ref.create(); + if (isReturnRedundant(statement, ignoreInThenBranch, constructorRef)) { + registerStatementError(statement, constructorRef.get()); } - final PsiElement methodParent = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, PsiLambdaExpression.class); - PsiCodeBlock codeBlock = null; - final boolean constructor; - if (methodParent instanceof PsiMethod) { - final PsiMethod method = (PsiMethod)methodParent; - codeBlock = method.getBody(); - constructor = method.isConstructor(); - } - else if (methodParent instanceof PsiLambdaExpression) { - constructor = false; - final PsiLambdaExpression lambdaExpression = (PsiLambdaExpression)methodParent; - final PsiElement lambdaBody = lambdaExpression.getBody(); - if (lambdaBody instanceof PsiCodeBlock) { - codeBlock = (PsiCodeBlock)lambdaBody; - } - } - else { - return; - } - if (codeBlock == null) { - return; - } - if (!ControlFlowUtils.blockCompletesWithStatement(codeBlock, statement)) { - return; - } - if (ignoreInThenBranch && isInThenBranch(statement)) { - return; - } - registerStatementError(statement, Boolean.valueOf(constructor)); } - private boolean isInThenBranch(PsiStatement statement) { - final PsiIfStatement ifStatement = - PsiTreeUtil.getParentOfType(statement, PsiIfStatement.class, true, PsiMethod.class, PsiLambdaExpression.class); - if (ifStatement == null) { - return false; - } - final PsiStatement elseBranch = ifStatement.getElseBranch(); - return elseBranch != null && !PsiTreeUtil.isAncestor(elseBranch, statement, true); + } + + public static boolean isReturnRedundant(@NotNull PsiReturnStatement statement, + boolean ignoreInThenBranch, + @Nullable Ref isInConstructorRef) { + if (statement.getReturnValue() != null) { + return false; } + final PsiElement methodParent = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, PsiLambdaExpression.class); + PsiCodeBlock codeBlock = null; + if (methodParent instanceof PsiMethod) { + final PsiMethod method = (PsiMethod)methodParent; + codeBlock = method.getBody(); + if (isInConstructorRef != null) { + isInConstructorRef.set(method.isConstructor()); + } + } + else if (methodParent instanceof PsiLambdaExpression) { + isInConstructorRef.set(false); + final PsiLambdaExpression lambdaExpression = (PsiLambdaExpression)methodParent; + final PsiElement lambdaBody = lambdaExpression.getBody(); + if (lambdaBody instanceof PsiCodeBlock) { + codeBlock = (PsiCodeBlock)lambdaBody; + } + } + else { + return false; + } + if (codeBlock == null) { + return false; + } + if (!ControlFlowUtils.blockCompletesWithStatement(codeBlock, statement)) { + return false; + } + if (ignoreInThenBranch && isInThenBranch(statement)) { + return false; + } + return true; + } + + private static boolean isInThenBranch(PsiStatement statement) { + final PsiIfStatement ifStatement = + PsiTreeUtil.getParentOfType(statement, PsiIfStatement.class, true, PsiMethod.class, PsiLambdaExpression.class); + if (ifStatement == null) { + return false; + } + final PsiStatement elseBranch = ifStatement.getElseBranch(); + return elseBranch != null && !PsiTreeUtil.isAncestor(elseBranch, statement, true); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dataflow/TooBroadScopeInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dataflow/TooBroadScopeInspectionBase.java index 960460d28c93..abaa5582e5ed 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dataflow/TooBroadScopeInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dataflow/TooBroadScopeInspectionBase.java @@ -20,6 +20,8 @@ import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; import com.intellij.psi.*; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.FileTypeUtils; +import com.intellij.psi.util.InheritanceUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.Query; @@ -27,7 +29,6 @@ import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.psiutils.*; -import com.intellij.psi.util.FileTypeUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -81,6 +82,15 @@ public class TooBroadScopeInspectionBase extends BaseInspection { if (PsiUtil.isConstantExpression(expression) || ExpressionUtils.isNullLiteral(expression)) { return true; } + if (expression instanceof PsiArrayInitializerExpression) { + final PsiArrayInitializerExpression arrayInitializerExpression = (PsiArrayInitializerExpression)expression; + for (PsiExpression initializer : arrayInitializerExpression.getInitializers()) { + if (!isMoveable(initializer)) { + return false; + } + } + return true; + } if (expression instanceof PsiNewExpression) { final PsiNewExpression newExpression = (PsiNewExpression)expression; final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions(); @@ -93,32 +103,35 @@ public class TooBroadScopeInspectionBase extends BaseInspection { return true; } final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer(); - boolean result = true; if (arrayInitializer != null) { final PsiExpression[] initializers = arrayInitializer.getInitializers(); for (final PsiExpression initializerExpression : initializers) { - result &= isMoveable(initializerExpression); + if (!isMoveable(initializerExpression)) { + return false; + } } + return true; } final PsiType type = newExpression.getType(); if (type == null) { return false; } else if (!m_allowConstructorAsInitializer) { - // constructors located in library packages probably have no non-local side effects - if (!ClassUtils.isImmutable(type) && !LibraryUtil.isTypeInLibrary(type)) { + if (!isAllowedType(type)) { return false; } } final PsiExpressionList argumentList = newExpression.getArgumentList(); if (argumentList == null) { - return result; + return false; } final PsiExpression[] expressions = argumentList.getExpressions(); for (final PsiExpression argumentExpression : expressions) { - result &= isMoveable(argumentExpression); + if (!isMoveable(argumentExpression)) { + return false; + } } - return result; + return true; } if (expression instanceof PsiReferenceExpression) { final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression; @@ -147,10 +160,12 @@ public class TooBroadScopeInspectionBase extends BaseInspection { return true; } if (expression instanceof PsiMethodCallExpression) { - // methods located in library packages probably have no non-local side effects + if (!isAllowedType(expression.getType())) { + return false; + } final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression; final PsiMethod method = methodCallExpression.resolveMethod(); - if (!(method instanceof PsiCompiledElement)) { + if (!isAllowedMethod(method)) { return false; } final PsiExpressionList argumentList = methodCallExpression.getArgumentList(); @@ -164,6 +179,43 @@ public class TooBroadScopeInspectionBase extends BaseInspection { return false; } + private static boolean isAllowedMethod(PsiMethod method) { + if (method == null) { + return false; + } + final PsiClass aClass = method.getContainingClass(); + if (aClass == null) { + return false; + } + final String qualifiedName = aClass.getQualifiedName(); + if (qualifiedName == null || !qualifiedName.startsWith("java.")) { + return false; + } + final String methodName = method.getName(); + return !"now".equals(methodName) && !"currentTimeMillis".equals(methodName) && !"nanoTime".equals(methodName); + } + + private static boolean isAllowedType(PsiType type) { + if (ClassUtils.isImmutable(type)) { + return true; + } + if (!(type instanceof PsiClassType)) { + return false; + } + final PsiClassType classType = (PsiClassType)type; + final PsiClass aClass = classType.resolve(); + return isAllowedClass(aClass); + } + + private static boolean isAllowedClass(@Nullable PsiClass aClass) { + // allow some "safe" jdk types + if (InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_UTIL_COLLECTION) || + InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_UTIL_MAP)) { + return true; + } + return aClass != null && aClass.isEnum(); + } + @Override public BaseInspectionVisitor buildVisitor() { return new TooBroadScopeVisitor(); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/memory/ReplaceEmptyArrayToConstantFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/memory/ReplaceEmptyArrayToConstantFix.java new file mode 100644 index 000000000000..a280e2e5bcb2 --- /dev/null +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/memory/ReplaceEmptyArrayToConstantFix.java @@ -0,0 +1,59 @@ +/* + * 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. + */ +package com.siyeh.ig.memory; + +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.*; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.InspectionGadgetsFix; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; + +/** + * @author Konstantin Bulenkov + */ +public class ReplaceEmptyArrayToConstantFix extends InspectionGadgetsFix { + private final String myText; + private final String myName; + + public ReplaceEmptyArrayToConstantFix(PsiClass aClass, PsiField field) { + myText = aClass.getQualifiedName() + "." + field.getName(); + myName = InspectionGadgetsBundle.message("replace.with", aClass.getName() + "." + field.getName()); + } + + @Nls + @NotNull + @Override + public String getName() { + return myName; + } + + @Nls + @NotNull + @Override + public String getFamilyName() { + return InspectionGadgetsBundle.message("constant.for.zero.length.array.quickfix.family"); + } + + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) { + PsiExpression newExp = JavaPsiFacade.getInstance(project).getElementFactory().createExpressionFromText(myText, descriptor.getPsiElement()); + PsiElement element = descriptor.getPsiElement().replace(newExp); + JavaCodeStyleManager.getInstance(project).shortenClassReferences(element); + } +} diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/memory/UnnecessaryEmptyArrayUsageInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/memory/UnnecessaryEmptyArrayUsageInspection.java new file mode 100644 index 000000000000..5505aa678b0c --- /dev/null +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/memory/UnnecessaryEmptyArrayUsageInspection.java @@ -0,0 +1,82 @@ +/* + * 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. + */ +package com.siyeh.ig.memory; + +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiTypesUtil; +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.BaseInspection; +import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.psiutils.ExpressionUtils; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Konstantin Bulenkov + */ +public class UnnecessaryEmptyArrayUsageInspection extends BaseInspection { + @Nls + @NotNull + @Override + public String getDisplayName() { + return InspectionGadgetsBundle.message("constant.for.zero.length.array.display.name"); + } + + @NotNull + @Override + protected String buildErrorString(Object... infos) { + return InspectionGadgetsBundle.message("constant.for.zero.length.array.problem.descriptor"); + } + + @Nullable + @Override + protected InspectionGadgetsFix buildFix(Object... infos) { + return new ReplaceEmptyArrayToConstantFix((PsiClass)infos[0], (PsiField)infos[1]); + } + + @Override + public BaseInspectionVisitor buildVisitor() { + return new BaseInspectionVisitor() { + @Override + public void visitNewExpression(PsiNewExpression expression) { + if (ExpressionUtils.isZeroLengthArrayConstruction(expression)) { + PsiType type = expression.getType(); + if (type instanceof PsiArrayType) { + PsiType arrayType = ((PsiArrayType)type).getComponentType(); + PsiClass typeClass = PsiTypesUtil.getPsiClass(arrayType); + if (typeClass != null) { + for (PsiField field : typeClass.getFields()) { + PsiModifierList modifiers = field.getModifierList(); + if (modifiers != null + && !typeClass.isEquivalentTo(PsiTreeUtil.findFirstParent(expression, (e) -> e instanceof PsiClass)) + && modifiers.hasModifierProperty(PsiModifier.FINAL) + && modifiers.hasModifierProperty(PsiModifier.PUBLIC) + && ExpressionUtils.isZeroLengthArrayConstruction(field.getInitializer())) { + registerError(expression, typeClass, field); + return; + } + } + } + } + } + super.visitNewExpression(expression); + } + }; + } +} diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ClassUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ClassUtils.java index 0ded3aae25b1..a361fd33eb93 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ClassUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ClassUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2016 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.siyeh.ig.psiutils; +import com.intellij.codeInspection.concurrencyAnnotations.JCiPUtil; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.TypeConversionUtil; @@ -68,14 +69,22 @@ public class ClassUtils { immutableTypes.add(CommonClassNames.JAVA_LANG_BYTE); immutableTypes.add(CommonClassNames.JAVA_LANG_STRING); immutableTypes.add("java.awt.Font"); + immutableTypes.add("java.awt.BasicStroke"); immutableTypes.add("java.awt.Color"); + immutableTypes.add("java.awt.Cursor"); immutableTypes.add("java.math.BigDecimal"); immutableTypes.add("java.math.BigInteger"); immutableTypes.add("java.math.MathContext"); immutableTypes.add("java.nio.channels.FileLock"); immutableTypes.add("java.nio.charset.Charset"); immutableTypes.add("java.io.File"); + immutableTypes.add("java.net.Inet4Address"); + immutableTypes.add("java.net.Inet6Address"); + immutableTypes.add("java.net.InetSocketAddress"); immutableTypes.add("java.net.URI"); + immutableTypes.add("java.net.URL"); + immutableTypes.add("java.util.Locale"); + immutableTypes.add("java.util.UUID"); immutableTypes.add("java.util.regex.Pattern"); } @@ -107,8 +116,14 @@ public class ClassUtils { return false; } final PsiClassType classType = (PsiClassType)type; - final String className = classType.getCanonicalText(); - return immutableTypes.contains(className); + final PsiClass aClass = classType.resolve(); + if (aClass == null) { + return false; + } + if (immutableTypes.contains(aClass.getQualifiedName())) { + return true; + } + return JCiPUtil.isImmutable(aClass); } public static boolean inSamePackage(@Nullable PsiElement element1, diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionBase.java index e170a817fb82..c1b94759e129 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2016 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,7 @@ public class LambdaParameterHidingMemberVariableInspectionBase extends BaseInspe @Override public JComponent createOptionsPanel() { final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this); - optionsPanel.addCheckbox(InspectionGadgetsBundle.message("parameter.hides.member.variable.ignore.superclass.option"), + optionsPanel.addCheckbox(InspectionGadgetsBundle.message("lambda.parameter.hides.member.variable.ignore.invisible.option"), "m_ignoreInvisibleFields"); return optionsPanel; } @@ -98,13 +98,13 @@ public class LambdaParameterHidingMemberVariableInspectionBase extends BaseInspe } PsiClass aClass = ClassUtils.getContainingClass(variable); while (aClass != null) { - final PsiField[] fields = aClass.getAllFields(); - for (PsiField field : fields) { - final String fieldName = field.getName(); - if (!variableName.equals(fieldName)) { - continue; + final PsiField field = aClass.findFieldByName(variableName, true); + if (field != null) { + if (!m_ignoreInvisibleFields){ + return aClass; } - if (!m_ignoreInvisibleFields || ClassUtils.isFieldVisible(field, aClass)) { + else if (ClassUtils.isFieldVisible(field, aClass) && + (PsiUtil.getEnclosingStaticElement(variable, aClass) == null) || field.hasModifierProperty(PsiModifier.STATIC)){ return aClass; } } diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/LambdaParameterHidingMemberVariable.html b/plugins/InspectionGadgets/src/inspectionDescriptions/LambdaParameterHidingMemberVariable.html index 3c06751478b0..4e2fdc1a161b 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/LambdaParameterHidingMemberVariable.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/LambdaParameterHidingMemberVariable.html @@ -1,10 +1,10 @@ -Reports lambda parameters named identically to visible fields of the surrounding classes -and their superclasses. +Reports lambda parameters named identically to fields of the surrounding classes or their superclasses.

-Use the checkbox below to ignore fields that are not actually visible from the lambda expression, for example private fields +Use the checkbox below to ignore fields that are not actually visible from the lambda expression. +For example private fields in a super class.

\ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/UnnecessaryEmptyArrayUsage.html b/plugins/InspectionGadgets/src/inspectionDescriptions/UnnecessaryEmptyArrayUsage.html new file mode 100644 index 000000000000..c1745110e071 --- /dev/null +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/UnnecessaryEmptyArrayUsage.html @@ -0,0 +1,8 @@ + + +Reports on allocations of arrays with known lengths of zero when there is a constant for that in the class of array's type. + +

+ + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/CovariantEqualsInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/CovariantEqualsInspection.java deleted file mode 100644 index e0ea3d2009f0..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/CovariantEqualsInspection.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.siyeh.igtest.bugs; - -public class CovariantEqualsInspection -{ - public CovariantEqualsInspection() - { - } - - public boolean equals(CovariantEqualsInspection foo) - { - return true; - } -} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/CovariantEqualsInspection2.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/CovariantEqualsInspection2.java deleted file mode 100644 index 526f7e7887ac..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/CovariantEqualsInspection2.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.siyeh.igtest.bugs; - -public class CovariantEqualsInspection2 -{ - public CovariantEqualsInspection2() - { - } - - public boolean equals(CovariantEqualsInspection2 foo) - { - return true; - } - - public boolean equals(Object foo) - { - return true; - } -} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariant_equals/CovariantEquals.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariant_equals/CovariantEquals.java index e34f07954ea3..8c53ae024b66 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariant_equals/CovariantEquals.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariant_equals/CovariantEquals.java @@ -28,4 +28,9 @@ class D implements I { public boolean equals(I i) { return false; } +} +class E { + boolean equals(E e) { + return false; + } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/scope/TooBroadScope.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/scope/TooBroadScope.java index 44ffdf41a6e5..6b45d6f66368 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/scope/TooBroadScope.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/scope/TooBroadScope.java @@ -150,6 +150,7 @@ public class TooBroadScope } private final String[] EMPTY = {}; + private final String[] ONE = {"one"}; void abc() { String[] strings = EMPTY; System.out.println(); @@ -160,5 +161,41 @@ public class TooBroadScope System.out.println(); System.out.println(); System.out.println(list); + + String[] ss = new String[10]; + System.out.println(); + System.out.println(); + System.out.println(ss); + + String[] ss2 = new String[] {""}; + System.out.println(); + System.out.println(); + System.out.println(ss2); + + String[] ss3 = {}; + System.out.println(); + System.out.println(); + System.out.println(ss3); + + String[] ss3a = {ONE[0]}; + backgroundAction(); + System.out.println(); + System.out.println(ss3a); + + List ss4 = Arrays.asList(ONE); + backgroundAction(); + System.out.println(); + System.out.println(ss4); + } + + void backgroundAction() { + ONE[0] = "two"; + } + + void time() { + long start = System.currentTimeMillis(); + System.out.println(); + long end = System.currentTimeMillis(); + System.out.println("elapsed: " + (end - start)); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionTest.java index e7c3b75f1a6d..1f6a804a3bde 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionTest.java @@ -45,4 +45,24 @@ public class LambdaParameterHidingMemberVariableInspectionTest extends LightInsp " }" + "}"); } + + public void testStatic() { + doTest("import java.util.function.Function;" + + "class X {" + + " private String s;" + + " static Function m() {" + + " return s -> null; " + + " }" + + "}"); + } + + public void testStaticStatic() { + doTest("import java.util.function.Function;" + + "class X {" + + " private static String s;" + + " static Function m() {" + + " return /*Lambda parameter 's' hides field in class 'X'*/s/**/ -> null; " + + " }" + + "}"); + } } diff --git a/plugins/IntelliLang/IntelliLang-java.iml b/plugins/IntelliLang/IntelliLang-java.iml index 585a1f6d5a17..66a00fa603db 100644 --- a/plugins/IntelliLang/IntelliLang-java.iml +++ b/plugins/IntelliLang/IntelliLang-java.iml @@ -11,7 +11,7 @@ - + @@ -22,5 +22,4 @@ - - + \ No newline at end of file diff --git a/plugins/IntelliLang/IntelliLang-xml.iml b/plugins/IntelliLang/IntelliLang-xml.iml index 20db7d65ff08..1659417efc9d 100644 --- a/plugins/IntelliLang/IntelliLang-xml.iml +++ b/plugins/IntelliLang/IntelliLang-xml.iml @@ -10,7 +10,7 @@ - + @@ -22,5 +22,4 @@ - - + \ No newline at end of file diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java index 59b051bf2807..bbb29dc539a3 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java @@ -53,7 +53,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.xml.XmlFile; -import com.intellij.util.ActionRunner; import com.intellij.util.EventDispatcher; import com.intellij.util.StringSetSpinAllocator; import com.intellij.util.concurrency.Semaphore; @@ -89,7 +88,7 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis @Nullable public String get(final AbstractPropertyContainer container) { if (!container.hasProperty(this)) return null; - AntConfiguration antConfiguration = AntConfigurationImpl.INSTANCE.get(container); + AntConfiguration antConfiguration = INSTANCE.get(container); return ProjectRootManager.getInstance(antConfiguration.getProject()).getProjectSdkName(); } @@ -145,7 +144,7 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis daemon.restart(); } else { - SwingUtilities.invokeLater(() -> daemon.restart()); + SwingUtilities.invokeLater(daemon::restart); } } }); @@ -172,19 +171,42 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis public Element getState() { try { - final Element e = new Element("state"); - writeExternal(e); - return e; + final Element state = new Element("state"); + getProperties().writeExternal(state); + ApplicationManager.getApplication().runReadAction(() -> { + for (final AntBuildFileBase buildFile : getBuildFiles()) { + final Element element = new Element(BUILD_FILE); + element.setAttribute(URL, buildFile.getVirtualFile().getUrl()); + buildFile.writeProperties(element); + saveEvents(element, buildFile); + state.addContent(element); + } + + final List files = new ArrayList(myAntFileToContextFileMap.keySet()); + // sort in order to minimize changes + Collections.sort(files, (o1, o2) -> o1.getUrl().compareTo(o2.getUrl())); + for (VirtualFile file : files) { + final Element element = new Element(CONTEXT_MAPPING); + final VirtualFile contextFile = myAntFileToContextFileMap.get(file); + element.setAttribute(URL, file.getUrl()); + element.setAttribute(CONTEXT, contextFile.getUrl()); + state.addContent(element); + } + }); + return state; } - catch (WriteExternalException e1) { - LOG.error(e1); + catch (WriteExternalException e) { + LOG.error(e); return null; } } public void loadState(Element state) { try { - readExternal(state); + myIsInitialized = Boolean.FALSE; + myAntWorkspaceConfiguration.loadFromProjectSettings(state); + getProperties().readExternal(state); + runWhenInitialized(() -> loadBuildFileProjectProperties(state)); } catch (InvalidDataException e) { LOG.error(e); @@ -348,17 +370,6 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis } } - public void handleTargetRename(String oldTargetName, String newTargetName) { - synchronized (myEventToTargetMap) { - for (Map.Entry> entry : myEventToTargetMap.entrySet()) { - final Pair pair = entry.getValue(); - if (pair != null && Comparing.equal(pair.getSecond(), oldTargetName)) { - entry.setValue(Pair.create(pair.getFirst(), newTargetName)); - } - } - } - } - public void updateBuildFile(final AntBuildFile buildFile) { incModificationCount(); myEventDispatcher.getMulticaster().buildFileChanged(buildFile); @@ -387,57 +398,12 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis return getModel(buildFile); } - private void readExternal(final Element parentNode) throws InvalidDataException { - myIsInitialized = Boolean.FALSE; - myAntWorkspaceConfiguration.loadFromProjectSettings(parentNode); - getProperties().readExternal(parentNode); - runWhenInitialized(() -> loadBuildFileProjectProperties(parentNode)); - } - private void runWhenInitialized(final Runnable runnable) { if (getProject().isInitialized()) { - ApplicationManager.getApplication().runReadAction(() -> runnable.run()); + ApplicationManager.getApplication().runReadAction(runnable); } else { - myStartupManager.runWhenProjectIsInitialized(() -> runnable.run()); - } - } - - private void writeExternal(final Element parentNode) throws WriteExternalException { - getProperties().writeExternal(parentNode); - try { - ActionRunner.runInsideReadAction(new ActionRunner.InterruptibleRunnable() { - public void run() throws WriteExternalException { - for (final AntBuildFileBase buildFile : getBuildFiles()) { - final Element element = new Element(BUILD_FILE); - element.setAttribute(URL, buildFile.getVirtualFile().getUrl()); - buildFile.writeProperties(element); - saveEvents(element, buildFile); - parentNode.addContent(element); - } - final List files = new ArrayList(myAntFileToContextFileMap.keySet()); - // sort in order to minimize changes - Collections.sort(files, (o1, o2) -> o1.getUrl().compareTo(o2.getUrl())); - for (VirtualFile file : files) { - final Element element = new Element(CONTEXT_MAPPING); - final VirtualFile contextFile = myAntFileToContextFileMap.get(file); - element.setAttribute(URL, file.getUrl()); - element.setAttribute(CONTEXT, contextFile.getUrl()); - parentNode.addContent(element); - } - } - }); - } - catch (WriteExternalException e) { - LOG.error(e); - throw e; - } - catch (RuntimeException e) { - LOG.error(e); - throw e; - } - catch (Exception e) { - LOG.error(e); + myStartupManager.runWhenProjectIsInitialized(runnable); } } @@ -607,7 +573,7 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis } public static boolean executeTargetSynchronously(final DataContext dataContext, final AntBuildTarget target) { - return executeTargetSynchronously(dataContext, target, Collections.emptyList()); + return executeTargetSynchronously(dataContext, target, Collections.emptyList()); } public static boolean executeTargetSynchronously(final DataContext dataContext, final AntBuildTarget target, final List additionalProperties) { @@ -658,8 +624,7 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis private void loadBuildFileProjectProperties(final Element parentNode) { final List> files = new ArrayList>(); final VirtualFileManager vfManager = VirtualFileManager.getInstance(); - for (final Object o : parentNode.getChildren(BUILD_FILE)) { - final Element element = (Element)o; + for (final Element element : parentNode.getChildren(BUILD_FILE)) { final String url = element.getAttributeValue(URL); if (url != null) { files.add(Pair.create(element, url)); @@ -668,8 +633,7 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis // contexts myAntFileToContextFileMap.clear(); - for (final Object o : parentNode.getChildren(CONTEXT_MAPPING)) { - final Element element = (Element)o; + for (final Element element : parentNode.getChildren(CONTEXT_MAPPING)) { final String url = element.getAttributeValue(URL); final String contextUrl = element.getAttributeValue(CONTEXT); final VirtualFile file = vfManager.findFileByUrl(url); @@ -831,7 +795,7 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis if (!app.isDispatchThread() || task.isHeadless()) { // for headless tasks we need to ensure async execution. // Otherwise calls to AntConfiguration.getInstance() from the task will cause SOE - app.invokeLater(() -> task.queue(), ModalityState.any()); + app.invokeLater(task::queue, ModalityState.any()); } else { task.queue(); diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntWorkspaceConfiguration.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntWorkspaceConfiguration.java index a48956d803e0..af38da22f48b 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntWorkspaceConfiguration.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntWorkspaceConfiguration.java @@ -29,12 +29,12 @@ import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; -import java.util.List; import java.util.concurrent.atomic.AtomicReference; @State(name = "antWorkspaceConfiguration", storages = @Storage(StoragePathMacros.WORKSPACE_FILE)) public class AntWorkspaceConfiguration implements PersistentStateComponent { private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.config.impl.AntWorkspaceConfiguration"); + private final Project myProject; @NonNls private static final String BUILD_FILE = "buildFile"; @NonNls private static final String URL = "url"; @@ -68,9 +68,6 @@ public class AntWorkspaceConfiguration implements PersistentStateComponent - + diff --git a/plugins/editorconfig/src/org/editorconfig/Utils.java b/plugins/editorconfig/src/org/editorconfig/Utils.java index ada5beb69761..ed7886bc9e38 100644 --- a/plugins/editorconfig/src/org/editorconfig/Utils.java +++ b/plugins/editorconfig/src/org/editorconfig/Utils.java @@ -1,13 +1,37 @@ package org.editorconfig; +import com.intellij.codeStyle.CodeStyleFacade; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; +import com.intellij.openapi.fileTypes.FileNameMatcher; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.encoding.EncodingProjectManager; import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import com.intellij.psi.search.FileTypeIndex; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.LineSeparator; +import org.editorconfig.configmanagement.EditorConfigIndentOptionsProvider; +import org.editorconfig.configmanagement.EditorSettingsManager; +import org.editorconfig.configmanagement.EncodingManager; +import org.editorconfig.configmanagement.LineEndingsManager; import org.editorconfig.core.EditorConfig.OutPair; import org.editorconfig.plugincomponents.EditorConfigNotifier; import org.editorconfig.settings.EditorConfigSettings; +import org.jetbrains.annotations.NotNull; +import java.io.IOException; +import java.nio.charset.Charset; import java.util.List; +import java.util.Locale; +import java.util.Map; public class Utils { public static String configValueForKey(List outPairs, String key) { @@ -37,4 +61,108 @@ public class Utils { } return file.getCanonicalPath(); } + + public static void export(Project project) { + final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project); + final CommonCodeStyleSettings.IndentOptions commonIndentOptions = settings.getIndentOptions(); + StringBuilder result = new StringBuilder(); + addIndentOptions(result, "*", commonIndentOptions, getEncoding(project) + + getLineEndings(project) + + getTrailingSpaces() + + getEndOfFile()); + for (FileType fileType : FileTypeManager.getInstance().getRegisteredFileTypes()) { + if (!FileTypeIndex.containsFileOfType(fileType, GlobalSearchScope.allScope(project))) continue; + + final CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptions(fileType); + if (!equalIndents(commonIndentOptions, options)) { + addIndentOptions(result, buildPattern(fileType), options, ""); + } + } + final VirtualFile baseDir = project.getBaseDir(); + final VirtualFile child = baseDir.findChild(".editorconfig"); + if (child != null) { + final String message = ".editorconfig already present in " + baseDir.getPath() + "\nOverwrite?"; + if (Messages.showYesNoDialog(project, message, ".editorconfig exists", null) == Messages.NO) return; + } + ApplicationManager.getApplication().runWriteAction(() -> { + try { + final VirtualFile editorConfig = baseDir.findOrCreateChildData(Utils.class, ".editorconfig"); + VfsUtil.saveText(editorConfig, result.toString()); + } catch (IOException e) { + Logger.getInstance(Utils.class).error(e); + } + }); + } + + private static String getEndOfFile() { + return EditorSettingsManager.insertFinalNewlineKey + "=" + EditorSettingsExternalizable.getInstance().isEnsureNewLineAtEOF() + "\n"; + } + + private static String getTrailingSpaces() { + final String spaces = EditorSettingsExternalizable.getInstance().getStripTrailingSpaces(); + if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE.equals(spaces)) return EditorSettingsManager.trimTrailingWhitespaceKey + "=false\n"; + if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE.equals(spaces)) return EditorSettingsManager.trimTrailingWhitespaceKey + "=true\n"; + return ""; + } + + private static String getLineEndings(Project project) { + final String separator = CodeStyleFacade.getInstance(project).getLineSeparator(); + for (LineSeparator s : LineSeparator.values()) { + if (separator.equals(s.getSeparatorString())) { + return LineEndingsManager.lineEndingsKey + "=" + s.name().toLowerCase(Locale.US) + "\n"; + } + } + return ""; + } + + @NotNull + private static String getEncoding(Project project) { + final Charset charset = EncodingProjectManager.getInstance(project).getDefaultCharset(); + for (Map.Entry entry : EncodingManager.encodingMap.entrySet()) { + if (entry.getValue() == charset) { + return EncodingManager.charsetKey + "=" + entry.getKey() + "\n"; + } + } + return ""; + } + + @NotNull + private static String buildPattern(FileType fileType) { + final StringBuilder result = new StringBuilder(); + final List associations = FileTypeManager.getInstance().getAssociations(fileType); + for (FileNameMatcher matcher : associations) { + if (result.length() != 0) result.append(","); + result.append(matcher.getPresentableString()); + } + if (associations.size() > 1) { + result.insert(0, "{").append("}"); + } + return result.toString(); + } + + private static boolean equalIndents(CommonCodeStyleSettings.IndentOptions commonIndentOptions, + CommonCodeStyleSettings.IndentOptions options) { + return options.USE_TAB_CHARACTER == commonIndentOptions.USE_TAB_CHARACTER && + options.TAB_SIZE == commonIndentOptions.TAB_SIZE && + options.INDENT_SIZE == commonIndentOptions.INDENT_SIZE; + } + + private static void addIndentOptions(StringBuilder result, + String pattern, + CommonCodeStyleSettings.IndentOptions options, + String additionalText) { + if (pattern.isEmpty()) return; + + result.append("[").append(pattern).append("]").append("\n"); + result.append(additionalText); + result.append(EditorConfigIndentOptionsProvider.indentStyleKey).append("="); + if (options.USE_TAB_CHARACTER) { + result.append("tab\n"); + result.append(EditorConfigIndentOptionsProvider.tabWidthKey).append("=").append(options.TAB_SIZE).append("\n"); + } else { + result.append("space\n"); + result.append(EditorConfigIndentOptionsProvider.indentSizeKey).append("=").append(options.INDENT_SIZE).append("\n"); + } + result.append("\n"); + } } diff --git a/plugins/editorconfig/src/org/editorconfig/configmanagement/EditorConfigIndentOptionsProvider.java b/plugins/editorconfig/src/org/editorconfig/configmanagement/EditorConfigIndentOptionsProvider.java index a94063aca717..5bcfa4f7fbab 100644 --- a/plugins/editorconfig/src/org/editorconfig/configmanagement/EditorConfigIndentOptionsProvider.java +++ b/plugins/editorconfig/src/org/editorconfig/configmanagement/EditorConfigIndentOptionsProvider.java @@ -19,10 +19,10 @@ import java.util.List; */ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider { // Handles the following EditorConfig settings: - private static final String indentSizeKey = "indent_size"; - private static final String continuationSizeKey = "continuation_indent_size"; - private static final String tabWidthKey = "tab_width"; - private static final String indentStyleKey = "indent_style"; + public static final String indentSizeKey = "indent_size"; + public static final String continuationSizeKey = "continuation_indent_size"; + public static final String tabWidthKey = "tab_width"; + public static final String indentStyleKey = "indent_style"; @Nullable @Override diff --git a/plugins/editorconfig/src/org/editorconfig/configmanagement/EditorSettingsManager.java b/plugins/editorconfig/src/org/editorconfig/configmanagement/EditorSettingsManager.java index 8e3f7db77a60..4bcfb24123d0 100644 --- a/plugins/editorconfig/src/org/editorconfig/configmanagement/EditorSettingsManager.java +++ b/plugins/editorconfig/src/org/editorconfig/configmanagement/EditorSettingsManager.java @@ -21,8 +21,8 @@ import java.util.Map; public class EditorSettingsManager extends FileDocumentManagerAdapter { // Handles the following EditorConfig settings: - private static final String trimTrailingWhitespaceKey = "trim_trailing_whitespace"; - private static final String insertFinalNewlineKey = "insert_final_newline"; + public static final String trimTrailingWhitespaceKey = "trim_trailing_whitespace"; + public static final String insertFinalNewlineKey = "insert_final_newline"; private static final Map trimMap; static { diff --git a/plugins/editorconfig/src/org/editorconfig/configmanagement/EncodingManager.java b/plugins/editorconfig/src/org/editorconfig/configmanagement/EncodingManager.java index 3aec6497f144..abcaf7510cab 100644 --- a/plugins/editorconfig/src/org/editorconfig/configmanagement/EncodingManager.java +++ b/plugins/editorconfig/src/org/editorconfig/configmanagement/EncodingManager.java @@ -22,11 +22,11 @@ import java.util.Map; public class EncodingManager extends FileDocumentManagerAdapter { // Handles the following EditorConfig settings: - private static final String charsetKey = "charset"; + public static final String charsetKey = "charset"; private final Project myProject; - private static final Map encodingMap; + public static final Map encodingMap; static { Map map = new HashMap(); diff --git a/plugins/editorconfig/src/org/editorconfig/configmanagement/LineEndingsManager.java b/plugins/editorconfig/src/org/editorconfig/configmanagement/LineEndingsManager.java index eb2cfea56b6a..f860bd841f75 100644 --- a/plugins/editorconfig/src/org/editorconfig/configmanagement/LineEndingsManager.java +++ b/plugins/editorconfig/src/org/editorconfig/configmanagement/LineEndingsManager.java @@ -29,7 +29,7 @@ import java.util.Locale; */ public class LineEndingsManager extends FileDocumentManagerAdapter { // Handles the following EditorConfig settings: - private static final String lineEndingsKey = "end_of_line"; + public static final String lineEndingsKey = "end_of_line"; private final Project myProject; private boolean statusBarUpdated = false; diff --git a/plugins/editorconfig/src/org/editorconfig/settings/EditorConfigConfigurable.java b/plugins/editorconfig/src/org/editorconfig/settings/EditorConfigConfigurable.java index 15678c6d322f..64b03df40714 100644 --- a/plugins/editorconfig/src/org/editorconfig/settings/EditorConfigConfigurable.java +++ b/plugins/editorconfig/src/org/editorconfig/settings/EditorConfigConfigurable.java @@ -4,16 +4,19 @@ import com.intellij.application.options.GeneralCodeStyleOptionsProvider; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.ui.VerticalFlowLayout; +import com.intellij.openapi.wm.IdeFrame; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsProvider; import com.intellij.psi.codeStyle.CustomCodeStyleSettings; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.components.JBCheckBox; import com.intellij.util.ui.UIUtil; +import org.editorconfig.Utils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.awt.*; /** * @author Dennis.Ushakov @@ -25,14 +28,27 @@ public class EditorConfigConfigurable extends CodeStyleSettingsProvider implemen @Override public JComponent createComponent() { myEnabled = new JBCheckBox("Enable EditorConfig support"); + final JPanel result = new JPanel(); + result.setLayout(new BoxLayout(result, BoxLayout.LINE_AXIS)); final JPanel panel = new JPanel(new VerticalFlowLayout()); - panel.setBorder(IdeBorderFactory.createTitledBorder("EditorConfig", false)); + result.setBorder(IdeBorderFactory.createTitledBorder("EditorConfig", false)); panel.add(myEnabled); final JLabel warning = new JLabel("EditorConfig may override the IDE code style settings"); warning.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); warning.setBorder(IdeBorderFactory.createEmptyBorder(0, 20, 0, 0)); panel.add(warning); - return panel; + panel.setAlignmentY(Component.TOP_ALIGNMENT); + result.add(panel); + final JButton export = new JButton("Export"); + export.addActionListener((event) -> { + final Component parent = UIUtil.findUltimateParent(result); + if (parent instanceof IdeFrame) { + Utils.export(((IdeFrame)parent).getProject()); + } + }); + export.setAlignmentY(Component.TOP_ALIGNMENT); + result.add(export); + return result; } @Override diff --git a/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java b/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java index 54325fd289e5..588e7fbcd717 100644 --- a/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java +++ b/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java @@ -140,6 +140,13 @@ public enum GitVersionSpecialty { public boolean existsIn(@NotNull GitVersion version) { return version.isLaterOrEqual(new GitVersion(1, 9, 0, 0)); } + }, + + LOG_AUTHOR_FILTER_SUPPORTS_VERTICAL_BAR { + @Override + public boolean existsIn(@NotNull GitVersion version) { + return !SystemInfo.isMac || version.isLaterOrEqual(new GitVersion(1, 8, 3, 3)); + } }; public abstract boolean existsIn(@NotNull GitVersion version); diff --git a/plugins/git4idea/src/git4idea/history/GitHistoryProvider.java b/plugins/git4idea/src/git4idea/history/GitHistoryProvider.java index 0e6e48c65c37..ececeb24c9d9 100644 --- a/plugins/git4idea/src/git4idea/history/GitHistoryProvider.java +++ b/plugins/git4idea/src/git4idea/history/GitHistoryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -65,7 +65,7 @@ public class GitHistoryProvider implements VcsHistoryProviderEx, VcsCacheableHis } public VcsDependentHistoryComponents getUICustomization(final VcsHistorySession session, JComponent forShortcutRegistration) { - return VcsDependentHistoryComponents.createOnlyColumns(new ColumnInfo[0]); + return VcsDependentHistoryComponents.createOnlyColumns(ColumnInfo.EMPTY_ARRAY); } public AnAction[] getAdditionalActions(Runnable refresher) { diff --git a/plugins/git4idea/src/git4idea/log/GitLogProvider.java b/plugins/git4idea/src/git4idea/log/GitLogProvider.java index 119e72de33bf..1b89ce1c83d0 100644 --- a/plugins/git4idea/src/git4idea/log/GitLogProvider.java +++ b/plugins/git4idea/src/git4idea/log/GitLogProvider.java @@ -52,6 +52,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.stream.Collectors; public class GitLogProvider implements VcsLogProvider { @@ -462,9 +463,12 @@ public class GitLogProvider implements VcsLogProvider { } if (filterCollection.getUserFilter() != null) { - String authorFilter = - StringUtil.join(ContainerUtil.map(filterCollection.getUserFilter().getUserNames(root), UserNameRegex.BASIC_INSTANCE), "\\|"); - filterParameters.add(prepareParameter("author", authorFilter)); + List authors = ContainerUtil.map(filterCollection.getUserFilter().getUserNames(root), UserNameRegex.BASIC_INSTANCE); + if (GitVersionSpecialty.LOG_AUTHOR_FILTER_SUPPORTS_VERTICAL_BAR.existsIn(myVcs.getVersion())) { + filterParameters.add(prepareParameter("author", StringUtil.join(authors, "\\|"))); + } else { + filterParameters.addAll(authors.stream().map(a -> prepareParameter("author", a)).collect(Collectors.toList())); + } } if (filterCollection.getDateFilter() != null) { diff --git a/plugins/github/test/org/jetbrains/plugins/github/GithubCreateGistContentTest.java b/plugins/github/test/org/jetbrains/plugins/github/GithubCreateGistContentTest.java index 4fc79bc26283..5dec1ac81a36 100644 --- a/plugins/github/test/org/jetbrains/plugins/github/GithubCreateGistContentTest.java +++ b/plugins/github/test/org/jetbrains/plugins/github/GithubCreateGistContentTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -110,7 +110,7 @@ public class GithubCreateGistContentTest extends GithubCreateGistContentTestBase public void testCreateFromEmptyFiles() throws Throwable { List expected = new ArrayList(); - VirtualFile[] files = new VirtualFile[0]; + VirtualFile[] files = VirtualFile.EMPTY_ARRAY; List actual = GithubCreateGistAction.collectContents(myProject, null, null, files); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleRerunFailedTestsAction.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleRerunFailedTestsAction.java index d1c894d73b04..f26953d12bf5 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleRerunFailedTestsAction.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleRerunFailedTestsAction.java @@ -59,7 +59,7 @@ public class GradleRerunFailedTestsAction extends JavaRerunFailedTestsAction { @NotNull @Override public Module[] getModules() { - return new Module[0]; + return Module.EMPTY_ARRAY; } @Nullable diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/AbstractConfigUtils.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/AbstractConfigUtils.java index 971d4ff5b1d1..86ac333f3a07 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/AbstractConfigUtils.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/config/AbstractConfigUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -140,7 +140,7 @@ public abstract class AbstractConfigUtils { } public Library[] getProjectSDKLibraries(Project project) { - if (project == null || project.isDisposed()) return new Library[0]; + if (project == null || project.isDisposed()) return Library.EMPTY_ARRAY; final LibraryTable table = ProjectLibraryTable.getInstance(project); final List all = ContainerUtil.findAll(table.getLibraries(), LIB_SEARCH_CONDITION); return all.toArray(new Library[all.size()]); diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocFieldReferenceImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocFieldReferenceImpl.java index 67b4250f41c3..69d5691d0472 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocFieldReferenceImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocFieldReferenceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -108,7 +108,7 @@ public class GrDocFieldReferenceImpl extends GrDocMemberReferenceImpl implements } return candidates; } - return new ResolveResult[0]; + return ResolveResult.EMPTY_ARRAY; } } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocMethodReferenceImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocMethodReferenceImpl.java index c807d5628d2d..34f53c04ef58 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocMethodReferenceImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocMethodReferenceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -118,7 +118,7 @@ public class GrDocMethodReferenceImpl extends GrDocMemberReferenceImpl implement resolved.processDeclarations(constructorProcessor, ResolveState.initial(), resolved, this); return ArrayUtil.mergeArrays(processor.getCandidates(), constructorProcessor.getCandidates()); } - return new ResolveResult[0]; + return ResolveResult.EMPTY_ARRAY; } @Override diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java index e5e0add0b99b..460324c46c62 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java @@ -317,7 +317,7 @@ public class PsiUtil { if (namedArgs.length > 0) { GrNamedArgument context = namedArgs[0]; - result.add(GrMapType.createFromNamedArgs(context, byShape ? new GrNamedArgument[0] : namedArgs)); + result.add(GrMapType.createFromNamedArgs(context, byShape ? GrNamedArgument.EMPTY_ARRAY : namedArgs)); } for (GrExpression expression : expressions) { diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/util/LibrariesUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/util/LibrariesUtil.java index 5076e87faede..6a7e132d4e01 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/util/LibrariesUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/util/LibrariesUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -39,7 +39,6 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.config.GroovyConfigUtils; import java.io.File; -import java.io.FilenameFilter; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -55,7 +54,7 @@ public class LibrariesUtil { } public static Library[] getLibrariesByCondition(final Module module, final Condition condition) { - if (module == null) return new Library[0]; + if (module == null) return Library.EMPTY_ARRAY; final ArrayList libraries = new ArrayList(); AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/util/dynamicMembers/GrDynamicMethodImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/util/dynamicMembers/GrDynamicMethodImpl.java index d1dead93a06b..478b9d8f8521 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/util/dynamicMembers/GrDynamicMethodImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/util/dynamicMembers/GrDynamicMethodImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -113,7 +113,7 @@ public class GrDynamicMethodImpl extends LightElement implements GrMethod { @Override @NotNull public PsiMethod[] findDeepestSuperMethods() { - return new PsiMethod[0]; + return PsiMethod.EMPTY_ARRAY; } @Override @@ -123,7 +123,7 @@ public class GrDynamicMethodImpl extends LightElement implements GrMethod { @Override public GrMember[] getMembers() { - return new GrMember[0]; + return GrMember.EMPTY_ARRAY; } @Override diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/CreateClassFix.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/CreateClassFix.java index 776b7777a240..6ed1bc3411b7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/CreateClassFix.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/CreateClassFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -137,7 +137,7 @@ public abstract class CreateClassFix { method = (GrMethod)targetClass.addBefore(method, null); final PsiElement context = PsiTreeUtil.getParentOfType(refElement, PsiMethod.class, PsiClass.class, PsiFile.class); - IntentionUtils.createTemplateForMethod(argTypes, paramTypesExpressions, method, targetClass, new TypeConstraint[0], true, context); + IntentionUtils.createTemplateForMethod(argTypes, paramTypesExpressions, method, targetClass, TypeConstraint.EMPTY_ARRAY, true, context); } finally { writeLock.finish(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovyColorsAndFontsPage.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovyColorsAndFontsPage.java index 1319b7e5161d..1437d6af8b75 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovyColorsAndFontsPage.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovyColorsAndFontsPage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -94,7 +94,7 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage { @Override @NotNull public ColorDescriptor[] getColorDescriptors() { - return new ColorDescriptor[0]; + return ColorDescriptor.EMPTY_ARRAY; } @Override diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/GroovySmartEnterProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/GroovySmartEnterProcessor.java index b79d652a826d..e52fb2c6953c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/GroovySmartEnterProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/smartEnter/GroovySmartEnterProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -194,7 +194,7 @@ public class GroovySmartEnterProcessor extends SmartEnterProcessorWithFixers { private static PsiElement[] getChildren(PsiElement element) { PsiElement psiChild = element.getFirstChild(); - if (psiChild == null) return new PsiElement[0]; + if (psiChild == null) return PsiElement.EMPTY_ARRAY; List result = new ArrayList(); while (psiChild != null) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/memberPullUp/GrPullUpConflictsUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/memberPullUp/GrPullUpConflictsUtil.java index 5692e834cec0..5bb58006d9cd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/memberPullUp/GrPullUpConflictsUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/memberPullUp/GrPullUpConflictsUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -144,7 +144,7 @@ public class GrPullUpConflictsUtil { ContainerUtil.addIfNotNull(checkModuleConflictsList, method.getReturnTypeElement()); ContainerUtil.addIfNotNull(checkModuleConflictsList, method.getTypeParameterList()); } - GrRefactoringConflictsUtil.analyzeModuleConflicts(subclass.getProject(), checkModuleConflictsList, new UsageInfo[0], targetRepresentativeElement, conflicts); + GrRefactoringConflictsUtil.analyzeModuleConflicts(subclass.getProject(), checkModuleConflictsList, UsageInfo.EMPTY_ARRAY, targetRepresentativeElement, conflicts); final String fqName = subclass.getQualifiedName(); final String packageName; if (fqName != null) { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java index fe3a08730058..48a0879c269e 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java @@ -42,7 +42,7 @@ public class HgRefManager implements VcsLogRefManager { public static final VcsRefType TAG = new SimpleRefType(false, VcsLogStandardColors.Refs.TAG); public static final VcsRefType LOCAL_TAG = new SimpleRefType(false, LOCAL_TAG_COLOR); public static final VcsRefType MQ_APPLIED_TAG = new SimpleRefType(false, MQ_TAG_COLOR); - + // first has the highest priority private static final List REF_TYPE_PRIORITIES = Arrays.asList(TIP, HEAD, BRANCH, BOOKMARK, TAG); @@ -71,18 +71,19 @@ public class HgRefManager implements VcsLogRefManager { return typeComparison; } - if (type1 == BRANCH) { - if (ref1.getName().equals(DEFAULT)) { - return -1; - } - if (ref2.getName().equals(DEFAULT)) { - return 1; - } - } int nameComparison = ref1.getName().compareTo(ref2.getName()); if (nameComparison != 0) { + if (type1 == BRANCH) { + if (ref1.getName().equals(DEFAULT)) { + return -1; + } + if (ref2.getName().equals(DEFAULT)) { + return 1; + } + } return nameComparison; } + return VcsLogUtil.compareRoots(ref1.getRoot(), ref2.getRoot()); } }; diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgHistoryProvider.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgHistoryProvider.java index 13600b9c029d..a4625d4af521 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgHistoryProvider.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgHistoryProvider.java @@ -57,7 +57,7 @@ public class HgHistoryProvider implements VcsHistoryProvider { public VcsDependentHistoryComponents getUICustomization(VcsHistorySession session, JComponent forShortcutRegistration) { - return VcsDependentHistoryComponents.createOnlyColumns(new ColumnInfo[0]); + return VcsDependentHistoryComponents.createOnlyColumns(ColumnInfo.EMPTY_ARRAY); } public AnAction[] getAdditionalActions(Runnable runnable) { diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxNamespaceDescriptor.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxNamespaceDescriptor.java index f6cdd51a0807..d2c8bfd0e1ae 100644 --- a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxNamespaceDescriptor.java +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxNamespaceDescriptor.java @@ -11,7 +11,6 @@ import com.intellij.psi.xml.XmlDocument; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.ArrayUtil; -import com.intellij.util.Processor; import com.intellij.xml.XmlElementDescriptor; import com.intellij.xml.XmlNSDescriptor; import org.jetbrains.annotations.NotNull; @@ -59,7 +58,7 @@ public class JavaFxNamespaceDescriptor implements XmlNSDescriptor, Validator { final Runnable callCleanupWorker = new Runnable() { public void run() { if (myProject.isDisposed()) return; - new CleanupWorker(new VirtualFile[]{}, myProject, "action.Subversion.cleanup.progress.title") { + new CleanupWorker(VirtualFile.EMPTY_ARRAY, myProject, "action.Subversion.cleanup.progress.title") { @Override protected void chanceToFillRoots() { final List infos = getAllWcInfos(); diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnChangesCorrectlyRefreshedNativeTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnChangesCorrectlyRefreshedNativeTest.java index 5143b76be991..a279d2deecbe 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnChangesCorrectlyRefreshedNativeTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnChangesCorrectlyRefreshedNativeTest.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package org.jetbrains.idea.svn; import com.intellij.openapi.fileEditor.impl.LoadTextUtil; @@ -78,7 +93,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -104,7 +119,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s1.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -129,7 +144,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s1.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -161,7 +176,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s2.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -197,7 +212,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { Assert.assertEquals(SubTree.ourS1Contents, text.toString()); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -220,7 +235,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.myRootDir, "target"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); for (VirtualFile file : files) { Assert.assertTrue(file.getPath(), clManager.isUnversioned(file)); @@ -263,7 +278,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.myTargetDir, "t15.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Nullable diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnChangesCorrectlyRefreshedTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnChangesCorrectlyRefreshedTest.java index e13959d3a288..732b058e74f8 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnChangesCorrectlyRefreshedTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnChangesCorrectlyRefreshedTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * 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. @@ -86,7 +86,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn17TestCase { VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -112,7 +112,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s1.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -137,7 +137,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s1.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -169,7 +169,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s2.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -205,7 +205,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn17TestCase { Assert.assertEquals(SubTree.ourS1Contents, text.toString()); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -228,7 +228,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn17TestCase { assertVF(subTree.myRootDir, "target"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); for (VirtualFile file : files) { Assert.assertTrue(file.getPath(), clManager.isUnversioned(file)); @@ -271,7 +271,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn17TestCase { assertVF(subTree.myTargetDir, "t15.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Nullable diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnChangesCorrectlyRefreshedNativeTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnChangesCorrectlyRefreshedNativeTest.java index 6ffd3cef8cf8..54c751c42fb8 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnChangesCorrectlyRefreshedNativeTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnChangesCorrectlyRefreshedNativeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -93,7 +93,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -119,7 +119,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s1.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -144,7 +144,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s1.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -176,7 +176,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.mySourceDir, "s2.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -212,7 +212,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { Assert.assertEquals(SubTree.ourS1Contents, text.toString()); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -235,7 +235,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.myRootDir, "target"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); for (VirtualFile file : files) { Assert.assertTrue(file.getPath(), clManager.isUnversioned(file)); @@ -278,7 +278,7 @@ public class SvnChangesCorrectlyRefreshedNativeTest extends Svn17TestCase { assertVF(subTree.myTargetDir, "t15.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Nullable diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnChangesCorrectlyRefreshedTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnChangesCorrectlyRefreshedTest.java index 5bfe54fbf7ec..bb5080084984 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnChangesCorrectlyRefreshedTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnChangesCorrectlyRefreshedTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * 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. @@ -112,7 +112,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn16TestCase { VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -138,7 +138,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn16TestCase { assertVF(subTree.mySourceDir, "s1.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -163,7 +163,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn16TestCase { assertVF(subTree.mySourceDir, "s1.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -195,7 +195,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn16TestCase { assertVF(subTree.mySourceDir, "s2.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -231,7 +231,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn16TestCase { Assert.assertEquals(SubTree.ourS1Contents, text.toString()); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Test @@ -254,7 +254,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn16TestCase { assertVF(subTree.myRootDir, "target"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); for (VirtualFile file : files) { Assert.assertTrue(file.getPath(), clManager.isUnversioned(file)); @@ -297,7 +297,7 @@ public class SvnChangesCorrectlyRefreshedTest extends Svn16TestCase { assertVF(subTree.myTargetDir, "t15.txt"); clManager.ensureUpToDate(false); - DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] {}, clManager.getDefaultListName(), clManager); + DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager); } @Nullable diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/LocalTaskImpl.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/LocalTaskImpl.java index 0f96aed5c2f8..63eadd378ef8 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/LocalTaskImpl.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/LocalTaskImpl.java @@ -1,17 +1,17 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.intellij.tasks.impl; @@ -47,7 +47,7 @@ public class LocalTaskImpl extends LocalTask { private String myId = ""; private String mySummary = ""; private String myDescription = null; - private Comment[] myComments = new Comment[0]; + private Comment[] myComments = Comment.EMPTY_ARRAY; private boolean myClosed = false; private Date myCreated; private Date myUpdated; diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/lighthouse/LighthouseRepository.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/lighthouse/LighthouseRepository.java index 61a50d5c9b3e..672479abc587 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/lighthouse/LighthouseRepository.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/lighthouse/LighthouseRepository.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.intellij.tasks.lighthouse; import com.intellij.openapi.diagnostic.Logger; @@ -158,7 +173,7 @@ public class LighthouseRepository extends BaseRepositoryImpl { @NotNull @Override public Comment[] getComments() { - return new Comment[0]; + return Comment.EMPTY_ARRAY; } @NotNull diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepository.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepository.java index ffcaa23a2168..153178dcf1b5 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepository.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -148,7 +148,7 @@ public class TracRepository extends BaseRepositoryImpl { @NotNull @Override public Comment[] getComments() { - return new Comment[0]; + return Comment.EMPTY_ARRAY; } @NotNull diff --git a/plugins/tasks/tasks-tests/test/com/intellij/tasks/vcs/TaskVcsTest.java b/plugins/tasks/tasks-tests/test/com/intellij/tasks/vcs/TaskVcsTest.java index dcfc7f0e5b67..fcd17ae4cb21 100644 --- a/plugins/tasks/tasks-tests/test/com/intellij/tasks/vcs/TaskVcsTest.java +++ b/plugins/tasks/tasks-tests/test/com/intellij/tasks/vcs/TaskVcsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -425,7 +425,7 @@ public class TaskVcsTest extends CodeInsightFixtureTestCase { @NotNull @Override public Comment[] getComments() { - return new Comment[0]; + return Comment.EMPTY_ARRAY; } @NotNull diff --git a/plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnGroupsInspection.java b/plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnGroupsInspection.java index 3727a250d8a3..586ed4fbf07e 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnGroupsInspection.java +++ b/plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnGroupsInspection.java @@ -139,7 +139,7 @@ public class DependsOnGroupsInspection extends BaseJavaLocalInspectionTool { } } } - return problemDescriptors.toArray(new ProblemDescriptor[]{}); + return problemDescriptors.toArray(ProblemDescriptor.EMPTY_ARRAY); } private class GroupNameQuickFix implements LocalQuickFix { diff --git a/plugins/ui-designer-core/src/com/intellij/designer/model/EmptyXmlTag.java b/plugins/ui-designer-core/src/com/intellij/designer/model/EmptyXmlTag.java index f96cc95d91db..5260402a0420 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/model/EmptyXmlTag.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/model/EmptyXmlTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * 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. @@ -76,7 +76,7 @@ public class EmptyXmlTag implements XmlTag { @NotNull @Override public XmlAttribute[] getAttributes() { - return new XmlAttribute[0]; + return XmlAttribute.EMPTY_ARRAY; } @Override @@ -125,19 +125,19 @@ public class EmptyXmlTag implements XmlTag { @NotNull @Override public XmlTag[] getSubTags() { - return new XmlTag[0]; + return XmlTag.EMPTY; } @NotNull @Override public XmlTag[] findSubTags(@NonNls String qname) { - return new XmlTag[0]; + return XmlTag.EMPTY; } @NotNull @Override public XmlTag[] findSubTags(@NonNls String localName, @NonNls String namespace) { - return new XmlTag[0]; + return XmlTag.EMPTY; } @Override @@ -185,13 +185,13 @@ public class EmptyXmlTag implements XmlTag { @NotNull @Override public XmlTagChild[] getChildren() { - return new XmlTagChild[0]; + return XmlTagChild.EMPTY_ARRAY; } @NotNull @Override public XmlText[] getTextElements() { - return new XmlText[0]; + return XmlText.EMPTY_ARRAY; } @NotNull @@ -287,7 +287,7 @@ public class EmptyXmlTag implements XmlTag { @NotNull @Override public PsiElement[] getChildren() { - return new PsiElement[0]; + return PsiElement.EMPTY_ARRAY; } @Override @@ -475,7 +475,7 @@ public class EmptyXmlTag implements XmlTag { @NotNull @Override public PsiReference[] getReferences() { - return new PsiReference[0]; + return PsiReference.EMPTY_ARRAY; } @Override diff --git a/plugins/ui-designer/ui-designer.iml b/plugins/ui-designer/ui-designer.iml index e6a868e99465..eca27c766b69 100644 --- a/plugins/ui-designer/ui-designer.iml +++ b/plugins/ui-designer/ui-designer.iml @@ -19,7 +19,7 @@ - + @@ -35,5 +35,4 @@ - - + \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathColorSettingsPage.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathColorSettingsPage.java index 491ac8dd250d..1473bbc4af72 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathColorSettingsPage.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPathColorSettingsPage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -65,7 +65,7 @@ public class XPathColorSettingsPage implements ColorSettingsPage { @NotNull public ColorDescriptor[] getColorDescriptors() { - return new ColorDescriptor[0]; + return ColorDescriptor.EMPTY_ARRAY; } @NotNull diff --git a/plugins/yaml/src/org/jetbrains/yaml/YAMLColorsPage.java b/plugins/yaml/src/org/jetbrains/yaml/YAMLColorsPage.java index 30c54292a437..40ff26d51184 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/YAMLColorsPage.java +++ b/plugins/yaml/src/org/jetbrains/yaml/YAMLColorsPage.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package org.jetbrains.yaml; import com.intellij.icons.AllIcons; @@ -46,8 +61,6 @@ public class YAMLColorsPage implements ColorSettingsPage { // Empty still private static final Map ADDITIONAL_HIGHLIGHT_DESCRIPTORS = new HashMap(); - private static final ColorDescriptor[] COLORS = new ColorDescriptor[0]; - @Nullable public Map getAdditionalHighlightingTagToDescriptorMap() { return ADDITIONAL_HIGHLIGHT_DESCRIPTORS; @@ -70,7 +83,7 @@ public class YAMLColorsPage implements ColorSettingsPage { @NotNull public ColorDescriptor[] getColorDescriptors() { - return COLORS; + return ColorDescriptor.EMPTY_ARRAY; } @NotNull diff --git a/python/educational-core/build.gradle b/python/educational-core/build.gradle index 3a0713eb64bd..fa978c18942b 100644 --- a/python/educational-core/build.gradle +++ b/python/educational-core/build.gradle @@ -1,7 +1,7 @@ import org.apache.tools.ant.filters.ReplaceTokens buildscript { - ext.kotlin_version = '1.0.2' + ext.kotlin_version = '1.0.3' repositories { mavenCentral() } diff --git a/python/educational-core/gradle.properties b/python/educational-core/gradle.properties index cef4aabef98a..38b89a6b45a1 100644 --- a/python/educational-core/gradle.properties +++ b/python/educational-core/gradle.properties @@ -1,6 +1,6 @@ ideaVersion IC-162-SNAPSHOT downloadIdeaSources false version 2.0.5 -buildNumber 162.75 +buildNumber 162.1121.10 javaVersion 1.8 updateBuildNumber false \ No newline at end of file diff --git a/python/educational-python/build.gradle b/python/educational-python/build.gradle index 9818379af820..9522fa071190 100644 --- a/python/educational-python/build.gradle +++ b/python/educational-python/build.gradle @@ -1,11 +1,22 @@ import org.apache.tools.ant.filters.ReplaceTokens +buildscript { + ext.kotlin_version = '1.0.3' + repositories { + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + plugins { id "org.jetbrains.intellij" version "0.0.39" } subprojects { apply plugin: 'java' + apply plugin: 'kotlin' apply plugin: "org.jetbrains.intellij" tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } @@ -13,7 +24,7 @@ subprojects { sourceSets { main { java.srcDirs 'src', '../src', '../gen' - resources.srcDirs 'resources' + kotlin.srcDirs 'src' resources.srcDirs 'resources', '../resources' } test { diff --git a/python/educational-python/gradle.properties b/python/educational-python/gradle.properties index f4bea5c8b3f6..e6fec73c49e3 100644 --- a/python/educational-python/gradle.properties +++ b/python/educational-python/gradle.properties @@ -1,7 +1,7 @@ -ideaVersion IC-2016.1 +ideaVersion IC-162-SNAPSHOT downloadIdeaSources false version 2.0.5 -buildNumber 162.75 +buildNumber 162.1121.10 javaVersion 1.8 pycharmVersion 162.75 updateBuildNumber false \ No newline at end of file diff --git a/python/helpers/pydev/_pydev_bundle/pydev_console_utils.py b/python/helpers/pydev/_pydev_bundle/pydev_console_utils.py index c9078e14457d..bbc37965ec58 100644 --- a/python/helpers/pydev/_pydev_bundle/pydev_console_utils.py +++ b/python/helpers/pydev/_pydev_bundle/pydev_console_utils.py @@ -189,10 +189,13 @@ class BaseInterpreterInterface: return self.need_more_for_code(self.buffer.text) - def create_std_in(self): - return StdIn(self, self.host, self.client_port) + def create_std_in(self, debugger=None, original_std_in=None): + if debugger is None: + return StdIn(self, self.host, self.client_port) + else: + return DebugConsoleStdIn(dbg=debugger, original_stdin=original_std_in) - def add_exec(self, code_fragment): + def add_exec(self, code_fragment, debugger=None): original_in = sys.stdin try: help = None @@ -210,7 +213,7 @@ class BaseInterpreterInterface: more = False try: - sys.stdin = self.create_std_in() + sys.stdin = self.create_std_in(debugger, original_in) try: if help is not None: #This will enable the help() function to work. diff --git a/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py b/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py index ec0c13d692b5..85d3267e9c73 100644 --- a/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py +++ b/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py @@ -1331,7 +1331,7 @@ class InternalConsoleExec(InternalThreadCommand): #don't trace new threads created by console command disable_trace_thread_modules() - result = pydevconsole.console_exec(self.thread_id, self.frame_id, self.expression) + result = pydevconsole.console_exec(self.thread_id, self.frame_id, self.expression, dbg) xml = "" xml += pydevd_vars.var_to_xml(result, "") xml += "" diff --git a/python/helpers/pydev/pydevconsole.py b/python/helpers/pydev/pydevconsole.py index 2ef4df593fb6..5beab3126b80 100644 --- a/python/helpers/pydev/pydevconsole.py +++ b/python/helpers/pydev/pydevconsole.py @@ -374,7 +374,7 @@ def get_completions(text, token, globals, locals): # Debugger integration #=============================================================================== -def exec_code(code, globals, locals): +def exec_code(code, globals, locals, debugger): interpreterInterface = get_interpreter() interpreterInterface.interpreter.update(globals, locals) @@ -383,7 +383,7 @@ def exec_code(code, globals, locals): if res: return True - interpreterInterface.add_exec(code) + interpreterInterface.add_exec(code, debugger) return False @@ -443,7 +443,7 @@ class ConsoleWriter(InteractiveInterpreter): tblist = tb = None sys.stderr.write(''.join(lines)) -def console_exec(thread_id, frame_id, expression): +def console_exec(thread_id, frame_id, expression, dbg): """returns 'False' in case expression is partially correct """ frame = pydevd_vars.find_frame(thread_id, frame_id) @@ -458,7 +458,7 @@ def console_exec(thread_id, frame_id, expression): updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals if IPYTHON: - need_more = exec_code(CodeFragment(expression), updated_globals, frame.f_locals) + need_more = exec_code(CodeFragment(expression), updated_globals, frame.f_locals, dbg) if not need_more: pydevd_save_locals.save_locals(frame) return need_more diff --git a/python/helpers/tools/versions.xml b/python/helpers/tools/versions.xml index a89ba6e8d570..4c6bc1e9306d 100644 --- a/python/helpers/tools/versions.xml +++ b/python/helpers/tools/versions.xml @@ -112,7 +112,6 @@ bsddb.test.test_sequence build_class builtins - bz2 cProfile collections collections.__main__ @@ -859,7 +858,6 @@ bsddb.test.test_sequence build_class builtins - bz2 cProfile collections.__main__ collections.abc @@ -1548,7 +1546,6 @@ bsddb.test.test_replication build_class builtins - bz2 collections.__main__ collections.abc concurrent @@ -2128,7 +2125,6 @@ bsddb.test.test_fileid build_class builtins - bz2 collections.__main__ collections.abc concurrent @@ -2541,7 +2537,6 @@ bsddb.test.test_env_close build_class builtins - bz2 collections.__main__ collections.abc concurrent @@ -2941,7 +2936,6 @@ bsddb.test.test_replication bsddb.test.test_sequence bsddb.test.test_thread - bz2 cPickle cStringIO collections.__main__ @@ -3480,7 +3474,6 @@ bsddb.test.test_sequence bsddb.test.test_thread build_class - bz2 cPickle cStringIO collections.__main__ @@ -3926,7 +3919,6 @@ bsddb.test.test_sequence bsddb.test.test_thread build_class - bz2 cPickle cStringIO collections.__main__ @@ -4232,7 +4224,6 @@ _abcoll _bootlocale _bytesio - _bz2 _collections_abc _compression _fileio @@ -4597,7 +4588,6 @@ __main__ _abcoll _bytesio - _bz2 _compression _fileio _hotshot diff --git a/python/ide/src/com/jetbrains/python/PyDirectoryIndexExcludePolicy.java b/python/ide/src/com/jetbrains/python/PyDirectoryIndexExcludePolicy.java index b5a671a5f28f..01dfbae6970b 100644 --- a/python/ide/src/com/jetbrains/python/PyDirectoryIndexExcludePolicy.java +++ b/python/ide/src/com/jetbrains/python/PyDirectoryIndexExcludePolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -56,6 +56,6 @@ public class PyDirectoryIndexExcludePolicy implements DirectoryIndexExcludePolic public VirtualFilePointer[] getExcludeRootsForModule(@NotNull ModuleRootModel rootModel) { - return new VirtualFilePointer[0]; + return VirtualFilePointer.EMPTY_ARRAY; } } diff --git a/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java b/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java index 2aacbc8735c1..8dbd96344776 100644 --- a/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java +++ b/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -41,7 +41,8 @@ public class PyStringLiteralFileReferenceSet extends RootFileReferenceSet { } public PyStringLiteralFileReferenceSet(@NotNull PyStringLiteralExpression element, boolean caseSensitive) { - this(element.getStringValue(), element, element.getStringValueTextRange().getStartOffset(), null, caseSensitive, true, new FileType[0]); + this(element.getStringValue(), element, element.getStringValueTextRange().getStartOffset(), null, caseSensitive, true, + FileType.EMPTY_ARRAY); } public PyStringLiteralFileReferenceSet(@NotNull String str, diff --git a/python/psi-api/src/com/jetbrains/python/PyNames.java b/python/psi-api/src/com/jetbrains/python/PyNames.java index 4b55f49acdb0..174db221d0c5 100644 --- a/python/psi-api/src/com/jetbrains/python/PyNames.java +++ b/python/psi-api/src/com/jetbrains/python/PyNames.java @@ -165,6 +165,7 @@ public class PyNames { public static final String DIV = "__div__"; public static final String TRUEDIV = "__truediv__"; public static final String AITER = "__aiter__"; + public static final String SIZEOF = "__sizeof__"; public static final String NAME = "__name__"; public static final String ENTER = "__enter__"; diff --git a/python/psi-api/src/com/jetbrains/python/psi/impl/PyPsiUtils.java b/python/psi-api/src/com/jetbrains/python/psi/impl/PyPsiUtils.java index 8dba1d02da9b..46f07970447a 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/impl/PyPsiUtils.java +++ b/python/psi-api/src/com/jetbrains/python/psi/impl/PyPsiUtils.java @@ -19,7 +19,6 @@ import com.google.common.base.Preconditions; import com.intellij.lang.ASTNode; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -604,6 +603,14 @@ public class PyPsiUtils { Preconditions.checkArgument(!module.isDisposed(), String.format("Module %s is disposed", module)); } + @NotNull + public static PsiFileSystemItem getFileSystemItem(@NotNull PsiElement element) { + if (element instanceof PsiFileSystemItem) { + return (PsiFileSystemItem)element; + } + return element.getContainingFile(); + } + private static abstract class TopLevelVisitor extends PyRecursiveElementVisitor { public void visitPyElement(final PyElement node) { super.visitPyElement(node); diff --git a/python/python-community-configure/src/com/jetbrains/python/configuration/PythonSdkDetailsDialog.java b/python/python-community-configure/src/com/jetbrains/python/configuration/PythonSdkDetailsDialog.java index ed458a4e9938..f800d97e41bb 100644 --- a/python/python-community-configure/src/com/jetbrains/python/configuration/PythonSdkDetailsDialog.java +++ b/python/python-community-configure/src/com/jetbrains/python/configuration/PythonSdkDetailsDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -47,7 +47,6 @@ import com.intellij.remote.RemoteSdkAdditionalData; import com.intellij.ui.*; import com.intellij.ui.components.JBList; import com.intellij.util.NullableConsumer; -import com.intellij.util.NullableFunction; import com.intellij.util.PathMappingSettings; import com.intellij.util.containers.FactoryMap; import com.jetbrains.python.PyBundle; @@ -564,7 +563,7 @@ public class PythonSdkDetailsDialog extends DialogWrapper { catch (Exception e) { LOG.error(e); } - return new VirtualFile[0]; + return VirtualFile.EMPTY_ARRAY; } @Override diff --git a/python/src/com/jetbrains/python/codeInsight/imports/ImportFromExistingAction.java b/python/src/com/jetbrains/python/codeInsight/imports/ImportFromExistingAction.java index e998ab07678a..02b95124f3dd 100644 --- a/python/src/com/jetbrains/python/codeInsight/imports/ImportFromExistingAction.java +++ b/python/src/com/jetbrains/python/codeInsight/imports/ImportFromExistingAction.java @@ -19,6 +19,7 @@ import com.intellij.codeInsight.hint.QuestionAction; import com.intellij.ide.DataManager; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.colors.EditorColorsManager; @@ -28,7 +29,10 @@ import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.ui.popup.PopupChooserBuilder; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiFileSystemItem; import com.intellij.psi.util.QualifiedName; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleTextAttributes; @@ -98,10 +102,12 @@ public class ImportFromExistingAction implements QuestionAction { return false; } // act - if (mySources.size() > 1) { + if (mySources.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) { + doWriteAction(mySources.get(0)); + } + else { selectSourceAndDo(); } - else doWriteAction(mySources.get(0)); return true; } diff --git a/python/src/com/jetbrains/python/console/completion/PydevConsoleReference.java b/python/src/com/jetbrains/python/console/completion/PydevConsoleReference.java index 5fe819f323b3..6fb65ae80ca0 100644 --- a/python/src/com/jetbrains/python/console/completion/PydevConsoleReference.java +++ b/python/src/com/jetbrains/python/console/completion/PydevConsoleReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -59,7 +59,7 @@ public class PydevConsoleReference extends PsiPolyVariantReferenceBase resultsFromProcessor = getResultsFromProcessor(referencedName, processor, realContext, roof); + + // resolve to module __doc__ + if (resultsFromProcessor.isEmpty() && referencedName.equals(PyNames.DOC)) { + ret.addAll( + Optional + .ofNullable(PyBuiltinCache.getInstance(myElement).getObjectType()) + .map(type -> type.resolveMember(referencedName, myElement, AccessDirection.of(myElement), myContext)) + .orElse(Collections.emptyList()) + ); + + return ret; + } + + return resultsFromProcessor; } protected List getResultsFromProcessor(@NotNull String referencedName, diff --git a/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java b/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java index e87c189f361f..04029133f240 100644 --- a/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java +++ b/python/src/com/jetbrains/python/psi/resolve/QualifiedNameFinder.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.util.QualifiedName; import com.jetbrains.python.PyNames; import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; @@ -30,7 +31,6 @@ import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyElement; import com.jetbrains.python.psi.PyFile; import com.jetbrains.python.psi.PyFunction; -import com.intellij.psi.util.QualifiedName; import com.jetbrains.python.psi.impl.PyBuiltinCache; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -85,13 +85,7 @@ public class QualifiedNameFinder { @Nullable private static QualifiedName shortestQName(@NotNull List qNames) { - QualifiedName result = null; - for (QualifiedName name : qNames) { - if (result == null || name.getComponentCount() < result.getComponentCount()) { - result = name; - } - } - return result; + return qNames.stream().min((o1, o2) -> o1.getComponentCount() - o2.getComponentCount()).orElse(null); } @Nullable @@ -142,8 +136,13 @@ public class QualifiedNameFinder { if (initPy == null) { break; } - if (initPy instanceof PyFile && toplevel.equals(((PyFile)initPy).getElementNamed(((PsiNamedElement)toplevel).getName()))) { - virtualFile = dir.getVirtualFile(); + if (initPy instanceof PyFile) { + //noinspection ConstantConditions + final List resolved = ((PyFile)initPy).multiResolveName(((PsiNamedElement)toplevel).getName()); + final PsiElement finalTopLevel = toplevel; + if (resolved.stream().anyMatch(r -> r.getElement() == finalTopLevel)) { + virtualFile = dir.getVirtualFile(); + } } dir = dir.getParentDirectory(); } diff --git a/python/src/com/jetbrains/python/psi/resolve/QualifiedNameResolverImpl.java b/python/src/com/jetbrains/python/psi/resolve/QualifiedNameResolverImpl.java index 5592b58c61c5..58b594e264a1 100644 --- a/python/src/com/jetbrains/python/psi/resolve/QualifiedNameResolverImpl.java +++ b/python/src/com/jetbrains/python/psi/resolve/QualifiedNameResolverImpl.java @@ -28,15 +28,13 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.FileIndexFacade; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiNamedElement; +import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.QualifiedName; import com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil; import com.jetbrains.python.console.PydevConsoleRunner; import com.jetbrains.python.facet.PythonPathContributingFacet; +import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyFile; import com.jetbrains.python.psi.PyUtil; import com.jetbrains.python.psi.impl.PyBuiltinCache; @@ -44,6 +42,7 @@ import com.jetbrains.python.psi.impl.PyImportResolver; import com.jetbrains.python.psi.impl.PyPsiUtils; import com.jetbrains.python.sdk.PySdkUtil; import com.jetbrains.python.sdk.PythonSdkType; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -52,6 +51,8 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import static com.jetbrains.python.psi.PyUtil.as; + /** * Resolves the specified qualified name in the specified context (module, all modules or a file) to a file or directory. * @@ -235,6 +236,7 @@ public class QualifiedNameResolverImpl implements RootVisitor, QualifiedNameReso final PsiFile footholdFile = myContext.getFootholdFile(); checkValidForTests(footholdFile); + boolean foundRelativeImport = false; if (myRelativeLevel >= 0 && footholdFile != null && !PyUserSkeletonsUtil.isUnderUserSkeletonsDirectory(footholdFile)) { PsiDirectory dir = footholdFile.getContainingDirectory(); checkValidForTests(dir); @@ -246,12 +248,13 @@ public class QualifiedNameResolverImpl implements RootVisitor, QualifiedNameReso PsiElement module = resolveModuleAt(dir); checkValidForTests(module); if (module != null) { + foundRelativeImport = isRelativeImportResult(dir, module); addRoot(module, true); } } final PythonPathCache cache = findMyCache(); - final boolean mayCache = cache != null && !myWithoutRoots && !myWithoutForeign; + final boolean mayCache = cache != null && !myWithoutRoots && !myWithoutForeign && !foundRelativeImport; if (mayCache) { final List cachedResults = cache.get(myQualifiedName); if (cachedResults != null) { @@ -293,6 +296,22 @@ public class QualifiedNameResolverImpl implements RootVisitor, QualifiedNameReso return results; } + + private boolean isRelativeImportResult(@NotNull PsiDirectory rootDirectory, @NotNull PsiElement result) { + if (myRelativeLevel > 0) { + return true; + } + final boolean isPython2 = LanguageLevel.forElement(rootDirectory).isOlderThan(LanguageLevel.PYTHON30); + if (myRelativeLevel == 0 && isPython2 && PyUtil.isPackage(rootDirectory, false, null)) { + // Candidate for implicit relative import doesn't necessarily means that the same module cannot be imported absolutely + final PsiFileSystemItem moduleOrPackage = as(result, PsiFileSystemItem.class); + if (moduleOrPackage != null && !myQualifiedName.equals(QualifiedNameFinder.findShortestImportableQName(moduleOrPackage))) { + return true; + } + } + return false; + } + /** * Resolve relative imports from sdk root to the skeleton dir */ @@ -421,6 +440,7 @@ public class QualifiedNameResolverImpl implements RootVisitor, QualifiedNameReso * * @param directory where to start from; top qualifier will be searched for here. */ + @Contract("null -> null") @Nullable public PsiElement resolveModuleAt(@Nullable PsiDirectory directory) { // prerequisites diff --git a/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java b/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java index 3660c809f15f..2c1c75042b59 100644 --- a/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java +++ b/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java @@ -195,10 +195,22 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType { } classMember = resolveClassMember(myClass, myIsDefinition, name, location); + + if (PyNames.__CLASS__.equals(name)) { + return resolveDunderClass(context, classMember); + } + if (classMember != null) { return ResolveResultList.to(classMember); } + if (PyNames.DOC.equals(name)) { + return Optional + .ofNullable(PyBuiltinCache.getInstance(myClass).getObjectType()) + .map(type -> type.resolveMember(name, location, direction, resolveContext)) + .orElse(Collections.emptyList()); + } + classMember = resolveByOverridingAncestorsMembersProviders(this, name, location); if (classMember != null) { final ResolveResultList list = new ResolveResultList(); @@ -293,6 +305,36 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType { return resultRef; } + @Nullable + private List resolveDunderClass(@NotNull TypeEvalContext context, @Nullable PsiElement classMember) { + final boolean newStyleClass = myClass.isNewStyleClass(context); + + if (!myIsDefinition) { + if (newStyleClass && classMember != null) { + return ResolveResultList.to(classMember); + } + + return ResolveResultList.to( + myClass.getAncestorClasses(context) + .stream() + .filter(cls -> !PyUtil.isObjectClass(cls)) + .map(cls -> cls.findClassAttribute(PyNames.__CLASS__, true, context)) + .filter(target -> target != null) + .findFirst() + .orElse(myClass) + ); + } + + if (LanguageLevel.forElement(myClass).isOlderThan(LanguageLevel.PYTHON30) && !newStyleClass) { + return ResolveResultList.to(classMember); + } + + return Optional + .ofNullable(PyBuiltinCache.getInstance(myClass).getTypeType()) + .map(typeType -> ResolveResultList.to(typeType.getPyClass())) + .orElse(null); + } + @Nullable @Override public PyClassLikeType getMetaClassType(@NotNull final TypeEvalContext context, boolean inherited) { diff --git a/python/src/com/jetbrains/python/refactoring/PyDefUseUtil.java b/python/src/com/jetbrains/python/refactoring/PyDefUseUtil.java index f4d6af60cff1..8f764caf55bd 100644 --- a/python/src/com/jetbrains/python/refactoring/PyDefUseUtil.java +++ b/python/src/com/jetbrains/python/refactoring/PyDefUseUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -21,13 +21,12 @@ import com.intellij.codeInsight.controlflow.ControlFlowUtil; import com.intellij.codeInsight.controlflow.Instruction; import com.intellij.openapi.util.Comparing; import com.intellij.psi.PsiElement; -import com.intellij.util.Function; +import com.intellij.psi.util.QualifiedName; import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache; import com.jetbrains.python.codeInsight.controlflow.ReadWriteInstruction; import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PyAugAssignmentStatementNavigator; -import com.intellij.psi.util.QualifiedName; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -112,7 +111,7 @@ public class PyDefUseUtil { final Instruction[] instructions = controlFlow.getInstructions(); final int instr = ControlFlowUtil.findInstructionNumberByElement(instructions, anchor); if (instr < 0) { - return new PyElement[0]; + return PyElement.EMPTY_ARRAY; } final boolean[] visited = new boolean[instructions.length]; final Collection result = Sets.newHashSet(); diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java index e593af40baa9..edca9e70620f 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java @@ -133,6 +133,7 @@ public class PythonSdkUpdater implements StartupActivity { return true; } + @SuppressWarnings("ThrowableInstanceNeverThrown") final Throwable methodCallStacktrace = new Throwable(); application.invokeLater(() -> { synchronized (ourLock) { if (!ourScheduledToRefresh.contains(homePath)) { @@ -165,6 +166,7 @@ public class PythonSdkUpdater implements StartupActivity { PyPackageManager.getInstance(sdk12).refreshAndGetPackages(true); } catch (ExecutionException e) { + e.initCause(methodCallStacktrace); LOG.warn(e); } } diff --git a/python/testData/inspections/PyCompatibilityInspection/bz2Module.py b/python/testData/inspections/PyCompatibilityInspection/bz2Module.py new file mode 100644 index 000000000000..b4e4ac25b00a --- /dev/null +++ b/python/testData/inspections/PyCompatibilityInspection/bz2Module.py @@ -0,0 +1 @@ +from bz2 import BZ2File \ No newline at end of file diff --git a/python/testData/inspections/PyCompatibilityInspection/underscoreBz2Module.py b/python/testData/inspections/PyCompatibilityInspection/underscoreBz2Module.py new file mode 100644 index 000000000000..8ae8a0c2ad87 --- /dev/null +++ b/python/testData/inspections/PyCompatibilityInspection/underscoreBz2Module.py @@ -0,0 +1 @@ +import _bz2 \ No newline at end of file diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/dunderClass.py b/python/testData/inspections/PyUnresolvedReferencesInspection/dunderClass.py new file mode 100644 index 000000000000..293405bd59bd --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/dunderClass.py @@ -0,0 +1,3 @@ +class A: + def foo(self): + return __class__ \ No newline at end of file diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection3K/dunderClass.py b/python/testData/inspections/PyUnresolvedReferencesInspection3K/dunderClass.py new file mode 100644 index 000000000000..82edcc21ab81 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection3K/dunderClass.py @@ -0,0 +1,3 @@ +class A: + def foo(self): + return __class__ \ No newline at end of file diff --git a/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/bar/__init__.py b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/bar/__init__.py new file mode 100644 index 000000000000..3fdf6be7ca9b --- /dev/null +++ b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/bar/__init__.py @@ -0,0 +1 @@ +from mod import MyClass \ No newline at end of file diff --git a/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/bar/mod.py b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/bar/mod.py new file mode 100644 index 000000000000..6f75e663c7a6 --- /dev/null +++ b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/bar/mod.py @@ -0,0 +1,2 @@ +class MyClass(object): + pass \ No newline at end of file diff --git a/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/foo/__init__.py b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/foo/__init__.py new file mode 100644 index 000000000000..3fdf6be7ca9b --- /dev/null +++ b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/foo/__init__.py @@ -0,0 +1 @@ +from mod import MyClass \ No newline at end of file diff --git a/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/foo/mod.py b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/foo/mod.py new file mode 100644 index 000000000000..6f75e663c7a6 --- /dev/null +++ b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/foo/mod.py @@ -0,0 +1,2 @@ +class MyClass(object): + pass \ No newline at end of file diff --git a/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/main.py b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/main.py new file mode 100644 index 000000000000..3d0c10c7fceb --- /dev/null +++ b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/main.py @@ -0,0 +1 @@ +MyClass() \ No newline at end of file diff --git a/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/main_after.py b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/main_after.py new file mode 100644 index 000000000000..8683c5a7c50e --- /dev/null +++ b/python/testData/quickFixes/AddImportQuickFixTest/canonicalNamesFromHigherLevelPackage/main_after.py @@ -0,0 +1,3 @@ +from foo import MyClass + +MyClass() \ No newline at end of file diff --git a/python/testData/resolve/ClassAttrInDeclaration.py b/python/testData/resolve/ClassAttrInDeclaration.py new file mode 100644 index 000000000000..bf5499858801 --- /dev/null +++ b/python/testData/resolve/ClassAttrInDeclaration.py @@ -0,0 +1,4 @@ +class A: + my_attr = 17 + print(my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/ClassAttrInDeclarationNewStyleClass.py b/python/testData/resolve/ClassAttrInDeclarationNewStyleClass.py new file mode 100644 index 000000000000..fb3c9705a2bd --- /dev/null +++ b/python/testData/resolve/ClassAttrInDeclarationNewStyleClass.py @@ -0,0 +1,4 @@ +class A(object): + my_attr = 17 + print(my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderClassInDeclaration.py b/python/testData/resolve/DunderClassInDeclaration.py new file mode 100644 index 000000000000..d5bcc9eb2794 --- /dev/null +++ b/python/testData/resolve/DunderClassInDeclaration.py @@ -0,0 +1,3 @@ +class A: + print(__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderClassInDeclarationInsideFunction.py b/python/testData/resolve/DunderClassInDeclarationInsideFunction.py new file mode 100644 index 000000000000..5a67313028ea --- /dev/null +++ b/python/testData/resolve/DunderClassInDeclarationInsideFunction.py @@ -0,0 +1,6 @@ +def foo(): + class A: + print(__class__) + # + + return A() \ No newline at end of file diff --git a/python/testData/resolve/DunderClassInDeclarationNewStyleClass.py b/python/testData/resolve/DunderClassInDeclarationNewStyleClass.py new file mode 100644 index 000000000000..317370258e67 --- /dev/null +++ b/python/testData/resolve/DunderClassInDeclarationNewStyleClass.py @@ -0,0 +1,3 @@ +class A(object): + print(__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderClassInDeclarationWithClassAttr.py b/python/testData/resolve/DunderClassInDeclarationWithClassAttr.py new file mode 100644 index 000000000000..9e790d60290f --- /dev/null +++ b/python/testData/resolve/DunderClassInDeclarationWithClassAttr.py @@ -0,0 +1,4 @@ +class A: + __class__ = 17 + print(__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderClassInDeclarationWithClassAttrNewStyleClass.py b/python/testData/resolve/DunderClassInDeclarationWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..1921ecd845da --- /dev/null +++ b/python/testData/resolve/DunderClassInDeclarationWithClassAttrNewStyleClass.py @@ -0,0 +1,4 @@ +class A(object): + __class__ = 17 + print(__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderClassInDeclarationWithInheritedClassAttr.py b/python/testData/resolve/DunderClassInDeclarationWithInheritedClassAttr.py new file mode 100644 index 000000000000..cb3986d46517 --- /dev/null +++ b/python/testData/resolve/DunderClassInDeclarationWithInheritedClassAttr.py @@ -0,0 +1,6 @@ +class A(object): + __class__ = 17 + +class B(A): + print(__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderDocInDeclaration.py b/python/testData/resolve/DunderDocInDeclaration.py new file mode 100644 index 000000000000..f542971e0ce5 --- /dev/null +++ b/python/testData/resolve/DunderDocInDeclaration.py @@ -0,0 +1,3 @@ +class A: + print(__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderDocInDeclarationNewStyleClass.py b/python/testData/resolve/DunderDocInDeclarationNewStyleClass.py new file mode 100644 index 000000000000..8deaa6098586 --- /dev/null +++ b/python/testData/resolve/DunderDocInDeclarationNewStyleClass.py @@ -0,0 +1,3 @@ +class A(object): + print(__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderDocInDeclarationWithClassAttr.py b/python/testData/resolve/DunderDocInDeclarationWithClassAttr.py new file mode 100644 index 000000000000..3e195cbb44ad --- /dev/null +++ b/python/testData/resolve/DunderDocInDeclarationWithClassAttr.py @@ -0,0 +1,4 @@ +class A: + __doc__ = 17 + print(__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderDocInDeclarationWithClassAttrNewStyleClass.py b/python/testData/resolve/DunderDocInDeclarationWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..6a0dc30bd74f --- /dev/null +++ b/python/testData/resolve/DunderDocInDeclarationWithClassAttrNewStyleClass.py @@ -0,0 +1,4 @@ +class A(object): + __doc__ = 17 + print(__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderDocInDeclarationWithInheritedClassAttr.py b/python/testData/resolve/DunderDocInDeclarationWithInheritedClassAttr.py new file mode 100644 index 000000000000..82af27afa69b --- /dev/null +++ b/python/testData/resolve/DunderDocInDeclarationWithInheritedClassAttr.py @@ -0,0 +1,6 @@ +class A(object): + __doc__ = 17 + +class B(A): + print(__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderSizeOfInDeclaration.py b/python/testData/resolve/DunderSizeOfInDeclaration.py new file mode 100644 index 000000000000..f15a8686048d --- /dev/null +++ b/python/testData/resolve/DunderSizeOfInDeclaration.py @@ -0,0 +1,3 @@ +class A: + print(__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderSizeOfInDeclarationNewStyleClass.py b/python/testData/resolve/DunderSizeOfInDeclarationNewStyleClass.py new file mode 100644 index 000000000000..52caeda412ac --- /dev/null +++ b/python/testData/resolve/DunderSizeOfInDeclarationNewStyleClass.py @@ -0,0 +1,3 @@ +class A(object): + print(__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderSizeOfInDeclarationWithClassAttr.py b/python/testData/resolve/DunderSizeOfInDeclarationWithClassAttr.py new file mode 100644 index 000000000000..9aa973e5cd79 --- /dev/null +++ b/python/testData/resolve/DunderSizeOfInDeclarationWithClassAttr.py @@ -0,0 +1,4 @@ +class A: + __sizeof__ = 17 + print(__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderSizeOfInDeclarationWithClassAttrNewStyleClass.py b/python/testData/resolve/DunderSizeOfInDeclarationWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..5daf08022681 --- /dev/null +++ b/python/testData/resolve/DunderSizeOfInDeclarationWithClassAttrNewStyleClass.py @@ -0,0 +1,4 @@ +class A(object): + __sizeof__ = 17 + print(__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/DunderSizeOfInDeclarationWithInheritedClassAttr.py b/python/testData/resolve/DunderSizeOfInDeclarationWithInheritedClassAttr.py new file mode 100644 index 000000000000..4d8a27e1cb0a --- /dev/null +++ b/python/testData/resolve/DunderSizeOfInDeclarationWithInheritedClassAttr.py @@ -0,0 +1,6 @@ +class A(object): + __sizeof__ = 17 + +class B(A): + print(__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitClassAttr.py b/python/testData/resolve/ImplicitClassAttr.py new file mode 100644 index 000000000000..2d8a3eff40c1 --- /dev/null +++ b/python/testData/resolve/ImplicitClassAttr.py @@ -0,0 +1,6 @@ +class A: + my_attr = 15 + + def foo(self): + return my_attr +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitClassAttrNewStyleClass.py b/python/testData/resolve/ImplicitClassAttrNewStyleClass.py new file mode 100644 index 000000000000..070be0694552 --- /dev/null +++ b/python/testData/resolve/ImplicitClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + my_attr = 15 + + def foo(self): + return my_attr +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderClass.py b/python/testData/resolve/ImplicitDunderClass.py new file mode 100644 index 000000000000..2e68ba7b1f22 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderClass.py @@ -0,0 +1,4 @@ +class A: + def foo(self): + return __class__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderClassNewStyleClass.py b/python/testData/resolve/ImplicitDunderClassNewStyleClass.py new file mode 100644 index 000000000000..99a8a16771b7 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderClassNewStyleClass.py @@ -0,0 +1,4 @@ +class A(object): + def foo(self): + return __class__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderClassWithClassAttr.py b/python/testData/resolve/ImplicitDunderClassWithClassAttr.py new file mode 100644 index 000000000000..81a09107ec71 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderClassWithClassAttr.py @@ -0,0 +1,6 @@ +class A: + __class__ = 15 + + def foo(self): + return __class__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderClassWithClassAttrNewStyleClass.py b/python/testData/resolve/ImplicitDunderClassWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..4e685fd46b6b --- /dev/null +++ b/python/testData/resolve/ImplicitDunderClassWithClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + __class__ = 15 + + def foo(self): + return __class__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderClassWithInheritedClassAttr.py b/python/testData/resolve/ImplicitDunderClassWithInheritedClassAttr.py new file mode 100644 index 000000000000..57cb96bf7405 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderClassWithInheritedClassAttr.py @@ -0,0 +1,7 @@ +class A(object): + __class__ = int + +class B(A): + def foo(self): + return __class__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderDoc.py b/python/testData/resolve/ImplicitDunderDoc.py new file mode 100644 index 000000000000..30d09c82fc71 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderDoc.py @@ -0,0 +1,4 @@ +class A: + def foo(self): + return __doc__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderDocNewStyleClass.py b/python/testData/resolve/ImplicitDunderDocNewStyleClass.py new file mode 100644 index 000000000000..1a93f8ff38b7 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderDocNewStyleClass.py @@ -0,0 +1,4 @@ +class A(object): + def foo(self): + return __doc__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderDocWithClassAttr.py b/python/testData/resolve/ImplicitDunderDocWithClassAttr.py new file mode 100644 index 000000000000..821ed805f054 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderDocWithClassAttr.py @@ -0,0 +1,6 @@ +class A: + __doc__ = 15 + + def foo(self): + return __doc__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderDocWithClassAttrNewStyleClass.py b/python/testData/resolve/ImplicitDunderDocWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..545b55d94a2e --- /dev/null +++ b/python/testData/resolve/ImplicitDunderDocWithClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + __doc__ = 15 + + def foo(self): + return __doc__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderDocWithInheritedClassAttr.py b/python/testData/resolve/ImplicitDunderDocWithInheritedClassAttr.py new file mode 100644 index 000000000000..71701270e7fe --- /dev/null +++ b/python/testData/resolve/ImplicitDunderDocWithInheritedClassAttr.py @@ -0,0 +1,7 @@ +class A(object): + __doc__ = "abc" + +class B(A): + def foo(self): + return __doc__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderSizeOf.py b/python/testData/resolve/ImplicitDunderSizeOf.py new file mode 100644 index 000000000000..e53d68134d68 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderSizeOf.py @@ -0,0 +1,4 @@ +class A: + def foo(self): + return __sizeof__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderSizeOfNewStyleClass.py b/python/testData/resolve/ImplicitDunderSizeOfNewStyleClass.py new file mode 100644 index 000000000000..c0400c03bf45 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderSizeOfNewStyleClass.py @@ -0,0 +1,4 @@ +class A(object): + def foo(self): + return __sizeof__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderSizeOfWithClassAttr.py b/python/testData/resolve/ImplicitDunderSizeOfWithClassAttr.py new file mode 100644 index 000000000000..46fe0e7ccd6e --- /dev/null +++ b/python/testData/resolve/ImplicitDunderSizeOfWithClassAttr.py @@ -0,0 +1,6 @@ +class A: + __sizeof__ = 15 + + def foo(self): + return __sizeof__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderSizeOfWithClassAttrNewStyleClass.py b/python/testData/resolve/ImplicitDunderSizeOfWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..3ed21284e59a --- /dev/null +++ b/python/testData/resolve/ImplicitDunderSizeOfWithClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + __sizeof__ = 15 + + def foo(self): + return __sizeof__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitDunderSizeOfWithInheritedClassAttr.py b/python/testData/resolve/ImplicitDunderSizeOfWithInheritedClassAttr.py new file mode 100644 index 000000000000..34e70e535cf8 --- /dev/null +++ b/python/testData/resolve/ImplicitDunderSizeOfWithInheritedClassAttr.py @@ -0,0 +1,7 @@ +class A(object): + __sizeof__ = 4 + +class B(A): + def foo(self): + return __sizeof__ +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitInheritedClassAttr.py b/python/testData/resolve/ImplicitInheritedClassAttr.py new file mode 100644 index 000000000000..2c72252ac833 --- /dev/null +++ b/python/testData/resolve/ImplicitInheritedClassAttr.py @@ -0,0 +1,7 @@ +class A(object): + my_attr = 4 + +class B(A): + def foo(self): + return my_attr +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitUndeclaredClassAttr.py b/python/testData/resolve/ImplicitUndeclaredClassAttr.py new file mode 100644 index 000000000000..d1c52ff2b51d --- /dev/null +++ b/python/testData/resolve/ImplicitUndeclaredClassAttr.py @@ -0,0 +1,4 @@ +class A: + def foo(self): + return my_attr +# \ No newline at end of file diff --git a/python/testData/resolve/ImplicitUndeclaredClassAttrNewStyleClass.py b/python/testData/resolve/ImplicitUndeclaredClassAttrNewStyleClass.py new file mode 100644 index 000000000000..557ef92b6202 --- /dev/null +++ b/python/testData/resolve/ImplicitUndeclaredClassAttrNewStyleClass.py @@ -0,0 +1,4 @@ +class A(object): + def foo(self): + return my_attr +# \ No newline at end of file diff --git a/python/testData/resolve/InheritedClassAttrInDeclaration.py b/python/testData/resolve/InheritedClassAttrInDeclaration.py new file mode 100644 index 000000000000..2b40795270fd --- /dev/null +++ b/python/testData/resolve/InheritedClassAttrInDeclaration.py @@ -0,0 +1,6 @@ +class A(object): + my_attr = 17 + +class B(A): + print(my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceClassAttr.py b/python/testData/resolve/InstanceClassAttr.py new file mode 100644 index 000000000000..6cd541bb959f --- /dev/null +++ b/python/testData/resolve/InstanceClassAttr.py @@ -0,0 +1,7 @@ +class A: + my_attr = 15 + + +a = A() +print(a.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceClassAttrNewStyleClass.py b/python/testData/resolve/InstanceClassAttrNewStyleClass.py new file mode 100644 index 000000000000..4dd67f501a87 --- /dev/null +++ b/python/testData/resolve/InstanceClassAttrNewStyleClass.py @@ -0,0 +1,7 @@ +class A(object): + my_attr = 15 + + +a = A() +print(a.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderClass.py b/python/testData/resolve/InstanceDunderClass.py new file mode 100644 index 000000000000..3f671b0c854d --- /dev/null +++ b/python/testData/resolve/InstanceDunderClass.py @@ -0,0 +1,7 @@ +class A: + pass + + +a = A() +print(a.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderClassNewStyleClass.py b/python/testData/resolve/InstanceDunderClassNewStyleClass.py new file mode 100644 index 000000000000..d64ab5e20ec1 --- /dev/null +++ b/python/testData/resolve/InstanceDunderClassNewStyleClass.py @@ -0,0 +1,7 @@ +class A(object): + pass + + +a = A() +print(a.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderClassWithClassAttr.py b/python/testData/resolve/InstanceDunderClassWithClassAttr.py new file mode 100644 index 000000000000..819e206ffab6 --- /dev/null +++ b/python/testData/resolve/InstanceDunderClassWithClassAttr.py @@ -0,0 +1,7 @@ +class A: + __class__ = 15 + + +a = A() +print(a.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderClassWithClassAttrNewStyleClass.py b/python/testData/resolve/InstanceDunderClassWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..a51fafbcb2a0 --- /dev/null +++ b/python/testData/resolve/InstanceDunderClassWithClassAttrNewStyleClass.py @@ -0,0 +1,7 @@ +class A(object): + __class__ = 15 + + +a = A() +print(a.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderClassWithInheritedClassAttr.py b/python/testData/resolve/InstanceDunderClassWithInheritedClassAttr.py new file mode 100644 index 000000000000..c685bbd9ce87 --- /dev/null +++ b/python/testData/resolve/InstanceDunderClassWithInheritedClassAttr.py @@ -0,0 +1,10 @@ +class A(object): + __class__ = 15 + +class B(A): + pass + + +b = B() +print(b.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderDoc.py b/python/testData/resolve/InstanceDunderDoc.py new file mode 100644 index 000000000000..04da49b0da7e --- /dev/null +++ b/python/testData/resolve/InstanceDunderDoc.py @@ -0,0 +1,7 @@ +class A: + pass + + +a = A() +print(a.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderDocNewStyleClass.py b/python/testData/resolve/InstanceDunderDocNewStyleClass.py new file mode 100644 index 000000000000..7639c9ecb3a4 --- /dev/null +++ b/python/testData/resolve/InstanceDunderDocNewStyleClass.py @@ -0,0 +1,7 @@ +class A(object): + pass + + +a = A() +print(a.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderDocWithClassAttr.py b/python/testData/resolve/InstanceDunderDocWithClassAttr.py new file mode 100644 index 000000000000..b83622ea787d --- /dev/null +++ b/python/testData/resolve/InstanceDunderDocWithClassAttr.py @@ -0,0 +1,7 @@ +class A: + __doc__ = 15 + + +a = A() +print(a.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderDocWithClassAttrNewStyleClass.py b/python/testData/resolve/InstanceDunderDocWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..8e71d90f7687 --- /dev/null +++ b/python/testData/resolve/InstanceDunderDocWithClassAttrNewStyleClass.py @@ -0,0 +1,7 @@ +class A(object): + __doc__ = 15 + + +a = A() +print(a.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderDocWithInheritedClassAttr.py b/python/testData/resolve/InstanceDunderDocWithInheritedClassAttr.py new file mode 100644 index 000000000000..3fef6e9429dc --- /dev/null +++ b/python/testData/resolve/InstanceDunderDocWithInheritedClassAttr.py @@ -0,0 +1,10 @@ +class A(object): + __doc__ = 16 + +class B(A): + pass + + +b = B() +print(b.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderSizeOf.py b/python/testData/resolve/InstanceDunderSizeOf.py new file mode 100644 index 000000000000..9a34e386d031 --- /dev/null +++ b/python/testData/resolve/InstanceDunderSizeOf.py @@ -0,0 +1,7 @@ +class A: + pass + + +a = A() +print(a.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderSizeOfNewStyleClass.py b/python/testData/resolve/InstanceDunderSizeOfNewStyleClass.py new file mode 100644 index 000000000000..58611a25ba1f --- /dev/null +++ b/python/testData/resolve/InstanceDunderSizeOfNewStyleClass.py @@ -0,0 +1,7 @@ +class A(object): + pass + + +a = A() +print(a.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderSizeOfWithClassAttr.py b/python/testData/resolve/InstanceDunderSizeOfWithClassAttr.py new file mode 100644 index 000000000000..7352e5b9b00d --- /dev/null +++ b/python/testData/resolve/InstanceDunderSizeOfWithClassAttr.py @@ -0,0 +1,7 @@ +class A: + __sizeof__ = 15 + + +a = A() +print(a.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderSizeOfWithClassAttrNewStyleClass.py b/python/testData/resolve/InstanceDunderSizeOfWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..3f89b2b1c9ba --- /dev/null +++ b/python/testData/resolve/InstanceDunderSizeOfWithClassAttrNewStyleClass.py @@ -0,0 +1,7 @@ +class A(object): + __sizeof__ = 15 + + +a = A() +print(a.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceDunderSizeOfWithInheritedClassAttr.py b/python/testData/resolve/InstanceDunderSizeOfWithInheritedClassAttr.py new file mode 100644 index 000000000000..2e79cdfbf9ea --- /dev/null +++ b/python/testData/resolve/InstanceDunderSizeOfWithInheritedClassAttr.py @@ -0,0 +1,10 @@ +class A(object): + __sizeof__ = 17 + +class B(A): + pass + + +b = B() +print(b.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceInheritedClassAttr.py b/python/testData/resolve/InstanceInheritedClassAttr.py new file mode 100644 index 000000000000..5620fe5d471d --- /dev/null +++ b/python/testData/resolve/InstanceInheritedClassAttr.py @@ -0,0 +1,10 @@ +class A(object): + my_attr = 17 + +class B(A): + pass + + +b = B() +print(b.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceUndeclaredClassAttr.py b/python/testData/resolve/InstanceUndeclaredClassAttr.py new file mode 100644 index 000000000000..a2d386057902 --- /dev/null +++ b/python/testData/resolve/InstanceUndeclaredClassAttr.py @@ -0,0 +1,7 @@ +class A: + pass + + +a = A() +print(a.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/InstanceUndeclaredClassAttrNewStyleClass.py b/python/testData/resolve/InstanceUndeclaredClassAttrNewStyleClass.py new file mode 100644 index 000000000000..72dc3f781122 --- /dev/null +++ b/python/testData/resolve/InstanceUndeclaredClassAttrNewStyleClass.py @@ -0,0 +1,7 @@ +class A(object): + pass + + +a = A() +print(a.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/LocalDunderClass.py b/python/testData/resolve/LocalDunderClass.py new file mode 100644 index 000000000000..01f4adf4e65c --- /dev/null +++ b/python/testData/resolve/LocalDunderClass.py @@ -0,0 +1,5 @@ +class A: + def foo(self): + __class__ = 16 + return __class__ +# \ No newline at end of file diff --git a/python/testData/resolve/TypeClassAttr.py b/python/testData/resolve/TypeClassAttr.py new file mode 100644 index 000000000000..b24b8608b08a --- /dev/null +++ b/python/testData/resolve/TypeClassAttr.py @@ -0,0 +1,6 @@ +class A: + my_attr = 15 + + +print(A.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeClassAttrNewStyleClass.py b/python/testData/resolve/TypeClassAttrNewStyleClass.py new file mode 100644 index 000000000000..5fef732aff6d --- /dev/null +++ b/python/testData/resolve/TypeClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + my_attr = 15 + + +print(A.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderClass.py b/python/testData/resolve/TypeDunderClass.py new file mode 100644 index 000000000000..9dc04760f400 --- /dev/null +++ b/python/testData/resolve/TypeDunderClass.py @@ -0,0 +1,6 @@ +class A: + pass + + +print(A.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderClassNewStyleClass.py b/python/testData/resolve/TypeDunderClassNewStyleClass.py new file mode 100644 index 000000000000..2793517a5778 --- /dev/null +++ b/python/testData/resolve/TypeDunderClassNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + pass + + +print(A.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderClassWithClassAttr.py b/python/testData/resolve/TypeDunderClassWithClassAttr.py new file mode 100644 index 000000000000..3696e7afca7d --- /dev/null +++ b/python/testData/resolve/TypeDunderClassWithClassAttr.py @@ -0,0 +1,6 @@ +class A: + __class__ = 15 + + +print(A.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderClassWithClassAttrNewStyleClass.py b/python/testData/resolve/TypeDunderClassWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..402f7f3ee014 --- /dev/null +++ b/python/testData/resolve/TypeDunderClassWithClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + __class__ = 15 + + +print(A.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderClassWithInheritedClassAttr.py b/python/testData/resolve/TypeDunderClassWithInheritedClassAttr.py new file mode 100644 index 000000000000..907d30dddf17 --- /dev/null +++ b/python/testData/resolve/TypeDunderClassWithInheritedClassAttr.py @@ -0,0 +1,9 @@ +class A(object): + __class__ = 17 + +class B(A): + pass + + +print(B.__class__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderDoc.py b/python/testData/resolve/TypeDunderDoc.py new file mode 100644 index 000000000000..64c531c8b0ed --- /dev/null +++ b/python/testData/resolve/TypeDunderDoc.py @@ -0,0 +1,6 @@ +class A: + pass + + +print(A.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderDocNewStyleClass.py b/python/testData/resolve/TypeDunderDocNewStyleClass.py new file mode 100644 index 000000000000..2c71c76dbc5c --- /dev/null +++ b/python/testData/resolve/TypeDunderDocNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + pass + + +print(A.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderDocWithClassAttr.py b/python/testData/resolve/TypeDunderDocWithClassAttr.py new file mode 100644 index 000000000000..8440e5ded58e --- /dev/null +++ b/python/testData/resolve/TypeDunderDocWithClassAttr.py @@ -0,0 +1,6 @@ +class A: + __doc__ = 16 + + +print(A.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderDocWithClassAttrNewStyleClass.py b/python/testData/resolve/TypeDunderDocWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..a06a2e5e863a --- /dev/null +++ b/python/testData/resolve/TypeDunderDocWithClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + __doc__ = 16 + + +print(A.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderDocWithInheritedClassAttr.py b/python/testData/resolve/TypeDunderDocWithInheritedClassAttr.py new file mode 100644 index 000000000000..77211eb54174 --- /dev/null +++ b/python/testData/resolve/TypeDunderDocWithInheritedClassAttr.py @@ -0,0 +1,9 @@ +class A(object): + __doc__ = 17 + +class B(A): + pass + + +print(B.__doc__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderSizeOf.py b/python/testData/resolve/TypeDunderSizeOf.py new file mode 100644 index 000000000000..a301afe2804c --- /dev/null +++ b/python/testData/resolve/TypeDunderSizeOf.py @@ -0,0 +1,6 @@ +class A: + pass + + +print(A.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderSizeOfNewStyleClass.py b/python/testData/resolve/TypeDunderSizeOfNewStyleClass.py new file mode 100644 index 000000000000..711370afac64 --- /dev/null +++ b/python/testData/resolve/TypeDunderSizeOfNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + pass + + +print(A.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderSizeOfWithClassAttr.py b/python/testData/resolve/TypeDunderSizeOfWithClassAttr.py new file mode 100644 index 000000000000..8c6ef22596fe --- /dev/null +++ b/python/testData/resolve/TypeDunderSizeOfWithClassAttr.py @@ -0,0 +1,6 @@ +class A: + __sizeof__ = 16 + + +print(A.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderSizeOfWithClassAttrNewStyleClass.py b/python/testData/resolve/TypeDunderSizeOfWithClassAttrNewStyleClass.py new file mode 100644 index 000000000000..564f57a45a67 --- /dev/null +++ b/python/testData/resolve/TypeDunderSizeOfWithClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + __sizeof__ = 16 + + +print(A.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeDunderSizeOfWithInheritedClassAttr.py b/python/testData/resolve/TypeDunderSizeOfWithInheritedClassAttr.py new file mode 100644 index 000000000000..4d70493199b3 --- /dev/null +++ b/python/testData/resolve/TypeDunderSizeOfWithInheritedClassAttr.py @@ -0,0 +1,9 @@ +class A(object): + __sizeof__ = 17 + +class B(A): + pass + + +print(B.__sizeof__) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeInheritedClassAttr.py b/python/testData/resolve/TypeInheritedClassAttr.py new file mode 100644 index 000000000000..28b4092ceb6e --- /dev/null +++ b/python/testData/resolve/TypeInheritedClassAttr.py @@ -0,0 +1,9 @@ +class A(object): + my_attr = 17 + +class B(A): + pass + + +print(B.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeUndeclaredClassAttr.py b/python/testData/resolve/TypeUndeclaredClassAttr.py new file mode 100644 index 000000000000..91cfa64f5eae --- /dev/null +++ b/python/testData/resolve/TypeUndeclaredClassAttr.py @@ -0,0 +1,6 @@ +class A: + pass + + +print(A.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/TypeUndeclaredClassAttrNewStyleClass.py b/python/testData/resolve/TypeUndeclaredClassAttrNewStyleClass.py new file mode 100644 index 000000000000..3f2e26f1df93 --- /dev/null +++ b/python/testData/resolve/TypeUndeclaredClassAttrNewStyleClass.py @@ -0,0 +1,6 @@ +class A(object): + pass + + +print(A.my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/UndeclaredClassAttrInDeclaration.py b/python/testData/resolve/UndeclaredClassAttrInDeclaration.py new file mode 100644 index 000000000000..df3a528fd108 --- /dev/null +++ b/python/testData/resolve/UndeclaredClassAttrInDeclaration.py @@ -0,0 +1,3 @@ +class A: + print(my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/UndeclaredClassAttrInDeclarationNewStyleClass.py b/python/testData/resolve/UndeclaredClassAttrInDeclarationNewStyleClass.py new file mode 100644 index 000000000000..cf1bce79bcf8 --- /dev/null +++ b/python/testData/resolve/UndeclaredClassAttrInDeclarationNewStyleClass.py @@ -0,0 +1,3 @@ +class A(object): + print(my_attr) +# \ No newline at end of file diff --git a/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg/__init__.py b/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg/__init__.py new file mode 100644 index 000000000000..3074a5c357d1 --- /dev/null +++ b/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg/__init__.py @@ -0,0 +1,2 @@ +import mod + \ No newline at end of file diff --git a/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg/mod.py b/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg/mod.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg2/__init__.py b/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg2/__init__.py new file mode 100644 index 000000000000..3074a5c357d1 --- /dev/null +++ b/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg2/__init__.py @@ -0,0 +1,2 @@ +import mod + \ No newline at end of file diff --git a/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg2/mod.py b/python/testData/resolve/multiFile/ambiguousImplicitRelativeImport/pkg2/mod.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/testSrc/com/jetbrains/env/PyEnvTaskRunner.java b/python/testSrc/com/jetbrains/env/PyEnvTaskRunner.java index a9eacd86c4ba..e60c81a8f8df 100644 --- a/python/testSrc/com/jetbrains/env/PyEnvTaskRunner.java +++ b/python/testSrc/com/jetbrains/env/PyEnvTaskRunner.java @@ -75,7 +75,7 @@ public class PyEnvTaskRunner { // Exception is thrown anyway, so we escape message before logging if (e.getMessage().contains("enteredTheMatrix")) { // .error( may lead to new exception with out of stacktrace. - logger.warn(e.getMessage().replace("##", "from test: \\##")); + logger.warn(PyEnvTestCase.escapeTestMessage(e.getMessage())); } else { logger.error(e); diff --git a/python/testSrc/com/jetbrains/env/PyEnvTestCase.java b/python/testSrc/com/jetbrains/env/PyEnvTestCase.java index 0582bb633e07..bec4ab9d5663 100644 --- a/python/testSrc/com/jetbrains/env/PyEnvTestCase.java +++ b/python/testSrc/com/jetbrains/env/PyEnvTestCase.java @@ -79,6 +79,13 @@ public abstract class PyEnvTestCase { } }; + /** + * Escape test output to prevent python test be processed as test result + */ + public static String escapeTestMessage(@NotNull final String message) { + return message.replace("##", "from test: \\##"); + } + protected boolean isStaging(Description description) { try { if (description.getTestClass().getMethod(description.getMethodName()).isAnnotationPresent(Staging.class)) { diff --git a/python/testSrc/com/jetbrains/env/PyToxTest.java b/python/testSrc/com/jetbrains/env/PyToxTest.java index ef8873ef665b..c2d1ead9cc30 100644 --- a/python/testSrc/com/jetbrains/env/PyToxTest.java +++ b/python/testSrc/com/jetbrains/env/PyToxTest.java @@ -267,7 +267,7 @@ public final class PyToxTest extends PyEnvTestCase { if (!stderr.isEmpty()) { - Logger.getInstance(PyToxTest.class).warn(stderr); + Logger.getInstance(PyToxTest.class).warn(PyEnvTestCase.escapeTestMessage(stderr)); } @@ -372,9 +372,21 @@ public final class PyToxTest extends PyEnvTestCase { // To help tox with all interpreters, we add all our environments to path // Envs should have binaries like "python2.7" (with version included), // and tox will find em: see tox_get_python_executable @ interpreters.py - final String join = StringUtil.join(getPythonRoots(), File.pathSeparator); - configuration.getEnvs().put("PATH", join); + //On linux we also need shared libs from Anaconda, so we add it to LD_LIBRARY_PATH + final List roots = new ArrayList<>(); + final List libs = new ArrayList<>(); + for (final String root : getPythonRoots()) { + File bin = new File(root, "/bin/"); + roots.add(bin.exists() ? bin.getAbsolutePath() : root); + File lib = new File(root, "/lib/"); + if (lib.exists()) { + libs.add(lib.getAbsolutePath()); + } + } + + configuration.getEnvs().put("PATH", StringUtil.join(roots, File.pathSeparator)); + configuration.getEnvs().put("LD_LIBRARY_PATH", StringUtil.join(libs, File.pathSeparator)); } } diff --git a/python/testSrc/com/jetbrains/python/Py3ResolveTest.java b/python/testSrc/com/jetbrains/python/Py3ResolveTest.java index 9edc7db4230c..4a7458f2ecad 100644 --- a/python/testSrc/com/jetbrains/python/Py3ResolveTest.java +++ b/python/testSrc/com/jetbrains/python/Py3ResolveTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -17,11 +17,15 @@ package com.jetbrains.python; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyResolveTestCase; import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.LanguageLevel; +import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyFunction; +import com.jetbrains.python.psi.PyTargetExpression; +import com.jetbrains.python.psi.impl.PyBuiltinCache; import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; /** @@ -60,4 +64,297 @@ public class Py3ResolveTest extends PyResolveTestCase { public void testTrueDiv() { assertResolvesTo(PyFunction.class, "__truediv__"); } + + // PY-13734 + public void testImplicitDunderClass() { + assertResolvesTo(PyClass.class, "A"); + } + + public void testImplicitDunderDoc() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testImplicitDunderSizeOf() { + assertUnresolved(); + } + + public void testImplicitUndeclaredClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testImplicitDunderClassWithClassAttr() { + assertResolvesTo(PyClass.class, "A"); + } + + public void testImplicitDunderDocWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testImplicitDunderSizeOfWithClassAttr() { + assertUnresolved(); + } + + public void testImplicitClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testImplicitDunderClassWithInheritedClassAttr() { + assertResolvesTo(PyClass.class, "B"); + } + + public void testImplicitDunderDocWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testImplicitDunderSizeOfWithInheritedClassAttr() { + assertUnresolved(); + } + + public void testImplicitInheritedClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testInstanceDunderClass() { + assertResolvesTo(PyClass.class, "A"); + } + + public void testInstanceDunderDoc() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testInstanceDunderSizeOf() { + final PyFunction expression = assertResolvesTo(PyFunction.class, PyNames.SIZEOF); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testInstanceUndeclaredClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testInstanceDunderClassWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceDunderDocWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceDunderSizeOfWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testInstanceDunderClassWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceDunderDocWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testInstanceDunderSizeOfWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testLocalDunderClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyFunction function = PsiTreeUtil.getParentOfType(expression, PyFunction.class); + assertNotNull(function); + assertEquals("foo", function.getName()); + } + + // PY-13734 + public void testTypeDunderClass() { + assertResolvesTo(PyClass.class, "type"); + } + + public void testTypeDunderDoc() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testTypeDunderSizeOf() { + final PyFunction expression = assertResolvesTo(PyFunction.class, PyNames.SIZEOF); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testTypeUndeclaredClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testTypeDunderClassWithClassAttr() { + assertResolvesTo(PyClass.class, "type"); + } + + public void testTypeDunderDocWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeDunderSizeOfWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testTypeDunderClassWithInheritedClassAttr() { + assertResolvesTo(PyClass.class, "type"); + } + + public void testTypeDunderDocWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testTypeDunderSizeOfWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testDunderClassInDeclaration() { + assertUnresolved(); + } + + public void testDunderDocInDeclaration() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testDunderSizeOfInDeclaration() { + assertUnresolved(); + } + + public void testUndeclaredClassAttrInDeclaration() { + assertUnresolved(); + } + + // PY-13734 + public void testDunderClassInDeclarationWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testDunderDocInDeclarationWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testDunderSizeOfInDeclarationWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testClassAttrInDeclaration() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testDunderClassInDeclarationWithInheritedClassAttr() { + assertUnresolved(); + } + + public void testDunderDocInDeclarationWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE_3K, expression.getContainingFile().getName()); + } + + public void testDunderSizeOfInDeclarationWithInheritedClassAttr() { + assertUnresolved(); + } + + public void testInheritedClassAttrInDeclaration() { + assertUnresolved(); + } + + // PY-13734 + public void testDunderClassInDeclarationInsideFunction() { + assertUnresolved(); + } } diff --git a/python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java b/python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java index c0294660b7ff..6d61dfaed139 100644 --- a/python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java @@ -18,6 +18,8 @@ package com.jetbrains.python; import com.google.common.collect.Lists; import com.intellij.openapi.module.Module; import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.source.PsiFileImpl; @@ -26,10 +28,14 @@ import com.jetbrains.python.fixtures.PyMultiFileResolveTestCase; import com.jetbrains.python.fixtures.PyResolveTestCase; import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.*; +import com.jetbrains.python.psi.impl.PyPsiUtils; import com.jetbrains.python.sdk.PythonSdkType; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @author yole @@ -459,4 +465,29 @@ public class PyMultiFileResolveTest extends PyMultiFileResolveTestCase { } } } + + // PY-19989 + public void testAmbiguousImplicitRelativeImport() { + prepareTestDirectory(); + assertSameElements(doMultiResolveAndGetFileUrls("pkg2/__init__.py"), "pkg2/mod.py"); + assertSameElements(doMultiResolveAndGetFileUrls("pkg/__init__.py"), "pkg/mod.py"); + } + + @NotNull + private List doMultiResolveAndGetFileUrls(@NotNull String currentFilePath) { + myFixture.configureByFile(currentFilePath); + final PsiReference reference = PyResolveTestCase.findReferenceByMarker(myFixture.getFile()); + final VirtualFile root = ModuleRootManager.getInstance(myFixture.getModule()).getSourceRoots()[0]; + + final Stream fileSystemItems; + if (reference instanceof PsiPolyVariantReference) { + final ResolveResult[] results = ((PsiPolyVariantReference)reference).multiResolve(false); + fileSystemItems = Arrays.stream(results).map(r -> PyPsiUtils.getFileSystemItem(r.getElement())); + } + else { + fileSystemItems = Stream.of(PyPsiUtils.getFileSystemItem(reference.resolve())); + } + return fileSystemItems.map(f -> VfsUtilCore.getRelativeLocation(f.getVirtualFile(), root)).collect(Collectors.toList()); + + } } \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index 0ba634018415..ea002c2e840b 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -26,6 +26,7 @@ import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; import com.jetbrains.python.documentation.docstrings.DocStringFormat; import com.jetbrains.python.fixtures.PyResolveTestCase; import com.jetbrains.python.psi.*; +import com.jetbrains.python.psi.impl.PyBuiltinCache; import com.jetbrains.python.psi.impl.PyPsiUtils; import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; import com.jetbrains.python.psi.resolve.ImportedResolveResult; @@ -406,7 +407,7 @@ public class PyResolveTest extends PyResolveTestCase { public void testBuiltinVsClassMember() { // PY-1654 final PyFunction pyFunction = assertResolvesTo(PyFunction.class, "eval"); - assertEquals("__builtin__.py", pyFunction.getContainingFile().getName()); + assertEquals(PyBuiltinCache.BUILTIN_FILE, pyFunction.getContainingFile().getName()); } public void testLambdaToClass() { // PY-2182 @@ -740,4 +741,481 @@ public class PyResolveTest extends PyResolveTestCase { assertResolvesTo(PyTargetExpression.class, "foo"); } + // PY-13734 + public void testImplicitDunderClass() { + assertUnresolved(); + } + + public void testImplicitDunderDoc() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testImplicitDunderSizeOf() { + assertUnresolved(); + } + + public void testImplicitUndeclaredClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testImplicitDunderClassNewStyleClass() { + assertUnresolved(); + } + + public void testImplicitDunderDocNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testImplicitDunderSizeOfNewStyleClass() { + assertUnresolved(); + } + + public void testImplicitUndeclaredClassAttrNewStyleClass() { + assertUnresolved(); + } + + // PY-13734 + public void testImplicitDunderClassWithClassAttr() { + assertUnresolved(); + } + + public void testImplicitDunderDocWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testImplicitDunderSizeOfWithClassAttr() { + assertUnresolved(); + } + + public void testImplicitClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testImplicitDunderClassWithClassAttrNewStyleClass() { + assertUnresolved(); + } + + public void testImplicitDunderDocWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testImplicitDunderSizeOfWithClassAttrNewStyleClass() { + assertUnresolved(); + } + + public void testImplicitClassAttrNewStyleClass() { + assertUnresolved(); + } + + // PY-13734 + public void testImplicitDunderClassWithInheritedClassAttr() { + assertUnresolved(); + } + + public void testImplicitDunderDocWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testImplicitDunderSizeOfWithInheritedClassAttr() { + assertUnresolved(); + } + + public void testImplicitInheritedClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testInstanceDunderClass() { + assertResolvesTo(PyClass.class, "A"); + } + + public void testInstanceDunderDoc() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testInstanceDunderSizeOf() { + assertUnresolved(); + } + + public void testInstanceUndeclaredClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testInstanceDunderClassNewStyleClass() { + assertResolvesTo(PyClass.class, "A"); + } + + public void testInstanceDunderDocNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testInstanceDunderSizeOfNewStyleClass() { + final PyFunction expression = assertResolvesTo(PyFunction.class, PyNames.SIZEOF); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testInstanceUndeclaredClassAttrNewStyleClass() { + assertUnresolved(); + } + + // PY-13734 + public void testInstanceDunderClassWithClassAttr() { + assertResolvesTo(PyClass.class, "A"); + } + + public void testInstanceDunderDocWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceDunderSizeOfWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testInstanceDunderClassWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceDunderDocWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceDunderSizeOfWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testInstanceDunderClassWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceDunderDocWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testInstanceDunderSizeOfWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testInstanceInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testLocalDunderClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyFunction function = PsiTreeUtil.getParentOfType(expression, PyFunction.class); + assertNotNull(function); + assertEquals("foo", function.getName()); + } + + // PY-13734 + public void testTypeDunderClass() { + assertUnresolved(); + } + + public void testTypeDunderDoc() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testTypeDunderSizeOf() { + assertUnresolved(); + } + + public void testTypeUndeclaredClassAttr() { + assertUnresolved(); + } + + // PY-13734 + public void testTypeDunderClassNewStyleClass() { + assertResolvesTo(PyClass.class, "type"); + } + + public void testTypeDunderDocNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testTypeDunderSizeOfNewStyleClass() { + final PyFunction expression = assertResolvesTo(PyFunction.class, PyNames.SIZEOF); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testTypeUndeclaredClassAttrNewStyleClass() { + assertUnresolved(); + } + + // PY-13734 + public void testTypeDunderClassWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeDunderDocWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeDunderSizeOfWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testTypeDunderClassWithClassAttrNewStyleClass() { + assertResolvesTo(PyClass.class, "type"); + } + + public void testTypeDunderDocWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeDunderSizeOfWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testTypeDunderClassWithInheritedClassAttr() { + assertResolvesTo(PyClass.class, "type"); + } + + public void testTypeDunderDocWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testTypeDunderSizeOfWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testTypeInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testDunderClassInDeclaration() { + assertUnresolved(); + } + + public void testDunderDocInDeclaration() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testDunderSizeOfInDeclaration() { + assertUnresolved(); + } + + public void testUndeclaredClassAttrInDeclaration() { + assertUnresolved(); + } + + // PY-13734 + public void testDunderClassInDeclarationNewStyleClass() { + assertUnresolved(); + } + + public void testDunderDocInDeclarationNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testDunderSizeOfInDeclarationNewStyleClass() { + assertUnresolved(); + } + + public void testUndeclaredClassAttrInDeclarationNewStyleClass() { + assertUnresolved(); + } + + // PY-13734 + public void testDunderClassInDeclarationWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testDunderDocInDeclarationWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testDunderSizeOfInDeclarationWithClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testClassAttrInDeclaration() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testDunderClassInDeclarationWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.__CLASS__); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testDunderDocInDeclarationWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testDunderSizeOfInDeclarationWithClassAttrNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.SIZEOF); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + public void testClassAttrInDeclarationNewStyleClass() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, "my_attr"); + + final PyClass cls = expression.getContainingClass(); + assertNotNull(cls); + assertEquals("A", cls.getName()); + } + + // PY-13734 + public void testDunderClassInDeclarationWithInheritedClassAttr() { + assertUnresolved(); + } + + public void testDunderDocInDeclarationWithInheritedClassAttr() { + final PyTargetExpression expression = assertResolvesTo(PyTargetExpression.class, PyNames.DOC); + assertEquals(PyBuiltinCache.BUILTIN_FILE, expression.getContainingFile().getName()); + } + + public void testDunderSizeOfInDeclarationWithInheritedClassAttr() { + assertUnresolved(); + } + + public void testInheritedClassAttrInDeclaration() { + assertUnresolved(); + } + + // PY-13734 + public void testDunderClassInDeclarationInsideFunction() { + assertUnresolved(); + } } diff --git a/python/testSrc/com/jetbrains/python/fixtures/PyResolveTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/PyResolveTestCase.java index 99d5a35a43d5..953a21ee1313 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/PyResolveTestCase.java +++ b/python/testSrc/com/jetbrains/python/fixtures/PyResolveTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -89,6 +89,17 @@ public abstract class PyResolveTestCase extends PyTestCase { return assertResolveResult(element, aClass, name, containingFilePath); } + protected void assertUnresolved() { + final PsiElement element; + try { + element = doResolve(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + assertNull(element); + } + public static T assertResolveResult(PsiElement element, Class aClass, String name) { diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java index dc43bc8b5f3a..0814f810f743 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java @@ -136,4 +136,9 @@ public class Py3UnresolvedReferencesInspectionTest extends PyTestCase { public void testDecodeBytesAfterSlicing() { doTest(); } + + // PY-13734 + public void testDunderClass() { + doTest(); + } } diff --git a/python/testSrc/com/jetbrains/python/inspections/PyCompatibilityInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyCompatibilityInspectionTest.java index e869d715e5fe..0f0065f449ad 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyCompatibilityInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyCompatibilityInspectionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -167,8 +167,17 @@ public class PyCompatibilityInspectionTest extends PyTestCase { doTest(LanguageLevel.PYTHON35); } + // PY-19523 + public void testBz2Module() { + doTest(); + } + + public void testUnderscoreBz2Module() { + doTest(); + } + private void doTest(@NotNull LanguageLevel level) { - runWithLanguageLevel(level, () -> doTest()); + runWithLanguageLevel(level, this::doTest); } private void doTest() { diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index 471e48ecac7a..3b2548bddaeb 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -234,17 +234,17 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase { // PY-6745 public void testQualNameAttribute() { - runWithLanguageLevel(LanguageLevel.PYTHON33, () -> doTest()); + runWithLanguageLevel(LanguageLevel.PYTHON33, this::doTest); } // PY-7389 public void testComprehensionScope27() { - runWithLanguageLevel(LanguageLevel.PYTHON27, () -> doTest()); + runWithLanguageLevel(LanguageLevel.PYTHON27, this::doTest); } // PY-7389 public void testComprehensionScope33() { - runWithLanguageLevel(LanguageLevel.PYTHON33, () -> doTest()); + runWithLanguageLevel(LanguageLevel.PYTHON33, this::doTest); } // PY-7516 @@ -724,6 +724,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase { doTest(); } + // PY-13734 + public void testDunderClass() { + doTest(); + } + @NotNull @Override protected Class getInspectionClass() { diff --git a/python/testSrc/com/jetbrains/python/quickFixes/AddImportQuickFixTest.java b/python/testSrc/com/jetbrains/python/quickFixes/AddImportQuickFixTest.java index 969b7cee4028..7eef13fc19a5 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/AddImportQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/quickFixes/AddImportQuickFixTest.java @@ -17,6 +17,7 @@ package com.jetbrains.python.quickFixes; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.ex.QuickFixWrapper; +import com.intellij.util.Processor; import com.intellij.util.containers.ContainerUtil; import com.jetbrains.python.PyQuickFixTestCase; import com.jetbrains.python.codeInsight.imports.AutoImportQuickFix; @@ -26,7 +27,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.function.Consumer; /** * @author Mikhail Golubev @@ -43,6 +43,17 @@ public class AddImportQuickFixTest extends PyQuickFixTestCase { final List candidates = fix.getCandidates(); final List names = ContainerUtil.map(candidates, c -> c.getPresentableText("join")); assertSameElements(names, "os.path.join(path, *paths)"); + return true; + }); + } + + // PY-19975 + public void testCanonicalNamesFromHigherLevelPackage() { + doMultiFileAutoImportTest("Import", fix -> { + final List candidates = fix.getCandidates(); + final List names = ContainerUtil.map(candidates, c -> c.getPresentableText("MyClass")); + assertSameElements(names, "foo.MyClass", "bar.MyClass"); + return true; }); } @@ -50,7 +61,7 @@ public class AddImportQuickFixTest extends PyQuickFixTestCase { doMultiFileAutoImportTest(hintPrefix, null); } - private void doMultiFileAutoImportTest(@NotNull String hintPrefix, @Nullable Consumer checkQuickfix) { + private void doMultiFileAutoImportTest(@NotNull String hintPrefix, @Nullable Processor checkQuickfix) { myFixture.copyDirectoryToProject(getTestName(true), ""); myFixture.enableInspections(PyUnresolvedReferencesInspection.class); final String entryPoint = "main"; @@ -62,10 +73,13 @@ public class AddImportQuickFixTest extends PyQuickFixTestCase { }); assertNotNull("Auto import quick fix starting with '" + hintPrefix + "' wasn't found", intention); final AutoImportQuickFix quickfix = (AutoImportQuickFix)((QuickFixWrapper)intention).getFix(); + boolean applyFix = true; if (checkQuickfix != null) { - checkQuickfix.accept(quickfix); + applyFix = checkQuickfix.process(quickfix); + } + if (applyFix) { + myFixture.launchAction(intention); + myFixture.checkResultByFile(getTestName(true) + "/" + entryPoint + "_after.py", true); } - myFixture.launchAction(intention); - myFixture.checkResultByFile(getTestName(true) + "/" + entryPoint + "_after.py", true); } } diff --git a/resources-en/src/messages/AntBundle.properties b/resources-en/src/messages/AntBundle.properties index e487c69484e4..287d330abd11 100644 --- a/resources-en/src/messages/AntBundle.properties +++ b/resources-en/src/messages/AntBundle.properties @@ -182,8 +182,8 @@ ant.inspections.display.name=Ant inspections ant.duplicate.targets.inspection=Duplicate targets ant.duplicate.imported.targets.inspection=Duplicate targets in imported files ant.missing.properties.file.inspection=Missing properties file -register.ant.build.progress=Registering Ant build file ''{0}''... -loading.ant.config.progress=Loading Ant configuration... +register.ant.build.progress=Registering Ant Build File ''{0}''... +loading.ant.config.progress=Loading Ant Configuration... intention.configure.highlighting.family.name=Configure highlighting intention.configure.highlighting.text=Configure highlighting build.file.properties.maximum.stack.size.label=Maximum &stack size (Mb): diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java index f5b2ba2c22dc..907375546361 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -233,7 +233,7 @@ public class DomHighlightingLiteTest extends DomTestCase { public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) { myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass()); - return new ProblemDescriptor[0]; + return ProblemDescriptor.EMPTY_ARRAY; } @Override @@ -266,7 +266,7 @@ public class DomHighlightingLiteTest extends DomTestCase { public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) { myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass()); - return new ProblemDescriptor[0]; + return ProblemDescriptor.EMPTY_ARRAY; } @Override diff --git a/xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java b/xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java index e3a23d3aa87a..73b4f74c7160 100644 --- a/xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java +++ b/xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -232,7 +232,7 @@ public abstract class AbstractXmlBlock extends AbstractBlock { return collectSubTags((XmlElement)myNode.getPsi()); } else { - return new XmlTag[0]; + return XmlTag.EMPTY; } } diff --git a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/AnyXmlElementDescriptor.java b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/AnyXmlElementDescriptor.java index a50c3a0ffea1..af9b1c90013d 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/AnyXmlElementDescriptor.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/AnyXmlElementDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -98,7 +98,7 @@ public class AnyXmlElementDescriptor implements XmlElementDescriptor { @Override public XmlAttributeDescriptor[] getAttributesDescriptors(final XmlTag context) { - return new XmlAttributeDescriptor[0]; + return XmlAttributeDescriptor.EMPTY; } @Override diff --git a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/NullElementDescriptor.java b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/NullElementDescriptor.java index 63a0c2da0466..477953a89ee5 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/NullElementDescriptor.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/NullElementDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -51,7 +51,7 @@ public class NullElementDescriptor implements XmlElementDescriptor { //todo: refactor to support full DTD spec @Override public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) { - return new XmlElementDescriptor[0]; + return XmlElementDescriptor.EMPTY_ARRAY; } @Override @@ -61,7 +61,7 @@ public class NullElementDescriptor implements XmlElementDescriptor { @Override public XmlAttributeDescriptor[] getAttributesDescriptors(final XmlTag context) { - return new XmlAttributeDescriptor[0]; + return XmlAttributeDescriptor.EMPTY; } @Override