mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tuple and map types improved.
Used VolatileNotNullLazyValue instead of AtomicNotNullLazyValue to avoid deadlock Got rid of GrTupleTypeWithLazyValue. All the functionality is moved to GrTupleType
This commit is contained in:
+7
-12
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl;
|
||||
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -26,15 +24,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class GrTupleTypeImpl extends GrTupleType {
|
||||
public class GrImmediateTupleType extends GrTupleType {
|
||||
private final PsiType[] myComponentTypes;
|
||||
|
||||
public GrTupleTypeImpl(PsiType[] componentTypes, JavaPsiFacade facade, GlobalSearchScope scope) {
|
||||
this(componentTypes, facade, scope, LanguageLevel.JDK_1_5);
|
||||
}
|
||||
|
||||
public GrTupleTypeImpl(PsiType[] componentTypes, JavaPsiFacade facade, GlobalSearchScope scope, LanguageLevel languageLevel) {
|
||||
super(scope, facade, languageLevel);
|
||||
public GrImmediateTupleType(@NotNull PsiType[] componentTypes, @NotNull JavaPsiFacade facade, @NotNull GlobalSearchScope scope) {
|
||||
super(scope, facade);
|
||||
myComponentTypes = componentTypes;
|
||||
}
|
||||
|
||||
@@ -46,12 +40,13 @@ public class GrTupleTypeImpl extends GrTupleType {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClassType setLanguageLevel(@NotNull final LanguageLevel languageLevel) {
|
||||
return new GrTupleTypeImpl(myComponentTypes, myFacade, myScope, languageLevel);
|
||||
@Override
|
||||
protected PsiType[] inferComponents() {
|
||||
return myComponentTypes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiType[] getComponentTypes() {
|
||||
return myComponentTypes;
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl;
|
||||
|
||||
import com.intellij.openapi.util.AtomicNotNullLazyValue;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.VolatileNotNullLazyValue;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
@@ -41,7 +41,7 @@ import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.
|
||||
public abstract class GrMapType extends GrLiteralClassType {
|
||||
private final String myJavaClassName;
|
||||
|
||||
private final AtomicNotNullLazyValue<PsiType[]> myParameters = new AtomicNotNullLazyValue<PsiType[]>() {
|
||||
private final VolatileNotNullLazyValue<PsiType[]> myParameters = new VolatileNotNullLazyValue<PsiType[]>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiType[] compute() {
|
||||
|
||||
+3
-3
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl;
|
||||
|
||||
import com.intellij.openapi.util.AtomicNotNullLazyValue;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.VolatileNotNullLazyValue;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -43,7 +43,7 @@ public class GrMapTypeFromNamedArgs extends GrMapType {
|
||||
private final Map<String, GrExpression> myStringEntries;
|
||||
private final List<Pair<GrExpression, GrExpression>> myOtherEntries;
|
||||
|
||||
private final AtomicNotNullLazyValue<List<Pair<PsiType, PsiType>>> myTypesOfOtherEntries = new AtomicNotNullLazyValue<List<Pair<PsiType, PsiType>>>() {
|
||||
private final VolatileNotNullLazyValue<List<Pair<PsiType, PsiType>>> myTypesOfOtherEntries = new VolatileNotNullLazyValue<List<Pair<PsiType, PsiType>>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<Pair<PsiType, PsiType>> compute() {
|
||||
@@ -56,7 +56,7 @@ public class GrMapTypeFromNamedArgs extends GrMapType {
|
||||
}
|
||||
};
|
||||
|
||||
private final AtomicNotNullLazyValue<Map<String, PsiType>> myTypesOfStringEntries = new AtomicNotNullLazyValue<Map<String, PsiType>>() {
|
||||
private final VolatileNotNullLazyValue<Map<String, PsiType>> myTypesOfStringEntries = new VolatileNotNullLazyValue<Map<String,PsiType>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, PsiType> compute() {
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl;
|
||||
|
||||
import com.intellij.openapi.util.AtomicNotNullLazyValue;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.VolatileNotNullLazyValue;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -31,7 +32,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUt
|
||||
* @author ven
|
||||
*/
|
||||
public abstract class GrTupleType extends GrLiteralClassType {
|
||||
private final AtomicNotNullLazyValue<PsiType[]> myParameters = new AtomicNotNullLazyValue<PsiType[]>() {
|
||||
private final VolatileNotNullLazyValue<PsiType[]> myParameters = new VolatileNotNullLazyValue<PsiType[]>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiType[] compute() {
|
||||
@@ -43,6 +44,14 @@ public abstract class GrTupleType extends GrLiteralClassType {
|
||||
}
|
||||
};
|
||||
|
||||
private final VolatileNotNullLazyValue<PsiType[]> myComponents = new VolatileNotNullLazyValue<PsiType[]>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiType[] compute() {
|
||||
return inferComponents();
|
||||
}
|
||||
};
|
||||
|
||||
public GrTupleType(@NotNull GlobalSearchScope scope, @NotNull JavaPsiFacade facade) {
|
||||
this(scope, facade, LanguageLevel.JDK_1_5);
|
||||
}
|
||||
@@ -122,5 +131,17 @@ public abstract class GrTupleType extends GrLiteralClassType {
|
||||
return super.isAssignableFrom(type);
|
||||
}
|
||||
|
||||
public abstract PsiType[] getComponentTypes();
|
||||
@NotNull
|
||||
public PsiType[] getComponentTypes() {
|
||||
return myComponents.getValue();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract PsiType[] inferComponents();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClassType setLanguageLevel(@NotNull LanguageLevel languageLevel) {
|
||||
return new GrImmediateTupleType(getComponentTypes(), myFacade, getResolveScope());
|
||||
}
|
||||
}
|
||||
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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.plugins.groovy.lang.psi.impl;
|
||||
|
||||
import com.intellij.openapi.util.AtomicNotNullLazyValue;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Created by Max Medvedev on 06/04/14
|
||||
*/
|
||||
public abstract class GrTupleTypeWithLazyComponents extends GrTupleType {
|
||||
private final AtomicNotNullLazyValue<PsiType[]> myComponents = new AtomicNotNullLazyValue<PsiType[]>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiType[] compute() {
|
||||
return inferComponents();
|
||||
}
|
||||
};
|
||||
|
||||
protected abstract PsiType[] inferComponents();
|
||||
|
||||
public GrTupleTypeWithLazyComponents(@NotNull GlobalSearchScope scope, @NotNull JavaPsiFacade facade) {
|
||||
super(scope, facade);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType[] getComponentTypes() {
|
||||
return myComponents.getValue();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClassType setLanguageLevel(@NotNull LanguageLevel languageLevel) {
|
||||
return new GrTupleTypeImpl(getComponentTypes(), myFacade, getResolveScope(), languageLevel);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-2
@@ -37,7 +37,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleTypeWithLazyComponents;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
|
||||
@@ -211,7 +211,8 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
}
|
||||
}
|
||||
|
||||
return new GrTupleTypeWithLazyComponents(scope, facade) {
|
||||
return new GrTupleType(scope, facade) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiType[] inferComponents() {
|
||||
return ContainerUtil.map(initializers, new Function<GrExpression, PsiType>() {
|
||||
|
||||
+3
-2
@@ -519,7 +519,7 @@ public class TypesUtil {
|
||||
components3[i] = getLeastUpperBound(c1, c2, manager);
|
||||
}
|
||||
}
|
||||
return new GrTupleTypeImpl(components3, JavaPsiFacade.getInstance(manager.getProject()), tuple1.getScope().intersectWith(tuple2.getResolveScope()));
|
||||
return new GrImmediateTupleType(components3, JavaPsiFacade.getInstance(manager.getProject()), tuple1.getScope().intersectWith(tuple2.getResolveScope()));
|
||||
}
|
||||
else if (checkEmptyListAndList(type1, type2)) {
|
||||
return genNewListBy(type2, manager);
|
||||
@@ -841,7 +841,8 @@ public class TypesUtil {
|
||||
}
|
||||
|
||||
public static PsiType getTupleByAnnotationArrayInitializer(final GrAnnotationArrayInitializer value) {
|
||||
return new GrTupleTypeWithLazyComponents(value.getResolveScope(), JavaPsiFacade.getInstance(value.getProject())) {
|
||||
return new GrTupleType(value.getResolveScope(), JavaPsiFacade.getInstance(value.getProject())) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiType[] inferComponents() {
|
||||
final GrAnnotationMemberValue[] initializers = value.getInitializers();
|
||||
|
||||
+2
-2
@@ -37,8 +37,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrRefere
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrImmediateTupleType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleTypeImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
@@ -218,7 +218,7 @@ public class GrIndexPropertyImpl extends GrExpressionImpl implements GrIndexProp
|
||||
}
|
||||
|
||||
if (candidates.length != 1) {
|
||||
final GrTupleType tupleType = new GrTupleTypeImpl(argTypes, JavaPsiFacade.getInstance(getProject()), resolveScope);
|
||||
final GrTupleType tupleType = new GrImmediateTupleType(argTypes, JavaPsiFacade.getInstance(getProject()), resolveScope);
|
||||
final GroovyResolveResult[] tupleCandidates = ResolveUtil.getMethodCandidates(thisType, name, invoked, tupleType);
|
||||
if (incompleteCode) {
|
||||
candidates = ArrayUtil.mergeArrays(candidates, tupleCandidates, new ArrayFactory<GroovyResolveResult>() {
|
||||
|
||||
Reference in New Issue
Block a user