mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
Generated
+3
-3
@@ -1,11 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Groovy">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/groovy-all-2.3.9.jar!/"/>
|
||||
<root url="jar://$PROJECT_DIR$/lib/groovy-all-2.4.6.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/src/groovy-all-2.3.9-sources.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/src/groovy-all-2.4.6-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
</component>
|
||||
Generated
+9
@@ -0,0 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="SceneBuilderKit">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/plugins/javaFX/lib/SceneBuilderKit-8.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -295,9 +295,8 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir
|
||||
jar("common-javaFX-plugin.jar") {
|
||||
module("common-javaFX-plugin")
|
||||
}
|
||||
fileset(dir: "${home}/plugins/javaFX/lib", includes: "SceneBuilderKit-8.1.1.jar");
|
||||
}
|
||||
|
||||
fileset(dir: "${home}/plugins/javaFX/FxBuilderEmbedder/lib", includes: "embedder.jar");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ binding.setVariable("checkLibLicenses", {
|
||||
}
|
||||
}
|
||||
|
||||
def libWithLicenses = licensesList.collectAll {it.libraryNames}.flatten() as Set
|
||||
def libWithLicenses = licensesList.collect {it.libraryNames}.flatten() as Set
|
||||
libWithLicenses.addAll(jetbrainsLibraries)
|
||||
|
||||
List<String> withoutLicenses = []
|
||||
@@ -204,7 +204,7 @@ libraryLicense(name: "gradle-tooling-api-2.9.jar", version: "2.9", license: "Apa
|
||||
libraryLicense(name: "Gradle", version: "2.9", license: "Apache 2.0", url: "http://gradle.org/", licenseUrl: "http://gradle.org/license")
|
||||
libraryLicense(name: "GradleGuava", version: "14.0.1", license: "Apache 2.0", url: "http://code.google.com/p/guava-libraries/", licenseUrl: "http://apache.org/licenses/LICENSE-2.0")
|
||||
libraryLicense(name: "GradleJnaPosix", version: "1.0.3", license: "LGPL 2.1", url: "http://www.jruby.org/", licenseUrl: "http://www.gnu.org/licenses/lgpl-2.1.txt")
|
||||
libraryLicense(name: "Groovy", version: "2.3.9", license: "Apache 2.0", url: "http://groovy.codehaus.org/")
|
||||
libraryLicense(name: "Groovy", version: "2.4.6", license: "Apache 2.0", url: "http://groovy-lang.org/")
|
||||
libraryLicense(name: "Gson", version: "2.2.4", libraryName: "gson", license: "Apache 2.0", url: "http://code.google.com/p/google-gson/")
|
||||
libraryLicense(name: "Guava", libraryName: "guava-tools", version: "14.0.1", license: "Apache 2.0", url: "http://code.google.com/p/guava-libraries/", licenseUrl: "http://ant.apache.org/license.html")
|
||||
libraryLicense(name: "Guava", version: "17.0", license: "Apache 2.0", url: "http://code.google.com/p/guava-libraries/", licenseUrl: "http://ant.apache.org/license.html")
|
||||
@@ -284,6 +284,7 @@ libraryLicense(name: "Rhino JavaScript Engine", libraryName: "rhino-js-1_7R4", v
|
||||
libraryLicense(name: "RMI Stubs", attachedTo: "xslt-debugger-engine", license: "Apache 2.0", url: "https://confluence.jetbrains.com/display/CONTEST/XSLT-Debugger", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0")
|
||||
libraryLicense(name: "Saxon-6.5.5", version: "6.5.5", license: "Mozilla Public License", url: "http://saxon.sourceforge.net/", licenseUrl: "http://www.mozilla.org/MPL/")
|
||||
libraryLicense(name: "Saxon-9HE", version: "9", license: "Mozilla Public License", url: "http://saxon.sourceforge.net/", licenseUrl: "http://www.mozilla.org/MPL/")
|
||||
libraryLicense(name: "SceneBuilderKit", version: "8.1.1", license: "BSD", url: "http://gluonhq.com/open-source/scene-builder/", licenseUrl: "http://www.oracle.com/technetwork/licenses/bsd-license-1835287.html")
|
||||
libraryLicense(name: "Sequence", libraryName: "sequence-library.jar", version: "bundled with SVNKit", license: "BSD (see LICENSE.txt in sequence-library.jar)", url:"http://www.syntevo.com")
|
||||
libraryLicense(name: "six.py", attachedTo: "python-helpers", version: "1.9.0", license: "MIT", url: "http://pythonhosted.org/six/")
|
||||
libraryLicense(name: "Slf4j", version: "1.7.10", license: "MIT License", url: "http://slf4j.org/", licenseUrl: "http://slf4j.org/license.html")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<component>
|
||||
<version codename="Community Edition" major="16" minor="0" eap="true"/>
|
||||
<version codename="Community Edition 16.7" major="2016" minor="2" eap="true"/>
|
||||
<company name="JetBrains s.r.o." url="https://www.jetbrains.com/?fromIDE"/>
|
||||
<build number="__BUILD_NUMBER__" date="__BUILD_DATE__"/>
|
||||
<install-over minbuild="129.1" maxbuild="139.9999" version="14"/>
|
||||
|
||||
@@ -135,7 +135,7 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy {
|
||||
candidates.removeAll(nested2);
|
||||
}
|
||||
|
||||
nestedTypes = candidates.isEmpty()? Collections.<ReferenceType>emptyList() : new ArrayList<>(candidates);
|
||||
nestedTypes = candidates.isEmpty() ? Collections.emptyList() : new ArrayList<>(candidates);
|
||||
}
|
||||
else {
|
||||
nestedTypes = Collections.emptyList();
|
||||
@@ -193,10 +193,7 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy {
|
||||
|
||||
public void threadStarted(ThreadReference thread) {
|
||||
DebuggerManagerThreadImpl.assertIsManagerThread();
|
||||
final Map<ThreadReference, ThreadReferenceProxyImpl> allThreads = myAllThreads;
|
||||
if (!allThreads.containsKey(thread)) {
|
||||
allThreads.put(thread, new ThreadReferenceProxyImpl(this, thread));
|
||||
}
|
||||
getThreadReferenceProxy(thread); // add a proxy
|
||||
}
|
||||
|
||||
public void threadStopped(ThreadReference thread) {
|
||||
@@ -576,13 +573,7 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy {
|
||||
return null;
|
||||
}
|
||||
|
||||
ThreadReferenceProxyImpl proxy = myAllThreads.get(thread);
|
||||
if (proxy == null) {
|
||||
proxy = new ThreadReferenceProxyImpl(this, thread);
|
||||
myAllThreads.put(thread, proxy);
|
||||
}
|
||||
|
||||
return proxy;
|
||||
return myAllThreads.computeIfAbsent(thread, t -> new ThreadReferenceProxyImpl(this, t));
|
||||
}
|
||||
|
||||
public ThreadGroupReferenceProxyImpl getThreadGroupReferenceProxy(ThreadGroupReference group) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.execution.remote.RemoteConfiguration;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.TransactionGuard;
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.compiler.CompileScope;
|
||||
import com.intellij.openapi.compiler.CompileStatusNotification;
|
||||
@@ -140,7 +141,7 @@ public class CompileStepBeforeRun extends BeforeRunTaskProvider<CompileStepBefor
|
||||
}
|
||||
};
|
||||
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
TransactionGuard.submitTransaction(new Runnable() {
|
||||
public void run() {
|
||||
CompileScope scope;
|
||||
final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
|
||||
|
||||
@@ -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.
|
||||
@@ -404,7 +404,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
|
||||
new LibraryInvocationHandler((Library)result));
|
||||
}
|
||||
else if (result instanceof LibraryTable.ModifiableModel) {
|
||||
return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{LibraryTableBase.ModifiableModelEx.class},
|
||||
return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{LibraryTableBase.ModifiableModel.class},
|
||||
new LibraryTableModelInvocationHandler((LibraryTable.ModifiableModel)result));
|
||||
}
|
||||
if (result instanceof Library[]) {
|
||||
|
||||
+2
-2
@@ -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.
|
||||
@@ -38,7 +38,7 @@ import java.util.*;
|
||||
* Date: 04-Jun-2006
|
||||
*/
|
||||
|
||||
public class LibrariesModifiableModel implements LibraryTableBase.ModifiableModelEx {
|
||||
public class LibrariesModifiableModel implements LibraryTableBase.ModifiableModel {
|
||||
//todo[nik] remove LibraryImpl#equals method instead of using identity maps
|
||||
private final Map<Library, ExistingLibraryEditor> myLibrary2EditorMap =
|
||||
ContainerUtil.<Library, ExistingLibraryEditor>newIdentityTroveMap();
|
||||
|
||||
+1
-1
@@ -502,7 +502,7 @@ public class GenericsHighlightUtil {
|
||||
if (unrelatedMethodContainingClass == null) continue;
|
||||
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT) && astracts != null && unrelatedMethodContainingClass.isInterface()) {
|
||||
if (defaultMethodContainingClass.isInheritor(unrelatedMethodContainingClass, true) &&
|
||||
MethodSignatureUtil.isSubsignature(unrelatedMethod.getSignature(PsiSubstitutor.EMPTY),
|
||||
MethodSignatureUtil.isSubsignature(unrelatedMethod.getSignature(TypeConversionUtil.getSuperClassSubstitutor(unrelatedMethodContainingClass, defaultMethodContainingClass, PsiSubstitutor.EMPTY)),
|
||||
defaultMethod.getSignature(PsiSubstitutor.EMPTY))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+26
-2
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -42,7 +43,9 @@ import com.intellij.util.containers.ContainerUtilRt;
|
||||
import com.intellij.util.containers.hash.LinkedHashMap;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.*;
|
||||
@@ -52,6 +55,8 @@ import java.util.*;
|
||||
*/
|
||||
public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
public static final Logger LOG = Logger.getInstance("#" + AnonymousCanBeLambdaInspection.class.getName());
|
||||
|
||||
public boolean reportNotAnnotatedInterfaces = true;
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@@ -78,6 +83,12 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
return "Convert2Lambda";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel("Report when interface is not annotated with @FunctionalInterface", this, "reportNotAnnotatedInterfaces");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
|
||||
@@ -89,7 +100,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
final PsiElement lambdaContext = parent != null ? parent.getParent() : null;
|
||||
if (lambdaContext != null &&
|
||||
(LambdaUtil.isValidLambdaContext(lambdaContext) || !(lambdaContext instanceof PsiExpressionStatement)) &&
|
||||
canBeConvertedToLambda(aClass, false)) {
|
||||
canBeConvertedToLambda(aClass, false, reportNotAnnotatedInterfaces)) {
|
||||
final PsiElement lBrace = aClass.getLBrace();
|
||||
LOG.assertTrue(lBrace != null);
|
||||
final TextRange rangeInElement = new TextRange(0, aClass.getStartOffsetInParent() + lBrace.getStartOffsetInParent());
|
||||
@@ -168,8 +179,21 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
}
|
||||
|
||||
public static boolean canBeConvertedToLambda(PsiAnonymousClass aClass, boolean acceptParameterizedFunctionTypes) {
|
||||
return canBeConvertedToLambda(aClass, acceptParameterizedFunctionTypes, true);
|
||||
}
|
||||
|
||||
public static boolean canBeConvertedToLambda(PsiAnonymousClass aClass,
|
||||
boolean acceptParameterizedFunctionTypes,
|
||||
boolean reportNotAnnotatedInterfaces) {
|
||||
if (PsiUtil.getLanguageLevel(aClass).isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(aClass.getBaseClassType());
|
||||
final PsiClassType baseClassType = aClass.getBaseClassType();
|
||||
final PsiClassType.ClassResolveResult resolveResult = baseClassType.resolveGenerics();
|
||||
final PsiClass baseClass = resolveResult.getElement();
|
||||
if (baseClass == null ||
|
||||
!reportNotAnnotatedInterfaces && !AnnotationUtil.isAnnotated(baseClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, false)) {
|
||||
return false;
|
||||
}
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult);
|
||||
if (interfaceMethod != null && (acceptParameterizedFunctionTypes || !interfaceMethod.hasTypeParameters())) {
|
||||
final PsiMethod[] methods = aClass.getMethods();
|
||||
if (methods.length == 1 &&
|
||||
|
||||
+13
-1
@@ -17,6 +17,7 @@ package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -25,6 +26,9 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.util.RedundantCastUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
@@ -32,6 +36,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class AnonymousCanBeMethodReferenceInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
public static final Logger LOG = Logger.getInstance("#" + AnonymousCanBeMethodReferenceInspection.class.getName());
|
||||
|
||||
public boolean reportNotAnnotatedInterfaces = true;
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -57,6 +63,12 @@ public class AnonymousCanBeMethodReferenceInspection extends BaseJavaBatchLocalI
|
||||
return "Anonymous2MethodRef";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel("Report when interface is not annotated with @FunctionalInterface", this, "reportNotAnnotatedInterfaces");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
|
||||
@@ -64,7 +76,7 @@ public class AnonymousCanBeMethodReferenceInspection extends BaseJavaBatchLocalI
|
||||
@Override
|
||||
public void visitAnonymousClass(PsiAnonymousClass aClass) {
|
||||
super.visitAnonymousClass(aClass);
|
||||
if (AnonymousCanBeLambdaInspection.canBeConvertedToLambda(aClass, true)) {
|
||||
if (AnonymousCanBeLambdaInspection.canBeConvertedToLambda(aClass, true, reportNotAnnotatedInterfaces)) {
|
||||
final PsiMethod method = aClass.getMethods()[0];
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
final PsiCallExpression callExpression =
|
||||
|
||||
+5
-1
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -48,7 +49,10 @@ public class SameReturnValueInspection extends GlobalJavaBatchInspectionTool {
|
||||
message = InspectionsBundle.message("inspection.same.return.value.problem.descriptor2", "<code>" + returnValue + "</code>");
|
||||
}
|
||||
|
||||
return new ProblemDescriptor[] {manager.createProblemDescriptor(refMethod.getElement().getNavigationElement(), message, false, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING)};
|
||||
final PsiModifierListOwner element = refMethod.getElement();
|
||||
if (element != null) {
|
||||
return new ProblemDescriptor[] {manager.createProblemDescriptor(element.getNavigationElement(), message, false, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING)};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ public class FieldCanBeLocalInspectionBase extends BaseJavaBatchLocalInspectionT
|
||||
}
|
||||
|
||||
private static void removeFieldsReferencedFromInitializers(final PsiClass aClass, final Set<PsiField> candidates) {
|
||||
aClass.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
aClass.accept(new JavaRecursiveElementVisitor() {
|
||||
@Override
|
||||
public void visitMethod(PsiMethod method) {
|
||||
if (method.isConstructor()) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../plugins/generate-tostring/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../plugins/generate-tostring/resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="module" module-name="boot" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
|
||||
+3
-7
@@ -72,8 +72,9 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
AutoPopupController.getInstance(context.getProject()).autoPopupMemberLookup(context.getEditor(), null);
|
||||
}
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(position, PsiDocComment.class, false) != null && shouldInsertFqnInJavadoc(item, file, project)) {
|
||||
context.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), getJavadocQualifiedName(psiClass));
|
||||
String qname = psiClass.getQualifiedName();
|
||||
if (qname != null && PsiTreeUtil.getParentOfType(position, PsiDocComment.class, false) != null && shouldInsertFqnInJavadoc(item, file, project)) {
|
||||
context.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), qname);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,11 +123,6 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
}
|
||||
}
|
||||
|
||||
private static String getJavadocQualifiedName(PsiClass psiClass) {
|
||||
PsiClass containingClass = psiClass.getContainingClass();
|
||||
return containingClass != null ? getJavadocQualifiedName(containingClass) + "#" + psiClass.getName() : psiClass.getQualifiedName();
|
||||
}
|
||||
|
||||
private static boolean shouldInsertFqnInJavadoc(@NotNull JavaPsiClassReferenceElement item,
|
||||
@NotNull PsiFile file,
|
||||
@NotNull Project project)
|
||||
|
||||
+4
-1
@@ -230,10 +230,13 @@ public class JavaDocCompletionContributor extends CompletionContributor {
|
||||
document.insertString(startOffset - sharpLength, link);
|
||||
document.insertString(context.getTailOffset(), "}");
|
||||
context.setTailOffset(context.getTailOffset() - 1);
|
||||
context.getOffsetMap().addOffset(CompletionInitializationContext.START_OFFSET, startOffset + link.length() + sharpLength);
|
||||
context.getOffsetMap().addOffset(CompletionInitializationContext.START_OFFSET, startOffset + link.length());
|
||||
|
||||
context.commitDocument();
|
||||
delegate.handleInsert(context, item);
|
||||
if (item.getObject() instanceof PsiField) {
|
||||
context.getEditor().getCaretModel().moveToOffset(context.getTailOffset() + 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,9 @@ public class JavaTypedHandler extends TypedHandlerDelegate {
|
||||
|
||||
@Override
|
||||
public Result beforeCharTyped(final char c, final Project project, final Editor editor, final PsiFile file, final FileType fileType) {
|
||||
if (c == '@' && file instanceof PsiJavaFile) {
|
||||
if (!(file instanceof PsiJavaFile)) return Result.CONTINUE;
|
||||
|
||||
if (c == '@') {
|
||||
autoPopupJavadocLookup(project, editor);
|
||||
}
|
||||
else if (c == '#' || c == '.') {
|
||||
@@ -94,16 +96,13 @@ public class JavaTypedHandler extends TypedHandlerDelegate {
|
||||
|
||||
//important to calculate before inserting charTyped
|
||||
myJavaLTTyped = '<' == c &&
|
||||
file instanceof PsiJavaFile &&
|
||||
!(file instanceof JspFile) &&
|
||||
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET &&
|
||||
PsiUtil.isLanguageLevel5OrHigher(file) &&
|
||||
isAfterClassLikeIdentifierOrDot(offsetBefore, editor);
|
||||
|
||||
if ('>' == c) {
|
||||
if (file instanceof PsiJavaFile && !(file instanceof JspFile) &&
|
||||
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET &&
|
||||
PsiUtil.isLanguageLevel5OrHigher(file)) {
|
||||
if (!(file instanceof JspFile) && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && PsiUtil.isLanguageLevel5OrHigher(file)) {
|
||||
if (handleJavaGT(editor, JavaTokenType.LT, JavaTokenType.GT, INVALID_INSIDE_REFERENCE)) return Result.STOP;
|
||||
}
|
||||
}
|
||||
|
||||
+87
-49
@@ -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.
|
||||
@@ -19,7 +19,6 @@ import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.lang.LangBundle;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -30,15 +29,21 @@ import java.util.List;
|
||||
public class HighlightExceptionsHandler extends HighlightUsagesHandlerBase<PsiClass> {
|
||||
private final PsiElement myTarget;
|
||||
private final PsiClassType[] myClassTypes;
|
||||
private final PsiElement myPlace;
|
||||
private final PsiElement myPlace, myOtherPlace;
|
||||
private final Condition<PsiType> myTypeFilter;
|
||||
|
||||
public HighlightExceptionsHandler(final Editor editor, final PsiFile file, final PsiElement target, final PsiClassType[] classTypes,
|
||||
final PsiElement place, final Condition<PsiType> typeFilter) {
|
||||
public HighlightExceptionsHandler(Editor editor,
|
||||
PsiFile file,
|
||||
PsiElement target,
|
||||
PsiClassType[] classTypes,
|
||||
PsiElement place,
|
||||
PsiElement otherPlace,
|
||||
Condition<PsiType> typeFilter) {
|
||||
super(editor, file);
|
||||
myTarget = target;
|
||||
myClassTypes = classTypes;
|
||||
myPlace = place;
|
||||
myOtherPlace = otherPlace;
|
||||
myTypeFilter = typeFilter;
|
||||
}
|
||||
|
||||
@@ -59,53 +64,58 @@ public class HighlightExceptionsHandler extends HighlightUsagesHandlerBase<PsiCl
|
||||
|
||||
@Override
|
||||
public void computeUsages(final List<PsiClass> targets) {
|
||||
final Project project = myEditor.getProject();
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
|
||||
|
||||
addOccurrence(myTarget);
|
||||
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(myEditor.getProject()).getElementFactory();
|
||||
for (PsiClass aClass : targets) {
|
||||
addExceptionThrownPlaces(factory.createType(aClass));
|
||||
addExceptionThrowPlaces(factory.createType(aClass), myPlace);
|
||||
if (myOtherPlace != null) {
|
||||
addExceptionThrowPlaces(factory.createType(aClass), myOtherPlace);
|
||||
}
|
||||
}
|
||||
buildStatusText(LangBundle.message("java.terms.exception"), myReadUsages.size()-1 /* exclude target */);
|
||||
|
||||
buildStatusText(LangBundle.message("java.terms.exception"), myReadUsages.size() - 1 /* exclude target */);
|
||||
}
|
||||
|
||||
private void addExceptionThrownPlaces(final PsiType type) {
|
||||
if (type instanceof PsiClassType) {
|
||||
myPlace.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
visitElement(expression);
|
||||
}
|
||||
private void addExceptionThrowPlaces(PsiClassType type, PsiElement place) {
|
||||
place.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
visitElement(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThrowStatement(PsiThrowStatement statement) {
|
||||
super.visitThrowStatement(statement);
|
||||
final List<PsiClassType> actualTypes = ExceptionUtil.getUnhandledExceptions(statement, myPlace);
|
||||
for (PsiClassType actualType : actualTypes) {
|
||||
if (actualType != null && type.isAssignableFrom(actualType) && myTypeFilter.value(actualType)) {
|
||||
PsiExpression psiExpression = statement.getException();
|
||||
if (psiExpression instanceof PsiReferenceExpression) {
|
||||
addOccurrence(psiExpression);
|
||||
@Override
|
||||
public void visitThrowStatement(PsiThrowStatement statement) {
|
||||
super.visitThrowStatement(statement);
|
||||
List<PsiClassType> actualTypes = ExceptionUtil.getUnhandledExceptions(statement, place);
|
||||
for (PsiClassType actualType : actualTypes) {
|
||||
if (actualType != null && type.isAssignableFrom(actualType) && myTypeFilter.value(actualType)) {
|
||||
PsiExpression psiExpression = statement.getException();
|
||||
if (psiExpression instanceof PsiReferenceExpression) {
|
||||
addOccurrence(psiExpression);
|
||||
}
|
||||
else if (psiExpression instanceof PsiNewExpression) {
|
||||
PsiJavaCodeReferenceElement ref = ((PsiNewExpression)psiExpression).getClassReference();
|
||||
if (ref != null) {
|
||||
addOccurrence(ref);
|
||||
}
|
||||
else if (psiExpression instanceof PsiNewExpression) {
|
||||
PsiJavaCodeReferenceElement ref = ((PsiNewExpression)psiExpression).getClassReference();
|
||||
if (ref != null) {
|
||||
addOccurrence(ref);
|
||||
}
|
||||
}
|
||||
else {
|
||||
addOccurrence(statement.getException());
|
||||
}
|
||||
else {
|
||||
PsiExpression exception = statement.getException();
|
||||
if (exception != null) {
|
||||
addOccurrence(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
PsiReference reference = expression.getMethodExpression().getReference();
|
||||
if (reference == null) return;
|
||||
List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledExceptions(expression, myPlace);
|
||||
@Override
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
PsiReference reference = expression.getMethodExpression().getReference();
|
||||
if (reference != null) {
|
||||
List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledExceptions(expression, place);
|
||||
for (final PsiClassType actualType : exceptionTypes) {
|
||||
if (type.isAssignableFrom(actualType) && myTypeFilter.value(actualType)) {
|
||||
addOccurrence(expression.getMethodExpression());
|
||||
@@ -113,13 +123,14 @@ public class HighlightExceptionsHandler extends HighlightUsagesHandlerBase<PsiCl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(PsiNewExpression expression) {
|
||||
super.visitNewExpression(expression);
|
||||
PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
|
||||
if (classReference == null) return;
|
||||
List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledExceptions(expression, myPlace);
|
||||
@Override
|
||||
public void visitNewExpression(PsiNewExpression expression) {
|
||||
super.visitNewExpression(expression);
|
||||
PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
|
||||
if (classReference != null) {
|
||||
List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledExceptions(expression, place);
|
||||
for (PsiClassType actualType : exceptionTypes) {
|
||||
if (type.isAssignableFrom(actualType) && myTypeFilter.value(actualType)) {
|
||||
addOccurrence(classReference);
|
||||
@@ -127,7 +138,34 @@ public class HighlightExceptionsHandler extends HighlightUsagesHandlerBase<PsiCl
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitResourceExpression(PsiResourceExpression expression) {
|
||||
super.visitResourceExpression(expression);
|
||||
List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledCloserExceptions(expression, place);
|
||||
for (PsiClassType actualType : exceptionTypes) {
|
||||
if (type.isAssignableFrom(actualType) && myTypeFilter.value(actualType)) {
|
||||
addOccurrence(expression);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitResourceVariable(PsiResourceVariable variable) {
|
||||
super.visitResourceVariable(variable);
|
||||
List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledCloserExceptions(variable, place);
|
||||
for (PsiClassType actualType : exceptionTypes) {
|
||||
if (type.isAssignableFrom(actualType) && myTypeFilter.value(actualType)) {
|
||||
PsiIdentifier name = variable.getNameIdentifier();
|
||||
if (name != null) {
|
||||
addOccurrence(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
-49
@@ -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.
|
||||
@@ -24,8 +24,8 @@ import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -49,70 +49,56 @@ public class HighlightExceptionsHandlerFactory extends HighlightUsagesHandlerFac
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightUsagesHandlerBase createHighlightTryHandler(final Editor editor,
|
||||
final PsiFile file,
|
||||
final PsiElement target,
|
||||
final PsiElement parent) {
|
||||
final PsiTryStatement tryStatement = (PsiTryStatement)parent;
|
||||
private static HighlightUsagesHandlerBase createHighlightTryHandler(Editor editor, PsiFile file, PsiElement target, PsiElement parent) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.highlight.throws");
|
||||
final PsiCodeBlock tryBlock = tryStatement.getTryBlock();
|
||||
|
||||
PsiCodeBlock tryBlock = ((PsiTryStatement)parent).getTryBlock();
|
||||
if (tryBlock == null) return null;
|
||||
final Collection<PsiClassType> psiClassTypes = ExceptionUtil.collectUnhandledExceptions(tryBlock, tryBlock);
|
||||
return new HighlightExceptionsHandler(editor, file, target, psiClassTypes.toArray(new PsiClassType[psiClassTypes.size()]), tryBlock, Conditions.<PsiType>alwaysTrue());
|
||||
|
||||
Collection<PsiClassType> unhandled = ExceptionUtil.collectUnhandledExceptions(tryBlock, tryBlock);
|
||||
PsiClassType[] types = unhandled.toArray(new PsiClassType[unhandled.size()]);
|
||||
return new HighlightExceptionsHandler(editor, file, target, types, tryBlock, null, Conditions.alwaysTrue());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightUsagesHandlerBase createHighlightCatchHandler(final Editor editor,
|
||||
final PsiFile file,
|
||||
final PsiElement target,
|
||||
final PsiElement parent) {
|
||||
final PsiCatchSection catchSection = (PsiCatchSection)parent;
|
||||
private static HighlightUsagesHandlerBase createHighlightCatchHandler(Editor editor, PsiFile file, PsiElement target, PsiElement parent) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.highlight.throws");
|
||||
|
||||
PsiTryStatement tryStatement = catchSection.getTryStatement();
|
||||
PsiTryStatement tryStatement = ((PsiCatchSection)parent).getTryStatement();
|
||||
PsiParameter parameter = ((PsiCatchSection)parent).getParameter();
|
||||
PsiCodeBlock tryBlock = tryStatement.getTryBlock();
|
||||
PsiResourceList resourceList = tryStatement.getResourceList();
|
||||
if (parameter == null || tryBlock == null) return null;
|
||||
|
||||
final PsiParameter param = catchSection.getParameter();
|
||||
if (param == null) return null;
|
||||
|
||||
final PsiParameter[] catchBlockParameters = tryStatement.getCatchBlockParameters();
|
||||
|
||||
final Collection<PsiClassType> allThrownExceptions = ExceptionUtil.collectUnhandledExceptions(tryStatement.getTryBlock(),
|
||||
tryStatement.getTryBlock());
|
||||
Condition<PsiType> filter = new Condition<PsiType>() {
|
||||
@Override
|
||||
public boolean value(PsiType type) {
|
||||
for (PsiParameter parameter : catchBlockParameters) {
|
||||
boolean isAssignable = parameter.getType().isAssignableFrom(type);
|
||||
if (parameter != param) {
|
||||
if (isAssignable) return false;
|
||||
}
|
||||
else {
|
||||
return isAssignable;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
PsiParameter[] parameters = tryStatement.getCatchBlockParameters();
|
||||
Condition<PsiType> filter = type -> {
|
||||
for (PsiParameter p : parameters) {
|
||||
boolean isAssignable = p.getType().isAssignableFrom(type);
|
||||
if (p == parameter) return isAssignable;
|
||||
else if (isAssignable) return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
ArrayList<PsiClassType> filtered = new ArrayList<PsiClassType>();
|
||||
for (PsiClassType type : allThrownExceptions) {
|
||||
if (filter.value(type)) filtered.add(type);
|
||||
Stream<PsiClassType> unhandled = ExceptionUtil.collectUnhandledExceptions(tryBlock, tryBlock).stream();
|
||||
if (resourceList != null) {
|
||||
unhandled = Stream.concat(unhandled, ExceptionUtil.collectUnhandledExceptions(resourceList, resourceList).stream());
|
||||
}
|
||||
|
||||
return new HighlightExceptionsHandler(editor, file, target, filtered.toArray(new PsiClassType[filtered.size()]),
|
||||
tryStatement.getTryBlock(), filter);
|
||||
PsiClassType[] types = unhandled.filter(filter::value).toArray(PsiClassType[]::new);
|
||||
return new HighlightExceptionsHandler(editor, file, target, types, tryBlock, resourceList, filter);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightUsagesHandlerBase createThrowsHandler(final Editor editor, final PsiFile file, final PsiElement target) {
|
||||
private static HighlightUsagesHandlerBase createThrowsHandler(Editor editor, PsiFile file, PsiElement target) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.highlight.throws");
|
||||
|
||||
PsiElement grand = target.getParent().getParent();
|
||||
if (!(grand instanceof PsiMethod)) return null;
|
||||
PsiMethod method = (PsiMethod)grand;
|
||||
if (method.getBody() == null) return null;
|
||||
PsiCodeBlock body = ((PsiMethod)grand).getBody();
|
||||
if (body == null) return null;
|
||||
|
||||
final Collection<PsiClassType> psiClassTypes = ExceptionUtil.collectUnhandledExceptions(method.getBody(), method.getBody());
|
||||
|
||||
return new HighlightExceptionsHandler(editor, file, target, psiClassTypes.toArray(new PsiClassType[psiClassTypes.size()]), method.getBody(), Conditions.<PsiType>alwaysTrue());
|
||||
Collection<PsiClassType> unhandled = ExceptionUtil.collectUnhandledExceptions(body, body);
|
||||
PsiClassType[] types = unhandled.toArray(new PsiClassType[unhandled.size()]);
|
||||
return new HighlightExceptionsHandler(editor, file, target, types, body, null, Conditions.alwaysTrue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,12 +104,7 @@ public class MacroUtil {
|
||||
PsiElement scope = place;
|
||||
boolean innermostClass = true;
|
||||
while (scope != null) {
|
||||
if (scope instanceof PsiMethod && ((PsiMethod)scope).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
// Method is static, we don't want to add its enclosing class to the list of returned expressions.
|
||||
// Since this loop only can potentially add enclosing classes, just break out of it.
|
||||
break;
|
||||
}
|
||||
else if (scope instanceof PsiClass) {
|
||||
if (scope instanceof PsiClass) {
|
||||
PsiClass aClass = (PsiClass)scope;
|
||||
String name = aClass.getName();
|
||||
if (innermostClass) {
|
||||
|
||||
@@ -44,8 +44,8 @@ public class JavaMembersGetter extends MembersGetter {
|
||||
}
|
||||
|
||||
public void addMembers(boolean searchInheritors, final Consumer<LookupElement> results) {
|
||||
addConstantsFromTargetClass(results, searchInheritors);
|
||||
if (myExpectedType instanceof PsiPrimitiveType && PsiType.DOUBLE.isAssignableFrom(myExpectedType)) {
|
||||
addConstantsFromTargetClass(results, searchInheritors);
|
||||
addConstantsFromReferencedClassesInSwitch(results);
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -113,8 +113,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
else if (usage instanceof MethodReferenceUsageInfo && MethodReferenceUsageInfo.needToExpand((JavaChangeInfo)changeInfo)) {
|
||||
final PsiElement element = usage.getElement();
|
||||
if (element instanceof PsiMethodReferenceExpression ) {
|
||||
final PsiLambdaExpression lambdaExpression = LambdaRefactoringUtil.convertMethodReferenceToLambda((PsiMethodReferenceExpression)element, false, true);
|
||||
final PsiExpression expression = LambdaUtil.extractSingleExpressionFromBody(lambdaExpression.getBody());
|
||||
final PsiExpression expression = LambdaRefactoringUtil.convertToMethodCallInLambdaBody((PsiMethodReferenceExpression)element);
|
||||
if (expression instanceof PsiCallExpression) {
|
||||
((MethodReferenceUsageInfo)usage).setCallExpression((PsiCallExpression)expression);
|
||||
return true;
|
||||
@@ -132,8 +131,10 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
else if (element instanceof PsiMethodReferenceExpression) {
|
||||
final PsiLambdaExpression lambdaExpression =
|
||||
LambdaRefactoringUtil.convertMethodReferenceToLambda((PsiMethodReferenceExpression)element, false, true);
|
||||
processMethodParams(((JavaChangeInfo)changeInfo), interfaceMethod, elementFactory, PsiSubstitutor.EMPTY,
|
||||
lambdaExpression.getParameterList(), lambdaExpression.getBody());
|
||||
if (lambdaExpression != null) {
|
||||
processMethodParams(((JavaChangeInfo)changeInfo), interfaceMethod, elementFactory, PsiSubstitutor.EMPTY,
|
||||
lambdaExpression.getParameterList(), lambdaExpression.getBody());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1007,7 +1008,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
checkContract(conflictDescriptions, method);
|
||||
}
|
||||
else if (element instanceof PsiMethodReferenceExpression && MethodReferenceUsageInfo.needToExpand(myChangeInfo)) {
|
||||
conflictDescriptions.putValue(element, "Changed method is used in method reference. Proceeding would result in conversion to lambda expression");
|
||||
conflictDescriptions.putValue(element, RefactoringBundle.message("expand.method.reference.warning"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -131,7 +131,8 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
|
||||
for (PsiMethod usedMethod : usedMethods) {
|
||||
if (usedMethod.getModifierList().hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
if (usedMethod.hasModifierProperty(PsiModifier.PRIVATE) &&
|
||||
(!usedMethod.hasModifierProperty(PsiModifier.STATIC) || myExtractProcessor.isStatic())) {
|
||||
PsiMethod toMove = usedMethod;
|
||||
for (PsiReference reference : ReferencesSearch.search(usedMethod)) {
|
||||
if (!PsiTreeUtil.isAncestor(getMethod(), reference.getElement(), false)) {
|
||||
@@ -333,12 +334,14 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
for (PsiVariable variable : outputVariables) {
|
||||
PsiVariable var = (PsiVariable)declaredElement;
|
||||
if (Comparing.strEqual(var.getName(), variable.getName())) {
|
||||
final PsiExpression initializer = var.getInitializer();
|
||||
PsiExpression initializer = var.getInitializer();
|
||||
if (initializer == null) {
|
||||
replacementMap.put(statement, null);
|
||||
replacementMap.put(var, null);
|
||||
}
|
||||
else {
|
||||
replacementMap.put(var, var);
|
||||
PsiStatement assignmentStatement = myElementFactory
|
||||
.createStatementFromText(var2FieldNames.get(variable.getName()) + " = " + initializer.getText() + ";", statement);
|
||||
replacementMap.put(var, assignmentStatement);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,14 +376,11 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
final PsiElement replacement = replacementMap.get(statement);
|
||||
if (replacement != null) {
|
||||
if (statement instanceof PsiLocalVariable) {
|
||||
final PsiLocalVariable variable = (PsiLocalVariable)statement;
|
||||
PsiLocalVariable variable = (PsiLocalVariable)statement;
|
||||
variable.normalizeDeclaration();
|
||||
final PsiExpression initializer = variable.getInitializer();
|
||||
LOG.assertTrue(initializer != null);
|
||||
final PsiStatement assignmentStatement = myElementFactory.createStatementFromText(var2FieldNames.get(variable.getName()) + " = " + initializer.getText() + ";", statement);
|
||||
final PsiDeclarationStatement declaration = PsiTreeUtil.getParentOfType(statement, PsiDeclarationStatement.class);
|
||||
PsiDeclarationStatement declaration = PsiTreeUtil.getParentOfType(statement, PsiDeclarationStatement.class);
|
||||
LOG.assertTrue(declaration != null);
|
||||
declaration.replace(assignmentStatement);
|
||||
declaration.replace(replacement);
|
||||
} else {
|
||||
if (statement instanceof PsiReturnStatement) {
|
||||
final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue();
|
||||
|
||||
@@ -510,6 +510,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
private void inlineMethodReference(PsiMethodReferenceExpression reference) {
|
||||
final PsiLambdaExpression lambdaExpression = LambdaRefactoringUtil.convertMethodReferenceToLambda(reference, false, false);
|
||||
if (lambdaExpression == null) return;
|
||||
final PsiExpression callExpression = LambdaUtil.extractSingleExpressionFromBody(lambdaExpression.getBody());
|
||||
if (callExpression instanceof PsiMethodCallExpression) {
|
||||
inlineMethodCall(((PsiMethodCallExpression)callExpression).getMethodExpression());
|
||||
|
||||
+29
-7
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
@@ -30,7 +31,9 @@ import com.intellij.psi.impl.source.resolve.DefaultParameterTypeInferencePolicy;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.util.FieldConflictsResolver;
|
||||
import com.intellij.refactoring.util.LambdaRefactoringUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.refactoring.util.javadoc.MethodJavaDocHelper;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
@@ -60,8 +63,17 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
|
||||
}
|
||||
|
||||
public boolean processChangeMethodUsage(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
|
||||
if (!isMethodUsage(usage)) return true;
|
||||
final PsiElement ref = usage.getElement();
|
||||
PsiElement ref = usage.getElement();
|
||||
if (ref instanceof PsiMethodReferenceExpression) {
|
||||
final PsiExpression callExpression = LambdaRefactoringUtil.convertToMethodCallInLambdaBody((PsiMethodReferenceExpression)ref);
|
||||
if (callExpression == null) {
|
||||
return true;
|
||||
}
|
||||
ref = callExpression;
|
||||
}
|
||||
else if (!isMethodUsage(usage)) {
|
||||
return true;
|
||||
}
|
||||
PsiCall callExpression = RefactoringUtil.getCallExpressionByMethodReference(ref);
|
||||
PsiExpressionList argList = RefactoringUtil.getArgumentListByMethodReference(ref);
|
||||
if (argList == null) return true;
|
||||
@@ -113,7 +125,7 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
|
||||
|
||||
final PsiExpressionList argumentList = callExpression.getArgumentList();
|
||||
LOG.assertTrue(argumentList != null, callExpression.getText());
|
||||
removeParametersFromCall(argumentList, data.getParametersToRemove());
|
||||
removeParametersFromCall(argumentList, data.getParametersToRemove(), methodToSearchFor);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -130,12 +142,19 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
|
||||
JavaPsiFacade.getElementFactory(project));
|
||||
}
|
||||
|
||||
private static void removeParametersFromCall(@NotNull final PsiExpressionList argList, TIntArrayList parametersToRemove) {
|
||||
private static void removeParametersFromCall(@NotNull final PsiExpressionList argList, TIntArrayList parametersToRemove, PsiMethod method) {
|
||||
final int parametersCount = method.getParameterList().getParametersCount();
|
||||
final PsiExpression[] exprs = argList.getExpressions();
|
||||
parametersToRemove.forEachDescending(new TIntProcedure() {
|
||||
public boolean execute(final int paramNum) {
|
||||
public boolean execute(int paramNum) {
|
||||
try {
|
||||
if (paramNum < exprs.length) {
|
||||
//parameter was introduced before varargs
|
||||
if (method.isVarArgs() && paramNum == parametersCount - 1) {
|
||||
for (int i = paramNum + 1; i < exprs.length; i++) {
|
||||
exprs[i].delete();
|
||||
}
|
||||
}
|
||||
else if (paramNum < exprs.length) {
|
||||
exprs[paramNum].delete();
|
||||
}
|
||||
}
|
||||
@@ -164,8 +183,11 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
|
||||
final PsiMethod method = data.getMethodToReplaceIn();
|
||||
final int parametersCount = method.getParameterList().getParametersCount();
|
||||
for (UsageInfo usage : usages) {
|
||||
if (!isMethodUsage(usage)) continue;
|
||||
final PsiElement element = usage.getElement();
|
||||
if (element instanceof PsiMethodReferenceExpression && !ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
conflicts.putValue(element, RefactoringBundle.message("expand.method.reference.warning"));
|
||||
}
|
||||
if (!isMethodUsage(usage)) continue;
|
||||
final PsiCall call = RefactoringUtil.getCallExpressionByMethodReference(element);
|
||||
final PsiExpressionList argList = call.getArgumentList();
|
||||
if (argList != null) {
|
||||
|
||||
+60
-6
@@ -18,13 +18,18 @@ package com.intellij.refactoring.introduceParameter;
|
||||
import com.intellij.codeInsight.generation.GenerateMembersUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.IntroduceParameterRefactoring;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -92,6 +97,10 @@ public class OldReferenceResolver {
|
||||
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();
|
||||
|
||||
replaceOldRefWithNew(mappingsSet, factory);
|
||||
}
|
||||
|
||||
private static void replaceOldRefWithNew(Set<Map.Entry<PsiExpression, String>> mappingsSet, PsiElementFactory factory) {
|
||||
for (Map.Entry<PsiExpression, String> entry : mappingsSet) {
|
||||
PsiExpression oldRef = entry.getKey();
|
||||
PsiElement newRef = factory.createExpressionFromText(entry.getValue(), null);
|
||||
@@ -120,15 +129,31 @@ public class OldReferenceResolver {
|
||||
PsiParameterList parameterList = myMethodToReplaceIn.getParameterList();
|
||||
|
||||
if (subj.getParent() != parameterList) return;
|
||||
int index = parameterList.getParameterIndex((PsiParameter)subj);
|
||||
final PsiParameter parameter = (PsiParameter)subj;
|
||||
int index = parameterList.getParameterIndex(parameter);
|
||||
if (index < 0) return;
|
||||
if (index < myActualArgs.length) {
|
||||
PsiExpression actualArg = myActualArgs[index];
|
||||
int copyingSafetyLevel = RefactoringUtil.verifySafeCopyExpression(actualArg);
|
||||
if (copyingSafetyLevel == RefactoringUtil.EXPR_COPY_PROHIBITED) {
|
||||
actualArg = factory.createExpressionFromText(getTempVar(actualArg), null);
|
||||
PsiExpression initializer = actualArg;
|
||||
|
||||
final PsiType parameterType = parameter.getType();
|
||||
if (parameter.isVarArgs() && parameterType instanceof PsiEllipsisType) {
|
||||
final String varargsJoin = StringUtil.join(ContainerUtil.map2Array(myActualArgs, String.class, new Function<PsiExpression, String>() {
|
||||
@Override
|
||||
public String fun(PsiExpression expression) {
|
||||
return expression != null ? expression.getText() : "null";
|
||||
}
|
||||
}), index + 1, myActualArgs.length, ",");
|
||||
String newArrayInitializer = "new " + ((PsiEllipsisType)parameterType).toArrayType().getCanonicalText() + " {" + varargsJoin + "}";
|
||||
initializer = replaceInitializerWithVarargSubstitution(factory, parameter, initializer, newArrayInitializer);
|
||||
}
|
||||
|
||||
if (RefactoringUtil.verifySafeCopyExpression(actualArg) == RefactoringUtil.EXPR_COPY_PROHIBITED) {
|
||||
newExpr = newExpr.replace(factory.createExpressionFromText(getTempVar(actualArg, initializer), null));
|
||||
}
|
||||
else {
|
||||
newExpr = newExpr.replace(initializer);
|
||||
}
|
||||
newExpr = newExpr.replace(actualArg);
|
||||
}
|
||||
}
|
||||
// "naked" field and methods (should become qualified)
|
||||
@@ -188,6 +213,31 @@ public class OldReferenceResolver {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiExpression replaceInitializerWithVarargSubstitution(PsiElementFactory factory,
|
||||
final PsiParameter parameter,
|
||||
PsiExpression initializer, String newArrayInitializer) {
|
||||
final String tempVar = getTempVar(factory.createExpressionFromText(newArrayInitializer, myContext));
|
||||
final Map<PsiExpression, String> map = new HashMap<>();
|
||||
if (initializer instanceof PsiReferenceExpression && Comparing.strEqual(parameter.getName(), initializer.getText())) {
|
||||
initializer = factory.createExpressionFromText(tempVar, myContext);
|
||||
}
|
||||
else {
|
||||
initializer = (PsiExpression)initializer.copy();
|
||||
initializer.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
if (Comparing.strEqual(parameter.getName(), expression.getText())) {
|
||||
map.put(expression, tempVar);
|
||||
}
|
||||
}
|
||||
});
|
||||
replaceOldRefWithNew(map.entrySet(), factory);
|
||||
}
|
||||
return initializer;
|
||||
}
|
||||
|
||||
private PsiExpression getInstanceRef(PsiElementFactory factory) throws IncorrectOperationException {
|
||||
int copyingSafetyLevel = RefactoringUtil.verifySafeCopyExpression(myInstanceRef);
|
||||
|
||||
@@ -199,12 +249,16 @@ public class OldReferenceResolver {
|
||||
}
|
||||
|
||||
private String getTempVar(PsiExpression expr) throws IncorrectOperationException {
|
||||
return getTempVar(expr, expr);
|
||||
}
|
||||
|
||||
private String getTempVar(PsiExpression expr, PsiExpression initializer) throws IncorrectOperationException {
|
||||
String id = myTempVars.get(expr);
|
||||
if (id != null) {
|
||||
return id;
|
||||
}
|
||||
else {
|
||||
id = RefactoringUtil.createTempVar(expr, myContext, true);
|
||||
id = RefactoringUtil.createTempVar(initializer, myContext, true);
|
||||
myTempVars.put(expr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
+4
-2
@@ -220,12 +220,14 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
|
||||
final String paramName = parameterChunk != null ? parameterChunk.parameter.name : replacedParameter.getName();
|
||||
final PsiType paramType = parameterChunk != null ? parameterChunk.parameter.type : replacedParameter.getType();
|
||||
if (getter == null) {
|
||||
getter = GenerateMembersUtil.suggestGetterName(paramName, paramType, myProject);
|
||||
getter = parameterChunk != null && parameterChunk.field != null ? GenerateMembersUtil.suggestGetterName(parameterChunk.field)
|
||||
: GenerateMembersUtil.suggestGetterName(paramName, paramType, myProject);
|
||||
paramsNeedingGetters.add(replacedParameter);
|
||||
}
|
||||
@NonNls String setter = parameterChunk != null ? parameterChunk.setter : null;
|
||||
if (setter == null) {
|
||||
setter = GenerateMembersUtil.suggestSetterName(paramName, paramType, myProject);
|
||||
setter = parameterChunk != null && parameterChunk.field != null ? GenerateMembersUtil.suggestSetterName(parameterChunk.field)
|
||||
: GenerateMembersUtil.suggestSetterName(paramName, paramType, myProject);
|
||||
}
|
||||
if (RefactoringUtil.isPlusPlusOrMinusMinus(paramUsage.getParent())) {
|
||||
usages.add(new ReplaceParameterIncrementDecrement(paramUsage, fixedParamName, setter, getter));
|
||||
|
||||
+9
-2
@@ -28,6 +28,7 @@ import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.LambdaRefactoringUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Query;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
@@ -168,7 +169,13 @@ public class JavaInvertBooleanDelegate extends InvertBooleanDelegate {
|
||||
expression = expression.getParent();
|
||||
}
|
||||
|
||||
if (!(expression.getParent() instanceof PsiExpressionStatement)) {
|
||||
if (expression instanceof PsiMethodReferenceExpression) {
|
||||
final PsiExpression callExpression = LambdaRefactoringUtil.convertToMethodCallInLambdaBody((PsiMethodReferenceExpression)expression);
|
||||
if (callExpression instanceof PsiCallExpression) {
|
||||
callExpression.replace(CodeInsightServicesUtil.invertCondition(callExpression));
|
||||
}
|
||||
}
|
||||
else if (!(expression.getParent() instanceof PsiExpressionStatement)) {
|
||||
expression.replace(CodeInsightServicesUtil.invertCondition((PsiExpression)expression));
|
||||
}
|
||||
}
|
||||
@@ -266,7 +273,7 @@ public class JavaInvertBooleanDelegate extends InvertBooleanDelegate {
|
||||
for (UsageInfo info : usageInfos) {
|
||||
final PsiElement element = info.getElement();
|
||||
if (element instanceof PsiMethodReferenceExpression) {
|
||||
conflicts.putValue(element, "Method is used in method reference expression");
|
||||
conflicts.putValue(element, RefactoringBundle.message("expand.method.reference.warning"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceJavaDeleteUsageInfo;
|
||||
import com.intellij.refactoring.util.LambdaRefactoringUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -91,5 +92,21 @@ public class JavaSafeDeleteDelegateImpl implements JavaSafeDeleteDelegate {
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiMethodReferenceExpression) {
|
||||
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, parameter, true) {
|
||||
public void deleteElement() throws IncorrectOperationException {
|
||||
final PsiExpression callExpression = LambdaRefactoringUtil.convertToMethodCallInLambdaBody((PsiMethodReferenceExpression)element);
|
||||
if (callExpression instanceof PsiCallExpression) {
|
||||
final PsiExpressionList expressionList = ((PsiCallExpression)callExpression).getArgumentList();
|
||||
if (expressionList != null) {
|
||||
final PsiExpression[] args = expressionList.getExpressions();
|
||||
if (index < args.length) {
|
||||
args[index].delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.RedundantCastUtil;
|
||||
import com.intellij.refactoring.introduceField.ElementToWorkOn;
|
||||
@@ -34,6 +35,7 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import com.siyeh.ig.psiutils.SideEffectChecker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -43,7 +45,13 @@ import java.util.Map;
|
||||
public class LambdaRefactoringUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#" + LambdaRefactoringUtil.class.getName());
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public static PsiExpression convertToMethodCallInLambdaBody(PsiMethodReferenceExpression element) {
|
||||
final PsiLambdaExpression lambdaExpression = convertMethodReferenceToLambda(element, false, true);
|
||||
return lambdaExpression != null ? LambdaUtil.extractSingleExpressionFromBody(lambdaExpression.getBody()) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiLambdaExpression convertMethodReferenceToLambda(final PsiMethodReferenceExpression referenceExpression,
|
||||
final boolean ignoreCast,
|
||||
final boolean simplifyToExpressionLambda) {
|
||||
@@ -51,7 +59,9 @@ public class LambdaRefactoringUtil {
|
||||
final PsiType functionalInterfaceType = referenceExpression.getFunctionalInterfaceType();
|
||||
final PsiClassType.ClassResolveResult functionalInterfaceResolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
|
||||
LOG.assertTrue(interfaceMethod != null);
|
||||
if (interfaceMethod == null) {
|
||||
return null;
|
||||
}
|
||||
final PsiSubstitutor psiSubstitutor = LambdaUtil.getSubstitutor(interfaceMethod, functionalInterfaceResolveResult);
|
||||
final MethodSignature signature = interfaceMethod.getSignature(psiSubstitutor);
|
||||
final boolean isReceiver;
|
||||
@@ -121,14 +131,9 @@ public class LambdaRefactoringUtil {
|
||||
if (!PsiType.VOID.equals(interfaceMethod.getReturnType())) {
|
||||
buf.append("return ");
|
||||
}
|
||||
final PsiMethodReferenceUtil.QualifierResolveResult qualifierResolveResult = PsiMethodReferenceUtil.getQualifierResolveResult(referenceExpression);
|
||||
final PsiElement qualifier = referenceExpression.getQualifier();
|
||||
PsiClass containingClass = null;
|
||||
if (resolveElement instanceof PsiMethod) {
|
||||
containingClass = ((PsiMember)resolveElement).getContainingClass();
|
||||
LOG.assertTrue(containingClass != null);
|
||||
} else if (resolveElement instanceof PsiClass) {
|
||||
containingClass = (PsiClass)resolveElement;
|
||||
}
|
||||
PsiClass containingClass = qualifierResolveResult.getContainingClass();
|
||||
|
||||
final boolean onArrayRef =
|
||||
elementFactory.getArrayClass(PsiUtil.getLanguageLevel(referenceExpression)) == containingClass;
|
||||
@@ -141,9 +146,13 @@ public class LambdaRefactoringUtil {
|
||||
if (qualifier instanceof PsiTypeElement) {
|
||||
final PsiJavaCodeReferenceElement referenceElement = ((PsiTypeElement)qualifier).getInnermostComponentReferenceElement();
|
||||
LOG.assertTrue(referenceElement != null);
|
||||
buf.append(referenceElement.getReferenceName()).append(".");
|
||||
if (!PsiTreeUtil.isAncestor(containingClass, referenceExpression, false)) {
|
||||
buf.append(referenceElement.getReferenceName()).append(".");
|
||||
}
|
||||
}
|
||||
else if (qualifier != null && !(qualifier instanceof PsiThisExpression && ((PsiThisExpression)qualifier).getQualifier() == null)) {
|
||||
else if (qualifier != null &&
|
||||
!(qualifier instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifier).getQualifier() == null && PsiTreeUtil.isAncestor(containingClass, referenceExpression, false) ||
|
||||
qualifier instanceof PsiThisExpression && ((PsiThisExpression)qualifier).getQualifier() == null)) {
|
||||
buf.append(qualifier.getText()).append(".");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ public class RefactoringUtil {
|
||||
}
|
||||
|
||||
public static PsiCall getCallExpressionByMethodReference(PsiElement ref) {
|
||||
if (ref instanceof PsiEnumConstant) return (PsiCall)ref;
|
||||
if (ref instanceof PsiCall) return (PsiCall)ref;
|
||||
PsiElement parent = ref.getParent();
|
||||
if (parent instanceof PsiMethodCallExpression) {
|
||||
return (PsiMethodCallExpression)parent;
|
||||
|
||||
@@ -119,9 +119,6 @@ public class PsiMethodReferenceUtil {
|
||||
}
|
||||
|
||||
methodReturnType = subst.substitute(methodReturnType);
|
||||
if (methodReturnType != null) {
|
||||
methodReturnType = PsiUtil.captureToplevelWildcards(methodReturnType, expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (resolve instanceof PsiClass) {
|
||||
@@ -145,6 +142,8 @@ public class PsiMethodReferenceUtil {
|
||||
methodReturnType = JavaPsiFacade.getElementFactory(expression.getProject()).createType(containingClass, subst);
|
||||
}
|
||||
|
||||
methodReturnType = PsiUtil.captureToplevelWildcards(methodReturnType, expression);
|
||||
|
||||
if (TypeConversionUtil.isAssignable(interfaceReturnType, methodReturnType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ public class RedundantCastUtil {
|
||||
}
|
||||
|
||||
if (oldMethod.equals(newResult.getElement()) &&
|
||||
Comparing.equal(((PsiCallExpression)newCall).getType(), ((PsiCallExpression)expression).getType()) &&
|
||||
(!(newCall instanceof PsiCallExpression) || Comparing.equal(((PsiCallExpression)newCall).getType(), ((PsiCallExpression)expression).getType())) &&
|
||||
newResult.isValidResult()) {
|
||||
if (!(newArgs[i] instanceof PsiFunctionalExpression) || castType != null && castType.equals(((PsiFunctionalExpression)newArgs[i]).getFunctionalInterfaceType())) {
|
||||
addToResults(cast);
|
||||
|
||||
+4
-2
@@ -132,8 +132,7 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
@Nullable
|
||||
@Override
|
||||
public Result<PsiMember> compute() {
|
||||
return Result.createSingleDependency(getPotentiallyApplicableMemberInternal(),
|
||||
PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
|
||||
return Result.create(getPotentiallyApplicableMemberInternal(), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, PsiMethodReferenceExpressionImpl.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -366,6 +365,9 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
if (element instanceof PsiMethod) {
|
||||
return handleElementRename(((PsiMethod)element).getName());
|
||||
}
|
||||
else if (element instanceof PsiClass) {
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
throw new IncorrectOperationException(element.toString());
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class Foo {
|
||||
public static final String FOO_FOO;
|
||||
public static final String FOO_BAR;
|
||||
|
||||
void foo(String x);
|
||||
}
|
||||
|
||||
public class Bar {
|
||||
|
||||
{
|
||||
new Foo().foo(Foo.FOO_BAR);<caret>
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class Foo {
|
||||
public static final String FOO_FOO;
|
||||
public static final String FOO_BAR;
|
||||
|
||||
void foo(String x);
|
||||
}
|
||||
|
||||
public class Bar {
|
||||
|
||||
{
|
||||
new Foo().foo(FB<caret>)
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import java.util.*;
|
||||
class Test {
|
||||
public static void foo(final List<? extends Comparable> comparables) {
|
||||
Collections.sort(comparables);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
{
|
||||
zoo(o -> o.<caret>)
|
||||
}
|
||||
|
||||
void zoo(NonLambda arg, int a) {}
|
||||
void zoo(NonLambda arg, int a, int b) {}
|
||||
}
|
||||
class NonLambda {}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class Test {
|
||||
interface IOfInt extends Consumer<Integer> {
|
||||
default void accept(Integer i) {}
|
||||
}
|
||||
|
||||
interface TS<T> extends Consumer<T> {}
|
||||
interface TS1<T> extends TS<T> {}
|
||||
|
||||
class OfInt implements TS<Integer>, IOfInt {}
|
||||
class OfInt1 implements Consumer<Integer>, IOfInt {}
|
||||
class OfInt2 implements TS<Integer>, IOfInt {}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class Test {
|
||||
private static Class<?>[] getArguments(Stream<Class<String>> classStream) {
|
||||
return classStream.toArray(Class<?>[]::new);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Convert to local" "true"
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
class FieldCanBeLocalTest extends JPanel {
|
||||
|
||||
public FieldCanBeLocalTest() {
|
||||
super();
|
||||
String name = "MyName";
|
||||
setName(name);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Convert to local" "true"
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
class FieldCanBeLocalTest extends JPanel {
|
||||
|
||||
private String na<caret>me = "MyName";
|
||||
|
||||
public FieldCanBeLocalTest() {
|
||||
super();
|
||||
setName(name);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Make 'toString' return 'int'" "false"
|
||||
public class Foo {
|
||||
{
|
||||
int i = to<caret>String();
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Remove explicit type arguments" "false"
|
||||
class Test {
|
||||
|
||||
public void valueOfPasses() {
|
||||
assertEquals("a string", String.valueOf(this.<Obj<caret>ect>someProperty()));
|
||||
}
|
||||
|
||||
public static void assertEquals(Object expected, Object actual) {}
|
||||
|
||||
public <T> T someProperty() {
|
||||
//noinspection unchecked
|
||||
return (T) "a string";
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ interface P {
|
||||
|
||||
class A {
|
||||
public static void print() {
|
||||
List<Integer> someNumbers = A.returnAllNumbers((a) -> A.alwaysTrue());
|
||||
List<Integer> someNumbers = A.returnAllNumbers((a) -> alwaysTrue());
|
||||
}
|
||||
|
||||
private static List<Integer> returnAllNumbers(P predicate) {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
public class XXX {
|
||||
void f<caret>oo() {
|
||||
int i = 0 ;
|
||||
bar(i);
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
private static void bar(int i){}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
public class XXX {
|
||||
void foo() {
|
||||
new InnerClass().invoke();
|
||||
}
|
||||
|
||||
private static void bar(int i){}
|
||||
|
||||
private class InnerClass {
|
||||
public void invoke() {
|
||||
int i = 0 ;
|
||||
bar(i);
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
public class XXX {
|
||||
static void f<caret>oo() {
|
||||
int i = 0 ;
|
||||
bar(i);
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
private static void bar(int i){}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
public class XXX {
|
||||
static void foo() {
|
||||
InnerClass.invoke();
|
||||
}
|
||||
|
||||
private static class InnerClass {
|
||||
private static void invoke() {
|
||||
int i = 0 ;
|
||||
bar(i);
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
private static void bar(int i){}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
public int context1() {
|
||||
<selection>int i, j;
|
||||
i = 0;
|
||||
j = 1;
|
||||
if (j > 0) return i;
|
||||
</selection>
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
class Test {
|
||||
public int context1() {
|
||||
Inner inner = new Inner().invoke();
|
||||
if (inner.is()) return inner.getI();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private class Inner {
|
||||
private boolean myResult;
|
||||
private int i;
|
||||
|
||||
boolean is() {
|
||||
return myResult;
|
||||
}
|
||||
|
||||
public int getI() {
|
||||
return i;
|
||||
}
|
||||
|
||||
public Inner invoke() {
|
||||
int j;
|
||||
i = 0;
|
||||
j = 1;
|
||||
if (j > 0) {
|
||||
myResult = true;
|
||||
return this;
|
||||
}
|
||||
myResult = false;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class Test {
|
||||
|
||||
void f(String strings) {
|
||||
final String[] strings1 = new String[]{"c", "d"};
|
||||
extract("a", "b", strings1);
|
||||
}
|
||||
|
||||
private static void extract(final String from, final String to, String[] anObject) {
|
||||
|
||||
new Foo(anObject);
|
||||
}
|
||||
|
||||
private static class Foo {
|
||||
public Foo(String[] extensions) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface I {
|
||||
boolean m(int a);
|
||||
}
|
||||
|
||||
class A {
|
||||
{
|
||||
I predicate = (a) -> alwaysTrue(a, "");
|
||||
}
|
||||
|
||||
private static boolean alwaysTrue(int a, String anObject) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class Test {
|
||||
|
||||
void f(String strings) {
|
||||
final String[] strings1 = new String[]{"c", "d"};
|
||||
final Foo foo = new Foo(strings1);
|
||||
extract("a", "b", foo);
|
||||
}
|
||||
|
||||
private static void extract(final String from, final String to, Foo anObject) {
|
||||
|
||||
}
|
||||
|
||||
private static class Foo {
|
||||
public Foo(String[] extensions) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class Test {
|
||||
|
||||
void f(String strings) {
|
||||
extract("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
private static void extract(final String from, final String to, final String... extensions) {
|
||||
|
||||
new Foo(<selection>extensions</selection>);
|
||||
}
|
||||
|
||||
private static class Foo {
|
||||
public Foo(String[] extensions) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
interface I {
|
||||
boolean m(int a);
|
||||
}
|
||||
|
||||
class A {
|
||||
{
|
||||
I predicate = A::alwaysTrue;
|
||||
}
|
||||
|
||||
private static boolean alwaysTrue(int a) {
|
||||
<selection>""</selection>
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class Test {
|
||||
|
||||
void f(String strings) {
|
||||
extract("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
private static void extract(final String from, final String to, final String... extensions) {
|
||||
|
||||
<selection>new Foo(extensions)</selection>;
|
||||
}
|
||||
|
||||
private static class Foo {
|
||||
public Foo(String[] extensions) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class Param {
|
||||
private String myClass;
|
||||
|
||||
public P(String myClass) {
|
||||
this.myClass = myClass;
|
||||
}
|
||||
|
||||
public String getSourceClass() {
|
||||
return myClass;
|
||||
}
|
||||
|
||||
public String getMyClass() {
|
||||
return myClass;
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Test {
|
||||
void foo(Param param) {
|
||||
System.out.println(param.getMyClass());
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class Param {
|
||||
private String myClass;
|
||||
|
||||
public P(String myClass) {
|
||||
this.myClass = myClass;
|
||||
}
|
||||
|
||||
public String getSourceClass() {
|
||||
return myClass;
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Test {
|
||||
void foo(String aClass) {
|
||||
System.out.println(aClass);
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
Method is used in method reference expression
|
||||
Method is used in method reference. Proceeding would result in conversion to lambda expression
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Tes<caret>t {
|
||||
interface I {
|
||||
Class[] m(int i);
|
||||
}
|
||||
|
||||
{
|
||||
final I aNew = Class[]::new;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class NewName {
|
||||
interface I {
|
||||
Class[] m(int i);
|
||||
}
|
||||
|
||||
{
|
||||
final I aNew = Class[]::new;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface I {
|
||||
boolean m(int i);
|
||||
}
|
||||
|
||||
class A {
|
||||
{
|
||||
I predicate = A::alwaysTrue;
|
||||
}
|
||||
|
||||
private static boolean alwaysTrue(int <caret>a) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface I {
|
||||
boolean m(int i);
|
||||
}
|
||||
|
||||
class A {
|
||||
{
|
||||
I predicate = (a) -> alwaysTrue();
|
||||
}
|
||||
|
||||
private static boolean alwaysTrue() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -600,7 +600,7 @@ class Foo {
|
||||
myFixture.addClass('package zoo; public class Outer { public static class FooBarGoo{}}')
|
||||
myFixture.configureByText 'a.java', "/** FooBarGo<caret> */"
|
||||
myFixture.completeBasic()
|
||||
myFixture.checkResult "/** {@link zoo.Outer#FooBarGoo<caret>} */"
|
||||
myFixture.checkResult "/** {@link zoo.Outer.FooBarGoo<caret>} */"
|
||||
}
|
||||
|
||||
public void "test insert link to imported class"() {
|
||||
@@ -616,6 +616,13 @@ class Foo {
|
||||
myFixture.checkResult "/** a. {@link #foo(int)}<caret> */ interface Foo { void foo(int a); }}"
|
||||
}
|
||||
|
||||
public void "test insert link to field"() {
|
||||
myFixture.configureByText 'a.java', "/** a. #fo<caret> */ interface Foo { int foo; }}"
|
||||
myFixture.completeBasic()
|
||||
myFixture.type('\n')
|
||||
myFixture.checkResult "/** a. {@link #foo}<caret> */ interface Foo { int foo; }}"
|
||||
}
|
||||
|
||||
public void "test wrap null into code tag"() {
|
||||
myFixture.configureByText 'a.java', "/** nul<caret> */"
|
||||
myFixture.completeBasic()
|
||||
|
||||
+1
@@ -240,4 +240,5 @@ class Test88 {
|
||||
configureByTestName()
|
||||
myFixture.assertPreferredCompletionItems(0, 'toString', 'wait')
|
||||
}
|
||||
public void testUnexpectedLambdaInAmbiguousCall() { doAntiTest() }
|
||||
}
|
||||
|
||||
+2
-1
@@ -698,6 +698,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testUseIntConstantsFromTargetClass() throws Throwable { doTest(); }
|
||||
public void testUseObjectConstantsFromTargetClass() { doTest(); }
|
||||
public void testUseIntConstantsFromTargetClassReturnValue() throws Throwable { doTest(); }
|
||||
public void testUseIntConstantsFromConstructedClass() throws Throwable { doTest(); }
|
||||
public void testUseIntConstantsInPlus() throws Throwable { doTest(); }
|
||||
@@ -836,7 +837,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testIDEADEV2626() throws Exception {
|
||||
doActionTest();
|
||||
doItemTest();
|
||||
}
|
||||
|
||||
public void testDontSuggestWildcardGenerics() { doItemTest(); }
|
||||
|
||||
+4
@@ -974,4 +974,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testCapturedWildcardPassedThroughMethodCallChain() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIDEA152179() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -36,6 +36,7 @@ public class Interface8MethodsHighlightingTest extends LightCodeInsightFixtureTe
|
||||
public void testStaticMethodCalls() { doTest(false, false); }
|
||||
public void testStaticMethodCallsAndOverloadResolution() { doTest(false, false); }
|
||||
public void testDefaultMethodOverrideEquivalentObject() { doTest(false, false); }
|
||||
public void testDefaultMethodOverrideAbstract() { doTest(false, false); }
|
||||
public void testModifierNativeInInterface() { doTest(false, false); }
|
||||
public void testStaticMethods() { doTest(false, false); }
|
||||
public void testFinalStaticDefaultMethods() { doTest(false, false); }
|
||||
|
||||
+4
@@ -494,6 +494,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCaptureTypeOfNewArrayExpression() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
+27
-1
@@ -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.
|
||||
@@ -223,6 +223,32 @@ public class HighlightUsagesHandlerTest extends LightCodeInsightFixtureTestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testExceptionsInTryWithResources() {
|
||||
myFixture.configureByText 'A.java', '''
|
||||
import java.io.*;
|
||||
class A {
|
||||
void test() throws IOException {
|
||||
try (InputStream in = new FileInputStream("file.name")) { }
|
||||
<caret>catch (FileNotFoundException e) { throw new FileNotFoundException("no highlighting here"); }
|
||||
}
|
||||
}'''.stripIndent()
|
||||
ctrlShiftF7()
|
||||
assertRangeText 'FileInputStream', 'catch'
|
||||
}
|
||||
|
||||
public void testExceptionsResourceCloser() {
|
||||
myFixture.configureByText 'A.java', '''
|
||||
import java.io.*;
|
||||
class A {
|
||||
void test() {
|
||||
try (InputStream in = new FileInputStream("file.name")) { }
|
||||
<caret>catch (IOException e) { }
|
||||
}
|
||||
}'''.stripIndent()
|
||||
ctrlShiftF7()
|
||||
assertRangeText 'in', 'FileInputStream', 'FileInputStream', 'catch'
|
||||
}
|
||||
|
||||
private void configureFile() {
|
||||
def testName = getTestName(false)
|
||||
def file = myFixture.copyFileToProject "/codeInsight/highlightUsagesHandler/${testName}.java", "${testName}.java"
|
||||
|
||||
@@ -54,7 +54,7 @@ public class OfflineIRVTest extends TestSourceBasedTestCase {
|
||||
private LocalInspectionToolWrapper myToolWrapper;
|
||||
|
||||
private static String varMessage(String name) {
|
||||
return InspectionsBundle.message("inspection.unused.assignment.problem.descriptor1", "<code>"+name+"</code>") + ".";
|
||||
return InspectionsBundle.message("inspection.unused.assignment.problem.descriptor1", "'" + name + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,7 +146,7 @@ public class OfflineIRVTest extends TestSourceBasedTestCase {
|
||||
+ " -f()\n"
|
||||
+ " -D\n"
|
||||
+ " -b()\n"
|
||||
+ " " + InspectionsBundle.message("inspection.unused.assignment.problem.descriptor1", "'" + "r" + "'") + "\n"
|
||||
+ " " + varMessage("r") + "\n"
|
||||
+ " -anonymous (java.lang.Runnable)\n"
|
||||
+ " -run()\n"
|
||||
+ " " + varMessage("i") + "\n"
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.roots.impl;
|
||||
|
||||
import com.intellij.openapi.roots.ContentIterator;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.testFramework.IdeaTestCase;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.intellij.testFramework.VfsTestUtil.getEvents;
|
||||
import static com.intellij.testFramework.VfsTestUtil.print;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
@PlatformTestCase.WrapInCommand
|
||||
public class DirectoryIndexRestoreTest extends IdeaTestCase {
|
||||
private VirtualFile myTempVFile;
|
||||
private String myTestDirPath;
|
||||
private ProjectFileIndex myFileIndex;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
LocalFileSystem fs = LocalFileSystem.getInstance();
|
||||
File temp = createTempDirectory();
|
||||
myTempVFile = fs.findFileByIoFile(temp);
|
||||
assertNotNull(myTempVFile);
|
||||
File root = new File(temp, "top/d1/d2/root");
|
||||
assertTrue(root.mkdirs());
|
||||
VirtualFile rootVFile = fs.findFileByIoFile(root);
|
||||
assertNotNull(rootVFile);
|
||||
|
||||
VirtualFile moduleDir = createChildDirectory(rootVFile, "module");
|
||||
VirtualFile srcDir = createChildDirectory(moduleDir, "src");
|
||||
VirtualFile testDir = createChildDirectory(srcDir, "pkg");
|
||||
ModuleRootModificationUtil.setModuleSdk(myModule, null);
|
||||
PsiTestUtil.addContentRoot(myModule, moduleDir);
|
||||
PsiTestUtil.addSourceRoot(myModule, srcDir);
|
||||
|
||||
myTestDirPath = testDir.getPath();
|
||||
myFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
|
||||
|
||||
// to not interfere with previous test firing vfs events
|
||||
VirtualFileManager.getInstance().syncRefresh();
|
||||
}
|
||||
|
||||
public void testDeepDeleteAndRecreate() throws IOException {
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
ContentIterator iterator = (file) -> {
|
||||
boolean found = file.getPath().equals(myTestDirPath);
|
||||
if (found) counter.incrementAndGet();
|
||||
return !found;
|
||||
};
|
||||
File topFile = new File(myTempVFile.getPath(), "top"), bakFile = new File(myTempVFile.getPath(), "top.bak");
|
||||
String topPath = myTempVFile.getPath() + "/top";
|
||||
|
||||
myFileIndex.iterateContent(iterator);
|
||||
assertEquals(1, counter.get());
|
||||
|
||||
FileUtil.rename(topFile, bakFile);
|
||||
List<String> events1 = print(getEvents(() -> myTempVFile.refresh(false, true)));
|
||||
assertEquals(singletonList("D : " + topPath), events1);
|
||||
myFileIndex.iterateContent(iterator);
|
||||
assertEquals(1, counter.get());
|
||||
|
||||
FileUtil.rename(bakFile, topFile);
|
||||
List<String> events2 = print(getEvents(() -> myTempVFile.refresh(false, true)));
|
||||
assertEquals(singletonList("C : " + topPath), events2);
|
||||
myFileIndex.iterateContent(iterator);
|
||||
assertEquals(2, counter.get());
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
@@ -17,7 +17,6 @@ package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
@@ -41,13 +40,10 @@ import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@PlatformTestCase.WrapInCommand
|
||||
public class DirectoryIndexTest extends IdeaTestCase {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.DirectoryIndexTest");
|
||||
|
||||
private DirectoryIndexImpl myIndex;
|
||||
|
||||
private Module myModule2, myModule3;
|
||||
@@ -184,7 +180,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void testDirInfos() throws IOException {
|
||||
public void testDirInfos() {
|
||||
assertNotInProject(myRootVFile);
|
||||
|
||||
// beware: files in directory index
|
||||
@@ -221,7 +217,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertNull(myFileIndex.getPackageNameByDirectory(cvs));
|
||||
}
|
||||
|
||||
public void testDirsByPackageName() throws IOException {
|
||||
public void testDirsByPackageName() {
|
||||
checkPackage("", true, mySrcDir1, myTestSrc1, myResDir, myTestResDir, mySrcDir2, myLibSrcDir, myLibClsDir);
|
||||
checkPackage("", false, mySrcDir1, myTestSrc1, myResDir, myTestResDir, mySrcDir2, myLibClsDir);
|
||||
|
||||
@@ -254,7 +250,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
checkPackage("pack1", true, myPack1Dir, myModule3Dir);
|
||||
}
|
||||
|
||||
public void testPackageDirectoriesWithDots() throws IOException {
|
||||
public void testPackageDirectoriesWithDots() {
|
||||
VirtualFile fooBar = createChildDirectory(mySrcDir1, "foo.bar");
|
||||
VirtualFile goo1 = createChildDirectory(fooBar, "goo");
|
||||
VirtualFile foo = createChildDirectory(mySrcDir2, "foo");
|
||||
@@ -266,14 +262,14 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
checkPackage("foo.bar.goo", false, goo2, goo1);
|
||||
}
|
||||
|
||||
public void testCreateDir() throws Exception {
|
||||
public void testCreateDir() {
|
||||
String path = mySrcDir1.getPath().replace('/', File.separatorChar);
|
||||
assertTrue(new File(path + File.separatorChar + "dir1" + File.separatorChar + "dir2").mkdirs());
|
||||
assertTrue(new File(path + File.separatorChar + "CVS").mkdirs());
|
||||
VirtualFileManager.getInstance().syncRefresh();
|
||||
}
|
||||
|
||||
public void testDeleteDir() throws Exception {
|
||||
public void testDeleteDir() {
|
||||
VirtualFile subdir1 = createChildDirectory(mySrcDir1, "subdir1");
|
||||
VirtualFile subdir2 = createChildDirectory(subdir1, "subdir2");
|
||||
createChildDirectory(subdir2, "subdir3");
|
||||
@@ -281,29 +277,29 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
VfsTestUtil.deleteFile(subdir1);
|
||||
}
|
||||
|
||||
public void testMoveDir() throws Exception {
|
||||
public void testMoveDir() {
|
||||
VirtualFile subdir = createChildDirectory(mySrcDir2, "subdir1");
|
||||
createChildDirectory(subdir, "subdir2");
|
||||
|
||||
move(subdir, mySrcDir1);
|
||||
}
|
||||
|
||||
public void testRenameDir() throws Exception {
|
||||
public void testRenameDir() {
|
||||
VirtualFile subdir = createChildDirectory(mySrcDir2, "subdir1");
|
||||
createChildDirectory(subdir, "subdir2");
|
||||
|
||||
rename(subdir, "abc.d");
|
||||
}
|
||||
|
||||
public void testRenameRoot() throws Exception {
|
||||
public void testRenameRoot() {
|
||||
rename(myModule1Dir, "newName");
|
||||
}
|
||||
|
||||
public void testMoveRoot() throws Exception {
|
||||
public void testMoveRoot() {
|
||||
move(myModule1Dir, myModule3Dir);
|
||||
}
|
||||
|
||||
public void testAddProjectDir() throws Exception {
|
||||
public void testAddProjectDir() {
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
@@ -315,7 +311,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
public void testChangeIgnoreList() throws Exception {
|
||||
public void testChangeIgnoreList() {
|
||||
VirtualFile newDir = createChildDirectory(myModule1Dir, "newDir");
|
||||
|
||||
assertInProject(newDir);
|
||||
@@ -343,7 +339,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIgnoredFile() throws IOException {
|
||||
public void testIgnoredFile() {
|
||||
VirtualFile ignoredFile = createChildData(myModule1Dir, "CVS");
|
||||
DirectoryInfo info = myIndex.getInfoForFile(ignoredFile);
|
||||
assertTrue(info.isIgnored());
|
||||
@@ -353,8 +349,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertNull(myFileIndex.getModuleForFile(ignoredFile, false));
|
||||
}
|
||||
|
||||
public void testAddModule() throws Exception {
|
||||
|
||||
public void testAddModule() {
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
@@ -367,7 +362,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
public void testModuleUnderIgnoredDir() throws IOException {
|
||||
public void testModuleUnderIgnoredDir() {
|
||||
final VirtualFile ignored = createChildDirectory(myRootVFile, "RCS");
|
||||
assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored));
|
||||
assertTrue(myFileIndex.isExcluded(ignored));
|
||||
@@ -387,10 +382,9 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
checkInfo(module4, module, false, false, null, null);
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
}
|
||||
|
||||
public void testModuleInIgnoredDir() throws IOException {
|
||||
public void testModuleInIgnoredDir() {
|
||||
final VirtualFile ignored = createChildDirectory(myRootVFile, "RCS");
|
||||
assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored));
|
||||
|
||||
@@ -419,14 +413,14 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertFalse(myFileIndex.isUnderIgnored(myExcludedLibSrcDir));
|
||||
}
|
||||
|
||||
public void testExplicitExcludeOfInner() throws Exception {
|
||||
public void testExplicitExcludeOfInner() {
|
||||
PsiTestUtil.addExcludedRoot(myModule, myModule2Dir);
|
||||
|
||||
checkInfo(myModule2Dir, myModule2, false, false, null, null);
|
||||
checkInfo(mySrcDir2, myModule2, false, false, "", JavaSourceRootType.SOURCE, myModule2, myModule3);
|
||||
}
|
||||
|
||||
public void testResettingProjectOutputPath() throws Exception {
|
||||
public void testResettingProjectOutputPath() {
|
||||
VirtualFile output1 = createChildDirectory(myModule1Dir, "output1");
|
||||
VirtualFile output2 = createChildDirectory(myModule1Dir, "output2");
|
||||
|
||||
@@ -459,8 +453,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
return orderEntries.toArray(new OrderEntry[orderEntries.size()]);
|
||||
}
|
||||
|
||||
public void testModuleSourceAsLibrarySource() throws Exception {
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule, "someLib", Collections.<String>emptyList(), Arrays.asList(mySrcDir1.getUrl()));
|
||||
public void testModuleSourceAsLibrarySource() {
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule, "someLib", Collections.emptyList(), Collections.singletonList(mySrcDir1.getUrl()));
|
||||
|
||||
checkInfo(mySrcDir1, myModule, false, true, "", JavaSourceRootType.SOURCE, myModule, myModule);
|
||||
Collection<OrderEntry> entriesResult = myIndex.getOrderEntries(myIndex.getInfoForFile(mySrcDir1));
|
||||
@@ -476,8 +470,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertInstanceOf(entries[1], ModuleSourceOrderEntry.class);
|
||||
}
|
||||
|
||||
public void testModuleSourceAsLibraryClasses() throws Exception {
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule, "someLib", Arrays.asList(mySrcDir1.getUrl()), Collections.<String>emptyList());
|
||||
public void testModuleSourceAsLibraryClasses() {
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule, "someLib", Collections.singletonList(mySrcDir1.getUrl()), Collections.emptyList());
|
||||
checkInfo(mySrcDir1, myModule, true, false, "", JavaSourceRootType.SOURCE, myModule);
|
||||
assertInstanceOf(assertOneElement(toArray(myIndex.getOrderEntries(assertInProject(mySrcDir1)))), ModuleSourceOrderEntry.class);
|
||||
}
|
||||
@@ -512,7 +506,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertExcluded(mySrcDir1, myModule);
|
||||
}
|
||||
|
||||
public void testExcludedDirShouldBeExcludedRightAfterItsCreation() throws Exception {
|
||||
public void testExcludedDirShouldBeExcludedRightAfterItsCreation() {
|
||||
VirtualFile excluded = createChildDirectory(myModule1Dir, "excluded");
|
||||
VirtualFile projectOutput = createChildDirectory(myModule1Dir, "projectOutput");
|
||||
VirtualFile module2Output = createChildDirectory(myModule1Dir, "module2Output");
|
||||
@@ -567,7 +561,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertEquals(created.toString(), 4, created.size());
|
||||
}
|
||||
|
||||
public void testExcludesShouldBeRecognizedRightOnRefresh() throws Exception {
|
||||
public void testExcludesShouldBeRecognizedRightOnRefresh() {
|
||||
final VirtualFile dir = createChildDirectory(myModule1Dir, "dir");
|
||||
final VirtualFile excluded = createChildDirectory(dir, "excluded");
|
||||
PsiTestUtil.addExcludedRoot(myModule, excluded);
|
||||
@@ -615,7 +609,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertInProject(LocalFileSystem.getInstance().findFileByIoFile(f));
|
||||
}
|
||||
|
||||
public void testLibraryDirInContent() throws Exception {
|
||||
public void testLibraryDirInContent() {
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule, myModule1Dir.getUrl());
|
||||
|
||||
checkInfo(myModule1Dir, myModule, true, false, "", null, myModule);
|
||||
@@ -647,7 +641,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
checkPackage("exc", true);
|
||||
}
|
||||
|
||||
public void testExcludeCompilerOutputOutsideOfContentRoot() throws Exception {
|
||||
public void testExcludeCompilerOutputOutsideOfContentRoot() {
|
||||
assertTrue(myFileIndex.isExcluded(myOutputDir));
|
||||
assertFalse(myFileIndex.isUnderIgnored(myOutputDir));
|
||||
assertTrue(myFileIndex.isExcluded(myModule1OutputDir));
|
||||
@@ -689,7 +683,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertExcluded(projectOutputUnderContent, myModule);
|
||||
}
|
||||
|
||||
public void testFileContentAndSourceRoots() throws IOException {
|
||||
public void testFileContentAndSourceRoots() {
|
||||
VirtualFile fileRoot = createChildData(myRootVFile, "fileRoot.txt");
|
||||
VirtualFile fileSourceRoot = createChildData(myRootVFile, "fileSourceRoot.txt");
|
||||
VirtualFile fileTestSourceRoot = createChildData(myRootVFile, "fileTestSourceRoot.txt");
|
||||
@@ -699,6 +693,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertIteratedContent(myFileIndex, null, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot));
|
||||
|
||||
ContentEntry contentEntry = PsiTestUtil.addContentRoot(myModule, fileRoot);
|
||||
assertNotNull(contentEntry);
|
||||
assertEquals(fileRoot, contentEntry.getFile());
|
||||
checkInfo(fileRoot, myModule, false, false, "", null);
|
||||
assertTrue(myFileIndex.isInContent(fileRoot));
|
||||
@@ -730,12 +725,12 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertNotInProject(fileRoot);
|
||||
assertFalse(myFileIndex.isInContent(fileRoot));
|
||||
assertFalse(myFileIndex.isInSource(fileRoot));
|
||||
assertIteratedContent(myFileIndex, Arrays.asList(fileSourceRoot, fileTestSourceRoot), Arrays.asList(fileRoot));
|
||||
assertIteratedContent(myFileIndex, Arrays.asList(fileSourceRoot, fileTestSourceRoot), Collections.singletonList(fileRoot));
|
||||
}
|
||||
|
||||
private void assertIteratedContent(ProjectFileIndex fileIndex,
|
||||
@Nullable List<VirtualFile> contains,
|
||||
@Nullable List<VirtualFile> doesntContain) {
|
||||
private static void assertIteratedContent(ProjectFileIndex fileIndex,
|
||||
@Nullable List<VirtualFile> contains,
|
||||
@Nullable List<VirtualFile> doesntContain) {
|
||||
final Set<VirtualFile> collected = new THashSet<VirtualFile>();
|
||||
fileIndex.iterateContent(new ContentIterator() {
|
||||
@Override
|
||||
@@ -748,7 +743,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
if (doesntContain != null) assertDoesntContain(collected, doesntContain);
|
||||
}
|
||||
|
||||
public void testFileSourceRootsUnderDirContentRoot() throws IOException {
|
||||
public void testFileSourceRootsUnderDirContentRoot() {
|
||||
VirtualFile fileSourceRoot = createChildData(myModule1Dir, "fileSourceRoot.txt");
|
||||
assertTrue(myFileIndex.isInContent(fileSourceRoot));
|
||||
assertFalse(myFileIndex.isInSource(fileSourceRoot));
|
||||
@@ -764,11 +759,11 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertFalse(myFileIndex.isInSource(fileSourceRoot));
|
||||
}
|
||||
|
||||
public void testFileModuleExcludeRootUnderDirectoryRoot() throws IOException {
|
||||
public void testFileModuleExcludeRootUnderDirectoryRoot() {
|
||||
VirtualFile fileExcludeRoot = createChildData(mySrcDir1, "fileExcludeRoot.txt");
|
||||
assertTrue(myFileIndex.isInContent(fileExcludeRoot));
|
||||
assertTrue(myFileIndex.isInSource(fileExcludeRoot));
|
||||
assertIteratedContent(myFileIndex, Arrays.asList(fileExcludeRoot), null);
|
||||
assertIteratedContent(myFileIndex, Collections.singletonList(fileExcludeRoot), null);
|
||||
|
||||
PsiTestUtil.addExcludedRoot(myModule, fileExcludeRoot);
|
||||
assertFalse(myFileIndex.isInContent(fileExcludeRoot));
|
||||
@@ -778,46 +773,46 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertNull(myFileIndex.getModuleForFile(fileExcludeRoot));
|
||||
assertEquals(myModule, myFileIndex.getModuleForFile(fileExcludeRoot, false));
|
||||
assertExcluded(fileExcludeRoot, myModule);
|
||||
assertIteratedContent(myFileIndex, null, Arrays.asList(fileExcludeRoot));
|
||||
assertIteratedContent(myFileIndex, null, Collections.singletonList(fileExcludeRoot));
|
||||
|
||||
// removing file exclude root
|
||||
PsiTestUtil.removeExcludedRoot(myModule, fileExcludeRoot);
|
||||
assertTrue(myFileIndex.isInContent(fileExcludeRoot));
|
||||
assertTrue(myFileIndex.isInSource(fileExcludeRoot));
|
||||
assertIteratedContent(myFileIndex, Arrays.asList(fileExcludeRoot), null);
|
||||
assertIteratedContent(myFileIndex, Collections.singletonList(fileExcludeRoot), null);
|
||||
}
|
||||
|
||||
public void testFileModuleExcludeRootUnderFileRoot() throws IOException {
|
||||
public void testFileModuleExcludeRootUnderFileRoot() {
|
||||
VirtualFile fileRoot = createChildData(myRootVFile, "fileRoot.txt");
|
||||
PsiTestUtil.addContentRoot(myModule, fileRoot);
|
||||
checkInfo(fileRoot, myModule, false, false, "", null);
|
||||
assertTrue(myFileIndex.isInContent(fileRoot));
|
||||
assertIteratedContent(myFileIndex, Arrays.asList(fileRoot), null);
|
||||
assertIteratedContent(myFileIndex, Collections.singletonList(fileRoot), null);
|
||||
|
||||
PsiTestUtil.addExcludedRoot(myModule, fileRoot);
|
||||
assertFalse(myFileIndex.isInContent(fileRoot));
|
||||
assertExcluded(fileRoot, myModule);
|
||||
assertIteratedContent(myFileIndex, null, Arrays.asList(fileRoot));
|
||||
assertIteratedContent(myFileIndex, null, Collections.singletonList(fileRoot));
|
||||
|
||||
// removing file exclude root
|
||||
PsiTestUtil.removeExcludedRoot(myModule, fileRoot);
|
||||
checkInfo(fileRoot, myModule, false, false, "", null);
|
||||
assertTrue(myFileIndex.isInContent(fileRoot));
|
||||
assertIteratedContent(myFileIndex, Arrays.asList(fileRoot), null);
|
||||
assertIteratedContent(myFileIndex, Collections.singletonList(fileRoot), null);
|
||||
}
|
||||
|
||||
public void testFileLibraryInsideFolderLibrary() throws IOException {
|
||||
public void testFileLibraryInsideFolderLibrary() {
|
||||
VirtualFile file = createChildData(myLibSrcDir, "empty.txt");
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib2",
|
||||
Collections.<String>emptyList(), Collections.singletonList(file.getUrl()),
|
||||
Collections.<String>emptyList(), DependencyScope.COMPILE, true);
|
||||
Collections.emptyList(), Collections.singletonList(file.getUrl()),
|
||||
Collections.emptyList(), DependencyScope.COMPILE, true);
|
||||
|
||||
// same for the dir and for the file
|
||||
checkInfo(file, myModule, false, true, "", null, myModule2, myModule3);
|
||||
checkInfo(myLibSrcDir, myModule, false, true, "", null, myModule2, myModule3);
|
||||
}
|
||||
|
||||
public void testFileContentRootsModifications() throws IOException {
|
||||
public void testFileContentRootsModifications() {
|
||||
assertNotInProject(myRootVFile);
|
||||
VirtualFile temp = createChildDirectory(myRootVFile, "temp");
|
||||
|
||||
@@ -944,5 +939,4 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
assertEquals("Invalid package name for dir " + dir + ": " + packageName, packageName, actualName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 06-May-2008
|
||||
@@ -117,6 +133,14 @@ public class ExtractMethodObjectTest extends LightRefactoringTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWithPrivateStaticMethodUsed() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWithPrivateStaticMethodUsed2() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWithPrivateMethodWhichCantBeMoved() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
+20
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 06-May-2008
|
||||
@@ -72,6 +88,10 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightRefactor
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMultilineDeclarationsWithReturn() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testConditionalExit() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -239,6 +239,10 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase{
|
||||
doTestExistingClass("Param", "", false);
|
||||
}
|
||||
|
||||
public void testExistingWithAnotherFieldNames() throws Exception {
|
||||
doTestExistingClass("Param", "", true);
|
||||
}
|
||||
|
||||
public void testWrongBean() throws Exception {
|
||||
checkExceptionThrown("Param", "", "Cannot perform the refactoring.\n" + "Getters for the following fields are required:\n" + "i.\n");
|
||||
}
|
||||
|
||||
@@ -142,6 +142,18 @@ public class IntroduceParameterTest extends LightRefactoringTestCase {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false);
|
||||
}
|
||||
|
||||
public void testExpandMethodReference() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false);
|
||||
}
|
||||
|
||||
public void testBareRefToVararg() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, true, false, false, false);
|
||||
}
|
||||
|
||||
public void testNewWithRefToVararg() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, true, false, false, false);
|
||||
}
|
||||
|
||||
public void testSuperWithSideEffect() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false, false,
|
||||
"Parameter initializer contains <b><code>super</code></b>, but not all calls to method are in its class");
|
||||
|
||||
@@ -44,6 +44,10 @@ public class RenameMembersInplaceTest extends LightCodeInsightTestCase {
|
||||
doTestInplaceRename("NEW_NAME");
|
||||
}
|
||||
|
||||
public void testClassWithConstructorReferenceInside() throws Exception {
|
||||
doTestInplaceRename("NewName");
|
||||
}
|
||||
|
||||
public void testIncomplete() throws Exception {
|
||||
doTestInplaceRename("Klazz");
|
||||
}
|
||||
|
||||
@@ -300,6 +300,11 @@ public class SafeDeleteTest extends MultiFileTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testParameterInMethodUsedInMethodReference() throws Exception {
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
doSingleFileTest();
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String qClassName) throws Exception {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
SafeDeleteTest.this.performAction(qClassName);
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
*/
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -56,7 +58,9 @@ public class PackageWrapper {
|
||||
}
|
||||
|
||||
public boolean exists() {
|
||||
return JavaPsiFacade.getInstance(myManager.getProject()).findPackage(myQualifiedName) != null;
|
||||
final Project project = myManager.getProject();
|
||||
final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(myQualifiedName);
|
||||
return aPackage != null && aPackage.getDirectories(GlobalSearchScope.projectScope(project)).length > 0;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class JSStringLiteralEscaper<T extends PsiLanguageInjectionHost>
|
||||
String subText = rangeInsideHost.substring(myHost.getText());
|
||||
|
||||
Ref<int[]> sourceOffsetsRef = new Ref<int[]>();
|
||||
boolean result = parseStringCharacters(subText, outChars, sourceOffsetsRef, isRegExpLiteral());
|
||||
boolean result = parseStringCharacters(subText, outChars, sourceOffsetsRef, isRegExpLiteral(), !isOneLine());
|
||||
outSourceOffsets = sourceOffsetsRef.get();
|
||||
return result;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public abstract class JSStringLiteralEscaper<T extends PsiLanguageInjectionHost>
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean parseStringCharacters(String chars, StringBuilder outChars, Ref<int[]> sourceOffsetsRef, boolean regExp) {
|
||||
public static boolean parseStringCharacters(String chars, StringBuilder outChars, Ref<int[]> sourceOffsetsRef, boolean regExp, boolean escapeBacktick) {
|
||||
int[] sourceOffsets = new int[chars.length() + 1];
|
||||
sourceOffsetsRef.set(sourceOffsets);
|
||||
|
||||
@@ -60,7 +60,9 @@ public abstract class JSStringLiteralEscaper<T extends PsiLanguageInjectionHost>
|
||||
}
|
||||
if (index == chars.length()) return false;
|
||||
c = chars.charAt(index++);
|
||||
if (regExp) {
|
||||
if (escapeBacktick && c == '`') {
|
||||
outChars.append(c);
|
||||
} else if (regExp) {
|
||||
if (c != '/') {
|
||||
outChars.append('\\');
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package com.jetbrains.jsonSchema.extension;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.PatternUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.jsonSchema.JsonSchemaMappingsConfigurationBase;
|
||||
import com.jetbrains.jsonSchema.JsonSchemaMappingsProjectConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -30,12 +33,11 @@ public class JsonSchemaImportedProviderFactory implements JsonSchemaProviderFact
|
||||
public JsonSchemaFileProvider[] getProviders(@Nullable Project project) {
|
||||
final List<JsonSchemaFileProvider> list = new ArrayList<JsonSchemaFileProvider>();
|
||||
|
||||
//processConfiguration(project, JsonSchemaMappingsApplicationConfiguration.getInstance(), list);
|
||||
if (project != null) {
|
||||
processConfiguration(project, JsonSchemaMappingsProjectConfiguration.getInstance(project), list);
|
||||
}
|
||||
|
||||
return list.toArray(new JsonSchemaFileProvider[list.size()]);
|
||||
return list.isEmpty() ? EMPTY : list.toArray(new JsonSchemaFileProvider[list.size()]);
|
||||
}
|
||||
|
||||
private static void processConfiguration(@Nullable Project project, @NotNull final JsonSchemaMappingsConfigurationBase configuration,
|
||||
@@ -49,6 +51,7 @@ public class JsonSchemaImportedProviderFactory implements JsonSchemaProviderFact
|
||||
}
|
||||
|
||||
private static class MyProvider implements JsonSchemaFileProvider, JsonSchemaImportedProviderMarker {
|
||||
@Nullable private final Project myProject;
|
||||
@NotNull private final String myName;
|
||||
@NotNull private final File myFile;
|
||||
@NotNull private final List<Processor<VirtualFile>> myPatterns;
|
||||
@@ -57,6 +60,7 @@ public class JsonSchemaImportedProviderFactory implements JsonSchemaProviderFact
|
||||
@NotNull String name,
|
||||
@NotNull File file,
|
||||
@NotNull List<JsonSchemaMappingsConfigurationBase.Item> patterns) {
|
||||
myProject = project;
|
||||
myName = name;
|
||||
myFile = file;
|
||||
myPatterns = new ArrayList<Processor<VirtualFile>>();
|
||||
@@ -77,9 +81,19 @@ public class JsonSchemaImportedProviderFactory implements JsonSchemaProviderFact
|
||||
}
|
||||
|
||||
String path = pattern.getPath().replace('\\', '/');
|
||||
final String[] parts = path.split("/");
|
||||
final VirtualFile relativeFile = VfsUtil.findRelativeFile(project.getBaseDir(), parts);
|
||||
if (relativeFile == null) continue;
|
||||
final List<String> parts = ContainerUtil.filter(path.split("/"), new Condition<String>() {
|
||||
@Override
|
||||
public boolean value(String s) {
|
||||
return !".".equals(s);
|
||||
}
|
||||
});
|
||||
final VirtualFile relativeFile;
|
||||
if (parts.isEmpty()) {
|
||||
relativeFile = project.getBaseDir();
|
||||
} else {
|
||||
relativeFile = VfsUtil.findRelativeFile(project.getBaseDir(), ArrayUtil.toStringArray(parts));
|
||||
if (relativeFile == null) continue;
|
||||
}
|
||||
|
||||
if (pattern.isDirectory()) {
|
||||
myPatterns.add(new Processor<VirtualFile>() {
|
||||
@@ -108,7 +122,8 @@ public class JsonSchemaImportedProviderFactory implements JsonSchemaProviderFact
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull VirtualFile file) {
|
||||
if (file.isDirectory() || !file.isValid()) return false;
|
||||
if (file.isDirectory() || !file.isValid() ||
|
||||
myProject != null && JsonSchemaMappingsProjectConfiguration.getInstance(myProject).isRegisteredSchemaFile(file)) return false;
|
||||
for (Processor<VirtualFile> pattern : myPatterns) {
|
||||
if (pattern.process(file)) return true;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface JsonSchemaProviderFactory {
|
||||
ExtensionPointName<JsonSchemaProviderFactory> EP_NAME = ExtensionPointName.create("JavaScript.JsonSchema.ProviderFactory");
|
||||
JsonSchemaFileProvider[] EMPTY = new JsonSchemaFileProvider[0];
|
||||
|
||||
JsonSchemaFileProvider[] getProviders(@Nullable Project project);
|
||||
}
|
||||
|
||||
+24
-14
@@ -63,7 +63,10 @@ public class JsonSchemaConflictNotificationProvider extends EditorNotifications.
|
||||
final List<Pair<Boolean, String>> descriptors = myJsonSchemaService.getMatchingSchemaDescriptors(file);
|
||||
if (descriptors == null || descriptors.size() <= 1) return null;
|
||||
|
||||
final String message = createMessage(descriptors);
|
||||
final Worker worker = new Worker();
|
||||
final String message = worker.createMessage(descriptors);
|
||||
if (message == null) return null;
|
||||
|
||||
final EditorNotificationPanel panel = new EditorNotificationPanel() {
|
||||
@Override
|
||||
public Color getBackground() {
|
||||
@@ -81,20 +84,27 @@ public class JsonSchemaConflictNotificationProvider extends EditorNotifications.
|
||||
return panel;
|
||||
}
|
||||
|
||||
private static String createMessage(@NotNull final List<Pair<Boolean, String>> descriptors) {
|
||||
boolean haveSystemSchemas = false;
|
||||
for (Pair<Boolean, String> pair : descriptors) {
|
||||
haveSystemSchemas |= !Boolean.TRUE.equals(pair.getFirst());
|
||||
}
|
||||
boolean withTypes = haveSystemSchemas;
|
||||
final List<String> names = new ArrayList<>();
|
||||
for (Pair<Boolean, String> pair : descriptors) {
|
||||
if (withTypes) {
|
||||
names.add((Boolean.TRUE.equals(pair.getFirst()) ? "user" : "system") + " schema '" + pair.getSecond() + "'");
|
||||
} else {
|
||||
names.add(pair.getSecond());
|
||||
private static class Worker {
|
||||
public String createMessage(@NotNull final List<Pair<Boolean, String>> descriptors) {
|
||||
int numOfSystemSchemas = 0;
|
||||
for (Pair<Boolean, String> pair : descriptors) {
|
||||
if (!Boolean.TRUE.equals(pair.getFirst())) {
|
||||
++ numOfSystemSchemas;
|
||||
}
|
||||
}
|
||||
if (numOfSystemSchemas == 1) {
|
||||
return null;
|
||||
}
|
||||
boolean withTypes = numOfSystemSchemas > 0;
|
||||
final List<String> names = new ArrayList<>();
|
||||
for (Pair<Boolean, String> pair : descriptors) {
|
||||
if (withTypes) {
|
||||
names.add((Boolean.TRUE.equals(pair.getFirst()) ? "user" : "system") + " schema '" + pair.getSecond() + "'");
|
||||
} else {
|
||||
names.add(pair.getSecond());
|
||||
}
|
||||
}
|
||||
return "<html>There are several JSON Schemas mapped to this file: " + StringUtil.join(names, "; ") + "</html>";
|
||||
}
|
||||
return "<html>There are several JSON Schemas mapped to this file: " + StringUtil.join(names, "; ") + "</html>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +411,8 @@ public class JsonSchemaReader {
|
||||
while (in.peek() != JsonToken.END_ARRAY) {
|
||||
if (in.peek() == JsonToken.STRING) {
|
||||
required.add(in.nextString());
|
||||
} else {
|
||||
in.skipValue();
|
||||
}
|
||||
}
|
||||
in.endArray();
|
||||
@@ -479,7 +481,7 @@ public class JsonSchemaReader {
|
||||
while (in.peek() != JsonToken.END_ARRAY) {
|
||||
if (in.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
list.add(readInnerObject(in));
|
||||
}
|
||||
} else in.skipValue();
|
||||
}
|
||||
in.endArray();
|
||||
object.setItemsSchemaList(list);
|
||||
|
||||
@@ -5,12 +5,16 @@ import com.intellij.codeInsight.completion.CompletionContributor;
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet;
|
||||
import com.intellij.idea.RareLogger;
|
||||
import com.intellij.json.JsonLanguage;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.lang.documentation.CompositeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.DocumentationProvider;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.LanguageFileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -110,11 +114,16 @@ public class JsonSchemaServiceImpl implements JsonSchemaService {
|
||||
|
||||
@Nullable
|
||||
private CodeInsightProviders getWrapper(@Nullable VirtualFile file) {
|
||||
final List<JsonSchemaObjectCodeInsightWrapper> wrappers = getWrappers(file);
|
||||
if (wrappers == null || wrappers.isEmpty()) {
|
||||
return null;
|
||||
if (file == null) return null;
|
||||
final FileType type = file.getFileType();
|
||||
if (type instanceof LanguageFileType && ((LanguageFileType)type).getLanguage().isKindOf(JsonLanguage.INSTANCE)) {
|
||||
final List<JsonSchemaObjectCodeInsightWrapper> wrappers = getWrappers(file);
|
||||
if (wrappers == null || wrappers.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return (wrappers.size() == 1 ? wrappers.get(0) : new CompositeCodeInsightProviderWithWarning(wrappers));
|
||||
}
|
||||
return (wrappers.size() == 1 ? wrappers.get(0) : new CompositeCodeInsightProviderWithWarning(wrappers));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -148,7 +157,21 @@ public class JsonSchemaServiceImpl implements JsonSchemaService {
|
||||
private DocumentationProvider myDocumentationProvider;
|
||||
|
||||
public CompositeCodeInsightProviderWithWarning(List<JsonSchemaObjectCodeInsightWrapper> wrappers) {
|
||||
myWrappers = wrappers;
|
||||
final List<JsonSchemaObjectCodeInsightWrapper> userSchemaWrappers =
|
||||
ContainerUtil.filter(wrappers, new Condition<JsonSchemaObjectCodeInsightWrapper>() {
|
||||
@Override
|
||||
public boolean value(JsonSchemaObjectCodeInsightWrapper wrapper) {
|
||||
return wrapper.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 {
|
||||
myWrappers = wrappers;
|
||||
}
|
||||
myContributor = new CompletionContributor() {
|
||||
@Override
|
||||
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.jetbrains.jsonSchema.impl;
|
||||
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* @author Irina.Chernushina on 8/29/2015.
|
||||
@@ -60,4 +65,51 @@ public class JsonSchemaReadTest {
|
||||
final JsonSchemaObject read = reader.read(new FileReader(file));
|
||||
Assert.assertTrue(read.getDefinitions().get("common").getProperties().containsKey("id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadSchemaWithWrongRequired() throws Exception {
|
||||
testSchemaReadNotHung(new File(PlatformTestUtil.getCommunityPath(), "json/tests/testData/jsonSchema/WithWrongRequired.json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadSchemaWithWrongItems() throws Exception {
|
||||
testSchemaReadNotHung(new File(PlatformTestUtil.getCommunityPath(), "json/tests/testData/jsonSchema/WithWrongItems.json"));
|
||||
}
|
||||
|
||||
private void testSchemaReadNotHung(final File file) throws IOException {
|
||||
// because of threading
|
||||
if (Runtime.getRuntime().availableProcessors() < 2) return;
|
||||
|
||||
Assert.assertTrue(file.exists());
|
||||
|
||||
final AtomicBoolean done = new AtomicBoolean();
|
||||
final AtomicReference<IOException> error = new AtomicReference<>();
|
||||
final Semaphore semaphore = new Semaphore();
|
||||
semaphore.down();
|
||||
final Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final JsonSchemaReader reader = new JsonSchemaReader();
|
||||
try {
|
||||
reader.read(new FileReader(file));
|
||||
done.set(true);
|
||||
}
|
||||
catch (IOException e) {
|
||||
error.set(e);
|
||||
}
|
||||
finally {
|
||||
semaphore.up();
|
||||
}
|
||||
}
|
||||
}, getClass().getName() + ": read test json schema " + file.getName());
|
||||
thread.setDaemon(true);
|
||||
try {
|
||||
thread.start();
|
||||
semaphore.waitFor(TimeUnit.SECONDS.toMillis(120));
|
||||
if (error.get() != null) throw error.get();
|
||||
Assert.assertTrue("Reading test schema hung!", done.get());
|
||||
} finally {
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"properties": {
|
||||
"a": {
|
||||
"items": [
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"required": [{}]
|
||||
}
|
||||
Binary file not shown.
@@ -17,7 +17,7 @@ httpclient-4.4.1.jar
|
||||
fluent-hc-4.4.1.jar
|
||||
httpmime-4.4.1.jar
|
||||
ecj-4.4.2.jar
|
||||
groovy-all-2.3.9.jar
|
||||
groovy-all-2.4.6.jar
|
||||
gson-2.5.jar
|
||||
guava-17.0.jar
|
||||
hamcrest-core-1.3.jar
|
||||
@@ -64,6 +64,7 @@ purejavacomm.jar
|
||||
resolver.jar
|
||||
rhino-js-1_7R4.jar
|
||||
sanselan-0.98-snapshot.jar
|
||||
SceneBuilderKit-8.1.1.jar
|
||||
serviceMessages.jar
|
||||
snappy-in-java-0.3.1.jar
|
||||
swingx-core-1.6.2.jar
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+8
@@ -39,6 +39,14 @@ public abstract class PriorityActionWrapper extends LocalQuickFixAndIntentionAct
|
||||
return fix.getFamilyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
@NotNull PsiElement startElement,
|
||||
@NotNull PsiElement endElement) {
|
||||
return fix.isAvailable(project, file, startElement, endElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
|
||||
+5
-4
@@ -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.
|
||||
@@ -16,23 +16,24 @@
|
||||
|
||||
package com.intellij.lang.properties.charset;
|
||||
|
||||
import java.nio.charset.spi.CharsetProvider;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Iterator;
|
||||
import java.nio.charset.spi.CharsetProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author Alexey
|
||||
*/
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public class Native2AsciiCharsetProvider extends CharsetProvider {
|
||||
public Native2AsciiCharsetProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Charset charsetForName(String charsetName) {
|
||||
return Native2AsciiCharset.forName(charsetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Charset> charsets() {
|
||||
return Collections.<Charset>emptyList().iterator();
|
||||
}
|
||||
|
||||
@@ -41,16 +41,15 @@ import java.io.IOException
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.file.Path
|
||||
|
||||
open class DirectoryBasedStorage(private val dir: Path,
|
||||
private val splitter: StateSplitter,
|
||||
private val pathMacroSubstitutor: TrackingPathMacroSubstitutor? = null) : StateStorageBase<StateMap>() {
|
||||
private @Volatile var virtualFile: VirtualFile? = null
|
||||
abstract class DirectoryBasedStorageBase(@Suppress("DEPRECATION") protected val splitter: StateSplitter,
|
||||
protected val pathMacroSubstitutor: TrackingPathMacroSubstitutor? = null) : StateStorageBase<StateMap>() {
|
||||
protected var componentName: String? = null
|
||||
|
||||
private var componentName: String? = null
|
||||
protected abstract val virtualFile: VirtualFile?
|
||||
|
||||
fun setVirtualDir(dir: VirtualFile?) {
|
||||
virtualFile = dir
|
||||
}
|
||||
override fun loadData() = StateMap.fromMap(DirectoryStorageUtil.loadFrom(virtualFile, pathMacroSubstitutor))
|
||||
|
||||
override fun startExternalization(): StateStorage.ExternalizationSession? = null
|
||||
|
||||
override fun analyzeExternalChangesAndUpdateIfNeed(componentNames: MutableSet<String>) {
|
||||
// todo reload only changed file, compute diff
|
||||
@@ -89,15 +88,26 @@ open class DirectoryBasedStorage(private val dir: Path,
|
||||
return state
|
||||
}
|
||||
|
||||
override fun loadData() = StateMap.fromMap(DirectoryStorageUtil.loadFrom(getVirtualFile(), pathMacroSubstitutor))
|
||||
override fun hasState(storageData: StateMap, componentName: String) = storageData.hasStates()
|
||||
}
|
||||
|
||||
private fun getVirtualFile(): VirtualFile? {
|
||||
var result = virtualFile
|
||||
if (result == null) {
|
||||
result = LocalFileSystem.getInstance().findFileByPath(dir.systemIndependentPath)
|
||||
virtualFile = result
|
||||
open class DirectoryBasedStorage(private val dir: Path,
|
||||
@Suppress("DEPRECATION") splitter: StateSplitter,
|
||||
pathMacroSubstitutor: TrackingPathMacroSubstitutor? = null) : DirectoryBasedStorageBase(splitter, pathMacroSubstitutor) {
|
||||
private @Volatile var cachedVirtualFile: VirtualFile? = null
|
||||
|
||||
override val virtualFile: VirtualFile?
|
||||
get() {
|
||||
var result = cachedVirtualFile
|
||||
if (result == null) {
|
||||
result = LocalFileSystem.getInstance().findFileByPath(dir.systemIndependentPath)
|
||||
cachedVirtualFile = result
|
||||
}
|
||||
return result
|
||||
}
|
||||
return result
|
||||
|
||||
internal fun setVirtualDir(dir: VirtualFile?) {
|
||||
cachedVirtualFile = dir
|
||||
}
|
||||
|
||||
override fun startExternalization(): StateStorage.ExternalizationSession? = if (checkIsSavingDisabled()) null else MySaveSession(this, getStorageData())
|
||||
@@ -159,7 +169,7 @@ open class DirectoryBasedStorage(private val dir: Path,
|
||||
override fun save() {
|
||||
val stateMap = StateMap.fromMap(copiedStorageData!!)
|
||||
|
||||
var dir = storage.getVirtualFile()
|
||||
var dir = storage.virtualFile
|
||||
if (copiedStorageData!!.isEmpty()) {
|
||||
if (dir != null && dir.exists()) {
|
||||
deleteFile(this, dir)
|
||||
@@ -170,7 +180,7 @@ open class DirectoryBasedStorage(private val dir: Path,
|
||||
|
||||
if (dir == null || !dir.isValid) {
|
||||
dir = createDir(storage.dir, this)
|
||||
storage.virtualFile = dir
|
||||
storage.cachedVirtualFile = dir
|
||||
}
|
||||
|
||||
if (!dirtyFileNames.isEmpty) {
|
||||
@@ -233,8 +243,6 @@ open class DirectoryBasedStorage(private val dir: Path,
|
||||
private fun setStorageData(newStates: StateMap) {
|
||||
storageDataRef.set(newStates)
|
||||
}
|
||||
|
||||
override fun hasState(storageData: StateMap, componentName: String) = storageData.hasStates()
|
||||
}
|
||||
|
||||
private val NON_EXISTENT_FILE_DATA = Pair.create<ByteArray, String>(null, SystemProperties.getLineSeparator())
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user