Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anton Makeev
2017-11-17 17:36:49 +01:00
7 changed files with 124 additions and 105 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui.impl.watch;
import com.intellij.debugger.DebuggerBundle;
@@ -31,7 +17,9 @@ import com.intellij.debugger.settings.NodeRendererSettings;
import com.intellij.debugger.ui.tree.FieldDescriptor;
import com.intellij.debugger.ui.tree.NodeDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiExpression;
@@ -95,13 +83,32 @@ public class FieldDescriptorImpl extends ValueDescriptorImpl implements FieldDes
public Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
DebuggerManagerThreadImpl.assertIsManagerThread();
try {
return (myObject != null) ? myObject.getValue(myField) : myField.declaringType().getValue(myField);
if (myObject != null) {
populateExceptionStackTraceIfNeeded(evaluationContext);
return myObject.getValue(myField);
}
else {
return myField.declaringType().getValue(myField);
}
}
catch (ObjectCollectedException ignored) {
throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED;
}
}
private void populateExceptionStackTraceIfNeeded(EvaluationContextImpl evaluationContext) {
if ("stackTrace".equals(getName()) &&
Registry.is("debugger.populate.exception.stack") &&
DebuggerUtils.instanceOf(myObject.type(), CommonClassNames.JAVA_LANG_THROWABLE)) {
try {
invokeExceptionGetStackTrace(myObject, evaluationContext);
}
catch (Throwable e) {
LOG.info(e); // catch all exceptions to ensure the method returns gracefully
}
}
}
public boolean isStatic() {
return myIsStatic;
}
@@ -223,25 +223,31 @@ public abstract class ValueDescriptorImpl extends NodeDescriptorImpl implements
}
@Nullable
private static ObjectReference getTargetExceptionWithStackTraceFilled(EvaluationContextImpl evaluationContext,
protected static Value invokeExceptionGetStackTrace(ObjectReference exceptionObj, EvaluationContextImpl evaluationContext)
throws EvaluateException {
Method method = ((ClassType)exceptionObj.referenceType()).concreteMethodByName("getStackTrace", "()[Ljava/lang/StackTraceElement;");
if (method != null) {
return evaluationContext.getDebugProcess().invokeMethod(evaluationContext, exceptionObj, method, Collections.emptyList());
}
return null;
}
@Nullable
private static ObjectReference getTargetExceptionWithStackTraceFilled(@Nullable EvaluationContextImpl evaluationContext,
EvaluateException ex,
boolean printToConsole) {
final ObjectReference exceptionObj = ex.getExceptionFromTargetVM();
if (exceptionObj != null && evaluationContext != null) {
try {
ClassType refType = (ClassType)exceptionObj.referenceType();
Method method = refType.concreteMethodByName("getStackTrace", "()[Ljava/lang/StackTraceElement;");
if (method != null) {
final DebugProcessImpl process = evaluationContext.getDebugProcess();
Value trace = process.invokeMethod(evaluationContext, exceptionObj, method, Collections.emptyList());
Value trace = invokeExceptionGetStackTrace(exceptionObj, evaluationContext);
// print to console as well
if (printToConsole && trace instanceof ArrayReference) {
ArrayReference traceArray = (ArrayReference)trace;
process.printToConsole(DebuggerUtils.getValueAsString(evaluationContext, exceptionObj) + "\n");
for (Value stackElement : traceArray.getValues()) {
process.printToConsole("\tat " + DebuggerUtils.getValueAsString(evaluationContext, stackElement) + "\n");
}
// print to console as well
if (printToConsole && trace instanceof ArrayReference) {
DebugProcessImpl process = evaluationContext.getDebugProcess();
ArrayReference traceArray = (ArrayReference)trace;
process.printToConsole(DebuggerUtils.getValueAsString(evaluationContext, exceptionObj) + "\n");
for (Value stackElement : traceArray.getValues()) {
process.printToConsole("\tat " + DebuggerUtils.getValueAsString(evaluationContext, stackElement) + "\n");
}
}
}
@@ -811,7 +811,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
*
* @param child variable declaration child node which alignment is to be defined
* @return alignment to use for the given node
* @see CodeStyleSettings#ALIGN_GROUP_FIELD_DECLARATIONS
* @see CommonCodeStyleSettings#ALIGN_GROUP_FIELD_DECLARATIONS
*/
private boolean shouldAlignFieldInColumns(@NotNull ASTNode child) {
// The whole idea of variable declarations alignment is that complete declaration blocks which children are to be aligned hold
@@ -21,8 +21,6 @@ import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.LightCodeInsightTestCase;
@@ -43,81 +41,81 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
public void testLiteralSCR4989() { doTest(); }
public void testSCR3493() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
boolean use_tab_character = settings.useTabCharacter(null);
boolean smart_tabs = settings.isSmartTabs(null);
CommonCodeStyleSettings settings = getJavaSettings();
boolean use_tab_character = settings.getIndentOptions().USE_TAB_CHARACTER;
boolean smart_tabs = settings.getIndentOptions().SMART_TABS;
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
doTest();
} finally {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
settings.getIndentOptions().USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions().SMART_TABS = smart_tabs;
}
}
public void testSCR3493a() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
boolean use_tab_character = settings.useTabCharacter(null);
boolean smart_tabs = settings.isSmartTabs(null);
CommonCodeStyleSettings settings = getJavaSettings();
boolean use_tab_character = settings.getIndentOptions().USE_TAB_CHARACTER;
boolean smart_tabs = settings.getIndentOptions().SMART_TABS;
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
doTest();
} finally {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
settings.getIndentOptions().USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions().SMART_TABS = smart_tabs;
}
}
public void testSCR3493b() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
boolean use_tab_character = settings.useTabCharacter(null);
boolean smart_tabs = settings.isSmartTabs(null);
CommonCodeStyleSettings settings = getJavaSettings();
boolean use_tab_character = settings.getIndentOptions().USE_TAB_CHARACTER;;
boolean smart_tabs = settings.getIndentOptions().SMART_TABS;
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
doTest();
} finally {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
settings.getIndentOptions().USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions().SMART_TABS = smart_tabs;
}
}
public void testSCR3493c() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
boolean use_tab_character = settings.useTabCharacter(null);
boolean smart_tabs = settings.isSmartTabs(null);
CommonCodeStyleSettings settings = getJavaSettings();
boolean use_tab_character = settings.getIndentOptions().USE_TAB_CHARACTER;
boolean smart_tabs = settings.getIndentOptions().SMART_TABS;
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
doTest();
} finally {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
settings.getIndentOptions().USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions().SMART_TABS = smart_tabs;
}
}
public void testSCR3493d() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
boolean use_tab_character = settings.useTabCharacter(null);
boolean smart_tabs = settings.isSmartTabs(null);
CommonCodeStyleSettings settings = getJavaSettings();
boolean use_tab_character = settings.getIndentOptions().USE_TAB_CHARACTER;
boolean smart_tabs = settings.getIndentOptions().SMART_TABS;
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
doTest();
} finally {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
settings.getIndentOptions().USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions().SMART_TABS = smart_tabs;
}
}
public void testSCR3493e() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
boolean use_tab_character = settings.useTabCharacter(null);
boolean smart_tabs = settings.isSmartTabs(null);
CommonCodeStyleSettings settings = getJavaSettings();
boolean use_tab_character = settings.getIndentOptions().USE_TAB_CHARACTER;
boolean smart_tabs = settings.getIndentOptions().SMART_TABS;
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
doTest();
} finally {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
settings.getIndentOptions().USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions().SMART_TABS = smart_tabs;
}
}
public void testSCR5959() {
@@ -138,49 +136,54 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
public void testDeclarationWithInitializer() {doTest(); }
public void testUnwrapCodeBlock1() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
boolean use_tab_character = settings.useTabCharacter(null);
boolean smart_tabs = settings.isSmartTabs(null);
CommonCodeStyleSettings settings = getJavaSettings();
boolean use_tab_character = settings.getIndentOptions().USE_TAB_CHARACTER;
boolean smart_tabs = settings.getIndentOptions().SMART_TABS;
int old = settings.IF_BRACE_FORCE;
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getCommonSettings(JavaLanguage.INSTANCE).IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_IF_MULTILINE;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_IF_MULTILINE;
doTest();
} finally {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
settings.getCommonSettings(JavaLanguage.INSTANCE).IF_BRACE_FORCE = old;
settings.getIndentOptions().USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions().SMART_TABS = smart_tabs;
settings.IF_BRACE_FORCE = old;
}
}
public void testUnwrapCodeBlock2() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
boolean use_tab_character = settings.useTabCharacter(null);
boolean smart_tabs = settings.isSmartTabs(null);
CommonCodeStyleSettings settings = getJavaSettings();
boolean use_tab_character = settings.getIndentOptions().USE_TAB_CHARACTER;
boolean smart_tabs = settings.getIndentOptions().SMART_TABS;
int old = settings.IF_BRACE_FORCE;
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getCommonSettings(JavaLanguage.INSTANCE).IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
doTest();
} finally {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
settings.getCommonSettings(JavaLanguage.INSTANCE).IF_BRACE_FORCE = old;
settings.getIndentOptions().USE_TAB_CHARACTER = use_tab_character;
settings.getIndentOptions().SMART_TABS = smart_tabs;
settings.IF_BRACE_FORCE = old;
}
}
@NotNull
protected CommonCodeStyleSettings getJavaSettings() {
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
}
public void testAssignmentExpression() {
doTest();
}
public void testReformatInsertsNewlines() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
CommonCodeStyleSettings settings = getJavaSettings();
final Element root = new Element("fake");
settings.writeExternal(root);
try {
settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
settings.getIndentOptions().USE_TAB_CHARACTER = true;
settings.getIndentOptions().SMART_TABS = true;
settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
doTest();
@@ -190,7 +193,7 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
}
public void testForceBrace() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
CommonCodeStyleSettings settings = getJavaSettings();
int old = settings.IF_BRACE_FORCE;
try {
settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
@@ -201,8 +204,8 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
}
public void testWrongWrapping() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.setDefaultRightMargin(80);
CommonCodeStyleSettings settings = getJavaSettings();
settings.RIGHT_MARGIN = 80;
settings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
doTest();
@@ -210,9 +213,9 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
public void testSubsequentJoiningAndUnexpectedTextRemoval() {
// Inspired by IDEA-65342
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.setDefaultRightMargin(50);
settings.getCommonSettings(JavaLanguage.INSTANCE).CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
CommonCodeStyleSettings settings = getJavaSettings();
settings.RIGHT_MARGIN = 50;
settings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
doTest(2);
}
@@ -223,7 +226,7 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
}
public void testJoiningMethodCallWhenItDoesntFit() {
CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
CommonCodeStyleSettings settings = getJavaSettings();
settings.METHOD_CALL_CHAIN_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
settings.RIGHT_MARGIN = 20;
doTest();
@@ -232,7 +235,7 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
public void testMultipleBlockComments() { doTest(); }
public void testPreserveSpaceIfOnNewLineOptionEnabled() {
CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
CommonCodeStyleSettings settings = getJavaSettings();
settings.CATCH_ON_NEW_LINE = true;
doTest();
}
@@ -83,7 +83,7 @@ public class DetectIndentAndTypeTest extends LightPlatformCodeInsightFixtureTest
public void testContinuationTab_AsTabSize() {
CommonCodeStyleSettings common = mySettings.getCommonSettings(JavaLanguage.INSTANCE);
mySettings.ALIGN_MULTILINE_BINARY_OPERATION = false;
common.ALIGN_MULTILINE_BINARY_OPERATION = false;
CommonCodeStyleSettings.IndentOptions indentOptions = common.getIndentOptions();
assert indentOptions != null;
@@ -106,7 +106,7 @@ public class DetectIndentAndTypeTest extends LightPlatformCodeInsightFixtureTest
public void testContinuationTabs_AsDoubleTabSize() {
CommonCodeStyleSettings common = mySettings.getCommonSettings(JavaLanguage.INSTANCE);
mySettings.ALIGN_MULTILINE_BINARY_OPERATION = false;
common.ALIGN_MULTILINE_BINARY_OPERATION = false;
CommonCodeStyleSettings.IndentOptions indentOptions = common.getIndentOptions();
assert indentOptions != null;
@@ -64,6 +64,7 @@ public class _FirstInSuiteTest extends TestCase {
// some tests do not initialize Application but want to use parallel streams
IdeaForkJoinWorkerThreadFactory.setupForkJoinCommonPool();
System.out.println("ForkJoinPool.commonPool: " + ForkJoinPool.commonPool());
System.out.println("cpu cores: " + Runtime.getRuntime().availableProcessors());
suiteStarted = System.nanoTime();
@@ -368,6 +368,8 @@ debugger.keep.step.requests=false
debugger.enable.memory.view=true
debugger.enable.overhead.monitor=true
debugger.tree.states.depth=100
debugger.populate.exception.stack=true
debugger.populate.exception.stack.description=Automatically fill exception's stacktrace by calling getStackTrace
analyze.exceptions.on.the.fly=false
analyze.exceptions.on.the.fly.description=Automatically analyze clipboard on frame activation,\