diff --git a/build/scripts/libLicenses.gant b/build/scripts/libLicenses.gant index 7867afb48412..3007b785c02e 100644 --- a/build/scripts/libLicenses.gant +++ b/build/scripts/libLicenses.gant @@ -312,4 +312,3 @@ jetbrainsLibrary("Maven Embedder") jetbrainsLibrary("tcServiceMessages") jetbrainsLibrary("optimizedFileManager.jar") jetbrainsLibrary("KotlinJavaRuntime") -jetbrainsLibrary("testDiscoveryInstrumenter.jar") diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java index 701eec904a61..df4c905f42c2 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java @@ -416,6 +416,7 @@ public class DebugProcessEvents extends DebugProcessImpl { final int nextStepDepth = hint.getNextStepDepth(suspendContext); if (nextStepDepth == RequestHint.RESUME) { getSession().resetIgnoreStepFiltersFlag(); + getSession().clearSteppingThrough(); shouldResume = true; } else if (nextStepDepth != RequestHint.STOP) { diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java index 9b9a571463e3..1b499e146afe 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java @@ -40,6 +40,7 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; @@ -106,7 +107,7 @@ public class JavaDebugProcess extends XDebugProcess { || event == DebuggerSession.Event.REFRESH && myJavaSession.isPaused()) { final SuspendContextImpl newSuspendContext = newContext.getSuspendContext(); - if (newSuspendContext != null && newSuspendContext != getSession().getSuspendContext()) { + if (newSuspendContext != null && shouldApplyContext(newContext)) { process.getManagerThread().schedule(new SuspendContextCommandImpl(newSuspendContext) { @Override public void contextAction() throws Exception { @@ -119,10 +120,12 @@ public class JavaDebugProcess extends XDebugProcess { XBreakpoint xBreakpoint = breakpoint.getXBreakpoint(); if (xBreakpoint != null) { ((XDebugSessionImpl)getSession()).breakpointReachedNoProcessing(xBreakpoint, newSuspendContext); + unsetPausedIfNeeded(newContext); return; } } getSession().positionReached(newSuspendContext); + unsetPausedIfNeeded(newContext); } }); } @@ -181,6 +184,21 @@ public class JavaDebugProcess extends XDebugProcess { }); } + private void unsetPausedIfNeeded(DebuggerContextImpl context) { + SuspendContextImpl suspendContext = context.getSuspendContext(); + if (suspendContext != null && context.getThreadProxy() != suspendContext.getThread()) { + ((XDebugSessionImpl)getSession()).unsetPaused(); + } + } + + private boolean shouldApplyContext(DebuggerContextImpl context) { + SuspendContextImpl suspendContext = context.getSuspendContext(); + SuspendContextImpl currentContext = (SuspendContextImpl)getSession().getSuspendContext(); + if (suspendContext != null && !suspendContext.equals(currentContext)) return true; + JavaExecutionStack currentExecutionStack = currentContext != null ? currentContext.getActiveExecutionStack() : null; + return currentExecutionStack == null || !Comparing.equal(context.getThreadProxy(), currentExecutionStack.getThreadProxy()); + } + public void saveNodeHistory() { saveNodeHistory(getDebuggerStateManager().getContext().getFrameProxy()); } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaExecutionStack.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaExecutionStack.java index cb145df147dd..b0d8d3e6539d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaExecutionStack.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaExecutionStack.java @@ -48,14 +48,11 @@ public class JavaExecutionStack extends XExecutionStack { super(calcRepresentation(threadProxy), calcIcon(threadProxy, current)); myThreadProxy = threadProxy; myDebugProcess = debugProcess; - if (current) { - initTopFrame(); - } } private static Icon calcIcon(ThreadReferenceProxyImpl threadProxy, boolean current) { if (current) { - return AllIcons.Debugger.ThreadCurrent; + return threadProxy.isSuspended() ? AllIcons.Debugger.ThreadCurrent : AllIcons.Debugger.ThreadRunning; } else if (threadProxy.isAtBreakpoint()) { return AllIcons.Debugger.ThreadAtBreakpoint; @@ -217,4 +214,9 @@ public class JavaExecutionStack extends XExecutionStack { public int hashCode() { return myThreadProxy.hashCode(); } + + @Override + public String toString() { + return getDisplayName(); + } } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java index 3a8c2b6bac48..8d08444e9b86 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaStackFrame.java @@ -138,7 +138,7 @@ public class JavaStackFrame extends XStackFrame { xFrame.computeChildren(node); return; } - myDebugProcess.getManagerThread().schedule(new DebuggerContextCommandImpl(myDebugProcess.getDebuggerContext()) { + myDebugProcess.getManagerThread().schedule(new DebuggerContextCommandImpl(myDebugProcess.getDebuggerContext(), myDescriptor.getFrameProxy().threadProxy()) { @Override public Priority getPriority() { return Priority.NORMAL; diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java index 2a4dd9de6156..e0cacfe51ccd 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java @@ -26,7 +26,6 @@ import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Comparing; import com.intellij.util.containers.HashSet; -import com.intellij.xdebugger.frame.XExecutionStack; import com.intellij.xdebugger.frame.XSuspendContext; import com.sun.jdi.ObjectReference; import com.sun.jdi.ThreadReference; @@ -229,15 +228,18 @@ public abstract class SuspendContextImpl extends XSuspendContext implements Susp @Nullable @Override - public XExecutionStack getActiveExecutionStack() { + public JavaExecutionStack getActiveExecutionStack() { return myActiveExecutionStack; } - public void initExecutionStacks(ThreadReferenceProxyImpl newThread) { + public void initExecutionStacks(ThreadReferenceProxyImpl activeThread) { DebuggerManagerThreadImpl.assertIsManagerThread(); - myThread = newThread; - if (newThread != null) { - myActiveExecutionStack = new JavaExecutionStack(newThread, myDebugProcess, true); + if (myThread == null) { + myThread = activeThread; + } + if (activeThread != null) { + myActiveExecutionStack = new JavaExecutionStack(activeThread, myDebugProcess, myThread == activeThread); + myActiveExecutionStack.initTopFrame(); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java index 2edc16ff6953..0fe1e45cc5dc 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java @@ -115,13 +115,6 @@ public class SuspendManagerImpl implements SuspendManager { return suspendContext; } - public SuspendContextImpl createDummyContext(@MagicConstant(flagsFromClass = EventRequest.class) int suspendPolicy) { - return new SuspendContextImpl(myDebugProcess, suspendPolicy, 0, null) { - @Override - protected void resumeImpl() {} - }; - } - @Override public SuspendContextImpl pushSuspendContext(final EventSet set) { SuspendContextImpl suspendContext = new SuspendContextImpl(myDebugProcess, set.suspendPolicy(), set.size(), set) { @@ -360,7 +353,7 @@ public class SuspendManagerImpl implements SuspendManager { processVote(suspendContext); } - LinkedList getPausedContexts() { + public List getPausedContexts() { return myPausedContexts; } } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerContextImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerContextImpl.java index ad9e01e26409..336871008856 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerContextImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerContextImpl.java @@ -151,7 +151,6 @@ public final class DebuggerContextImpl implements DebuggerContext { ThreadReferenceProxyImpl threadProxy, StackFrameProxyImpl frameProxy) { LOG.assertTrue(frameProxy == null || threadProxy == null || threadProxy == frameProxy.threadProxy()); - LOG.assertTrue(session == null || session.getProcess() != null); return new DebuggerContextImpl(session, session != null ? session.getProcess() : null, context, threadProxy, frameProxy, null, null, context == null); } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java index 57f2bbc092a0..b33789a5bc6c 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java @@ -111,7 +111,7 @@ public class DebuggerSession implements AbstractDebuggerSession { mySteppingThroughThread.set(threadProxy); } - void clearSteppingThrough() { + public void clearSteppingThrough() { mySteppingThroughThread.set(null); } @@ -469,6 +469,8 @@ public class DebuggerSession implements AbstractDebuggerSession { LOG.debug("paused"); } + ThreadReferenceProxyImpl currentThread = suspendContext.getThread(); + if (!shouldSetAsActiveContext(suspendContext)) { DebuggerInvocationUtil.invokeLater(getProject(), new Runnable() { @Override @@ -476,7 +478,7 @@ public class DebuggerSession implements AbstractDebuggerSession { getContextManager().fireStateChanged(getContextManager().getContext(), Event.THREADS_REFRESH); } }); - final ThreadReferenceProxyImpl thread = suspendContext.getThread(); + ThreadReferenceProxyImpl thread = suspendContext.getThread(); if (thread != null) { List> descriptors = DebuggerUtilsEx.getEventDescriptors(suspendContext); if (!descriptors.isEmpty()) { @@ -492,7 +494,7 @@ public class DebuggerSession implements AbstractDebuggerSession { @Override public void contextAction() throws Exception { final DebuggerContextImpl debuggerContext = - DebuggerContextImpl.createDebuggerContext(DebuggerSession.this, suspendContext, thread, null); + DebuggerContextUtil.createDebuggerContext(DebuggerSession.this, suspendContext); DebuggerInvocationUtil.invokeLater(getProject(), new Runnable() { @Override @@ -507,12 +509,17 @@ public class DebuggerSession implements AbstractDebuggerSession { }).notify(getProject()); } } - return; + if (((SuspendManagerImpl)myDebugProcess.getSuspendManager()).getPausedContexts().size() > 1) { + return; + } + else { + currentThread = mySteppingThroughThread.get(); + } + } + else { + setSteppingThrough(currentThread); } - setSteppingThrough(suspendContext.getThread()); - - ThreadReferenceProxyImpl currentThread = suspendContext.getThread(); final StackFrameContext positionContext; if (currentThread == null) { @@ -626,7 +633,7 @@ public class DebuggerSession implements AbstractDebuggerSession { DebuggerInvocationUtil.invokeLater(getProject(), new Runnable() { @Override public void run() { - getContextManager().setState(debuggerContext, State.PAUSED, Event.PAUSE, null); + getContextManager().setState(debuggerContext, State.PAUSED, Event.PAUSE, getDescription(debuggerContext)); } }); } @@ -650,25 +657,28 @@ public class DebuggerSession implements AbstractDebuggerSession { @Override public void resumed(SuspendContextImpl suspendContext) { - SuspendManager suspendManager = getProcess().getSuspendManager(); - SuspendContextImpl context = suspendManager.getPausedContext(); + SuspendContextImpl context = getProcess().getSuspendManager().getPausedContext(); + ThreadReferenceProxyImpl steppingThread = null; // single thread stepping - if (suspendContext != null + if (context != null + && suspendContext != null && suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD && isSteppingThrough(suspendContext.getThread())) { - ThreadReferenceProxyImpl thread = suspendContext.getThread(); - if (context == null || !Comparing.equal(context.getThread(), thread)) { - context = ((SuspendManagerImpl)suspendManager).createDummyContext(suspendContext.getSuspendPolicy()); - context.setThread(thread.getThreadReference()); - } + steppingThread = suspendContext.getThread(); } - final SuspendContextImpl currentContext = context; + final DebuggerContextImpl debuggerContext = + context != null ? + DebuggerContextImpl.createDebuggerContext(DebuggerSession.this, + context, + steppingThread != null ? steppingThread : context.getThread(), + null) + : null; + DebuggerInvocationUtil.invokeLater(getProject(), new Runnable() { @Override public void run() { - if (currentContext != null) { - getContextManager().setState(DebuggerContextUtil.createDebuggerContext(DebuggerSession.this, currentContext), - State.PAUSED, Event.CONTEXT, null); + if (debuggerContext != null) { + getContextManager().setState(debuggerContext, State.PAUSED, Event.CONTEXT, getDescription(debuggerContext)); } else { getContextManager().setState(SESSION_EMPTY_CONTEXT, State.RUNNING, Event.CONTEXT, null); @@ -756,6 +766,14 @@ public class DebuggerSession implements AbstractDebuggerSession { } } + private static String getDescription(DebuggerContextImpl debuggerContext) { + SuspendContextImpl suspendContext = debuggerContext.getSuspendContext(); + if (suspendContext != null && debuggerContext.getThreadProxy() != suspendContext.getThread()) { + return DebuggerBundle.message("status.paused.in.another.thread"); + } + return null; + } + private class MyEvaluationListener implements EvaluationListener { @Override public void evaluationStarted(SuspendContextImpl context) { diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/ReloadClassesWorker.java b/java/debugger/impl/src/com/intellij/debugger/impl/ReloadClassesWorker.java index 7b3f46e27c8e..6693150f03aa 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/ReloadClassesWorker.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/ReloadClassesWorker.java @@ -176,7 +176,7 @@ class ReloadClassesWorker { SuspendContextImpl suspendContext = context.getSuspendContext(); if (suspendContext != null) { XExecutionStack stack = suspendContext.getActiveExecutionStack(); - if (stack instanceof JavaExecutionStack) { + if (stack != null) { ((JavaExecutionStack)stack).initTopFrame(); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java index 957ada3482a2..c75a41f1f613 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java @@ -193,6 +193,7 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { throw new EvaluateException(error.getMessage(), error); } + @NotNull @Override public ThreadReferenceProxyImpl threadProxy() { return myThreadProxy; diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java index 8fe745ca59b6..f1a0f269f7bb 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java @@ -493,6 +493,12 @@ public class RefJavaManagerImpl extends RefJavaManager { public void visitVariable(PsiVariable variable) { super.visitVariable(variable); myRefUtil.addTypeReference(variable, variable.getType(), myRefManager); + if (variable instanceof PsiParameter) { + final RefElement reference = myRefManager.getReference(variable); + if (reference instanceof RefParameterImpl) { + ((RefParameterImpl)reference).buildReferences(); + } + } } @Override diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java index f33145fa070e..cef4ea166238 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java @@ -102,6 +102,15 @@ public class RefParameterImpl extends RefJavaElementImpl implements RefParameter return myIndex; } + @Override + public void buildReferences() { + final RefJavaUtil refUtil = RefJavaUtil.getInstance(); + final PsiParameter parameter = getElement(); + if (parameter != null) { + refUtil.addReferences(parameter, this, parameter.getModifierList()); + } + } + public void updateTemplateValue(PsiExpression expression) { if (myActualValueTemplate == null) return; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java index 969d542a8d38..869a6d65d02f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java @@ -95,7 +95,7 @@ public class JavaLineMarkerProvider implements LineMarkerProvider { } if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) { PsiFile file = element1.getContainingFile(); - Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getDocument(file); + Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file); boolean drawSeparator = false; if (document != null) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java index 64c7f351753d..6069486d38c9 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java @@ -57,19 +57,21 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction { private final SmartPsiElementPointer myField; private final PsiClass myClass; + private int myConstructorsLength; public CreateConstructorParameterFromFieldFix(@NotNull PsiField field) { myClass = field.getContainingClass(); myField = SmartPointerManager.getInstance(field.getProject()).createSmartPsiElementPointer(field); if (myClass != null) { getFieldsToFix().add(myField); + myConstructorsLength = myClass.getConstructors().length; } } @Override @NotNull public String getText() { - if (getFieldsToFix().size() > 1 && myClass.getConstructors().length <= 1) return "Add constructor parameters"; + if (getFieldsToFix().size() > 1 && myConstructorsLength <= 1) return "Add constructor parameters"; return QuickFixBundle.message("add.constructor.parameter.name"); } @@ -81,7 +83,7 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction { @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return isAvailable(getField()); + return (myClass == null || myClass.isValid()) && isAvailable(getField()); } private static boolean isAvailable(PsiField field) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java index 5f29f99f08c4..01c10792b904 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java @@ -272,11 +272,19 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR private boolean resolveConflicts(List firstCandidates, List secondCandidates, int applicabilityLevel) { - checkApplicability(firstCandidates); + final int firstApplicability = checkApplicability(firstCandidates); checkSpecifics(firstCandidates, applicabilityLevel, myLanguageLevel); - checkApplicability(secondCandidates); + final int secondApplicability = checkApplicability(secondCandidates); checkSpecifics(secondCandidates, applicabilityLevel, myLanguageLevel); + + if (firstApplicability < secondApplicability) { + return secondCandidates.size() == 1; + } + + if (secondApplicability < firstApplicability) { + return firstCandidates.size() == 1; + } return firstCandidates.size() + secondCandidates.size() == 1; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/overloadResolution/IgnoreCandidatesWithLowerApplicabilityLevel.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/overloadResolution/IgnoreCandidatesWithLowerApplicabilityLevel.java new file mode 100644 index 000000000000..0e95d4b327d7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/overloadResolution/IgnoreCandidatesWithLowerApplicabilityLevel.java @@ -0,0 +1,23 @@ +import java.util.function.BiConsumer; + +class MyTest { + + { + BiConsumer, T> builderTBiConsumer = Builder::add; + BiConsumer, T> builderTBiConsumer1 = Builder::add; + + System.out.println(builderTBiConsumer); + System.out.println(builderTBiConsumer1); + } + + public static class Builder { + + public Builder add(E element) { + return this; + } + + public Builder add(E... elements) { + return this; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/unusedLibrary/usedInParameterAnnotation/expected.xml b/java/java-tests/testData/inspection/unusedLibrary/usedInParameterAnnotation/expected.xml new file mode 100644 index 000000000000..ec272abeaa3a --- /dev/null +++ b/java/java-tests/testData/inspection/unusedLibrary/usedInParameterAnnotation/expected.xml @@ -0,0 +1,3 @@ + + + diff --git a/java/java-tests/testData/inspection/unusedLibrary/usedInParameterAnnotation/src/MyTest.java b/java/java-tests/testData/inspection/unusedLibrary/usedInParameterAnnotation/src/MyTest.java new file mode 100644 index 000000000000..a82545d98af3 --- /dev/null +++ b/java/java-tests/testData/inspection/unusedLibrary/usedInParameterAnnotation/src/MyTest.java @@ -0,0 +1,4 @@ +import junit.framework.TestCase; +public class MyTest { + public static void main(@TestCase String[] args) {} +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/OverloadResolutionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/OverloadResolutionTest.java index 395830cf8117..7b11e93b5cba 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/OverloadResolutionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/OverloadResolutionTest.java @@ -146,6 +146,10 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testIgnoreCandidatesWithLowerApplicabilityLevel() throws Exception { + doTest(); + } + private void doTest() { doTest(true); } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java index 7409e200e86a..a06593a2f9cd 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/UnusedLibraryInspectionTest.java @@ -65,4 +65,5 @@ public class UnusedLibraryInspectionTest extends InspectionTestCase { public void testSimple() throws Exception { doTest(); } public void testUsedJunit() throws Exception { doTest(); } public void testUsedJunitFromField() throws Exception { doTest(); } + public void testUsedInParameterAnnotation() throws Exception { doTest(); } } diff --git a/lib/required_for_dist.txt b/lib/required_for_dist.txt index 54da6b0d7355..9b124ae26c65 100644 --- a/lib/required_for_dist.txt +++ b/lib/required_for_dist.txt @@ -66,7 +66,6 @@ snappy-in-java-0.3.1.jar swingx-core-1.6.2.jar slf4j-api-1.7.10.jar slf4j-log4j12-1.7.10.jar -testDiscoveryInstrumenter.jar trove4j.jar velocity.jar winp-1.23.jar diff --git a/lib/testDiscoveryInstrumenter.jar b/lib/testDiscoveryInstrumenter.jar deleted file mode 100644 index 00e07bacc2ed..000000000000 Binary files a/lib/testDiscoveryInstrumenter.jar and /dev/null differ diff --git a/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReferenceSet.java b/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReferenceSet.java index 29e0cf6c39e6..5d8cc29ae831 100644 --- a/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReferenceSet.java +++ b/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReferenceSet.java @@ -266,7 +266,7 @@ public class FileReferenceSet { if (curSep >= 0 && decoded.length() == wsHead + sepLen + wsTail) { // add extra reference for the only & leading "/" TextRange r = TextRange.create(startInElement, offset(curSep + Math.max(0, sepLen - 1), escaper, valueRange) + 1); - referencesList.add(createFileReference(r, 0, decoded.subSequence(curSep, curSep + sepLen).toString())); + referencesList.add(createFileReference(r, index ++, decoded.subSequence(curSep, curSep + sepLen).toString())); } curSep = curSep == wsHead ? curSep + sepLen : wsHead; // reset offsets & start again for simplicity sepLen = 0; diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java index d36d802a8008..93faaab938dd 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java @@ -186,15 +186,32 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF FileElement treeElement = createFileElement(viewProvider.getContents()); treeElement.setPsi(this); - final StubTree stub = derefStub(); - List> bindings = calcStubAstBindings(treeElement, cachedDocument, stub); + while (true) { + StubTree stub = derefStub(); + List> bindings = calcStubAstBindings(treeElement, cachedDocument, stub); + FileElement savedTree = ensureTreeElement(viewProvider, treeElement, stub, bindings); + if (savedTree != null) { + return savedTree; + } + } + } + + @Nullable + private FileElement ensureTreeElement(@NotNull FileViewProvider viewProvider, + @NotNull FileElement treeElement, + @Nullable StubTree stub, + @NotNull List> bindings) { synchronized (PsiLock.LOCK) { FileElement existing = derefTreeElement(); if (existing != null) { return existing; } + if (stub != derefStub()) { + return null; // stub has been just loaded by another thread, it needs to be bound to AST + } + if (stub != null) { treeElement.putUserData(STUB_TREE_IN_PARSED_TREE, new SoftReference(stub)); putUserData(ObjectStubTree.LAST_STUB_TREE_HASH, stub.hashCode()); diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewDropTarget.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewDropTarget.java index 56b0d63fa5a1..1e4593f2343d 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewDropTarget.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewDropTarget.java @@ -318,6 +318,12 @@ class ProjectViewDropTarget implements DnDNativeTarget { final Module module = getModule(targetNode); final DataContext dataContext = DataManager.getInstance().getDataContext(myTree); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + + if (!targetElement.isValid()) return; + for (PsiElement sourceElement : sourceElements) { + if (!sourceElement.isValid()) return; + } + getActionHandler().invoke(myProject, sourceElements, new DataContext() { @Override @Nullable diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/RenameElementAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/RenameElementAction.java index 929d7090016c..efe8f3fb8f28 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/actions/RenameElementAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/RenameElementAction.java @@ -24,6 +24,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiNamedElement; import com.intellij.psi.SyntheticElement; import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.rename.PsiElementRenameHandler; import com.intellij.refactoring.rename.RenameHandlerRegistry; import org.jetbrains.annotations.NotNull; @@ -43,7 +44,9 @@ public class RenameElementAction extends BaseRefactoringAction { if (elements.length != 1) return false; PsiElement element = elements[0]; - return element instanceof PsiNamedElement && !(element instanceof SyntheticElement); + return element instanceof PsiNamedElement && + !(element instanceof SyntheticElement) && + !PsiElementRenameHandler.isVetoed(element); } @Override diff --git a/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java b/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java index 91536d53deaa..527eaf22abb2 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java @@ -108,7 +108,7 @@ public final class TabInfo implements Queryable, PlaceProvider { public TabInfo setText(String text) { List attributes = myText.getAttributes(); - TextAttributes textAttributes = attributes.isEmpty() ? null : attributes.get(0).toTextAttributes(); + TextAttributes textAttributes = attributes.size() == 1 ? attributes.get(0).toTextAttributes() : null; TextAttributes defaultAttributes = getDefaultAttributes().toTextAttributes(); if (!myText.toString().equals(text) || !Comparing.equal(textAttributes, defaultAttributes)) { clearText(false); diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula_mac.properties b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula_mac.properties index 32f21a8df73c..463569a981c4 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula_mac.properties +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula_mac.properties @@ -1,3 +1,4 @@ # suppress inspection "UnusedProperty" for whole file darcula.selectionBackground=2F65CA -Menu.arrowIcon=AllIcons.Mac.Tree_white_right_arrow \ No newline at end of file +Menu.arrowIcon=AllIcons.Mac.Tree_white_right_arrow +MenuItem.acceleratorSelectionForeground=ffffff \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java index 37ed4123f72b..cebbc42aa245 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java @@ -329,18 +329,18 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { hasFocus = false; checkFocus(); - final Graphics2D g = (Graphics2D)g2; + final Graphics2D g = (Graphics2D)g2.create(); final Rectangle arrowButtonBounds = arrowButton.getBounds(); final int xxx = arrowButtonBounds.x - JBUI.scale(5); final int H = height - JBUI.scale(2); final int W = width - JBUI.scale(2); - final GraphicsConfig config = new GraphicsConfig(g); + final Shape clip = g.getClip(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); final int R = JBUI.scale(5); if (hasFocus) { - g.setClip(JBUI.scale(2), JBUI.scale(2), comboBox.getWidth()- JBUI.scale(4), comboBox.getHeight() - JBUI.scale(4)); + g.clipRect(JBUI.scale(2), JBUI.scale(2), comboBox.getWidth()- JBUI.scale(4), comboBox.getHeight() - JBUI.scale(4)); } if (editor != null && comboBox.isEditable()) { ((JComponent)editor).setBorder(null); @@ -368,7 +368,7 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { paintCurrentValue(g, r, false); if (hasFocus) { - g.setClip(0, 0, comboBox.getWidth(), comboBox.getHeight()); + g.setClip(clip); DarculaUIUtil.paintFocusRing(g, JBUI.scale(2), JBUI.scale(2), width - JBUI.scale(4), height - JBUI.scale(4)); } else { @@ -376,14 +376,12 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { g.drawRoundRect(JBUI.scale(1), JBUI.scale(1), width - JBUI.scale(2), height - JBUI.scale(2), R, R); if (!UIUtil.isUnderDarcula() && comboBox.isEnabled()) { g.setColor(getArrowButtonFillColor(getBorderColor())); - final Shape clip = g.getClip(); final int offX = xxx + JBUI.scale(5); - g.setClip(offX, y, width - offX, height); + g.clipRect(offX, y, width - offX, height); g.drawRoundRect(JBUI.scale(1), JBUI.scale(1), width - JBUI.scale(2), height - JBUI.scale(2), R, R); - g.setClip(clip); } } - config.restore(); + g.dispose(); } private void checkFocus() { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorHistoryManager.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorHistoryManager.java index ed3ffcda0caa..117a3ed7fb5d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorHistoryManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorHistoryManager.java @@ -53,7 +53,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme /** * State corresponding to the most recent file is the last */ - private final List myEntriesList = Collections.synchronizedList(new ArrayList()); + private final List myEntriesList = new ArrayList(); /** * Invoked by reflection @@ -81,7 +81,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme //noinspection unchecked for (final Element e : (Iterable)children) { try { - myEntriesList.add(new HistoryEntry(myProject, e)); + addEntry(new HistoryEntry(EditorHistoryManager.this.myProject, e)); } catch (InvalidDataException e1) { // OK here @@ -100,6 +100,14 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme ); } + private synchronized void addEntry(HistoryEntry entry) { + myEntriesList.add(entry); + } + + private synchronized void removeEntry(HistoryEntry entry) { + myEntriesList.remove(entry); + } + @Override @NotNull public String getComponentName(){ @@ -145,8 +153,8 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme final HistoryEntry entry = getEntry(file); if(entry != null){ - myEntriesList.remove(entry); - myEntriesList.add(entry); + removeEntry(entry); + addEntry(entry); } else { final FileEditorState[] states=new FileEditorState[editors.length]; @@ -157,7 +165,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme providers[i] = provider; states[i] = editors[i].getState(FileEditorStateLevel.FULL); } - myEntriesList.add(new HistoryEntry(file, providers, states, providers[selectedProviderIndex])); + addEntry(new HistoryEntry(file, providers, states, providers[selectedProviderIndex])); trimToSize(); } } @@ -222,8 +230,8 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme LOG.assertTrue(entry.mySelectedProvider != null); if(changeEntryOrderOnly){ - myEntriesList.remove(entry); - myEntriesList.add(entry); + removeEntry(entry); + addEntry(entry); } } } @@ -231,7 +239,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme /** * Removes all entries that correspond to invalid files */ - private void validateEntries(){ + private synchronized void validateEntries(){ for(int i=myEntriesList.size()-1; i>=0; i--){ final HistoryEntry entry = myEntriesList.get(i); if(!entry.myFile.isValid()){ @@ -243,7 +251,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme /** * @return array of valid files that are in the history, oldest first. May contain duplicates. */ - public VirtualFile[] getFiles(){ + public synchronized VirtualFile[] getFiles(){ validateEntries(); final VirtualFile[] result = new VirtualFile[myEntriesList.size()]; for(int i=myEntriesList.size()-1; i>=0 ;i--){ @@ -265,7 +273,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme return result; } - public boolean hasBeenOpen(@NotNull VirtualFile f) { + public synchronized boolean hasBeenOpen(@NotNull VirtualFile f) { for (HistoryEntry each : myEntriesList) { if (Comparing.equal(each.myFile, f)) return true; } @@ -276,13 +284,13 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme * Removes specified file from history. The method does * nothing if file is not in the history. * - * @exception java.lang.IllegalArgumentException if file + * @exception IllegalArgumentException if file * is null */ - public void removeFile(@NotNull final VirtualFile file){ + public synchronized void removeFile(@NotNull final VirtualFile file){ final HistoryEntry entry = getEntry(file); if(entry != null){ - myEntriesList.remove(entry); + removeEntry(entry); } } @@ -301,7 +309,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme return entry != null ? entry.mySelectedProvider : null; } - private HistoryEntry getEntry(@NotNull VirtualFile file){ + private synchronized HistoryEntry getEntry(@NotNull VirtualFile file){ validateEntries(); for (int i = myEntriesList.size() - 1; i >= 0; i--) { final HistoryEntry entry = myEntriesList.get(i); @@ -316,7 +324,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme * If total number of files in history more then UISettings.RECENT_FILES_LIMIT * then removes the oldest ones to fit the history to new size. */ - private void trimToSize(){ + private synchronized void trimToSize(){ final int limit = UISettings.getInstance().RECENT_FILES_LIMIT + 1; while(myEntriesList.size()>limit){ myEntriesList.remove(0); @@ -332,7 +340,7 @@ public final class EditorHistoryManager extends AbstractProjectComponent impleme } @Override - public void writeExternal(final Element element){ + public synchronized void writeExternal(final Element element){ // update history before saving final VirtualFile[] openFiles = FileEditorManager.getInstance(myProject).getOpenFiles(); for (int i = openFiles.length - 1; i >= 0; i--) { diff --git a/platform/platform-tests/testSrc/com/intellij/application/ApplicationImplTest.java b/platform/platform-tests/testSrc/com/intellij/application/ApplicationImplTest.java index 308a6545a5a2..f2eee2542ebb 100644 --- a/platform/platform-tests/testSrc/com/intellij/application/ApplicationImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/application/ApplicationImplTest.java @@ -15,6 +15,7 @@ */ package com.intellij.application; +import com.intellij.concurrency.JobSchedulerImpl; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.Application; @@ -52,6 +53,7 @@ public class ApplicationImplTest extends PlatformTestCase { protected void setUp() throws Exception { super.setUp(); exception = null; + timeOut = System.currentTimeMillis() + 2*60*1000; } private volatile Throwable exception; @@ -105,8 +107,8 @@ public class ApplicationImplTest extends PlatformTestCase { } - public void testReadWriteLockPerformance() throws InterruptedException { - int iterations = Timings.adjustAccordingToMySpeed(300000, true); + public void testRead50Write50LockPerformance() throws InterruptedException { + int iterations = Timings.adjustAccordingToMySpeed(400000, true); System.out.println("iterations = " + iterations); final int readIterations = iterations; final int writeIterations = iterations; @@ -114,8 +116,8 @@ public class ApplicationImplTest extends PlatformTestCase { runReadWrites(readIterations, writeIterations, 2000); } - public void testReadLockPerformance() throws InterruptedException { - int iterations = Timings.adjustAccordingToMySpeed(300000, true); + public void testRead100Write0LockPerformance() throws InterruptedException { + int iterations = Timings.adjustAccordingToMySpeed(400000, true); System.out.println("iterations = " + iterations); final int readIterations = iterations; final int writeIterations = 0; @@ -129,7 +131,7 @@ public class ApplicationImplTest extends PlatformTestCase { application.disableEventsUntil(disposable); try { - final int numOfThreads = 10; + final int numOfThreads = JobSchedulerImpl.CORES_COUNT; PlatformTestUtil.startPerformanceTest("lock performance", expectedMs, () -> { final CountDownLatch reads = new CountDownLatch(numOfThreads); for (int i = 0; i < numOfThreads; i++) { @@ -155,7 +157,7 @@ public class ApplicationImplTest extends PlatformTestCase { System.out.println("write end"); } reads.await(); - }).assertTiming(); + }).cpuBound().assertTiming(); } finally { Disposer.dispose(disposable); @@ -186,7 +188,7 @@ public class ApplicationImplTest extends PlatformTestCase { try { System.out.println("read lock1 acquired"); read1Acquired.set(true); - while (holdRead1.get()); + while (holdRead1.get() && ok()); } finally { lock.unlockRead(stamp); @@ -194,20 +196,20 @@ public class ApplicationImplTest extends PlatformTestCase { System.out.println("read lock1 released"); } } - catch (Exception e) { + catch (Throwable e) { exception = e; - throw e; + throw new RuntimeException(e); } }, "read lock1"); readAction1.start(); - while (!read1Acquired.get()); + while (!read1Acquired.get() && ok()); AtomicBoolean aboutToAcquireWrite = new AtomicBoolean(); // readActions2 should try to acquire read action when write action is pending Thread readActions2 = new Thread(() -> { try { assertFalse(ApplicationManager.getApplication().isDispatchThread()); - while (!aboutToAcquireWrite.get()); + while (!aboutToAcquireWrite.get() && ok()); TimeoutUtil.sleep(2000); // make sure it called writelock long stamp = lock.readLock(); try { @@ -220,9 +222,9 @@ public class ApplicationImplTest extends PlatformTestCase { System.out.println("read lock2 released"); } } - catch (Exception e) { + catch (Throwable e) { exception = e; - throw e; + throw new RuntimeException(e); } }, "read lock2"); readActions2.start(); @@ -230,12 +232,12 @@ public class ApplicationImplTest extends PlatformTestCase { Thread checkThread = new Thread(()->{ try { assertFalse(ApplicationManager.getApplication().isDispatchThread()); - while (!aboutToAcquireWrite.get()); - while (!read1Acquired.get()); + while (!aboutToAcquireWrite.get() && ok()); + while (!read1Acquired.get() && ok()); TimeoutUtil.sleep(2000); // make sure it called writelock long timeout = System.currentTimeMillis() + 10000; - while (System.currentTimeMillis() < timeout) { + while (System.currentTimeMillis() < timeout && ok()) { assertTrue(aboutToAcquireWrite.get()); assertTrue(read1Acquired.get()); assertFalse(read1Released.get()); @@ -249,10 +251,10 @@ public class ApplicationImplTest extends PlatformTestCase { } holdRead1.set(false); - while (!writeAcquired.get()); + while (!writeAcquired.get() && ok()); timeout = System.currentTimeMillis() + 10000; - while (System.currentTimeMillis() < timeout) { + while (System.currentTimeMillis() < timeout && ok()) { assertTrue(aboutToAcquireWrite.get()); assertTrue(read1Acquired.get()); assertTrue(read1Released.get()); @@ -266,11 +268,11 @@ public class ApplicationImplTest extends PlatformTestCase { holdWrite.set(false); - while (!read2Acquired.get()); + while (!read2Acquired.get() && ok()); TimeoutUtil.sleep(1000); // wait for immediate release of read lock2 timeout = System.currentTimeMillis() + 10000; - while (System.currentTimeMillis() < timeout) { + while (System.currentTimeMillis() < timeout && ok()) { assertTrue(aboutToAcquireWrite.get()); assertTrue(read1Acquired.get()); assertTrue(read1Released.get()); @@ -280,9 +282,9 @@ public class ApplicationImplTest extends PlatformTestCase { assertTrue(writeReleased.get()); } } - catch (Exception e) { + catch (Throwable e) { exception = e; - throw e; + throw new RuntimeException(e); } }, "check"); checkThread.start(); @@ -292,7 +294,7 @@ public class ApplicationImplTest extends PlatformTestCase { try { System.out.println("write lock acquired"); writeAcquired.set(true); - while (holdWrite.get() && exception == null); + while (holdWrite.get() && ok()); } finally { lock.unlockWrite(stamp); @@ -306,6 +308,12 @@ public class ApplicationImplTest extends PlatformTestCase { if (exception != null) throw exception; } + private static long timeOut; + private boolean ok() throws Throwable { + if (exception != null) throw exception; + return System.currentTimeMillis() < timeOut; + } + public void testAppLockReadWritePreference() throws Throwable { // take read lock1. // try to take write lock - must wait (because of taken read lock) @@ -329,7 +337,7 @@ public class ApplicationImplTest extends PlatformTestCase { try { System.out.println("read lock1 acquired"); read1Acquired.set(true); - while (holdRead1.get()); + while (holdRead1.get() && ok()); } finally { stamp.finish(); @@ -337,20 +345,20 @@ public class ApplicationImplTest extends PlatformTestCase { System.out.println("read lock1 released"); } } - catch (Exception e) { + catch (Throwable e) { exception = e; - throw e; + throw new RuntimeException(e); } }, "read lock1"); readAction1.start(); - while (!read1Acquired.get()); + while (!read1Acquired.get() && ok()); AtomicBoolean aboutToAcquireWrite = new AtomicBoolean(); // readActions2 should try to acquire read action when write action is pending Thread readActions2 = new Thread(() -> { try { assertFalse(ApplicationManager.getApplication().isDispatchThread()); - while (!aboutToAcquireWrite.get()); + while (!aboutToAcquireWrite.get() && ok()); TimeoutUtil.sleep(2000); // make sure it called writelock AccessToken stamp = application.acquireReadActionLock(); try { @@ -363,9 +371,9 @@ public class ApplicationImplTest extends PlatformTestCase { System.out.println("read lock2 released"); } } - catch (Exception e) { + catch (Throwable e) { exception = e; - throw e; + throw new RuntimeException(e); } }, "read lock2"); readActions2.start(); @@ -373,12 +381,12 @@ public class ApplicationImplTest extends PlatformTestCase { Thread checkThread = new Thread(()->{ try { assertFalse(ApplicationManager.getApplication().isDispatchThread()); - while (!aboutToAcquireWrite.get()); - while (!read1Acquired.get()); + while (!aboutToAcquireWrite.get() && ok()); + while (!read1Acquired.get() && ok()); TimeoutUtil.sleep(2000); // make sure it called writelock long timeout = System.currentTimeMillis() + 10000; - while (System.currentTimeMillis() < timeout) { + while (System.currentTimeMillis() < timeout && ok()) { assertTrue(aboutToAcquireWrite.get()); assertTrue(read1Acquired.get()); assertFalse(read1Released.get()); @@ -391,10 +399,10 @@ public class ApplicationImplTest extends PlatformTestCase { } holdRead1.set(false); - while (!writeAcquired.get()); + while (!writeAcquired.get() && ok()); timeout = System.currentTimeMillis() + 10000; - while (System.currentTimeMillis() < timeout) { + while (System.currentTimeMillis() < timeout && ok()) { assertTrue(aboutToAcquireWrite.get()); assertTrue(read1Acquired.get()); assertTrue(read1Released.get()); @@ -408,11 +416,11 @@ public class ApplicationImplTest extends PlatformTestCase { holdWrite.set(false); - while (!read2Acquired.get()); + while (!read2Acquired.get() && ok()); TimeoutUtil.sleep(1000); // wait for immediate release of read lock2 timeout = System.currentTimeMillis() + 10000; - while (System.currentTimeMillis() < timeout) { + while (System.currentTimeMillis() < timeout && ok()) { assertTrue(aboutToAcquireWrite.get()); assertTrue(read1Acquired.get()); assertTrue(read1Released.get()); @@ -422,9 +430,9 @@ public class ApplicationImplTest extends PlatformTestCase { assertTrue(writeReleased.get()); } } - catch (Exception e) { + catch (Throwable e) { exception = e; - throw e; + throw new RuntimeException(e); } }, "check"); checkThread.start(); @@ -434,7 +442,7 @@ public class ApplicationImplTest extends PlatformTestCase { try { System.out.println("write lock acquired"); writeAcquired.set(true); - while (holdWrite.get() && exception == null); + while (holdWrite.get() && ok()); } finally { stamp.finish(); @@ -461,10 +469,10 @@ public class ApplicationImplTest extends PlatformTestCase { final StringBuffer LOG = new StringBuffer(); new Thread(() -> { try { - ApplicationManager.getApplication().runReadAction(() -> { + ApplicationManager.getApplication().runReadAction((ThrowableComputable)() -> { LOG.append("inside read action\n"); readStarted = true; - while (!tryingToStartWriteAction); + while (!tryingToStartWriteAction && ok()); TimeoutUtil.sleep(100); for (int i = 0; i < anotherReadActionStarted.length; i++) { @@ -489,7 +497,7 @@ public class ApplicationImplTest extends PlatformTestCase { } for (AtomicBoolean threadStarted : anotherThreadStarted) { - while (!threadStarted.get()) ; + while (!threadStarted.get() && ok()) ; } // now the other threads try to get read lock. we should not let them for (int i=0; i<10; i++) { @@ -499,6 +507,7 @@ public class ApplicationImplTest extends PlatformTestCase { TimeoutUtil.sleep(20); } LOG.append("\nfinished read action"); + return null; }); } catch (Throwable e) { @@ -507,7 +516,7 @@ public class ApplicationImplTest extends PlatformTestCase { }, "read").start(); - while (!readStarted); + while (!readStarted && ok()); tryingToStartWriteAction = true; LOG.append("\nwrite about to start"); ApplicationManager.getApplication().runWriteAction(() -> { diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java index dac259da1dac..0b0bea6cac7c 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java @@ -332,6 +332,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso if (mySuite != null) { mySuite.setFinished(); myCurrentChildren.clear(); + myGetChildren = true; //fire events fireOnSuiteFinished(mySuite); @@ -520,6 +521,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso // current suite shouldn't be null otherwise test runner isn't correct // or may be we are in debug mode logProblem("Current suite is undefined. Root suite will be used."); + myGetChildren = true; return myTestsRootNode; } diff --git a/platform/util/src/com/intellij/util/containers/TransferToEDTQueue.java b/platform/util/src/com/intellij/util/containers/TransferToEDTQueue.java index ba9ebb5a8f7d..654e290c110d 100644 --- a/platform/util/src/com/intellij/util/containers/TransferToEDTQueue.java +++ b/platform/util/src/com/intellij/util/containers/TransferToEDTQueue.java @@ -22,6 +22,7 @@ import com.intellij.util.concurrency.Semaphore; import gnu.trove.Equality; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; import javax.swing.*; import java.util.Collection; @@ -160,6 +161,8 @@ public class TransferToEDTQueue { } } + @TestOnly + @NotNull public Collection dump() { synchronized (myQueue) { return myQueue.toList(); @@ -169,11 +172,9 @@ public class TransferToEDTQueue { // process all queue in current thread public void drain() { int processed = 0; - long start = System.currentTimeMillis(); while (processNext()) { processed++; } - long finish = System.currentTimeMillis(); } // blocks until all elements in the queue are processed diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java index 91c788c742c8..40359b2a6dd4 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java @@ -814,6 +814,10 @@ public class XDebugSessionImpl implements XDebugSession { }); } + public void unsetPaused() { + myPaused.set(false); + } + @Override public void positionReached(@NotNull final XSuspendContext suspendContext) { enableBreakpoints(); diff --git a/plugins/git4idea/src/git4idea/commands/GitHandlerUtil.java b/plugins/git4idea/src/git4idea/commands/GitHandlerUtil.java index a840249f1f89..a15bab7ca2f0 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandlerUtil.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandlerUtil.java @@ -251,19 +251,19 @@ public class GitHandlerUtil { /** * a progress manager to use */ - private final ProgressIndicator myProgressIndicator; + @Nullable private final ProgressIndicator myProgressIndicator; /** * A constructor * - * @param manager the project manager + * @param indicator the project manager * @param handler a handler instance * @param operationName an operation name * @param showErrors if true, the errors are shown when process is terminated */ - public GitLineHandlerListenerProgress(final ProgressIndicator manager, GitHandler handler, String operationName, boolean showErrors) { + public GitLineHandlerListenerProgress(@Nullable ProgressIndicator indicator, GitHandler handler, String operationName, boolean showErrors) { super(handler, operationName, showErrors); //To change body of overridden methods use File | Settings | File Templates. - myProgressIndicator = manager; + myProgressIndicator = indicator; } /** diff --git a/plugins/git4idea/src/git4idea/push/GitDefineRemoteDialog.java b/plugins/git4idea/src/git4idea/push/GitDefineRemoteDialog.java index 989e73edb9fc..945a7b8db8e8 100644 --- a/plugins/git4idea/src/git4idea/push/GitDefineRemoteDialog.java +++ b/plugins/git4idea/src/git4idea/push/GitDefineRemoteDialog.java @@ -15,13 +15,22 @@ */ package git4idea.push; -import com.intellij.openapi.project.Project; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.ui.components.JBLabel; import com.intellij.util.ui.GridBag; import com.intellij.util.ui.UIUtil; +import git4idea.commands.Git; +import git4idea.commands.GitCommandResult; import git4idea.repo.GitRemote; +import git4idea.repo.GitRepository; +import git4idea.validators.GitRefNameValidator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,11 +39,18 @@ import java.awt.*; class GitDefineRemoteDialog extends DialogWrapper { + private static final Logger LOG = Logger.getInstance(GitDefineRemoteDialog.class); + + @NotNull private final GitRepository myRepository; + @NotNull private final Git myGit; + @NotNull private final JTextField myRemoteName; @NotNull private final JTextField myRemoteUrl; - GitDefineRemoteDialog(@NotNull Project project) { - super(project); + GitDefineRemoteDialog(@NotNull GitRepository repository, @NotNull Git git) { + super(repository.getProject()); + myRepository = repository; + myGit = git; myRemoteName = new JTextField(GitRemote.ORIGIN_NAME, 20); myRemoteUrl = new JTextField(20); setTitle("Define Remote"); @@ -71,4 +87,42 @@ class GitDefineRemoteDialog extends DialogWrapper { public JComponent getPreferredFocusedComponent() { return myRemoteUrl; } + + @Override + protected void doOKAction() { + try { + String name = getRemoteName(); + String url = getRemoteUrl(); + String error = validateRemoteUnderModal(name, url); + if (error != null) { + LOG.warn(String.format("Invalid remote. Name: [%s], URL: [%s], error: %s", name, url, error)); + Messages.showErrorDialog(myRepository.getProject(), error, "Invalid Remote URL"); + } + else { + super.doOKAction(); + } + } + catch (ProcessCanceledException pce) { + // let the dialog stay open + } + } + + @Nullable + private String validateRemoteUnderModal(final String name, final String url) { + if (url.isEmpty()) { + return "URL can't be empty"; + } + if (!GitRefNameValidator.getInstance().checkInput(name)) { + return "Remote name is invalid"; + } + + return ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable() { + @Override + public String compute() throws ProcessCanceledException { + final GitCommandResult result = myGit.lsRemote(myRepository.getProject(), VfsUtilCore.virtualToIoFile(myRepository.getRoot()), url); + return !result.success() ? "Remote URL is invalid: " + result.getErrorOutputAsHtmlString() : null; + } + }, "Checking URL...", true, myRepository.getProject()); + } + } diff --git a/plugins/git4idea/src/git4idea/push/GitPushTargetPanel.java b/plugins/git4idea/src/git4idea/push/GitPushTargetPanel.java index ef36f95e59f6..fa0a7882b780 100644 --- a/plugins/git4idea/src/git4idea/push/GitPushTargetPanel.java +++ b/plugins/git4idea/src/git4idea/push/GitPushTargetPanel.java @@ -31,8 +31,6 @@ import com.intellij.openapi.ui.ValidationInfo; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; -import com.intellij.openapi.util.Ref; -import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; @@ -47,7 +45,6 @@ import git4idea.commands.Git; import git4idea.commands.GitCommandResult; import git4idea.repo.GitRemote; import git4idea.repo.GitRepository; -import git4idea.validators.GitRefNameValidator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -162,44 +159,12 @@ public class GitPushTargetPanel extends PushTargetPanel { } private void showDefineRemoteDialog() { - GitDefineRemoteDialog dialog = new GitDefineRemoteDialog(myRepository.getProject()); + GitDefineRemoteDialog dialog = new GitDefineRemoteDialog(myRepository, myGit); if (dialog.showAndGet()) { - String name = dialog.getRemoteName(); - String url = dialog.getRemoteUrl(); - String error = validateRemoteUnderModal(name, url); - if (error != null) { - LOG.warn(String.format("Invalid remote. Name: [%s], URL: [%s], error: %s", name, url, error)); - Messages.showErrorDialog(myRepository.getProject(), error, "Invalid Remote URL"); - } - else { - addRemoteUnderModal(name, url); - } + addRemoteUnderModal(dialog.getRemoteName(), dialog.getRemoteUrl()); } } - @Nullable - private String validateRemoteUnderModal(final String name, final String url) { - if (url.isEmpty()) { - return "URL can't be empty"; - } - if (!GitRefNameValidator.getInstance().checkInput(name)) { - return "Remote name is invalid"; - } - - final Ref error = Ref.create(); - ProgressManager.getInstance().run(new Task.Modal(myRepository.getProject(), "Checking URL...", true) { - @Override - public void run(@NotNull ProgressIndicator indicator) { - indicator.setIndeterminate(true); - final GitCommandResult result = myGit.lsRemote(myRepository.getProject(), VfsUtilCore.virtualToIoFile(myRepository.getRoot()), url); - if (!result.success()) { - error.set("Remote URL is invalid: " + result.getErrorOutputAsHtmlString()); - } - } - }); - return error.get(); - } - private void addRemoteUnderModal(@NotNull final String remoteName, @NotNull final String remoteUrl) { ProgressManager.getInstance().run(new Task.Modal(myRepository.getProject(), "Adding remote...", true) { private GitCommandResult myResult; diff --git a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java index dfc2d6bc9b38..ec5c56b37347 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java @@ -361,21 +361,17 @@ public class GitUnstashDialog extends DialogWrapper { AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { final Ref result = Ref.create(); - final Ref cancelled = Ref.create(); - ProgressManager.getInstance().run(new Task.Modal(h.project(), GitBundle.getString("unstash.unstashing"), true) { + final ProgressManager progressManager = ProgressManager.getInstance(); + boolean completed = progressManager.runProcessWithProgressSynchronously(new Runnable() { @Override - public void run(@NotNull final ProgressIndicator indicator) { - indicator.setIndeterminate(true); - h.addLineListener(new GitHandlerUtil.GitLineHandlerListenerProgress(indicator, h, "stash", false)); + public void run() { + h.addLineListener(new GitHandlerUtil.GitLineHandlerListenerProgress(progressManager.getProgressIndicator(), h, "stash", false)); Git git = ServiceManager.getService(Git.class); result.set(git.runCommand(new Computable.PredefinedValueComputable(h))); } - @Override - public void onCancel() { - cancelled.set(true); - } - }); - if (cancelled.get()) return; + }, GitBundle.getString("unstash.unstashing"), true, myProject); + + if (!completed) return; ServiceManager.getService(myProject, GitPlatformFacade.class).hardRefresh(root); GitCommandResult res = result.get(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyLineMarkerProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyLineMarkerProvider.java index db2212dd4682..f5e1a04c79df 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyLineMarkerProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyLineMarkerProvider.java @@ -116,7 +116,7 @@ public class GroovyLineMarkerProvider implements LineMarkerProvider { } if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) { PsiFile file = element1.getContainingFile(); - Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getDocument(file); + Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file); boolean drawSeparator = false; if (document != null) { CharSequence documentChars = document.getCharsSequence(); diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/PropertiesGroupingStructureViewComponent.java b/plugins/properties/src/com/intellij/lang/properties/editor/PropertiesGroupingStructureViewComponent.java index 8993be097090..894c03e7ddde 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/PropertiesGroupingStructureViewComponent.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/PropertiesGroupingStructureViewComponent.java @@ -24,7 +24,6 @@ import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.util.ArrayUtil; -import org.jetbrains.annotations.NonNls; import java.util.LinkedHashSet; import java.util.Set; @@ -138,10 +137,5 @@ public class PropertiesGroupingStructureViewComponent extends StructureViewCompo } } } - - @NonNls - public String getHelpID() { - return "editing.propertyFile.bundleEditor"; - } } diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java index 435f0c3a8c86..9c36ee1fa648 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleStructureViewComponent.java @@ -29,12 +29,9 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.pom.PomTargetPsiElement; -import com.intellij.pom.references.PomService; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.PsiTarget; import com.intellij.psi.util.PsiUtilCore; import com.intellij.refactoring.safeDelete.SafeDeleteHandler; import com.intellij.ui.PopupHandler; @@ -43,6 +40,7 @@ import com.intellij.usages.UsageView; import com.intellij.util.ArrayFactory; import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -235,5 +233,10 @@ public class ResourceBundleStructureViewComponent extends PropertiesGroupingStru return true; } } + + @NonNls + public String getHelpID() { + return "editing.propertyFile.bundleEditor"; + } } diff --git a/resources-en/src/messages/DebuggerBundle.properties b/resources-en/src/messages/DebuggerBundle.properties index 8c24513cc9d7..3eb9637f6ca6 100644 --- a/resources-en/src/messages/DebuggerBundle.properties +++ b/resources-en/src/messages/DebuggerBundle.properties @@ -91,6 +91,7 @@ status.step.into=Stepping into status.step.over=Stepping over status.run.to.cursor=Run to cursor status.process.resumed=Process resumed +status.paused.in.another.thread=Paused in another thread error.pop.bottom.stackframe=Cannot pop bottom frame error.pop.stackframe=An error occurred while popping stack frame: {0} error.class.not.loaded=Class not loaded : {0}