| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.debug.ui.liveedit; | 5 package org.chromium.debug.ui.liveedit; |
| 6 | 6 |
| 7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
| 8 import java.util.Arrays; |
| 9 import java.util.Collections; |
| 8 import java.util.List; | 10 import java.util.List; |
| 9 | 11 |
| 10 import org.chromium.debug.core.model.PushChangesPlan; | 12 import org.chromium.debug.core.model.PushChangesPlan; |
| 11 import org.chromium.debug.core.model.SourceWrapSupport; | 13 import org.chromium.debug.core.model.SourceWrapSupport; |
| 12 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.FunctionNode; | 14 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.FunctionNode; |
| 13 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.Side; | 15 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.Side; |
| 14 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.SourcePosition; | 16 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.SourcePosition; |
| 15 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.SourceText; | 17 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.SourceText; |
| 16 import org.chromium.sdk.UpdatableScript; | 18 import org.chromium.sdk.UpdatableScript; |
| 17 import org.chromium.sdk.UpdatableScript.NewFunctionNode; | 19 import org.chromium.sdk.UpdatableScript.NewFunctionNode; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 newSource = newSourceComment + wrapperMatch.wrap(newSourceRaw); | 60 newSource = newSourceComment + wrapperMatch.wrap(newSourceRaw); |
| 59 newPositionOffset = newSourceComment.length(); | 61 newPositionOffset = newSourceComment.length(); |
| 60 textualDiff = shiftNewPositions(changeDescription.getTextualDiff(), | 62 textualDiff = shiftNewPositions(changeDescription.getTextualDiff(), |
| 61 oldSourceComment.length(), newSourceComment.length(), wrapperMatch.get
PrefixLength(), | 63 oldSourceComment.length(), newSourceComment.length(), wrapperMatch.get
PrefixLength(), |
| 62 wrapperMatch.getSuffixLength(), oldSourceRaw.length(), newSourceRaw.le
ngth()); | 64 wrapperMatch.getSuffixLength(), oldSourceRaw.length(), newSourceRaw.le
ngth()); |
| 63 } | 65 } |
| 64 | 66 |
| 65 TreeBuilder builder = new TreeBuilder(previewMode, oldPositionOffset, newPos
itionOffset); | 67 TreeBuilder builder = new TreeBuilder(previewMode, oldPositionOffset, newPos
itionOffset); |
| 66 final FunctionNode rootFunction = builder.build(changeDescription); | 68 final FunctionNode rootFunction = builder.build(changeDescription); |
| 67 | 69 |
| 68 return new LiveEditDiffViewer.Input() { | 70 return new InputBase(newSource, oldSource) { |
| 69 public SourceText getNewSource() { | 71 @Override public FunctionNode getRootFunction() { |
| 70 return new SourceText() { | |
| 71 public String getText() { | |
| 72 return newSource; | |
| 73 } | |
| 74 public String getTitle() { | |
| 75 return Messages.PushResultParser_LOCAL_FILE; | |
| 76 } | |
| 77 }; | |
| 78 } | |
| 79 public SourceText getOldSource() { | |
| 80 return new SourceText() { | |
| 81 public String getText() { | |
| 82 return oldSource; | |
| 83 } | |
| 84 public String getTitle() { | |
| 85 return Messages.PushResultParser_SCRIPT_IN_VM; | |
| 86 } | |
| 87 }; | |
| 88 } | |
| 89 | |
| 90 public FunctionNode getRootFunction() { | |
| 91 return rootFunction; | 72 return rootFunction; |
| 92 } | 73 } |
| 93 | 74 @Override public TextualDiff getTextualDiff() { |
| 94 @Override | |
| 95 public TextualDiff getTextualDiff() { | |
| 96 return textualDiff; | 75 return textualDiff; |
| 97 } | 76 } |
| 98 }; | 77 }; |
| 99 } | 78 } |
| 79 |
| 80 static LiveEditDiffViewer.Input createCompileErrorViewerInput( |
| 81 final UpdatableScript.CompileErrorFailure compileError, PushChangesPlan ch
angesPlan, |
| 82 boolean previewMode) { |
| 83 |
| 84 final String newSource = changesPlan.getNewSource(); |
| 85 final String oldSource = changesPlan.getScript().getSource(); |
| 86 |
| 87 final int startOffset = compileError.getStartPosition().getOffset(); |
| 88 final int endOffset; |
| 89 if (compileError.getEndPosition() == null) { |
| 90 endOffset = startOffset + 1; |
| 91 } else { |
| 92 endOffset = compileError.getEndPosition().getOffset(); |
| 93 } |
| 94 final SourcePosition sourcePosition = new SourcePosition() { |
| 95 @Override public int getStart() { |
| 96 return startOffset; |
| 97 } |
| 98 @Override public int getEnd() { |
| 99 return endOffset; |
| 100 } |
| 101 }; |
| 102 |
| 103 final TextualDiff fakeTextualDiff = new TextualDiff() { |
| 104 @Override |
| 105 public List<Long> getChunks() { |
| 106 return Arrays.asList( |
| 107 0L, (long) oldSource.length(), (long) newSource.length()); |
| 108 } |
| 109 }; |
| 110 |
| 111 final FunctionNode fakeFunctionNode = new FunctionNode() { |
| 112 @Override public String getName() { |
| 113 return compileError.getCompilerMessage(); |
| 114 } |
| 115 @Override public String getStatus() { |
| 116 return Messages.PushResultParser_COMPILE_ERROR; |
| 117 } |
| 118 @Override public List<? extends FunctionNode> children() { |
| 119 return Collections.emptyList(); |
| 120 } |
| 121 @Override public SourcePosition getPosition(Side side) { |
| 122 switch (side) { |
| 123 case NEW: |
| 124 return sourcePosition; |
| 125 default: |
| 126 return null; |
| 127 } |
| 128 } |
| 129 @Override public FunctionNode getParent() { |
| 130 return null; |
| 131 } |
| 132 }; |
| 133 |
| 134 return new InputBase(newSource, oldSource) { |
| 135 @Override public FunctionNode getRootFunction() { |
| 136 return fakeFunctionNode; |
| 137 } |
| 138 @Override public TextualDiff getTextualDiff() { |
| 139 return fakeTextualDiff; |
| 140 } |
| 141 }; |
| 142 } |
| 100 | 143 |
| 101 private static class TreeBuilder { | 144 private static class TreeBuilder { |
| 102 private final StatusRenderer statusRenderer; | 145 private final StatusRenderer statusRenderer; |
| 103 private final boolean hideOldVersion; | 146 private final boolean hideOldVersion; |
| 104 private final int oldPositionOffset; | 147 private final int oldPositionOffset; |
| 105 private final int newPositionOffset; | 148 private final int newPositionOffset; |
| 106 | 149 |
| 107 public TreeBuilder(boolean previewOnly, int oldPositionOffset, int newPositi
onOffset) { | 150 public TreeBuilder(boolean previewOnly, int oldPositionOffset, int newPositi
onOffset) { |
| 108 if (previewOnly) { | 151 if (previewOnly) { |
| 109 this.statusRenderer = PREVIEW_STATUS_RENDERER; | 152 this.statusRenderer = PREVIEW_STATUS_RENDERER; |
| 110 } else { | 153 } else { |
| 111 this.statusRenderer = RESULT_STATUS_RENDERER; | 154 this.statusRenderer = RESULT_STATUS_RENDERER; |
| 112 } | 155 } |
| 113 this.hideOldVersion = !previewOnly; | 156 this.hideOldVersion = !previewOnly; |
| 114 this.oldPositionOffset = oldPositionOffset; | 157 this.oldPositionOffset = oldPositionOffset; |
| 115 this.newPositionOffset = newPositionOffset; | 158 this.newPositionOffset = newPositionOffset; |
| 116 } | 159 } |
| 117 | 160 |
| 118 public FunctionNode build(UpdatableScript.ChangeDescription changeDescriptio
n) { | 161 public FunctionNode build(UpdatableScript.ChangeDescription changeDescriptio
n) { |
| 119 return buildNode(changeDescription.getChangeTree()); | 162 return buildNode(changeDescription.getChangeTree(), Messages.PushResultPar
ser_SCRIPT); |
| 120 } | 163 } |
| 121 | 164 |
| 122 private NodeImpl buildNode(UpdatableScript.OldFunctionNode oldFunction) { | 165 private NodeImpl buildNode(UpdatableScript.OldFunctionNode oldFunction, |
| 166 String predefinedFunctionName) { |
| 123 List<NodeImpl> childListFirst = new ArrayList<NodeImpl>(); | 167 List<NodeImpl> childListFirst = new ArrayList<NodeImpl>(); |
| 124 for (UpdatableScript.OldFunctionNode oldChild : oldFunction.children()) { | 168 for (UpdatableScript.OldFunctionNode oldChild : oldFunction.children()) { |
| 125 NodeImpl nodeImpl = buildNode(oldChild); | 169 NodeImpl nodeImpl = buildNode(oldChild, null); |
| 126 childListFirst.add(nodeImpl); | 170 childListFirst.add(nodeImpl); |
| 127 } | 171 } |
| 128 List<NodeImpl> childListSecond = new ArrayList<NodeImpl>(); | 172 List<NodeImpl> childListSecond = new ArrayList<NodeImpl>(); |
| 129 for (NewFunctionNode newChild : oldFunction.newChildren()) { | 173 for (NewFunctionNode newChild : oldFunction.newChildren()) { |
| 130 NodeImpl nodeImpl = buildNode(newChild, newPositionOffset); | 174 NodeImpl nodeImpl = buildNode(newChild, newPositionOffset); |
| 131 childListSecond.add(nodeImpl); | 175 childListSecond.add(nodeImpl); |
| 132 } | 176 } |
| 133 // Merge lists by positions SIDE.NEW | 177 // Merge lists by positions SIDE.NEW |
| 134 List<NodeImpl> childList = new ArrayList<NodeImpl>(); | 178 List<NodeImpl> childList = new ArrayList<NodeImpl>(); |
| 135 { | 179 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 155 pos1++; | 199 pos1++; |
| 156 } else { | 200 } else { |
| 157 childList.add(childListSecond.get(pos2)); | 201 childList.add(childListSecond.get(pos2)); |
| 158 pos2++; | 202 pos2++; |
| 159 } | 203 } |
| 160 } | 204 } |
| 161 } | 205 } |
| 162 } | 206 } |
| 163 return new NodeImpl(oldFunction, | 207 return new NodeImpl(oldFunction, |
| 164 createPosition(oldFunction.getPositions(), oldPositionOffset), | 208 createPosition(oldFunction.getPositions(), oldPositionOffset), |
| 165 createPosition(oldFunction.getNewPositions(), newPositionOffset), chil
dList); | 209 createPosition(oldFunction.getNewPositions(), newPositionOffset), chil
dList, |
| 210 predefinedFunctionName); |
| 166 } | 211 } |
| 167 private NodeImpl buildNode(UpdatableScript.NewFunctionNode newFunction, | 212 private NodeImpl buildNode(UpdatableScript.NewFunctionNode newFunction, |
| 168 int newPositionOffset) { | 213 int newPositionOffset) { |
| 169 List<NodeImpl> childList = new ArrayList<NodeImpl>(); | 214 List<NodeImpl> childList = new ArrayList<NodeImpl>(); |
| 170 for (UpdatableScript.NewFunctionNode newChild : newFunction.children()) { | 215 for (UpdatableScript.NewFunctionNode newChild : newFunction.children()) { |
| 171 NodeImpl nodeImpl = buildNode(newChild, newPositionOffset); | 216 NodeImpl nodeImpl = buildNode(newChild, newPositionOffset); |
| 172 childList.add(nodeImpl); | 217 childList.add(nodeImpl); |
| 173 } | 218 } |
| 174 return new NodeImpl(newFunction, null, | 219 return new NodeImpl(newFunction, null, |
| 175 createPosition(newFunction.getPositions(), newPositionOffset), childLi
st); | 220 createPosition(newFunction.getPositions(), newPositionOffset), childLi
st, null); |
| 176 } | 221 } |
| 177 | 222 |
| 178 private static SourcePosition createPosition( | 223 private static SourcePosition createPosition( |
| 179 final UpdatableScript.FunctionPositions positions, final int offset) { | 224 final UpdatableScript.FunctionPositions positions, final int offset) { |
| 180 if (positions == null) { | 225 if (positions == null) { |
| 181 return null; | 226 return null; |
| 182 } | 227 } |
| 183 return new SourcePosition() { | 228 return new SourcePosition() { |
| 184 public int getStart() { | 229 public int getStart() { |
| 185 return (int) positions.getStart() + offset; | 230 return (int) positions.getStart() + offset; |
| 186 } | 231 } |
| 187 public int getEnd() { | 232 public int getEnd() { |
| 188 return (int) positions.getEnd() + offset; | 233 return (int) positions.getEnd() + offset; |
| 189 } | 234 } |
| 190 }; | 235 }; |
| 191 } | 236 } |
| 192 | 237 |
| 193 private class NodeImpl implements FunctionNode { | 238 private class NodeImpl implements FunctionNode { |
| 194 private final UpdatableScript.FunctionNode<?> rawFunction; | 239 private final UpdatableScript.FunctionNode<?> rawFunction; |
| 195 private final String name; | 240 private final String name; |
| 196 private final SourcePosition oldPosition; | 241 private final SourcePosition oldPosition; |
| 197 private final SourcePosition newPosition; | 242 private final SourcePosition newPosition; |
| 198 private final List<? extends FunctionNode> childList; | 243 private final List<? extends FunctionNode> childList; |
| 199 private FunctionNode parent = null; | 244 private FunctionNode parent = null; |
| 200 | 245 |
| 201 private NodeImpl(UpdatableScript.FunctionNode<?> rawFunction, SourcePositi
on oldPosition, | 246 private NodeImpl(UpdatableScript.FunctionNode<?> rawFunction, SourcePositi
on oldPosition, |
| 202 SourcePosition newPosition, List<? extends NodeImpl> childList) { | 247 SourcePosition newPosition, List<? extends NodeImpl> childList, |
| 248 String predefinedFunctionName) { |
| 203 this.rawFunction = rawFunction; | 249 this.rawFunction = rawFunction; |
| 204 this.name = rawFunction.getName(); | 250 if (predefinedFunctionName == null) { |
| 251 this.name = rawFunction.getName(); |
| 252 } else { |
| 253 this.name = predefinedFunctionName; |
| 254 } |
| 205 this.oldPosition = oldPosition; | 255 this.oldPosition = oldPosition; |
| 206 this.newPosition = newPosition; | 256 this.newPosition = newPosition; |
| 207 this.childList = childList; | 257 this.childList = childList; |
| 208 for (NodeImpl child : childList) { | 258 for (NodeImpl child : childList) { |
| 209 child.parent = this; | 259 child.parent = this; |
| 210 } | 260 } |
| 211 } | 261 } |
| 212 public List<? extends FunctionNode> children() { | 262 public List<? extends FunctionNode> children() { |
| 213 return childList; | 263 return childList; |
| 214 } | 264 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 shiftedChunks.add((long) originalOldLength + oldCommentLength); | 383 shiftedChunks.add((long) originalOldLength + oldCommentLength); |
| 334 shiftedChunks.add((long) originalNewLength + newCommentLength + prefixLength
+ suffixLength); | 384 shiftedChunks.add((long) originalNewLength + newCommentLength + prefixLength
+ suffixLength); |
| 335 | 385 |
| 336 return new TextualDiff() { | 386 return new TextualDiff() { |
| 337 @Override | 387 @Override |
| 338 public List<Long> getChunks() { | 388 public List<Long> getChunks() { |
| 339 return shiftedChunks; | 389 return shiftedChunks; |
| 340 } | 390 } |
| 341 }; | 391 }; |
| 342 } | 392 } |
| 393 |
| 394 private static abstract class InputBase implements LiveEditDiffViewer.Input { |
| 395 private final String newSource; |
| 396 private final String oldSource; |
| 397 |
| 398 InputBase(String newSource, String oldSource) { |
| 399 this.newSource = newSource; |
| 400 this.oldSource = oldSource; |
| 401 } |
| 402 |
| 403 public SourceText getNewSource() { |
| 404 return new SourceText() { |
| 405 public String getText() { |
| 406 return newSource; |
| 407 } |
| 408 public String getTitle() { |
| 409 return Messages.PushResultParser_LOCAL_FILE; |
| 410 } |
| 411 }; |
| 412 } |
| 413 public SourceText getOldSource() { |
| 414 return new SourceText() { |
| 415 public String getText() { |
| 416 return oldSource; |
| 417 } |
| 418 public String getTitle() { |
| 419 return Messages.PushResultParser_SCRIPT_IN_VM; |
| 420 } |
| 421 }; |
| 422 } |
| 423 } |
| 343 } | 424 } |
| OLD | NEW |