Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Vasily Romanikhin
2018-02-14 16:21:04 +03:00
284 changed files with 2108 additions and 1180 deletions
+3
View File
@@ -12,4 +12,7 @@
<option name="coroutinesState" value="enable" />
<option name="languageVersion" value="1.2" />
</component>
<component name="KotlinCompilerSettings">
<option name="additionalArguments" value="-version -Xstrict-java-nullability-assertions" />
</component>
</project>
+23
View File
@@ -0,0 +1,23 @@
<component name="libraryTable">
<library name="jackson-databind" type="repository">
<properties maven-id="com.fasterxml.jackson.core:jackson-databind:2.9.4" />
<ANNOTATIONS>
<root url="file://$PROJECT_DIR$/lib/annotations/jackson" />
</ANNOTATIONS>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.4/jackson-databind-2.9.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.4/jackson-core-2.9.4.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.4/jackson-databind-2.9.4-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.4/jackson-core-2.9.4-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.4/jackson-databind-2.9.4-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.4/jackson-core-2.9.4-sources.jar!/" />
</SOURCES>
</library>
</component>
+1 -1
View File
@@ -1,5 +1,5 @@
# The file might be automatically updated. Comments and empty lines will be removed.
kotlinPluginBuild=1.2.30-eap-16-IJ2018.1-1:ideadev
jetSignBuild=42.30
jdkBuild=u152b1136.12
jdkBuild=u152b1153.1
gradleApiVersion=4.4
@@ -21,6 +21,7 @@ import com.intellij.openapi.ui.MultiLineLabelUI
import com.intellij.openapi.util.text.StringUtil
import com.intellij.testGuiFramework.framework.RunWithIde
import com.intellij.testGuiFramework.impl.GuiTestCase
import com.intellij.testGuiFramework.impl.GuiTestUtilKt
import com.intellij.testGuiFramework.launcher.ide.CommunityIde
import org.junit.Assert.assertTrue
import org.junit.Test
@@ -46,6 +47,7 @@ public class Main {
actionLink("Create New Project").click()
dialog("New Project") {
jList("Java").clickItem("Java")
GuiTestUtilKt.waitProgressDialogUntilGone(robot(), "Loading Templates")
button("Next").click()
checkbox("Create project from template").click()
jList("Command Line App").clickItem("Command Line App")
@@ -51,7 +51,7 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
public class HotSwapProgressImpl extends HotSwapProgress{
public class HotSwapProgressImpl extends HotSwapProgress {
static final NotificationGroup NOTIFICATION_GROUP = NotificationGroup.toolWindowGroup("HotSwap", ToolWindowId.DEBUG);
private final TIntObjectHashMap<List<String>> myMessages = new TIntObjectHashMap<>();
@@ -59,6 +59,7 @@ public class HotSwapProgressImpl extends HotSwapProgress{
private String myTitle = DebuggerBundle.message("progress.hot.swap.title");
private final MergingUpdateQueue myUpdateQueue;
private WeakReference<XDebugSession> mySessionRef = null;
private List<HotSwapProgressListener> myListeners = ContainerUtil.newSmartList();
public HotSwapProgressImpl(Project project) {
super(project);
@@ -78,10 +79,22 @@ public class HotSwapProgressImpl extends HotSwapProgress{
myUpdateQueue = new MergingUpdateQueue("HotSwapProgress update queue", 100, true, null, myProgressWindow);
}
@Override
public void cancel() {
super.cancel();
for (HotSwapProgressListener listener : myListeners) {
listener.onCancel();
}
}
@Override
public void finished() {
super.finished();
for (HotSwapProgressListener listener : myListeners) {
listener.onFinish();
}
List<String> errors = getMessages(MessageCategory.ERROR);
List<String> warnings = getMessages(MessageCategory.WARNING);
@@ -143,7 +156,7 @@ public class HotSwapProgressImpl extends HotSwapProgress{
mySessionRef = new WeakReference<>(session.getXDebugSession());
}
private List<String> getMessages(int category) {
List<String> getMessages(int category) {
return ContainerUtil.notNullize(myMessages.get(category));
}
@@ -215,4 +228,16 @@ public class HotSwapProgressImpl extends HotSwapProgress{
myTitle = DebuggerBundle.message("progress.hot.swap.title") + " : " + session.getSessionName();
myProgressWindow.setTitle(myTitle);
}
void addProgressListener(@NotNull HotSwapProgressListener listener) {
myListeners.add(listener);
}
interface HotSwapProgressListener {
default void onCancel() {
}
default void onFinish() {
}
}
}
@@ -0,0 +1,10 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui;
import com.intellij.debugger.impl.DebuggerSession;
import java.util.List;
public interface HotSwapStatusListener {
void hotSwapFinished(boolean aborted, int errors, int warnings, List<DebuggerSession> sessions);
}
@@ -18,6 +18,8 @@ package com.intellij.debugger.ui;
import com.intellij.openapi.project.Project;
import com.intellij.debugger.impl.DebuggerSession;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
@@ -27,11 +29,12 @@ public abstract class HotSwapUI {
return project.getComponent(HotSwapUI.class);
}
public abstract void reloadChangedClasses(DebuggerSession session, boolean compileBeforeHotswap);
public abstract void reloadChangedClasses(@NotNull DebuggerSession session, boolean compileBeforeHotswap);
public abstract void reloadChangedClasses(@NotNull DebuggerSession session, @Nullable HotSwapStatusListener callback);
public abstract void dontPerformHotswapAfterThisCompilation();
public abstract void addListener(HotSwapVetoableListener listener);
public abstract void removeListener(HotSwapVetoableListener listener);
@@ -35,6 +35,7 @@ import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.ui.MessageCategory;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -96,7 +97,8 @@ public class HotSwapUIImpl extends HotSwapUI {
return sessions.stream().anyMatch(DebuggerSession::isPaused);
}
private void hotSwapSessions(final List<DebuggerSession> sessions, @Nullable final Map<String, List<String>> generatedPaths) {
private void hotSwapSessions(final List<DebuggerSession> sessions, @Nullable final Map<String, List<String>> generatedPaths,
@Nullable final HotSwapStatusListener callback) {
final boolean shouldAskBeforeHotswap = myAskBeforeHotswap;
myAskBeforeHotswap = true;
@@ -104,7 +106,14 @@ public class HotSwapUIImpl extends HotSwapUI {
final String runHotswap = settings.RUN_HOTSWAP_AFTER_COMPILE;
final boolean shouldDisplayHangWarning = shouldDisplayHangWarning(settings, sessions);
HotSwapStatusListener callbackWrapper = (aborted, errors, warnings, hotSwappedSessions) -> {
if (callback != null) {
callback.hotSwapFinished(aborted, errors, warnings, hotSwappedSessions);
}
};
if (shouldAskBeforeHotswap && DebuggerSettings.RUN_HOTSWAP_NEVER.equals(runHotswap)) {
callbackWrapper.hotSwapFinished(true, 0, 0, sessions);
return;
}
@@ -118,6 +127,14 @@ public class HotSwapUIImpl extends HotSwapUI {
boolean createProgress = sessions.stream().anyMatch(DebuggerSession::isModifiedClassesScanRequired);
findClassesProgress = createProgress ? new HotSwapProgressImpl(myProject) : null;
}
if (findClassesProgress != null) {
findClassesProgress.addProgressListener(new HotSwapProgressImpl.HotSwapProgressListener() {
@Override
public void onCancel() {
callbackWrapper.hotSwapFinished(true, 0, 0, sessions);
}
});
}
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses;
@@ -144,6 +161,7 @@ public class HotSwapUIImpl extends HotSwapUI {
if (modifiedClasses.isEmpty()) {
final String message = DebuggerBundle.message("status.hotswap.uptodate");
HotSwapProgressImpl.NOTIFICATION_GROUP.createNotification(message, NotificationType.INFORMATION).notify(myProject);
callbackWrapper.hotSwapFinished(false, 0, 0, sessions);
return;
}
@@ -154,6 +172,7 @@ public class HotSwapUIImpl extends HotSwapUI {
for (DebuggerSession session : modifiedClasses.keySet()) {
session.setModifiedClassesScanRequired(true);
}
callbackWrapper.hotSwapFinished(true, 0, 0, sessions);
return;
}
final Set<DebuggerSession> toReload = new HashSet<>(dialog.getSessionsToReload());
@@ -181,6 +200,7 @@ public class HotSwapUIImpl extends HotSwapUI {
for (DebuggerSession session : modifiedClasses.keySet()) {
session.setModifiedClassesScanRequired(true);
}
callbackWrapper.hotSwapFinished(true, 0, 0, sessions);
return;
}
}
@@ -192,6 +212,17 @@ public class HotSwapUIImpl extends HotSwapUI {
//noinspection ConstantConditions
progress.setSessionForActions(ContainerUtil.getFirstItem(modifiedClasses.keySet()));
}
progress.addProgressListener(new HotSwapProgressImpl.HotSwapProgressListener() {
@Override
public void onCancel() {
notifyStatusListener(callbackWrapper, progress, sessions, true);
}
@Override
public void onFinish() {
notifyStatusListener(callbackWrapper, progress, sessions, false);
}
});
application.executeOnPooledThread(() -> reloadModifiedClasses(modifiedClasses, progress));
}
}, ModalityState.NON_MODAL);
@@ -212,7 +243,8 @@ public class HotSwapUIImpl extends HotSwapUI {
return result.get();
}
private static void reloadModifiedClasses(final Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses, final HotSwapProgressImpl progress) {
private static void reloadModifiedClasses(final Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses,
final HotSwapProgressImpl progress) {
UsageTrigger.trigger("debugger.reload.classes");
ProgressManager.getInstance().runProcess(() -> {
HotSwapManager.reloadModifiedClasses(modifiedClasses, progress);
@@ -221,14 +253,25 @@ public class HotSwapUIImpl extends HotSwapUI {
}
@Override
public void reloadChangedClasses(final DebuggerSession session, boolean compileBeforeHotswap) {
public void reloadChangedClasses(@NotNull DebuggerSession session, boolean compileBeforeHotswap) {
reloadChangedClasses(session, null, compileBeforeHotswap);
}
@Override
public void reloadChangedClasses(@NotNull DebuggerSession session, @Nullable HotSwapStatusListener callback) {
reloadChangedClasses(session, callback, false);
}
private void reloadChangedClasses(@NotNull DebuggerSession session,
@Nullable HotSwapStatusListener callback,
boolean compileBeforeHotswap) {
dontAskHotswapAfterThisCompilation();
if (compileBeforeHotswap) {
CompilerManager.getInstance(session.getProject()).make(null);
}
else {
if (session.isAttached()) {
hotSwapSessions(Collections.singletonList(session), null);
hotSwapSessions(Collections.singletonList(session), null, callback);
}
}
}
@@ -278,7 +321,7 @@ public class HotSwapUIImpl extends HotSwapUI {
List<DebuggerSession> sessions = getHotSwappableDebugSessions();
if (!sessions.isEmpty()) {
hotSwapSessions(sessions, generated);
hotSwapSessions(sessions, generated, null);
}
}
myPerformHotswapAfterThisCompilation = true;
@@ -295,4 +338,14 @@ public class HotSwapUIImpl extends HotSwapUI {
.filter(HotSwapUIImpl::canHotSwap)
.collect(Collectors.toCollection(SmartList::new));
}
private static void notifyStatusListener(HotSwapStatusListener listener,
HotSwapProgressImpl progress,
List<DebuggerSession> sessions,
boolean aborted) {
listener.hotSwapFinished(aborted,
progress.getMessages(MessageCategory.ERROR).size(),
progress.getMessages(MessageCategory.WARNING).size(),
sessions);
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui.impl;
import com.intellij.debugger.actions.DebuggerAction;
@@ -40,6 +26,8 @@ import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Enumeration;
import java.util.NoSuchElementException;
public class ThreadsPanel extends DebuggerTreePanel{
@NonNls private static final String HELP_ID = "debugging.debugThreads";
@@ -138,11 +126,15 @@ public class ThreadsPanel extends DebuggerTreePanel{
}
private static void updateNodeLabels(DebuggerTreeNodeImpl from) {
final int childCount = from.getChildCount();
for (int idx = 0; idx < childCount; idx++) {
final DebuggerTreeNodeImpl child = (DebuggerTreeNodeImpl)from.getChildAt(idx);
child.getDescriptor().updateRepresentation(null, child::labelChanged);
updateNodeLabels(child);
Enumeration children = from.children();
try {
while (children.hasMoreElements()) {
DebuggerTreeNodeImpl child = (DebuggerTreeNodeImpl)children.nextElement();
child.getDescriptor().updateRepresentation(null, child::labelChanged);
updateNodeLabels(child);
}
}
catch (NoSuchElementException ignored) { // children have changed - just skip
}
}
@@ -17,7 +17,6 @@
<project-components>
<component>
<implementation-class>com.intellij.codeInsight.daemon.impl.JavaSoftKeywordHighlightingPassFactory</implementation-class>
<skipForDefaultProject/>
</component>
</project-components>
@@ -17,6 +17,7 @@ package com.intellij.codeInspection.miscGenerics;
import com.intellij.codeInsight.daemon.impl.analysis.JavaGenericsUtil;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.openapi.util.NullableLazyValue;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
import com.intellij.psi.search.GlobalSearchScope;
@@ -167,7 +168,7 @@ public class SuspiciousMethodCallUtil {
PsiElement element = resolveResult.getElement();
if (!(element instanceof PsiMethod)) return null;
PsiMethod calleeMethod = (PsiMethod)element;
PsiMethod contextMethod = PsiTreeUtil.getParentOfType(methodExpression, PsiMethod.class);
NullableLazyValue<PsiMethod> lazyContextMethod = NullableLazyValue.createValue(() -> PsiTreeUtil.getParentOfType(methodExpression, PsiMethod.class));
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (patternMethods) {
@@ -182,6 +183,7 @@ public class SuspiciousMethodCallUtil {
int index = indices.get(i);
//we are in collections method implementation
PsiMethod contextMethod = lazyContextMethod.getValue();
if (contextMethod != null && isInheritorOrSelf(contextMethod, patternMethod)) return null;
final PsiClass calleeClass = calleeMethod.getContainingClass();
@@ -332,6 +332,13 @@ public class JavaMethodCallElement extends LookupItem<PsiMethod> implements Type
}
}
public static void setCompletionModeIfNotSet(@NotNull PsiCall expression, @NotNull Disposable disposable) {
if (!isCompletionMode(expression)) {
setCompletionMode(expression, true);
Disposer.register(disposable, () -> setCompletionMode(expression, false));
}
}
public static void setCompletionMode(@NotNull PsiCall expression, boolean value) {
expression.putUserData(COMPLETION_HINTS, value ? Boolean.TRUE : null);
}
@@ -15,12 +15,10 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorModificationUtil;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.*;
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -94,7 +92,7 @@ class JavaMethodOverloadSwitchHandler extends EditorActionHandler {
currentIndex = mySwitchUp ? objects.length : -1;
}
else {
currentIndex = ContainerUtil.indexOf(Arrays.asList(objects), highlighted);
currentIndex = Arrays.asList(objects).indexOf(highlighted);
if (currentIndex < 0) return;
PsiMethod currentMethod = (PsiMethod)((CandidateInfo)objects[currentIndex]).getElement();
@@ -141,10 +139,7 @@ class JavaMethodOverloadSwitchHandler extends EditorActionHandler {
});
caret.moveToLogicalPosition(editor.offsetToLogicalPosition(targetCaretPosition.get()).leanForward(true));
PsiCall methodCall = (PsiCall)call;
if (!JavaMethodCallElement.isCompletionMode(methodCall)) {
JavaMethodCallElement.setCompletionMode(methodCall, true);
Disposer.register(controller, () -> JavaMethodCallElement.setCompletionMode(methodCall, false));
}
JavaMethodCallElement.setCompletionModeIfNotSet(methodCall, controller);
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
CompletionMemory.registerChosenMethod(targetMethod, methodCall);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.editorActions;
import com.intellij.codeInsight.hint.ParameterInfoController;
@@ -26,7 +12,6 @@ import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -70,7 +55,7 @@ public class JavaVarArgNextParameterHandler extends EditorActionHandler {
Object[] objects = controller.getObjects();
Object highlighted = controller.getHighlighted();
if (objects != null && objects.length > 0 && (highlighted != null || objects.length == 1)) {
int currentIndex = highlighted == null ? 0 : ContainerUtil.indexOf(Arrays.asList(objects), highlighted);
int currentIndex = highlighted == null ? 0 : Arrays.asList(objects).indexOf(highlighted);
if (currentIndex >= 0) {
PsiMethod currentMethod = (PsiMethod)((CandidateInfo)objects[currentIndex]).getElement();
if (currentMethod.isVarArgs()) {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.editorActions;
import com.intellij.codeInsight.hint.ParameterInfoController;
@@ -26,7 +12,6 @@ import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -65,7 +50,7 @@ public class JavaVarArgPrevParameterHandler extends EditorActionHandler {
Object[] objects = controller.getObjects();
Object highlighted = controller.getHighlighted();
if (objects != null && objects.length > 0 && (highlighted != null || objects.length == 1)) {
int currentIndex = highlighted == null ? 0 : ContainerUtil.indexOf(Arrays.asList(objects), highlighted);
int currentIndex = highlighted == null ? 0 : Arrays.asList(objects).indexOf(highlighted);
if (currentIndex >= 0) {
PsiMethod currentMethod = (PsiMethod)((CandidateInfo)objects[currentIndex]).getElement();
if (currentMethod.isVarArgs()) {
@@ -10,6 +10,7 @@ import com.intellij.codeInsight.completion.JavaCompletionUtil;
import com.intellij.codeInsight.completion.JavaMethodCallElement;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager;
import com.intellij.codeInsight.hint.ParameterInfoController;
import com.intellij.codeInsight.hints.ParameterHintsPass;
import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator;
import com.intellij.codeInsight.lookup.LookupElement;
@@ -55,7 +56,7 @@ import java.util.List;
public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabActionSupport<PsiExpressionList, Object, PsiExpression>, DumbAware {
private static final Set<Class> ourArgumentListAllowedParentClassesSet = ContainerUtil.newHashSet(
PsiMethodCallExpression.class, PsiNewExpression.class, PsiAnonymousClass.class, PsiEnumConstant.class);
private static final Set<? extends Class> ourStopSearch = Collections.singleton(PsiMethod.class);
private static final Set<Class> ourStopSearch = Collections.singleton(PsiMethod.class);
private static final String WHITESPACE = " \t";
private static final Key<Inlay> CURRENT_HINT = Key.create("current.hint");
private static final Key<List<Inlay>> HIGHLIGHTED_HINTS = Key.create("highlighted.hints");
@@ -110,7 +111,24 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
@Override
public void showParameterInfo(@NotNull final PsiExpressionList element, @NotNull final CreateParameterInfoContext context) {
context.showHint(element, element.getTextRange().getStartOffset(), this);
int offset = element.getTextRange().getStartOffset();
if (CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION) {
ParameterInfoController controller = ParameterInfoController.findControllerAtOffset(context.getEditor(), offset);
PsiElement parent = element.getParent();
if (parent instanceof PsiCall && controller != null && controller.isHintShown(false)) {
Object highlighted = controller.getHighlighted();
Object[] objects = controller.getObjects();
if (objects != null && objects.length > 0 && (highlighted != null || objects.length == 1)) {
PsiCall methodCall = (PsiCall)parent;
JavaMethodCallElement.setCompletionModeIfNotSet(methodCall, controller);
PsiMethod targetMethod = (PsiMethod)((CandidateInfo)(highlighted == null ? objects[0] : highlighted)).getElement();
CompletionMemory.registerChosenMethod(targetMethod, methodCall);
controller.setPreservedOnHintHidden(true);
ParameterHintsPass.syncUpdate(methodCall, context.getEditor());
}
}
}
context.showHint(element, offset, this);
}
@Override
@@ -499,7 +517,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
@NotNull
@Override
public Set<? extends Class> getArgListStopSearchClasses() {
public Set<Class> getArgListStopSearchClasses() {
return ourStopSearch;
}
@@ -26,22 +26,28 @@ public class DefaultAnnotationParamInspection extends AbstractBaseJavaLocalInspe
PsiAnnotationMemberValue defaultValue = ((PsiAnnotationMethod)element).getDefaultValue();
if (defaultValue == null) return;
if (AnnotationUtil.equal(value, defaultValue)) {
holder.registerProblem(value, "Redundant default parameter value assignment", ProblemHighlightType.LIKE_UNUSED_SYMBOL, new LocalQuickFix() {
@Nls
@NotNull
@Override
public String getFamilyName() {
return "Remove redundant parameter";
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement parent = descriptor.getPsiElement().getParent();
parent.delete();
}
});
holder.registerProblem(value, "Redundant default parameter value assignment", ProblemHighlightType.LIKE_UNUSED_SYMBOL,
createRemoveParameterFix());
}
}
};
}
@NotNull
private static LocalQuickFix createRemoveParameterFix() {
return new LocalQuickFix() {
@Nls
@NotNull
@Override
public String getFamilyName() {
return "Remove redundant parameter";
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement parent = descriptor.getPsiElement().getParent();
parent.delete();
}
};
}
}
@@ -52,17 +52,17 @@ public class AutomaticVariableRenamer extends AutomaticRenamer {
if (statement != null) {
for(PsiElement declaredElement: statement.getDeclaredElements()) {
if (declaredElement instanceof PsiVariable) {
checkRenameVariable(element, (PsiVariable) declaredElement, oldClassName);
checkRenameVariable(element, (PsiVariable) declaredElement, oldClassName, newClassName);
}
}
}
else {
PsiVariable variable = PsiTreeUtil.getParentOfType(element, PsiVariable.class);
if (variable != null) {
checkRenameVariable(element, variable, oldClassName);
checkRenameVariable(element, variable, oldClassName, newClassName);
if (variable instanceof PsiField) {
for(PsiField field: getFieldsInSameDeclaration((PsiField) variable)) {
checkRenameVariable(element, field, oldClassName);
checkRenameVariable(element, field, oldClassName, newClassName);
}
}
}
@@ -104,13 +104,18 @@ public class AutomaticVariableRenamer extends AutomaticRenamer {
return result;
}
private void checkRenameVariable(final PsiElement element, final PsiVariable variable, final String oldClassName) {
private void checkRenameVariable(final PsiElement element,
final PsiVariable variable,
final String oldClassName,
String newClassName) {
final PsiTypeElement typeElement = variable.getTypeElement();
if (typeElement == null) return;
final PsiJavaCodeReferenceElement ref = typeElement.getInnermostComponentReferenceElement();
if (ref == null) return;
final String variableName = variable.getName();
if (variableName != null && !StringUtil.containsIgnoreCase(variableName, oldClassName)) return;
if (variableName == null) return;
if (variableName.equalsIgnoreCase(newClassName)) return;
if (!StringUtil.containsIgnoreCase(variableName, oldClassName)) return;
if (ref.equals(element)) {
myElements.add(variable);
if (variable.getType() instanceof PsiArrayType) {
@@ -62,7 +62,7 @@ public class LambdaExpressionElementType extends FunctionalExpressionElementType
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
final IElementType elType = child.getElementType();
if (elType == JavaTokenType.ARROW) {
return ChildRole.ARROW;
@@ -70,7 +70,7 @@ public class MethodReferenceElementType extends FunctionalExpressionElementType<
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
final IElementType elType = child.getElementType();
if (elType == JavaTokenType.DOUBLE_COLON) {
return ChildRole.DOUBLE_COLON;
@@ -82,7 +82,7 @@ public class PsiImportStaticReferenceElementImpl extends CompositePsiElement imp
}
@Override
public final int getChildRole(ASTNode child) {
public final int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaElementType.JAVA_CODE_REFERENCE) {
@@ -247,7 +247,7 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
}
@Override
public final int getChildRole(final ASTNode child) {
public final int getChildRole(@NotNull final ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
final IElementType i = child.getElementType();
if (i == JavaElementType.REFERENCE_PARAMETER_LIST) {
@@ -199,7 +199,7 @@ public class PsiModifierListImpl extends JavaStubPsiElement<PsiModifierListStub>
final CompositeElement tree = (CompositeElement)getNode();
final IElementType type = NAME_TO_KEYWORD_TYPE_MAP.get(name);
return tree.findChildByType(type) != null;
return type != null && tree.findChildByType(type) != null;
}
@Override
@@ -44,7 +44,7 @@ public class CorePsiDocTagValueImpl extends CompositePsiElement implements PsiDo
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
if (child.getElementType() == JavaDocTokenType.DOC_TAG_VALUE_COMMA) {
return ChildRole.COMMA;
}
@@ -321,7 +321,7 @@ public class PsiDocCommentImpl extends LazyParseablePsiElement implements PsiDoc
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == DOC_TAG) {
@@ -77,7 +77,7 @@ public class PsiDocTagImpl extends CompositePsiElement implements PsiDocTag, Con
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
assert child.getTreeParent() == this : child.getTreeParent();
IElementType i = child.getElementType();
if (i == DOC_TAG_NAME) {
@@ -83,7 +83,7 @@ public class PsiInlineDocTagImpl extends CompositePsiElement implements PsiInlin
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
assert child.getTreeParent() == this : child.getTreeParent();
IElementType i = child.getElementType();
if (i == DOC_TAG_NAME) {
@@ -23,6 +23,7 @@ import com.intellij.psi.impl.source.tree.ChildRole;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
/**
* @author ven
@@ -35,7 +36,7 @@ public class AnnotationElement extends CompositeElement implements Constants {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.tree.java;
import com.intellij.psi.impl.source.tree.ChildRole;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
/**
* @author ven
@@ -36,7 +37,7 @@ public class AnnotationMethodElement extends MethodElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
if (ANNOTATION_MEMBER_VALUE_BIT_SET.contains(child.getElementType())) {
return ChildRole.ANNOTATION_DEFAULT_VALUE;
}
@@ -38,7 +38,7 @@ public class AnnotationParamListElement extends CompositeElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
IElementType i = child.getElementType();
if (i == JavaTokenType.COMMA) {
return ChildRole.COMMA;
@@ -22,6 +22,7 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
public abstract class AnonymousClassElementBase extends ClassElement {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.AnonymousClassElement");
@@ -52,7 +53,7 @@ public abstract class AnonymousClassElementBase extends ClassElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaElementType.JAVA_CODE_REFERENCE) {
@@ -323,7 +323,7 @@ public class ClassElement extends CompositeElement implements Constants {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
assert child.getTreeParent() == this;
IElementType i = child.getElementType();
@@ -22,6 +22,7 @@ import com.intellij.psi.impl.source.tree.ChildRole;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class ClassInitializerElement extends CompositeElement implements Constants {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.ClassInitializerElement");
@@ -46,7 +47,7 @@ public class ClassInitializerElement extends CompositeElement implements Constan
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == C_STYLE_COMMENT || i == END_OF_LINE_COMMENT) {
@@ -23,6 +23,7 @@ import com.intellij.psi.impl.source.Constants;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
/**
* @author dsl
@@ -63,7 +64,7 @@ public class EnumConstantElement extends CompositeElement implements Constants {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaDocElementType.DOC_COMMENT) {
@@ -20,7 +20,6 @@ import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.source.Constants;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.tree.IElementType;
@@ -83,7 +82,7 @@ public class FieldElement extends CompositeElement{
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
assert (child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaDocElementType.DOC_COMMENT) {
@@ -24,6 +24,7 @@ import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.TreeUtil;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
/**
* @author dsl
@@ -57,7 +58,7 @@ public class ImportStatementBaseElement extends CompositeElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaTokenType.IMPORT_KEYWORD) {
@@ -19,6 +19,7 @@ import com.intellij.lang.ASTNode;
import com.intellij.psi.impl.source.tree.ChildRole;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.tree.ChildRoleBase;
import org.jetbrains.annotations.NotNull;
public class ImportStaticStatementElement extends ImportStatementBaseElement {
@@ -46,7 +47,7 @@ public class ImportStaticStatementElement extends ImportStatementBaseElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
final int role = super.getChildRole(child);
if (role != ChildRoleBase.NONE) return role;
if (child.getElementType() == JavaElementType.IMPORT_STATIC_REFERENCE) {
@@ -66,7 +66,7 @@ public class JavaFileElement extends FileElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaElementType.PACKAGE_STATEMENT) {
@@ -123,7 +123,7 @@ public class MethodElement extends CompositeElement implements Constants {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaDocElementType.DOC_COMMENT) {
@@ -24,6 +24,8 @@ import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.ChildRoleBase;
import java.util.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ModifierListElement extends CompositeElement {
@@ -46,7 +48,7 @@ public class ModifierListElement extends CompositeElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
if (child.getElementType() == JavaElementType.ANNOTATION) return ChildRole.ANNOTATION;
return ChildRoleBase.NONE;
@@ -34,7 +34,7 @@ public class NameValuePairElement extends CompositeElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
if (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(child.getElementType())) {
return ChildRole.ANNOTATION_VALUE;
}
@@ -57,7 +57,7 @@ public class ParameterElement extends CompositeElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
@@ -127,7 +127,7 @@ public class ParameterListElement extends CompositeElement implements Constants
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (PARAMETER_SET.contains((i))) {
@@ -83,7 +83,7 @@ public class PsiArrayAccessExpressionImpl extends ExpressionPsiElement implement
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == LBRACKET) {
@@ -76,7 +76,7 @@ public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement impl
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaTokenType.COMMA) {
@@ -58,7 +58,7 @@ public class PsiArrayInitializerMemberValueImpl extends CompositePsiElement impl
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
@@ -78,7 +78,7 @@ public class PsiAssertStatementImpl extends CompositePsiElement implements PsiAs
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == ASSERT_KEYWORD) {
@@ -80,7 +80,7 @@ public class PsiAssignmentExpressionImpl extends ExpressionPsiElement implements
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) {
if (child == getFirstChildNode()) return ChildRole.LOPERAND;
@@ -109,7 +109,7 @@ public class PsiBinaryExpressionImpl extends ExpressionPsiElement implements Psi
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) {
if (child == getFirstChildNode()) return ChildRole.LOPERAND;
@@ -54,7 +54,7 @@ public class PsiBlockStatementImpl extends CompositePsiElement implements PsiBlo
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
if (child.getElementType() == JavaElementType.CODE_BLOCK) {
return ChildRole.BLOCK;
@@ -90,7 +90,7 @@ public class PsiBreakStatementImpl extends CompositePsiElement implements PsiBre
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == BREAK_KEYWORD) {
@@ -232,7 +232,7 @@ public class PsiCatchSectionImpl extends CompositePsiElement implements PsiCatch
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == PARAMETER) {
@@ -68,7 +68,7 @@ public class PsiClassObjectAccessExpressionImpl extends ExpressionPsiElement imp
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == TYPE) {
@@ -194,7 +194,7 @@ public class PsiCodeBlockImpl extends LazyParseablePsiElement implements PsiCode
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaTokenType.LBRACE) {
@@ -156,7 +156,7 @@ public class PsiConditionalExpressionImpl extends ExpressionPsiElement implement
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())){
int role = getChildRole(child, ChildRole.CONDITION);
@@ -86,7 +86,7 @@ public class PsiContinueStatementImpl extends CompositePsiElement implements Psi
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == CONTINUE_KEYWORD) {
@@ -39,7 +39,7 @@ public class PsiDeclarationStatementImpl extends CompositePsiElement implements
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
if (child.getElementType() == JavaTokenType.COMMA) return ChildRole.COMMA;
return super.getChildRole(child);
}
@@ -90,7 +90,7 @@ public class PsiDoWhileStatementImpl extends CompositePsiElement implements PsiD
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == DO_KEYWORD) {
@@ -81,7 +81,7 @@ public class PsiExpressionListImpl extends CompositePsiElement implements PsiExp
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaTokenType.COMMA) {
@@ -57,7 +57,7 @@ public class PsiExpressionListStatementImpl extends CompositePsiElement implemen
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == EXPRESSION_LIST) {
@@ -57,7 +57,7 @@ public class PsiExpressionStatementImpl extends CompositePsiElement implements P
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaTokenType.SEMICOLON) {
@@ -126,7 +126,7 @@ public class PsiForStatementImpl extends CompositePsiElement implements PsiForSt
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == FOR_KEYWORD) {
@@ -95,7 +95,7 @@ public class PsiForeachStatementImpl extends CompositePsiElement implements PsiF
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
@@ -149,7 +149,7 @@ public class PsiIfStatementImpl extends CompositePsiElement implements PsiIfStat
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == IF_KEYWORD) {
@@ -66,7 +66,7 @@ public class PsiInstanceOfExpressionImpl extends ExpressionPsiElement implements
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == TYPE) {
@@ -68,7 +68,7 @@ public class PsiLabeledStatementImpl extends CompositePsiElement implements PsiL
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == IDENTIFIER) {
@@ -262,7 +262,7 @@ public class PsiLocalVariableImpl extends CompositePsiElement implements PsiLoca
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == MODIFIER_LIST) {
@@ -107,7 +107,7 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaElementType.EXPRESSION_LIST) {
@@ -327,7 +327,7 @@ public class PsiNewExpressionImpl extends ExpressionPsiElement implements PsiNew
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaElementType.REFERENCE_PARAMETER_LIST) {
@@ -68,7 +68,7 @@ public class PsiPackageStatementImpl extends CompositePsiElement implements PsiP
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaTokenType.PACKAGE_KEYWORD) {
@@ -65,7 +65,7 @@ public class PsiParenthesizedExpressionImpl extends ExpressionPsiElement impleme
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == LPARENTH) {
@@ -92,7 +92,7 @@ public class PsiPolyadicExpressionImpl extends ExpressionPsiElement implements P
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
if (OUR_OPERATIONS_BIT_SET.contains(child.getElementType())) {
return ChildRole.OPERATION_SIGN;
@@ -71,7 +71,7 @@ public class PsiPostfixExpressionImpl extends ExpressionPsiElement implements Ps
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
if (child == getFirstChildNode()) return ChildRole.OPERAND;
if (child == getLastChildNode()) return ChildRole.OPERATION_SIGN;
@@ -88,7 +88,7 @@ public class PsiPrefixExpressionImpl extends ExpressionPsiElement implements Psi
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
if (child == getFirstChildNode()) return ChildRole.OPERATION_SIGN;
if (child == getLastChildNode() && ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) return ChildRole.OPERAND;
@@ -774,7 +774,7 @@ public class PsiReferenceExpressionImpl extends ExpressionPsiElement implements
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JavaTokenType.DOT) {
@@ -50,7 +50,7 @@ public class PsiReferenceParameterListImpl extends CompositePsiElement implement
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
IElementType i = child.getElementType();
if (i == JavaElementType.TYPE) {
return ChildRole.TYPE_IN_REFERENCE_PARAMETER_LIST;
@@ -60,7 +60,7 @@ public class PsiReturnStatementImpl extends CompositePsiElement implements PsiRe
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == RETURN_KEYWORD) {
@@ -122,7 +122,7 @@ public class PsiSuperExpressionImpl extends ExpressionPsiElement implements PsiS
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JAVA_CODE_REFERENCE) {
@@ -77,7 +77,7 @@ public class PsiSwitchLabelStatementImpl extends CompositePsiElement implements
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == CASE_KEYWORD) {
@@ -77,7 +77,7 @@ public class PsiSwitchStatementImpl extends CompositePsiElement implements PsiSw
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == SWITCH_KEYWORD) {
@@ -67,7 +67,7 @@ public class PsiSynchronizedStatementImpl extends CompositePsiElement implements
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == SYNCHRONIZED_KEYWORD) {
@@ -86,7 +86,7 @@ public class PsiThisExpressionImpl extends ExpressionPsiElement implements PsiTh
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == JAVA_CODE_REFERENCE) {
@@ -60,7 +60,7 @@ public class PsiThrowStatementImpl extends CompositePsiElement implements PsiThr
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == THROW_KEYWORD) {
@@ -135,7 +135,7 @@ public class PsiTryStatementImpl extends CompositePsiElement implements PsiTrySt
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == TRY_KEYWORD) {
@@ -72,7 +72,7 @@ public class PsiTypeCastExpressionImpl extends ExpressionPsiElement implements P
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
assert child.getTreeParent() == this: "child:"+child+"; child.getTreeParent():"+child.getTreeParent();
IElementType i = child.getElementType();
if (i == LPARENTH) {
@@ -78,7 +78,7 @@ public class PsiWhileStatementImpl extends CompositePsiElement implements PsiWhi
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == WHILE_KEYWORD) {
@@ -101,7 +101,7 @@ public class ReferenceListElement extends CompositeElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
assert child.getTreeParent() == this : child;
IElementType childType = child.getElementType();
if (childType == JavaTokenType.COMMA) return ChildRole.COMMA;
@@ -21,6 +21,7 @@ import com.intellij.psi.JavaTokenType;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
/**
* @author max
@@ -33,7 +34,7 @@ public class TypeParameterElement extends CompositeElement {
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
final IElementType i = child.getElementType();
if (i == JavaTokenType.IDENTIFIER) {
@@ -22,6 +22,7 @@ import com.intellij.psi.impl.source.tree.ChildRole;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class TypeParameterExtendsBoundsListElement extends ReferenceListElement {
public TypeParameterExtendsBoundsListElement() {
@@ -29,7 +30,7 @@ public class TypeParameterExtendsBoundsListElement extends ReferenceListElement
}
@Override
public int getChildRole(ASTNode child) {
public int getChildRole(@NotNull ASTNode child) {
assert child.getTreeParent() == this : child;
IElementType childType = child.getElementType();
if (childType == JavaTokenType.AND) return ChildRole.AMPERSAND_IN_BOUNDS_LIST;
@@ -38,7 +38,7 @@ public class TypeParameterListElement extends CompositeElement {
}
@Override
public int getChildRole(final ASTNode child) {
public int getChildRole(@NotNull final ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
final IElementType elType = child.getElementType();
if (elType == JavaElementType.TYPE_PARAMETER) {
@@ -901,6 +901,13 @@ public class CompletionHintsTest extends AbstractParameterInfoTestCase {
checkHintContents("<html><b>long</b>&nbsp;&nbsp;<i>a The <code>long</code> to be printed.</i></html>");
}
public void testSecondCtrlPShowsHints() {
configureJava("class C { void m() { System.setProperty(\"a\", \"<caret>b\"); } }");
showParameterInfo();
showParameterInfo();
checkResultWithInlays("class C { void m() { System.setProperty(<Hint text=\"key:\"/>\"a\", <HINT text=\"value:\"/>\"<caret>b\"); } }");
}
private void checkResultWithInlays(String text) {
myFixture.checkResultWithInlays(text);
}
@@ -193,7 +193,7 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
JUnitConfiguration configuration =
new JUnitConfiguration("", myProject, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
configuration.getPersistentData().TEST_OBJECT = JUnitConfiguration.TEST_DIRECTORY;
configuration.getPersistentData().setDirName(psiClass.getContainingFile().getContainingDirectory().getVirtualFile().getPath());
configuration.getPersistentData().setDirName(psiClass.getContainingFile().getContainingDirectory().getVirtualFile().getParent().getPath());
configuration.setModule(module1);
JavaParameters parameters = checkCanRun(configuration);
String filePath = ContainerUtil.find(parameters.getProgramParametersList().getArray(),
@@ -206,7 +206,8 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
"test1.DerivedTest", RT_INNER_TEST_NAME,
"test1.nested.TestA",
"test1.nested.TestWithJunit4",
"test1.ThirdPartyTest"},
"test1.ThirdPartyTest",
"TestA"},
lines);
}
@@ -245,34 +245,34 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
if (context == PatternTreeContext.Block) {
final PsiCodeBlock codeBlock = elementFactory.createCodeBlockFromText("{\n" + text + "\n}", null);
final PsiElement[] children = codeBlock.getChildren();
final int extraChildCount = 4;
PsiElement element = codeBlock.getFirstBodyElement();
if (element == null) return PsiElement.EMPTY_ARRAY;
final List<PsiElement> result = new SmartList<>();
final PsiElement lastBodyElement = codeBlock.getLastBodyElement();
while (element != null) {
if (!(element instanceof PsiWhiteSpace)) result.add(element);
if (element == lastBodyElement) break;
element = element.getNextSibling();
}
if (result.isEmpty()) return PsiElement.EMPTY_ARRAY;
if (children.length > extraChildCount) {
PsiElement[] result = new PsiElement[children.length - extraChildCount];
System.arraycopy(children, 2, result, 0, children.length - extraChildCount);
if (shouldTryExpressionPattern(result)) {
try {
final PsiElement[] expressionPattern =
createPatternTree(text, PatternTreeContext.Expression, fileType, language, contextName, extension, project, false);
if (expressionPattern.length == 1) {
result = expressionPattern;
}
} catch (IncorrectOperationException ignore) {}
}
else if (shouldTryClassPattern(result)) {
final PsiElement[] classPattern =
createPatternTree(text, PatternTreeContext.Class, fileType, language, contextName, extension, project, false);
if (classPattern.length == 1) {
result = classPattern;
if (shouldTryExpressionPattern(result)) {
try {
final PsiElement[] expressionPattern =
createPatternTree(text, PatternTreeContext.Expression, fileType, language, contextName, extension, project, false);
if (expressionPattern.length == 1) {
return expressionPattern;
}
} catch (IncorrectOperationException ignore) {}
}
else if (shouldTryClassPattern(result)) {
final PsiElement[] classPattern =
createPatternTree(text, PatternTreeContext.Class, fileType, language, contextName, extension, project, false);
if (classPattern.length == 1) {
return classPattern;
}
return result;
}
else {
return PsiElement.EMPTY_ARRAY;
}
return result.toArray(PsiElement.EMPTY_ARRAY);
}
else if (context == PatternTreeContext.Class) {
final PsiClass clazz = elementFactory.createClassFromText(text, null);
@@ -300,9 +300,9 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
}
}
private static boolean shouldTryExpressionPattern(PsiElement[] elements) {
if (elements.length >= 1 && elements.length <= 3) {
final PsiElement firstElement = elements[0];
private static boolean shouldTryExpressionPattern(List<PsiElement> elements) {
if (elements.size() >= 1 && elements.size() <= 3) {
final PsiElement firstElement = elements.get(0);
if (firstElement instanceof PsiDeclarationStatement) {
final PsiElement lastChild = firstElement.getLastChild();
if (lastChild instanceof PsiErrorElement && PsiTreeUtil.prevLeaf(lastChild) instanceof PsiErrorElement) {
@@ -316,13 +316,13 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
return false;
}
private static boolean shouldTryClassPattern(PsiElement[] elements) {
if (elements.length < 2) {
private static boolean shouldTryClassPattern(List<PsiElement> elements) {
if (elements.size() < 2) {
return false;
}
final PsiElement firstElement = elements[0];
final PsiElement secondElement = elements[1];
final PsiElement lastElement = elements[elements.length - 1];
final PsiElement firstElement = elements.get(0);
final PsiElement secondElement = elements.get(1);
final PsiElement lastElement = elements.get(elements.size() - 1);
if (firstElement instanceof PsiDocComment) {
// might be method with javadoc
@@ -437,7 +437,7 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
boolean targetFound = false;
for (final String name : matchOptions.getVariableConstraintNames()) {
final MatchVariableConstraint constraint = matchOptions.getVariableConstraint(name);
if (constraint.isPartOfSearchResults()) {
if (constraint.isPartOfSearchResults() && !Configuration.CONTEXT_VAR_NAME.equals(constraint.getName())) {
targetFound = true;
break;
}
@@ -73,7 +73,9 @@ public class Generator<T> {
/**
* Turns off automatic minimization for the data produced by this generator (and its components, if any).
* This can be useful to speed up minimization by not wasting time on shrinking objects where it makes no sense.
* This can be useful to speed up minimization by not wasting time on shrinking objects where it makes no sense.
* It's especially useful when using stateful generators (e.g. {@link ImperativeCommand}), because
* shrinkable values there can lead to doubling of the shrinking time.
*/
public Generator<T> noShrink() {
return from(data -> data.generateNonShrinkable(this));
@@ -176,7 +178,7 @@ public class Generator<T> {
/** Generates characters in the given range (both ends inclusive) */
public static Generator<Character> charsInRange(char min, char max) {
return integers(min, max).map(i -> (char)i.intValue()).noShrink();
return integers(min, max).map(i -> (char)i.intValue());
}
/** Generates ASCII characters excluding the system ones (lower than 32) */
@@ -82,7 +82,10 @@ public interface ImperativeCommand {
* The message is a Java format string, so you can use it to include the generated value, e.g.
* {@code String s = generateValue(stringsOf(asciiLetters(), "Generated %s")}.<p/>
* If you don't want to generate message, or would like to show the generated value in a custom way, pass {@code null}.
* You can use {@link #logMessage} later to still leave a trace of this value generation in the log.
* You can use {@link #logMessage} later to still leave a trace of this value generation in the log.<p/>
*
* Consider making generators non-shrinkable (by invoking {@link Generator#noShrink()}) where possible
* because it can speed up overall failing scenario minimization significantly.
*/
<T> T generateValue(@NotNull Generator<T> generator, @Nullable String logMessage);
@@ -71,7 +71,9 @@ class Iteration<T> {
String rechecking = failureReason != null && StatusNotifier.printStackTrace(failureReason).contains("ImperativeCommand.checkScenario") ?
"ImperativeCommand.checkScenario(" + iterationSeed + "L, " + sizeHint + ", ...))\n" :
"PropertyChecker.forAll(...).rechecking(" + iterationSeed + "L, " + sizeHint + ").shouldHold(...)\n";
return "To reproduce the last iteration, run " + rechecking + "Global seed: " + session.globalSeed + "L";
return "To reproduce the last iteration, run " + rechecking +
"To debug the minimal failing example, catch this exception and invoke 'replayMinimalExample' on it.\n" +
"Global seed: " + session.globalSeed + "L";
}
String printSeeds() {
@@ -125,4 +125,13 @@ public class PropertyFalsified extends RuntimeException {
public DataStructure getData() {
return failure.getMinimalCounterexample().createReplayData();
}
/**
* Re-invoke the generator and the property check on the minimal counter-example found after testing and shrinking. Useful for debugging.<p/>
*
* The same as {@code getFailure().getMinimalCounterexample().replay()}.
*/
public PropertyFailure.CounterExample<?> replayMinimalExample() {
return failure.getMinimalCounterexample().replay();
}
}
@@ -56,7 +56,7 @@ class RemoveListRange extends ShrinkStep {
}
int newEnd = start == 1 ? node.children.size() : start;
if (newEnd == lastSuccessfulRemove) return node.shrinkChild(1);
if (newEnd == lastSuccessfulRemove) return node.shrinkChild(node.children.size() - 1);
return new RemoveListRange(node, lastSuccessfulRemove, newEnd - 1, 1);
}
@@ -69,12 +69,13 @@ class StructureNode extends StructureElement {
ShrinkStep shrink() {
if (shrinkProhibited) return null;
return isList() ? new RemoveListRange(this) : shrinkChild(0);
return isList() ? new RemoveListRange(this) : shrinkChild(children.size() - 1);
}
@Nullable
ShrinkStep shrinkChild(int index) {
for (; index < children.size(); index++) {
int minIndex = isList() ? 1 : 0;
for (; index >= minIndex; index--) {
ShrinkStep childShrink = children.get(index).shrink();
if (childShrink != null) return wrapChildShrink(index, childShrink);
}
@@ -84,7 +85,7 @@ class StructureNode extends StructureElement {
@Nullable
private ShrinkStep wrapChildShrink(int index, @Nullable ShrinkStep step) {
if (step == null) return shrinkChild(index + 1);
if (step == null) return shrinkChild(index - 1);
NodeId oldChild = children.get(index).id;
@@ -229,7 +230,13 @@ class IntData extends StructureElement {
@Nullable
@Override
ShrinkStep shrink() {
return value == 0 ? null : tryInt(0, () -> null, this::tryNegation);
if (value == 0) return null;
int minValue = 0;
if (distribution instanceof BoundedIntDistribution) {
minValue = Math.max(minValue, ((BoundedIntDistribution)distribution).getMin());
}
return tryInt(minValue, () -> null, this::tryNegation);
}
private ShrinkStep tryNegation() {
@@ -242,7 +249,7 @@ class IntData extends StructureElement {
private ShrinkStep divisionLoop(int value) {
if (value == 0) return null;
int divided = value / 2;
return tryInt(divided, () -> divisionLoop(divided / 2), null);
return tryInt(divided, () -> divisionLoop(divided), null);
}
private ShrinkStep tryInt(int value, @NotNull Supplier<ShrinkStep> success, @Nullable Supplier<ShrinkStep> fail) {
@@ -68,4 +68,13 @@ public class ExceptionTest extends PropertyCheckerTestCase {
}
}
public void testRecommendReplay() {
PropertyFalsified e = checkFails(forAllStable(integers()), i -> {
throw new AssertionError("fail");
});
assertTrue(e.getMessage().contains("replayMinimalExample"));
assertNotNull(e.replayMinimalExample());
}
}

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