Skip to content

Commit

Permalink
Merge pull request #17 from Roenke/plugin-review-fixes
Browse files Browse the repository at this point in the history
Fixes after plugin overview/testing
  • Loading branch information
bibaev authored Apr 20, 2017
2 parents 95d1067 + a25e002 commit e406444
Show file tree
Hide file tree
Showing 32 changed files with 448 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ apply plugin: 'java'
apply plugin: "kotlin"

group 'com.intellij.debugger.stream'
version '0.0.8'
version '0.0.9'

intellij {
type = 'IC'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import com.intellij.debugger.streams.trace.TraceElement;
import com.intellij.debugger.streams.trace.TraceInfo;
import com.sun.jdi.Value;
import com.intellij.openapi.diagnostic.Logger;
import com.sun.jdi.*;
import one.util.streamex.StreamEx;
import org.jetbrains.annotations.NotNull;

Expand All @@ -30,6 +31,8 @@
* @author Vitaliy.Bibaev
*/
public class IdentityResolver implements ValuesOrderResolver {
private static final Logger LOG = Logger.getInstance(IdentityResolver.class);

@NotNull
@Override
public Result resolve(@NotNull TraceInfo info) {
Expand All @@ -39,15 +42,14 @@ public Result resolve(@NotNull TraceInfo info) {
final Map<TraceElement, List<TraceElement>> direct = new HashMap<>();
final Map<TraceElement, List<TraceElement>> reverse = new HashMap<>();

final Map<Value, List<TraceElement>> grouped = new HashMap<>(
StreamEx.of(after.keySet())
.sorted()
.map(after::get)
.groupingBy(TraceElement::getValue)
);
final Map<Object, List<TraceElement>> grouped = StreamEx
.of(after.keySet())
.sorted()
.map(after::get)
.groupingBy(IdentityResolver::extractKey);

for (final TraceElement element : before.values()) {
final Value value = element.getValue();
final Object value = extractKey(element);

final List<TraceElement> elements = grouped.get(value);
final TraceElement afterItem = elements.get(0);
Expand All @@ -60,4 +62,19 @@ public Result resolve(@NotNull TraceInfo info) {

return Result.of(direct, reverse);
}

private static Object extractKey(@NotNull TraceElement element) {
final Value value = element.getValue();
if (!(value instanceof PrimitiveValue)) return value;
if (value instanceof IntegerValue) return ((IntegerValue)value).value();
if (value instanceof DoubleValue) return ((DoubleValue)value).value();
if (value instanceof LongValue) return ((LongValue)value).value();
if (value instanceof BooleanValue) return ((BooleanValue)value).value();
if (value instanceof ByteValue) return ((ByteValue)value).value();
if (value instanceof CharValue) return ((CharValue)value).value();
if (value instanceof FloatValue) return ((FloatValue)value).value();

LOG.error("unknown primitive value: " + value.type().name());
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ private static String buildDeclarations(@NotNull StreamCallTraceHandler producer

@NotNull
private static String buildStreamExpression(@NotNull StreamChain chain) {
if (chain.getTerminationCall().isVoid()) {
final String resultInitialization = "final Object streamResult = null;" + LINE_SEPARATOR;
final GenericType resultType = chain.getTerminationCall().getResultType();
if (resultType.equals(GenericType.VOID)) {
final String resultInitialization = "final Object streamResult = new Object[1];" + LINE_SEPARATOR;
return resultInitialization + chain.getText() + ";" + LINE_SEPARATOR;
}
else {
return "final Object streamResult = " + chain.getText() + ";" + LINE_SEPARATOR;
return "final Object streamResult = new " + resultType.getVariableTypeName() + "[] { " + chain.getText() + " };" + LINE_SEPARATOR;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TraceResultInterpreterImpl implements TraceResultInterpreter {
@Override
public TracingResult interpret(@NotNull StreamChain chain, @NotNull ArrayReference resultArray) {
final ArrayReference info = (ArrayReference)resultArray.getValue(0);
final Value streamResult = resultArray.getValue(1);
final Value streamResult = ((ArrayReference)resultArray.getValue(1)).getValue(0);
final Value time = resultArray.getValue(2);
logTime(time);
final List<TraceInfo> trace = getTrace(chain, info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public interface GenericType {
@NotNull
String getGenericTypeName();

GenericType BOOLEAN = new GenericTypeImpl("boolean", "java.lang.Boolean");
GenericType INT = new GenericTypeImpl("int", "java.lang.Integer");
GenericType DOUBLE = new GenericTypeImpl("double", "java.lang.Double");
GenericType LONG = new GenericTypeImpl("long", "java.lang.Long");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.streams.trace.impl.handler.type;

import com.intellij.psi.CommonClassNames;
import com.intellij.psi.PsiType;
import com.intellij.psi.util.InheritanceUtil;
import org.jetbrains.annotations.NotNull;

/**
* @author Vitaliy.Bibaev
*/
public class GenericTypeUtil {

public static GenericType fromStreamPsiType(@NotNull PsiType streamPsiType) {
if (InheritanceUtil.isInheritor(streamPsiType, CommonClassNames.JAVA_UTIL_STREAM_INT_STREAM)) return GenericType.INT;
if (InheritanceUtil.isInheritor(streamPsiType, CommonClassNames.JAVA_UTIL_STREAM_LONG_STREAM)) return GenericType.LONG;
if (InheritanceUtil.isInheritor(streamPsiType, CommonClassNames.JAVA_UTIL_STREAM_DOUBLE_STREAM)) return GenericType.DOUBLE;
if (PsiType.VOID.equals(streamPsiType)) return GenericType.VOID;

return GenericType.OBJECT;
}

public static GenericType fromPsiType(@NotNull PsiType type) {
if (PsiType.VOID.equals(type)) return GenericType.VOID;
if (PsiType.INT.equals(type)) return GenericType.INT;
if (PsiType.DOUBLE.equals(type)) return GenericType.DOUBLE;
if (PsiType.LONG.equals(type)) return GenericType.LONG;
if (PsiType.BOOLEAN.equals(type)) return GenericType.BOOLEAN;
return GenericType.OBJECT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.intellij.ui.JBCardLayout;
import com.intellij.ui.JBTabsPaneImpl;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.JBDimension;
import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.XDebugSessionListener;
import com.sun.jdi.Value;
Expand All @@ -47,6 +48,8 @@
* @author Vitaliy.Bibaev
*/
public class EvaluationAwareTraceWindow extends DialogWrapper {
private static final int DEFAULT_WIDTH = 870;
private static final int DEFAULT_HEIGHT = 400;
private static final String FLAT_MODE_NAME = "Flat Mode";
private static final String TABBED_MODE_NAME = "Split Mode";
private final JPanel myCenterPane;
Expand Down Expand Up @@ -81,6 +84,7 @@ public void sessionStopped() {

myFlatContent = new MyPlaceholder();
myCenterPane.add(myFlatContent);
myCenterPane.setPreferredSize(new JBDimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));

init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*/
package com.intellij.debugger.streams.wrapper;

import com.intellij.debugger.streams.trace.impl.handler.type.GenericType;
import org.jetbrains.annotations.NotNull;

/**
* @author Vitaliy.Bibaev
*/
public interface TerminatorStreamCall extends StreamCall, TypeBeforeAwareCall {
boolean isVoid();
@NotNull
GenericType getResultType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.intellij.debugger.streams.wrapper.impl;

import com.intellij.debugger.streams.trace.impl.handler.type.GenericType;
import com.intellij.debugger.streams.trace.impl.handler.type.GenericTypeUtil;
import com.intellij.debugger.streams.wrapper.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Computable;
Expand Down Expand Up @@ -106,8 +107,8 @@ public StreamChain build(@NotNull PsiElement startElement) {
prevCallType = currentType;
}
else if (StreamCallType.TERMINATOR.equals(type)) {
final TerminatorStreamCallImpl terminator =
new TerminatorStreamCallImpl(callName, callArgs, prevCallType, currentType.equals(GenericType.VOID));
final GenericType genericType = resolveTerminationCallType(methodCall);
final TerminatorStreamCallImpl terminator = new TerminatorStreamCallImpl(callName, callArgs, prevCallType, genericType);
return new StreamChainImpl(producer, intermediateStreamCalls, terminator, startElement);
}
else {
Expand All @@ -126,27 +127,20 @@ else if (StreamCallType.TERMINATOR.equals(type)) {
private static GenericType resolveType(@NotNull PsiMethodCallExpression call) {
return ApplicationManager.getApplication().runReadAction((Computable<GenericType>)() -> {
final PsiMethod method = call.resolveMethod();
if (method != null) {
final PsiType returnType = method.getReturnType();
if (returnType != null) {
if (InheritanceUtil.isInheritor(returnType, CommonClassNames.JAVA_UTIL_STREAM_INT_STREAM)) {
return GenericType.INT;
}
if (InheritanceUtil.isInheritor(returnType, CommonClassNames.JAVA_UTIL_STREAM_LONG_STREAM)) {
return GenericType.LONG;
}
if (InheritanceUtil.isInheritor(returnType, CommonClassNames.JAVA_UTIL_STREAM_DOUBLE_STREAM)) {
return GenericType.DOUBLE;
}

if (returnType.equals(PsiType.VOID)) {
return GenericType.VOID;
}
if (method == null) return null;
final PsiType returnType = method.getReturnType();
if (returnType == null) return null;
return GenericTypeUtil.fromStreamPsiType(returnType);
});
}

return GenericType.OBJECT;
}
}
return null;
private static GenericType resolveTerminationCallType(@NotNull PsiMethodCallExpression call) {
return ApplicationManager.getApplication().runReadAction((Computable<GenericType>)() -> {
final PsiMethod method = call.resolveMethod();
if (method == null) return null;
final PsiType returnType = method.getReturnType();
if (returnType == null) return null;
return GenericTypeUtil.fromPsiType(returnType);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
*/
public class TerminatorStreamCallImpl extends StreamCallImpl implements TerminatorStreamCall {
private final GenericType myTypeBefore;
private final boolean myIsVoid;
private final GenericType myReturnType;

TerminatorStreamCallImpl(@NotNull String name, @NotNull String args, @NotNull GenericType typeBefore, boolean isVoid) {
TerminatorStreamCallImpl(@NotNull String name, @NotNull String args, @NotNull GenericType typeBefore, GenericType resultType) {
super(name, args, StreamCallType.TERMINATOR);
myTypeBefore = typeBefore;
myIsVoid = isVoid;
myReturnType = resultType;
}

@NotNull
Expand All @@ -39,8 +39,9 @@ public GenericType getTypeBefore() {
return myTypeBefore;
}

@NotNull
@Override
public boolean isVoid() {
return myIsVoid;
public GenericType getResultType() {
return myReturnType;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>org.jetbrains.debugger.streams</id>
<name>Java Streams Debugger</name>
<version>0.0.8</version>
<version>0.0.9</version>
<vendor url="https://www.jetbrains.com">JetBrains</vendor>

<description><![CDATA[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ void doTest() throws Exception {
checkResultChain(chain);
}



@NotNull
protected abstract String getDirectoryName();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.streams.chain.positive;

import com.intellij.debugger.streams.trace.impl.handler.type.GenericType;
import com.intellij.debugger.streams.wrapper.StreamChain;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;

/**
* @author Vitaliy.Bibaev
*/
public class TerminationCallTypeTest extends StreamChainBuilderPositiveTestBase {
public void testVoidType() throws Exception {
doTest(GenericType.VOID);
}

public void testBooleanType() throws Exception {
doTest(GenericType.BOOLEAN);
}

public void testIntType() throws Exception {
doTest(GenericType.INT);
}

public void testDoubleType() throws Exception {
doTest(GenericType.DOUBLE);
}

public void testLongType() throws Exception {
doTest(GenericType.LONG);
}

public void testReferenceType() throws Exception {
doTest(GenericType.OBJECT);
}

@NotNull
@Override
protected String getDirectoryName() {
return "terminationType";
}

protected void doTest(@NotNull GenericType returnType) throws Exception {
final PsiElement elementAtCaret = configureAndGetElementAtCaret();
assertNotNull(elementAtCaret);
final StreamChain chain = getChainBuilder().build(elementAtCaret);
assertNotNull(chain);
assertEquals(returnType, chain.getTerminationCall().getResultType());
}

@Override
protected void checkResultChain(StreamChain chain) {
}
}
Loading

0 comments on commit e406444

Please sign in to comment.