diff options
Diffstat (limited to 'platform/script-debugger/backend/src')
11 files changed, 64 insertions, 73 deletions
diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/HasUrl.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/HasUrl.java new file mode 100644 index 000000000000..56f51c5d6d51 --- /dev/null +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/HasUrl.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.debugger; + +import com.intellij.util.Url; +import org.jetbrains.annotations.NotNull; + + +public interface HasUrl { + @NotNull + Url getUrl(); +} diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/Script.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/Script.java index 354a51387a50..e44d308977d3 100755 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/Script.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/Script.java @@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.debugger.sourcemap.SourceMap; -public interface Script extends UserDataHolderEx { +public interface Script extends UserDataHolderEx, HasUrl { void setSourceMap(SourceMap sourceMap); enum Type { diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManager.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManager.java index 76157af7b808..c16ffe5d4b81 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManager.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManager.java @@ -19,13 +19,10 @@ public interface ScriptManager { boolean containsScript(Script script); /** - * Demands that script text should be replaced with a new one if possible. VM may get resumed - * after this command (this is defined by {@link ChangeDescription#isStackModified()}). In this - * case a standard 'suspended' notification is expected in a moment. - * - * @param newSource new text of script + * Demands that script text should be replaced with a new one if possible. VM may get resumed after this command */ - AsyncResult<?> setSourceOnRemote(@NotNull Script script, @NotNull String newSource, boolean preview); + @NotNull + AsyncResult<?> setSourceOnRemote(@NotNull Script script, @NotNull CharSequence newSource, boolean preview); void forEachScript(@NotNull Processor<Script> scriptProcessor); diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/ValueModifier.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/ValueModifier.java index dc452a2b7b64..e9ac90a7d023 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/ValueModifier.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/ValueModifier.java @@ -13,7 +13,7 @@ public interface ValueModifier { // it works quickly and we don't want to complicate our code and debugger SDK ActionCallback setValue(@NotNull Variable variable, String newValue, @NotNull EvaluateContext evaluateContext); - ActionCallback setValue(@NotNull Variable variable, Value newValue, @NotNull EvaluateContext evaluateContext); + ActionCallback setValue(@NotNull Variable variable, @NotNull Value newValue, @NotNull EvaluateContext evaluateContext); @NotNull AsyncResult<Value> evaluateGet(@NotNull Variable variable, @NotNull EvaluateContext evaluateContext); diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/ValueModifierUtil.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/ValueModifierUtil.java index b5edb7fa3282..d71261c5286b 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/ValueModifierUtil.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/ValueModifierUtil.java @@ -5,6 +5,7 @@ import com.intellij.openapi.util.AsyncResult; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.debugger.values.Value; +import org.jetbrains.io.JsonUtil; import java.util.Collections; import java.util.List; @@ -12,21 +13,6 @@ import java.util.regex.Pattern; public final class ValueModifierUtil { private static final Pattern KEY_NOTATION_PROPERTY_NAME_PATTERN = Pattern.compile("[\\p{L}_$]+[\\d\\p{L}_$]*"); - private static final String[] REPLACEMENT_CHARS; - - static { - REPLACEMENT_CHARS = new String[128]; - for (int i = 0; i <= 31; i++) { - REPLACEMENT_CHARS[i] = String.format("\\u%04x", (int)i); - } - REPLACEMENT_CHARS['"'] = "\\\""; - REPLACEMENT_CHARS['\\'] = "\\\\"; - REPLACEMENT_CHARS['\t'] = "\\t"; - REPLACEMENT_CHARS['\b'] = "\\b"; - REPLACEMENT_CHARS['\n'] = "\\n"; - REPLACEMENT_CHARS['\r'] = "\\r"; - REPLACEMENT_CHARS['\f'] = "\\f"; - } public static ActionCallback setValue(@NotNull final Variable variable, String newValue, @NotNull final EvaluateContext evaluateContext, @NotNull final ValueModifier modifier) { final ActionCallback callback = new ActionCallback(); @@ -77,44 +63,9 @@ public final class ValueModifierUtil { builder.append(name); } else { - escape(name, builder); + JsonUtil.escape(name, builder); } builder.append(']'); } } - - public static void escape(CharSequence value, StringBuilder sb) { - int length = value.length(); - sb.ensureCapacity(sb.capacity() + length + 2); - sb.append('"'); - int last = 0; - for (int i = 0; i < length; i++) { - char c = value.charAt(i); - String replacement; - if (c < 128) { - replacement = REPLACEMENT_CHARS[c]; - if (replacement == null) { - continue; - } - } - else if (c == '\u2028') { - replacement = "\\u2028"; - } - else if (c == '\u2029') { - replacement = "\\u2029"; - } - else { - continue; - } - if (last < i) { - sb.append(value, last, i); - } - sb.append(replacement); - last = i + 1; - } - if (last < length) { - sb.append(value, last, length); - } - sb.append('"'); - } }
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/MappingList.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/MappingList.java index e97386f90614..5d5aa818bcd5 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/MappingList.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/MappingList.java @@ -42,6 +42,15 @@ public abstract class MappingList { return middle; } else if (column < getColumn(mapping)) { + if (column == 0 || column == -1) { + // find first + int firstIndex = middle; + while (firstIndex > 0 && getLine(mappings.get(firstIndex - 1)) == line) { + firstIndex--; + } + return firstIndex; + } + if (middle == 0) { return -1; } diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/PrimitiveValue.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/PrimitiveValue.java index 12655e4ba921..f03565f2defa 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/PrimitiveValue.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/PrimitiveValue.java @@ -4,6 +4,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class PrimitiveValue extends ValueBase { + public static final PrimitiveValue NULL_VALUE = new PrimitiveValue(ValueType.NULL, "null"); + public static final PrimitiveValue UNDEFINED_VALUE = new PrimitiveValue(ValueType.UNDEFINED, "undefined"); + private final String valueString; public PrimitiveValue(@NotNull ValueType type, @NotNull String valueString) { diff --git a/platform/script-debugger/backend/src/org/jetbrains/rpc/CommandCallbackWithResponseBase.java b/platform/script-debugger/backend/src/org/jetbrains/rpc/CommandCallbackWithResponseBase.java index a0889cfc6ce6..aad3023ad340 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/rpc/CommandCallbackWithResponseBase.java +++ b/platform/script-debugger/backend/src/org/jetbrains/rpc/CommandCallbackWithResponseBase.java @@ -20,8 +20,8 @@ abstract class CommandCallbackWithResponseBase<SUCCESS_RESPONSE, C extends Actio onSuccess(resultReader.<RESULT>readResult(methodName, response)); } catch (Throwable e) { - callback.reject(e.getMessage()); MessageManager.LOG.error(e); + callback.reject(e.getMessage()); } } diff --git a/platform/script-debugger/backend/src/org/jetbrains/rpc/CommandSender.java b/platform/script-debugger/backend/src/org/jetbrains/rpc/CommandSender.java index b014cbefacf8..8df0824db5ae 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/rpc/CommandSender.java +++ b/platform/script-debugger/backend/src/org/jetbrains/rpc/CommandSender.java @@ -26,6 +26,11 @@ public interface CommandSender<ERROR_DETAILS> { @NotNull RequestWithResponse message, @NotNull PairConsumer<RESULT, AsyncResult<MAIN_RESULT>> consumer); + <RESULT, MAIN_RESULT> AsyncResult<MAIN_RESULT> send(@NotNull AsyncResult<MAIN_RESULT> result, + @NotNull RequestWithResponse message, + @NotNull PairConsumer<RESULT, AsyncResult<MAIN_RESULT>> consumer, + @Nullable ErrorConsumer<AsyncResult<MAIN_RESULT>, ERROR_DETAILS> errorConsumer); + <RESULT, MAIN_RESULT> AsyncResult<MAIN_RESULT> send(@NotNull RequestWithResponse message, @NotNull PairConsumer<RESULT, AsyncResult<MAIN_RESULT>> consumer); }
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageHandler.java b/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageHandler.java index fb6cabb9a577..1b87843c7168 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageHandler.java +++ b/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageHandler.java @@ -2,7 +2,6 @@ package org.jetbrains.rpc; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.AsyncResult; -import com.intellij.util.BooleanFunction; import com.intellij.util.Function; import com.intellij.util.PairConsumer; import org.jetbrains.annotations.NotNull; @@ -17,10 +16,7 @@ public abstract class MessageHandler<INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPON private final AtomicInteger currentSequence = new AtomicInteger(); protected final MessageManager<Request, INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPONSE, ERROR_DETAILS> messageManager; - private final BooleanFunction<Request> out; - - protected MessageHandler(@NotNull BooleanFunction<Request> out) { - this.out = out; + protected MessageHandler() { messageManager = new MessageManager<Request, INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPONSE, ERROR_DETAILS>(this); } @@ -33,11 +29,6 @@ public abstract class MessageHandler<INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPON } @Override - public boolean write(@NotNull Request message) { - return out.fun(message); - } - - @Override public final int getUpdatedSequence(Request message) { int id = currentSequence.incrementAndGet(); message.finalize(id); @@ -83,7 +74,16 @@ public abstract class MessageHandler<INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPON public final <RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull AsyncResult<TRANSFORMED_RESULT> result, @NotNull RequestWithResponse message, @NotNull PairConsumer<RESULT, AsyncResult<TRANSFORMED_RESULT>> consumer) { - messageManager.send(message, new NestedCommandCallbackWithResponse<SUCCESS_RESPONSE, RESULT, TRANSFORMED_RESULT, ERROR_DETAILS>(result, message.getMethodName(), consumer)); + messageManager.send(message, new NestedCommandCallbackWithResponse<SUCCESS_RESPONSE, RESULT, TRANSFORMED_RESULT, ERROR_DETAILS>(result, message.getMethodName(), consumer, null)); + return result; + } + + @Override + public final <RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull AsyncResult<TRANSFORMED_RESULT> result, + @NotNull RequestWithResponse message, + @NotNull PairConsumer<RESULT, AsyncResult<TRANSFORMED_RESULT>> consumer, + @Nullable ErrorConsumer<AsyncResult<TRANSFORMED_RESULT>, ERROR_DETAILS> errorConsumer) { + messageManager.send(message, new NestedCommandCallbackWithResponse<SUCCESS_RESPONSE, RESULT, TRANSFORMED_RESULT, ERROR_DETAILS>(result, message.getMethodName(), consumer, errorConsumer)); return result; } }
\ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/rpc/NestedCommandCallbackWithResponse.java b/platform/script-debugger/backend/src/org/jetbrains/rpc/NestedCommandCallbackWithResponse.java index ee5640ce91d9..d089bda2b0e5 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/rpc/NestedCommandCallbackWithResponse.java +++ b/platform/script-debugger/backend/src/org/jetbrains/rpc/NestedCommandCallbackWithResponse.java @@ -2,13 +2,14 @@ package org.jetbrains.rpc; import com.intellij.openapi.util.AsyncResult; import com.intellij.util.PairConsumer; +import org.jetbrains.annotations.Nullable; final class NestedCommandCallbackWithResponse<SUCCESS_RESPONSE, RESULT, MAIN_RESULT, ERROR_DETAILS> extends CommandCallbackWithResponseBase<SUCCESS_RESPONSE, AsyncResult<MAIN_RESULT>, RESULT, ERROR_DETAILS> { private final PairConsumer<RESULT, AsyncResult<MAIN_RESULT>> consumer; - public NestedCommandCallbackWithResponse(AsyncResult<MAIN_RESULT> result, String methodName, PairConsumer<RESULT, AsyncResult<MAIN_RESULT>> consumer) { - super(result, methodName, null); + public NestedCommandCallbackWithResponse(AsyncResult<MAIN_RESULT> result, String methodName, PairConsumer<RESULT, AsyncResult<MAIN_RESULT>> consumer, @Nullable ErrorConsumer<AsyncResult<MAIN_RESULT>, ERROR_DETAILS> errorConsumer) { + super(result, methodName, errorConsumer); this.consumer = consumer; } |