Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
vorlovjb committed Mar 3, 2014
2 parents 7683348 + 25d38b4 commit e700d39
Show file tree
Hide file tree
Showing 43 changed files with 409 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public abstract class DebuggerEditorImpl extends CompletionEditor{
private final JLabel myChooseFactory = new JLabel();
private WeakReference<ListPopup> myPopup;

private boolean myExplicitlyChosen = false;

private final PsiTreeChangeListener myPsiListener = new PsiTreeChangeAdapter() {
public void childRemoved(@NotNull PsiTreeChangeEvent event) {
checkContext();
Expand Down Expand Up @@ -142,7 +140,6 @@ private ListPopup createLanguagePopup() {
@Override
public void actionPerformed(AnActionEvent e) {
setFactory(fragmentFactory);
myExplicitlyChosen = true;
setText(getText());
IdeFocusManager.getInstance(getProject()).requestFocus(DebuggerEditorImpl.this, true);
}
Expand Down Expand Up @@ -300,33 +297,12 @@ public static CodeFragmentFactory findAppropriateFactory(@NotNull TextWithImport
return DefaultCodeFragmentFactory.getInstance();
}

@NotNull
private CodeFragmentFactory findFactoryForRestore(@NotNull TextWithImports text, @NotNull PsiElement context) {
List<CodeFragmentFactory> factories = DebuggerUtilsEx.getCodeFragmentFactories(context);

if (myExplicitlyChosen && factories.contains(myFactory)) return myFactory;

DefaultCodeFragmentFactory defaultFactory = DefaultCodeFragmentFactory.getInstance();
factories.remove(defaultFactory);
for (CodeFragmentFactory factory : factories) {
if (factory.getFileType().equals(text.getFileType())) {
return factory;
}
}
if (!factories.isEmpty()) return factories.get(0);
else return defaultFactory;
}

protected void restoreFactory(TextWithImports text) {
FileType fileType = text.getFileType();
if (fileType == null) return;
if (myContext == null) return;

CodeFragmentFactory newFactory = findFactoryForRestore(text, myContext);
if (!newFactory.equals(myFactory)) {
myExplicitlyChosen = false;
setFactory(newFactory);
}
setFactory(findAppropriateFactory(text, myContext));
}

private void setFactory(@NotNull final CodeFragmentFactory factory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import com.intellij.openapi.editor.markup.MarkupEditorFilterFactory;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
Expand Down Expand Up @@ -424,11 +426,10 @@ public void run() {
}

public boolean isAt(@NotNull Document document, int offset) {
RangeHighlighter highlighter = getHighlighter();
return highlighter != null &&
highlighter.isValid() &&
document.equals(highlighter.getDocument()) &&
getSourcePosition().getLine() == document.getLineNumber(offset);
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
int line = document.getLineNumber(offset);
XSourcePosition position = myXBreakpoint.getSourcePosition();
return position != null && position.getLine() == line && position.getFile().equals(file);
}

protected void reload(PsiFile psiFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.controlFlow.*;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
Expand Down Expand Up @@ -150,6 +151,10 @@ private static boolean isCollectCall(PsiStatement body) {
((PsiMethod)resolve).getParameterList().getParametersCount() == 1) {
final PsiExpression[] args = methodCallExpression.getArgumentList().getExpressions();
if (args.length == 1) {
if (args[0] instanceof PsiCallExpression) {
final PsiMethod method = ((PsiCallExpression)args[0]).resolveMethod();
return method != null && !method.hasTypeParameters();
}
return true;
}
}
Expand Down Expand Up @@ -260,7 +265,17 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri
iteration += ".filter(" + parameter.getName() + " -> " + condition.getText() +")";
}
}
iteration +=".map(" + parameter.getName() + " -> " + methodCallExpression.getArgumentList().getExpressions()[0].getText() + ").collect(java.util.stream.Collectors.";
iteration +=".map(";

final PsiExpression mapperCall = methodCallExpression.getArgumentList().getExpressions()[0];

final String methodReferenceText = LambdaCanBeMethodReferenceInspection.createMethodReferenceText(mapperCall, null, new PsiParameter[]{parameter});
if (methodReferenceText != null) {
iteration += methodReferenceText;
} else {
iteration += parameter.getName() + " -> " + mapperCall.getText();
}
iteration += ").collect(java.util.stream.Collectors.";

String variableName = null;
PsiExpression initializer = null;
Expand All @@ -276,7 +291,8 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri
} else if (qualifierExpression == null) {
variableName = "";
}


PsiElement result = null;
if (initializer != null) {
final PsiType initializerType = initializer.getType();
final PsiClassType rawType = initializerType instanceof PsiClassType ? ((PsiClassType)initializerType).rawType() : null;
Expand All @@ -288,11 +304,15 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri
iteration += "toCollection(() -> " + initializer.getText() +")";
}
iteration += ")";
initializer.replace(JavaPsiFacade.getElementFactory(project).createExpressionFromText(iteration, foreachStatement));
result = initializer.replace(JavaPsiFacade.getElementFactory(project).createExpressionFromText(iteration, foreachStatement));
foreachStatement.delete();
} else if (variableName != null){
iteration += "toList())";
foreachStatement.replace(JavaPsiFacade.getElementFactory(project).createStatementFromText(variableName + "addAll(" + iteration +");", foreachStatement));
result = foreachStatement.replace(JavaPsiFacade.getElementFactory(project).createStatementFromText(variableName + "addAll(" + iteration +");", foreachStatement));
}

if (result != null) {
result = JavaCodeStyleManager.getInstance(project).shortenClassReferences(result);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static PsiType getFunctionalTypeExplicit(PsiType psiClassType, PsiLambda
return null;
}

final PsiSubstitutor substitutor = session.resolveDependencies(session.getInferenceVariables());
final PsiSubstitutor substitutor = session.retrieveNonPrimitiveEqualsBounds(session.getInferenceVariables());
final PsiType[] newTypeParameters = new PsiType[parameters.length];
for (int i = 0; i < typeParameters.length; i++) {
PsiTypeParameter typeParameter = typeParameters[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ public PsiSubstitutor infer(PsiParameter[] parameters, PsiExpression[] args, Psi
return prepareSubstitution();
}

public PsiSubstitutor resolveDependencies(Collection<InferenceVariable> variables) {
public PsiSubstitutor retrieveNonPrimitiveEqualsBounds(Collection<InferenceVariable> variables) {
PsiSubstitutor substitutor = mySiteSubstitutor;
for (InferenceVariable variable : variables) {
final PsiType equalsBound = getEqualsBound(variable, substitutor);
if (equalsBound != PsiType.NULL) {
if (!(equalsBound instanceof PsiPrimitiveType)) {
substitutor = substitutor.put(variable.getParameter(), equalsBound);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public boolean reduce(InferenceSession session, List<ConstraintFormula> constrai
params[i] = typeParams[i];
}
}
final PsiSubstitutor siteSubstitutor = resolveResult instanceof MethodCandidateInfo ? ((MethodCandidateInfo)resolveResult).getSiteSubstitutor() : PsiSubstitutor.EMPTY;
final PsiSubstitutor siteSubstitutor = resolveResult instanceof MethodCandidateInfo && method != null && !method.isConstructor()
? ((MethodCandidateInfo)resolveResult).getSiteSubstitutor() : PsiSubstitutor.EMPTY;
for (PsiTypeParameter typeParameter : siteSubstitutor.getSubstitutionMap().keySet()) {
substitutor = substitutor.put(typeParameter, substitutor.substitute(siteSubstitutor.substitute(typeParameter)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class Test {
Set<String> collect(Stream<String> map){
return map.collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class IDEA100385 {
void foo(N<Double> n){
n.forEach((<error descr="Incompatible parameter types in lambda expression">double e</error>) -> { });
}
static interface N<E> {
void forEach(Consumer<? extends E> consumer);
}

interface Consumer<T> {
public void accept(T t);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ String getName() {
}

void collectNames(List<Person> persons){
List<String> names = persons.stream().map(person -> person.getName()).collect(Collectors.toList());
List<String> names = persons.stream().map(person::getName).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ String getName() {
}

void collectNames(List<Person> persons){
List<String> names = persons.stream().filter(person -> person != null).map(person -> person.getName()).collect(Collectors.toList());
List<String> names = persons.stream().filter(person -> person != null).map(person::getName).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;

public class Collect {
class Person {
String getName() {
return "";
}
}

void collectNames(List<Person> persons){
List<String> names = persons.stream().map(person -> "name: " + person.getName()).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ String getName() {
}

void collectNames(List<Person> persons){
Set<String> names = persons.stream().map(person -> person.getName()).collect(Collectors.toSet());
Set<String> names = persons.stream().map(person::getName).collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ String getName() {

Set<String> names = new HashSet<>();
void collectNames(List<Person> persons){
names.addAll(persons.stream().map(person -> person.getName()).collect(Collectors.toList()));
names.addAll(persons.stream().map(person::getName).collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ String getName() {
}

void collectNames(List<Person> persons){
Set<String> names = persons.stream().map(person -> person.getName()).collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
Set<String> names = persons.stream().map(person::getName).collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ String getName() {
}

void collectNames(List<Person> persons){
addAll(persons.stream().map(person -> person.getName()).collect(Collectors.toList()));
addAll(persons.stream().map(person::getName).collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ String getName() {
}

void collectNames(List<Person> persons, Set<String> names){
names.addAll(persons.stream().map(person -> person.getName()).collect(Collectors.toList()));
names.addAll(persons.stream().map(person::getName).collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;

public class Collect {
class Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;

public class Collect {
class Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// "Replace with collect" "true"
import java.util.*;

public class Collect {
class Person {
String getName() {
return "";
}
}

void collectNames(List<Person> persons){
List<String> names = new ArrayList<>();
for (Person person : pers<caret>ons) {
names.add("name: " + person.getName());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;

public class Collect {
class Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;

public class Collect {
class Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;

public class Collect {
class Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;

public abstract class Collect implements Collection<String>{
class Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;

public class Collect {
class Person {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public void testLambdaFormalParamTypesParametrization() throws Exception {
doTest();
}

public void testPrimitiveParameterTypes() throws Exception {
doTest();
}

private void doTest() {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
doTestNewInference(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public void testWildcardParameterization() throws Exception {
doTest();
}

public void testDiamondInLambdaReturn() throws Exception {
doTest();
}

private void doTest() {
doTest(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ public void setPrompt(@Nullable String prompt) {
}

private void setPromptInner(@Nullable final String prompt) {
myUpdateQueue.checkDisposed();

UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
Expand Down
6 changes: 5 additions & 1 deletion platform/platform-api/src/com/intellij/util/Alarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ else if (myThreadToUse == ThreadToUse.OWN_THREAD) {
}
}

public void checkDisposed() {
LOG.assertTrue(!myDisposed, "Already disposed");
}

public enum ThreadToUse {
SWING_THREAD,
SHARED_THREAD,
Expand Down Expand Up @@ -158,7 +162,7 @@ public void addRequest(@NotNull Runnable request, long delayMillis, @Nullable fi

protected void _addRequest(@NotNull Runnable request, long delayMillis, ModalityState modalityState) {
synchronized (LOCK) {
LOG.assertTrue(!myDisposed, "Already disposed");
checkDisposed();
final Request requestToSchedule = new Request(request, modalityState, delayMillis);

if (myActivationComponent == null || myActivationComponent.isShowing()) {
Expand Down
Loading

0 comments on commit e700d39

Please sign in to comment.