mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
less garbage
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -64,7 +64,7 @@ public class AddTypeArgumentsFix extends MethodArgumentFix {
|
||||
|
||||
final PsiTypeParameter[] typeParameters = method.getTypeParameters();
|
||||
if (typeParameters.length > 0) {
|
||||
PsiType[] mappings = new PsiType[typeParameters.length];
|
||||
PsiType[] mappings = PsiType.createArray(typeParameters.length);
|
||||
PsiResolveHelper helper = JavaPsiFacade.getInstance(expression.getProject()).getResolveHelper();
|
||||
LanguageLevel level = PsiUtil.getLanguageLevel(expression);
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
|
||||
+2
-3
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
@@ -102,7 +101,7 @@ public class GuessManagerImpl extends GuessManager {
|
||||
}
|
||||
}
|
||||
|
||||
return typesSet.toArray(new PsiType[typesSet.size()]);
|
||||
return typesSet.toArray(PsiType.createArray(typesSet.size()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -125,7 +124,7 @@ public class GuessManagerImpl extends GuessManager {
|
||||
addExprTypesWhenContainerElement(types, expr);
|
||||
addExprTypesByDerivedClasses(types, expr);
|
||||
|
||||
return types.toArray(new PsiType[types.size()]);
|
||||
return types.toArray(PsiType.createArray(types.size()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -163,7 +163,7 @@ public class ExpectedTypesProvider {
|
||||
}
|
||||
}
|
||||
|
||||
return set.toArray(new PsiType[set.size()]);
|
||||
return set.toArray(PsiType.createArray(set.size()));
|
||||
}
|
||||
|
||||
private static void processType(@NotNull PsiType type, @NotNull PsiTypeVisitor<PsiType> visitor, @NotNull Set<PsiType> typeSet) {
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -81,13 +81,13 @@ public class GuessTypeParameters {
|
||||
if (infos.length == 1 && substitutor != null && substitutor != PsiSubstitutor.EMPTY) {
|
||||
ExpectedTypeInfo info = infos[0];
|
||||
Map<PsiTypeParameter, PsiType> map = substitutor.getSubstitutionMap();
|
||||
PsiType[] vals = map.values().toArray(new PsiType[map.size()]);
|
||||
PsiType[] vals = map.values().toArray(PsiType.createArray(map.size()));
|
||||
PsiTypeParameter[] params = map.keySet().toArray(new PsiTypeParameter[map.size()]);
|
||||
|
||||
List<PsiType> types = matchingTypeParameters(vals, params, info);
|
||||
if (!types.isEmpty()) {
|
||||
ContainerUtil.addAll(types, ExpectedTypesProvider.processExpectedTypes(infos, new MyTypeVisitor(manager, scope), project));
|
||||
builder.replaceElement(typeElement, new TypeExpression(project, types.toArray(new PsiType[types.size()])));
|
||||
builder.replaceElement(typeElement, new TypeExpression(project, types.toArray(PsiType.createArray(types.size()))));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
@@ -180,8 +180,8 @@ public class GuessTypeParameters {
|
||||
if (!CommonClassNames.JAVA_LANG_OBJECT.equals(substituted.getCanonicalText()) && (toplevel || substituted.equals(type))) {
|
||||
types.add(substituted);
|
||||
}
|
||||
|
||||
builder.replaceElement(typeElement, new TypeExpression(project, types.toArray(new PsiType[types.size()])));
|
||||
|
||||
builder.replaceElement(typeElement, new TypeExpression(project, types.toArray(PsiType.createArray(types.size()))));
|
||||
return toplevel ? SUBSTITUTED_IN_REF : SUBSTITUTED_IN_PARAMETERS;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -60,6 +60,6 @@ public class ExpectedTypesGetter implements ContextGetter{
|
||||
}
|
||||
result.add(defaultType);
|
||||
}
|
||||
return result.toArray(new PsiType[result.size()]);
|
||||
return result.toArray(PsiType.createArray(result.size()));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -87,7 +87,7 @@ class InlineToAnonymousConstructorProcessor {
|
||||
PsiType substType = classResolveSubstitutor.substitute(mySuperType);
|
||||
|
||||
PsiTypeParameter[] typeParams = myClass.getTypeParameters();
|
||||
PsiType[] substitutedParameters = new PsiType[typeParams.length];
|
||||
PsiType[] substitutedParameters = PsiType.createArray(typeParams.length);
|
||||
for(int i=0; i< typeParams.length; i++) {
|
||||
substitutedParameters [i] = classResolveSubstitutor.substitute(typeParams [i]);
|
||||
}
|
||||
|
||||
+19
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -62,6 +62,7 @@ public class PsiTypeVariableFactory {
|
||||
private final int myIndex = myCurrent++;
|
||||
private final PsiElement myContext = context;
|
||||
|
||||
@Override
|
||||
public boolean isValidInContext(final PsiType type) {
|
||||
if (myContext == null) {
|
||||
return true;
|
||||
@@ -72,14 +73,17 @@ public class PsiTypeVariableFactory {
|
||||
}
|
||||
|
||||
return type.accept(new PsiTypeVisitor<Boolean>() {
|
||||
@Override
|
||||
public Boolean visitType(final PsiType type) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitArrayType(final PsiArrayType arrayType) {
|
||||
return arrayType.getDeepComponentType().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitWildcardType(final PsiWildcardType wildcardType) {
|
||||
final PsiType bound = wildcardType.getBound();
|
||||
|
||||
@@ -90,6 +94,7 @@ public class PsiTypeVariableFactory {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitClassType(final PsiClassType classType) {
|
||||
final PsiClassType.ClassResolveResult result = classType.resolveGenerics();
|
||||
final PsiClass aClass = result.getElement();
|
||||
@@ -143,33 +148,43 @@ public class PsiTypeVariableFactory {
|
||||
}).booleanValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getPresentableText() {
|
||||
return "$" + myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getCanonicalText() {
|
||||
return getPresentableText();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getInternalCanonicalText() {
|
||||
return getCanonicalText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean equalsToText(String text) {
|
||||
@Override
|
||||
public boolean equalsToText(@NotNull String text) {
|
||||
return text.equals(getPresentableText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalSearchScope getResolveScope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiType[] getSuperTypes() {
|
||||
return new PsiType[0];
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
@@ -187,6 +202,7 @@ public class PsiTypeVariableFactory {
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
+18
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -78,6 +78,7 @@ public class ResolverTree {
|
||||
private static class PsiTypeVarCollector extends PsiExtendedTypeVisitor {
|
||||
final HashSet<PsiTypeVariable> mySet = new HashSet<PsiTypeVariable>();
|
||||
|
||||
@Override
|
||||
public Object visitTypeVariable(final PsiTypeVariable var) {
|
||||
mySet.add(var);
|
||||
|
||||
@@ -209,10 +210,12 @@ public class ResolverTree {
|
||||
}
|
||||
|
||||
final DFSTBuilder<PsiTypeVariable> dfstBuilder = new DFSTBuilder<PsiTypeVariable>(new Graph<PsiTypeVariable>() {
|
||||
@Override
|
||||
public Collection<PsiTypeVariable> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<PsiTypeVariable> getIn(final PsiTypeVariable n) {
|
||||
final HashSet<PsiTypeVariable> in = ins.get(n);
|
||||
|
||||
@@ -223,6 +226,7 @@ public class ResolverTree {
|
||||
return in.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<PsiTypeVariable> getOut(final PsiTypeVariable n) {
|
||||
final HashSet<PsiTypeVariable> out = outs.get(n);
|
||||
|
||||
@@ -241,6 +245,7 @@ public class ResolverTree {
|
||||
sccs.forEach(new TIntProcedure() {
|
||||
int myTNumber = 0;
|
||||
|
||||
@Override
|
||||
public boolean execute(int size) {
|
||||
for (int j = 0; j < size; j++) {
|
||||
index.put(dfstBuilder.getNodeByTNumber(myTNumber + j), myTNumber);
|
||||
@@ -387,7 +392,7 @@ public class ResolverTree {
|
||||
|
||||
fillTypeRange(lowerBound, upperBound, range);
|
||||
|
||||
return range.toArray(new PsiType[]{});
|
||||
return range.toArray(PsiType.createArray(range.size()));
|
||||
}
|
||||
|
||||
private void reduceInterval(final Constraint left, final Constraint right) {
|
||||
@@ -451,7 +456,7 @@ public class ResolverTree {
|
||||
}
|
||||
|
||||
private void reduce() {
|
||||
if (myConstraints.size() == 0) {
|
||||
if (myConstraints.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -665,18 +670,22 @@ public class ResolverTree {
|
||||
|
||||
private void reduceTypeVar(final Constraint x, final Constraint y) {
|
||||
reduceSideVar(x, y, new Reducer() {
|
||||
@Override
|
||||
public LinkedList<Pair<PsiType, Binding>> unify(final PsiType x, final PsiType y) {
|
||||
return myBindingFactory.intersect(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint create(final PsiTypeVariable var, final PsiType type) {
|
||||
return new Subtype(type, var);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType getType(final Constraint c) {
|
||||
return c.getLeft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiTypeVariable getVar(final Constraint c) {
|
||||
return (PsiTypeVariable)c.getRight();
|
||||
}
|
||||
@@ -685,18 +694,22 @@ public class ResolverTree {
|
||||
|
||||
private void reduceVarType(final Constraint x, final Constraint y) {
|
||||
reduceSideVar(x, y, new Reducer() {
|
||||
@Override
|
||||
public LinkedList<Pair<PsiType, Binding>> unify(final PsiType x, final PsiType y) {
|
||||
return myBindingFactory.union(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint create(final PsiTypeVariable var, final PsiType type) {
|
||||
return new Subtype(var, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType getType(final Constraint c) {
|
||||
return c.getRight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiTypeVariable getVar(final Constraint c) {
|
||||
return (PsiTypeVariable)c.getLeft();
|
||||
}
|
||||
@@ -711,7 +724,7 @@ public class ResolverTree {
|
||||
|
||||
final LinkedList<Pair<PsiType, Binding>> union = reducer.unify(xType, yType);
|
||||
|
||||
if (union.size() == 0) {
|
||||
if (union.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -749,7 +762,7 @@ public class ResolverTree {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (myConstraints.size() == 0) {
|
||||
if (myConstraints.isEmpty()) {
|
||||
logSolution();
|
||||
|
||||
mySolutions.putSolution(myCurrentBinding);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -75,7 +75,7 @@ public class TypeSelector {
|
||||
}
|
||||
|
||||
public PsiType[] getTypes() {
|
||||
final PsiType[] types = new PsiType[myComboBoxModel.mySuggestions.length];
|
||||
final PsiType[] types = PsiType.createArray(myComboBoxModel.mySuggestions.length);
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
types[i] = myComboBoxModel.mySuggestions[i].getType();
|
||||
}
|
||||
@@ -147,11 +147,13 @@ public class TypeSelector {
|
||||
}
|
||||
|
||||
// implements javax.swing.ListModel
|
||||
@Override
|
||||
public int getSize() {
|
||||
return mySuggestions.length;
|
||||
}
|
||||
|
||||
// implements javax.swing.ListModel
|
||||
@Override
|
||||
public Object getElementAt(int index) {
|
||||
return mySuggestions[index];
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
|
||||
});
|
||||
|
||||
ArrayList<PsiType> result = normalizeTypeList(allowedTypes);
|
||||
return result.toArray(new PsiType[result.size()]);
|
||||
return result.toArray(PsiType.createArray(result.size()));
|
||||
}
|
||||
|
||||
private PsiType[] getTypesForAll(final boolean areTypesDirected) {
|
||||
@@ -232,7 +232,7 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
|
||||
if (!areTypesDirected) {
|
||||
Collections.reverse(result);
|
||||
}
|
||||
return result.toArray(new PsiType[result.size()]);
|
||||
return result.toArray(PsiType.createArray(result.size()));
|
||||
}
|
||||
|
||||
protected boolean isUsedAfter() {
|
||||
|
||||
@@ -90,7 +90,7 @@ public class GenericsUtil {
|
||||
for (PsiType type : conjuncts) {
|
||||
newConjuncts.add(getLeastUpperBound(type, type2, compared, manager));
|
||||
}
|
||||
return PsiIntersectionType.createIntersection(newConjuncts.toArray(new PsiType[newConjuncts.size()]));
|
||||
return PsiIntersectionType.createIntersection(newConjuncts.toArray(PsiType.createArray(newConjuncts.size())));
|
||||
}
|
||||
if (type2 instanceof PsiIntersectionType) {
|
||||
return getLeastUpperBound(type2, type1, compared, manager);
|
||||
@@ -454,7 +454,7 @@ public class GenericsUtil {
|
||||
result.add(substitutionMap.get(key));
|
||||
}
|
||||
}
|
||||
return PsiSubstitutor.EMPTY.putAll(psiClass, result.toArray(new PsiType[result.size()]));
|
||||
return PsiSubstitutor.EMPTY.putAll(psiClass, result.toArray(PsiType.createArray(result.size())));
|
||||
}
|
||||
|
||||
public static PsiType eliminateWildcards(PsiType type) {
|
||||
@@ -463,7 +463,7 @@ public class GenericsUtil {
|
||||
|
||||
public static PsiType eliminateWildcards(PsiType type, final boolean eliminateInTypeArguments) {
|
||||
if (eliminateInTypeArguments && type instanceof PsiClassType) {
|
||||
PsiClassType classType = ((PsiClassType)type);
|
||||
PsiClassType classType = (PsiClassType)type;
|
||||
JavaResolveResult resolveResult = classType.resolveGenerics();
|
||||
PsiClass aClass = (PsiClass)resolveResult.getElement();
|
||||
if (aClass != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -34,7 +34,7 @@ public abstract class HierarchicalMethodSignature extends MethodSignatureBackedB
|
||||
|
||||
private static PsiType[] getParameterTypes(PsiMethod method) {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
final PsiType[] paramTypes = new PsiType[parameters.length];
|
||||
final PsiType[] paramTypes = PsiType.createArray(parameters.length);
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
paramTypes[i] = parameters[i].getType();
|
||||
}
|
||||
|
||||
@@ -41,19 +41,22 @@ public class PsiArrayType extends PsiType {
|
||||
myComponentType = componentType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return StringUtil.joinOrNull(myComponentType.getPresentableText(), getAnnotationsTextPrefix(false, true, true), "[]");
|
||||
return StringUtil.join(myComponentType.getPresentableText(), getAnnotationsTextPrefix(false, true, true), "[]");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getCanonicalText() {
|
||||
return StringUtil.joinOrNull(myComponentType.getCanonicalText(), "[]");
|
||||
return StringUtil.join(myComponentType.getCanonicalText(), "[]");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getInternalCanonicalText() {
|
||||
return StringUtil.joinOrNull(myComponentType.getInternalCanonicalText(), getAnnotationsTextPrefix(true, true, true), "[]");
|
||||
return StringUtil.join(myComponentType.getInternalCanonicalText(), getAnnotationsTextPrefix(true, true, true), "[]");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +65,7 @@ public class PsiArrayType extends PsiType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsToText(String text) {
|
||||
public boolean equalsToText(@NotNull String text) {
|
||||
return text.endsWith("[]") && myComponentType.equalsToText(text.substring(0, text.length() - 2));
|
||||
}
|
||||
|
||||
@@ -80,7 +83,7 @@ public class PsiArrayType extends PsiType {
|
||||
@NotNull
|
||||
public PsiType[] getSuperTypes() {
|
||||
final PsiType[] superTypes = myComponentType.getSuperTypes();
|
||||
final PsiType[] result = new PsiType[superTypes.length];
|
||||
final PsiType[] result = createArray(superTypes.length);
|
||||
for (int i = 0; i < superTypes.length; i++) {
|
||||
result[i] = superTypes[i].createArrayType();
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ public abstract class PsiClassType extends PsiType {
|
||||
if (aClass == null) return EMPTY_ARRAY;
|
||||
|
||||
PsiClassType[] superTypes = aClass.getSuperTypes();
|
||||
PsiType[] substitutionResults = new PsiType[superTypes.length];
|
||||
PsiType[] substitutionResults = createArray(superTypes.length);
|
||||
for (int i = 0; i < superTypes.length; i++) {
|
||||
substitutionResults[i] = resolveResult.getSubstitutor().substitute(superTypes[i]);
|
||||
}
|
||||
@@ -248,6 +248,7 @@ public abstract class PsiClassType extends PsiType {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiSubstitutor getSubstitutor() {
|
||||
return PsiSubstitutor.EMPTY;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -91,7 +91,7 @@ public abstract class PsiDiamondType extends PsiType {
|
||||
if (myErrorMessage != null) {
|
||||
return PsiType.EMPTY_ARRAY;
|
||||
}
|
||||
return myInferredTypes.toArray(new PsiType[myInferredTypes.size()]);
|
||||
return myInferredTypes.toArray(createArray(myInferredTypes.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@ public class PsiIntersectionType extends PsiType {
|
||||
|
||||
@NotNull
|
||||
public static PsiType createIntersection(@NotNull List<PsiType> conjuncts) {
|
||||
return createIntersection(conjuncts.toArray(new PsiType[conjuncts.size()]));
|
||||
return createIntersection(conjuncts.toArray(createArray(conjuncts.size())));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -53,7 +53,7 @@ public class PsiIntersectionType extends PsiType {
|
||||
private static PsiType[] flattenAndRemoveDuplicates(PsiType[] conjuncts) {
|
||||
try {
|
||||
Set<PsiType> flattened = flatten(conjuncts, new THashSet<PsiType>());
|
||||
return flattened.toArray(new PsiType[flattened.size()]);
|
||||
return flattened.toArray(createArray(flattened.size()));
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
throw new RuntimeException(Arrays.toString(conjuncts), e);
|
||||
@@ -71,7 +71,7 @@ public class PsiIntersectionType extends PsiType {
|
||||
}
|
||||
}
|
||||
if (types.size() > 1) {
|
||||
PsiType[] array = types.toArray(new PsiType[types.size()]);
|
||||
PsiType[] array = types.toArray(createArray(types.size()));
|
||||
for (Iterator<PsiType> iterator = types.iterator(); iterator.hasNext(); ) {
|
||||
PsiType type = iterator.next();
|
||||
|
||||
@@ -97,6 +97,7 @@ public class PsiIntersectionType extends PsiType {
|
||||
return myConjuncts;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return StringUtil.join(myConjuncts, new Function<PsiType, String>() {
|
||||
@@ -107,11 +108,13 @@ public class PsiIntersectionType extends PsiType {
|
||||
}, " & ");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getCanonicalText() {
|
||||
return myConjuncts[0].getCanonicalText();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getInternalCanonicalText() {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
@@ -131,7 +134,7 @@ public class PsiIntersectionType extends PsiType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsToText(String text) {
|
||||
public boolean equalsToText(@NotNull String text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,16 +51,19 @@ public class PsiPrimitiveType extends PsiType {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return getAnnotationsTextPrefix(false, false, true) + myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getCanonicalText() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getInternalCanonicalText() {
|
||||
return getAnnotationsTextPrefix(true, false, true) + myName;
|
||||
@@ -75,7 +78,7 @@ public class PsiPrimitiveType extends PsiType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsToText(String text) {
|
||||
public boolean equalsToText(@NotNull String text) {
|
||||
return myName.equals(text);
|
||||
}
|
||||
|
||||
@@ -92,7 +95,7 @@ public class PsiPrimitiveType extends PsiType {
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiType[] getSuperTypes() {
|
||||
return new PsiType[0];
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.psi;
|
||||
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ArrayFactory;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -37,6 +38,17 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
public static final PsiPrimitiveType NULL = new PsiPrimitiveType("null", (String)null);
|
||||
|
||||
public static final PsiType[] EMPTY_ARRAY = new PsiType[0];
|
||||
public static final ArrayFactory<PsiType> ARRAY_FACTORY = new ArrayFactory<PsiType>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiType[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new PsiType[count];
|
||||
}
|
||||
};
|
||||
@NotNull
|
||||
public static PsiType[] createArray(int count) {
|
||||
return ARRAY_FACTORY.create(count);
|
||||
}
|
||||
|
||||
private final PsiAnnotation[] myAnnotations;
|
||||
|
||||
@@ -56,7 +68,7 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* Creates array type with this type as a component.
|
||||
*/
|
||||
@NotNull
|
||||
public PsiArrayType createArrayType(PsiAnnotation... annotations) {
|
||||
public PsiArrayType createArrayType(@NotNull PsiAnnotation... annotations) {
|
||||
return new PsiArrayType(this, annotations);
|
||||
}
|
||||
|
||||
@@ -64,18 +76,21 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* @return text of the type that can be presented to a user (non-qualified references, with annotations).
|
||||
*/
|
||||
@NonNls
|
||||
@NotNull
|
||||
public abstract String getPresentableText();
|
||||
|
||||
/**
|
||||
* @return text of the type (fully-qualified references, no annotations).
|
||||
*/
|
||||
@NonNls
|
||||
@NotNull
|
||||
public abstract String getCanonicalText();
|
||||
|
||||
/**
|
||||
* @return text of the type (fully-qualified references, with annotations).
|
||||
*/
|
||||
@NonNls
|
||||
@NotNull
|
||||
public abstract String getInternalCanonicalText();
|
||||
|
||||
/**
|
||||
@@ -106,7 +121,7 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* @param text the text to compare with.
|
||||
* @return true if the string is equivalent to the type, false otherwise
|
||||
*/
|
||||
public abstract boolean equalsToText(@NonNls String text);
|
||||
public abstract boolean equalsToText(@NotNull @NonNls String text);
|
||||
|
||||
/**
|
||||
* Returns the class type for the java.lang.Object class.
|
||||
@@ -128,7 +143,8 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* @param resolveScope the scope in which the class is searched.
|
||||
* @return the class instance.
|
||||
*/
|
||||
public static PsiClassType getJavaLangClass(PsiManager manager, GlobalSearchScope resolveScope) {
|
||||
@NotNull
|
||||
public static PsiClassType getJavaLangClass(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
return factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_CLASS, resolveScope);
|
||||
}
|
||||
@@ -140,7 +156,8 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* @param resolveScope the scope in which the class is searched.
|
||||
* @return the class instance.
|
||||
*/
|
||||
public static PsiClassType getJavaLangThrowable(PsiManager manager, GlobalSearchScope resolveScope) {
|
||||
@NotNull
|
||||
public static PsiClassType getJavaLangThrowable(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
return factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_THROWABLE, resolveScope);
|
||||
}
|
||||
@@ -153,7 +170,7 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* @return the class instance.
|
||||
*/
|
||||
@NotNull
|
||||
public static PsiClassType getJavaLangString(PsiManager manager, GlobalSearchScope resolveScope) {
|
||||
public static PsiClassType getJavaLangString(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
return factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING, resolveScope);
|
||||
}
|
||||
@@ -165,7 +182,8 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* @param resolveScope the scope in which the class is searched.
|
||||
* @return the class instance.
|
||||
*/
|
||||
public static PsiClassType getJavaLangError(PsiManager manager, GlobalSearchScope resolveScope) {
|
||||
@NotNull
|
||||
public static PsiClassType getJavaLangError(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
return factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_ERROR, resolveScope);
|
||||
}
|
||||
@@ -177,7 +195,8 @@ public abstract class PsiType implements PsiAnnotationOwner {
|
||||
* @param resolveScope the scope in which the class is searched.
|
||||
* @return the class instance.
|
||||
*/
|
||||
public static PsiClassType getJavaLangRuntimeException(PsiManager manager, GlobalSearchScope resolveScope) {
|
||||
@NotNull
|
||||
public static PsiClassType getJavaLangRuntimeException(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
return factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION, resolveScope);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -80,7 +80,7 @@ public class MethodSignatureBackedByPsiMethod extends MethodSignatureBase {
|
||||
assert substitutor.isValid();
|
||||
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
PsiType[] parameterTypes = new PsiType[parameters.length];
|
||||
PsiType[] parameterTypes = PsiType.createArray(parameters.length);
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
PsiType type = parameter.getType();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -31,7 +31,7 @@ public abstract class MethodSignatureBase implements MethodSignature {
|
||||
protected MethodSignatureBase(@NotNull PsiSubstitutor substitutor, @NotNull PsiType[] parameterTypes, @NotNull PsiTypeParameter[] typeParameters) {
|
||||
mySubstitutor = substitutor;
|
||||
assert substitutor.isValid();
|
||||
myParameterTypes = parameterTypes.length == 0 ? PsiType.EMPTY_ARRAY : new PsiType[parameterTypes.length];
|
||||
myParameterTypes = PsiType.createArray(parameterTypes.length);
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
PsiType type = parameterTypes[i];
|
||||
if (type != null) {
|
||||
@@ -52,7 +52,7 @@ public abstract class MethodSignatureBase implements MethodSignature {
|
||||
}
|
||||
else {
|
||||
final PsiParameter[] parameters = parameterList.getParameters();
|
||||
myParameterTypes = parameters.length == 0 ? PsiType.EMPTY_ARRAY : new PsiType[parameters.length];
|
||||
myParameterTypes = PsiType.createArray(parameters.length);
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiType type = parameters[i].getType();
|
||||
if (type instanceof PsiEllipsisType) type = ((PsiEllipsisType)type).toArrayType();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -72,7 +72,7 @@ public class MethodSignatureUtil {
|
||||
if (parameterTypes.length == 0) return PsiType.EMPTY_ARRAY;
|
||||
|
||||
PsiSubstitutor substitutor = signature.getSubstitutor();
|
||||
PsiType[] erasedTypes = new PsiType[parameterTypes.length];
|
||||
PsiType[] erasedTypes = PsiType.createArray(parameterTypes.length);
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
erasedTypes[i] = TypeConversionUtil.erasure(substitutor.substitute(parameterTypes[i]), substitutor);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
|
||||
public class JavaDocUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.javadoc.JavaDocUtil");
|
||||
|
||||
private static final @NonNls Pattern ourTypePattern = Pattern.compile("[ ]+[^ ^\\[^\\]]");
|
||||
@NonNls private static final Pattern ourTypePattern = Pattern.compile("[ ]+[^ ^\\[^\\]]");
|
||||
|
||||
private JavaDocUtil() {
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class JavaDocUtil {
|
||||
}
|
||||
else {
|
||||
String classRef = refText.substring(0, poundIndex).trim();
|
||||
if (classRef.length() > 0) {
|
||||
if (!classRef.isEmpty()) {
|
||||
PsiClass aClass = facade.getResolveHelper().resolveReferencedClass(classRef, context);
|
||||
|
||||
if (aClass == null) aClass = facade.findClass(classRef, context.getResolveScope());
|
||||
@@ -127,7 +127,7 @@ public class JavaDocUtil {
|
||||
|
||||
String parmsText = memberRefText.substring(parenthIndex + 1, rparenIndex).trim();
|
||||
StringTokenizer tokenizer = new StringTokenizer(parmsText.replaceAll("[*]", ""), ",");
|
||||
PsiType[] types = new PsiType[tokenizer.countTokens()];
|
||||
PsiType[] types = PsiType.createArray(tokenizer.countTokens());
|
||||
int i = 0;
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory();
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
@@ -290,7 +290,7 @@ public class JavaDocUtil {
|
||||
String classRef = refText.substring(0, poundIndex).trim();
|
||||
String memberText = refText.substring(poundIndex + 1);
|
||||
String memberLabel = getMemberLabelText(project, manager, memberText, context);
|
||||
if (classRef.length() > 0) {
|
||||
if (!classRef.isEmpty()) {
|
||||
PsiElement refClass = findReferenceTarget(manager, classRef, context);
|
||||
if (refClass instanceof PsiClass) {
|
||||
PsiElement scope = context;
|
||||
|
||||
@@ -275,7 +275,7 @@ public class PsiImplUtil {
|
||||
|
||||
@NotNull
|
||||
public static PsiType[] typesByTypeElements(@NotNull PsiTypeElement[] typeElements) {
|
||||
PsiType[] types = new PsiType[typeElements.length];
|
||||
PsiType[] types = PsiType.createArray(typeElements.length);
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
types[i] = typeElements[i].getType();
|
||||
}
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class ClsReferenceParameterListImpl extends ClsElementImpl implements Psi
|
||||
public PsiType[] getTypeArguments() {
|
||||
PsiType[] cachedTypes = myTypeParametersCachedTypes;
|
||||
if (cachedTypes == null) {
|
||||
cachedTypes = myTypeParameters.length == 0 ? PsiType.EMPTY_ARRAY : new PsiType[myTypeParameters.length];
|
||||
cachedTypes = PsiType.createArray(myTypeParameters.length);
|
||||
for (int i = 0; i < cachedTypes.length; i++) {
|
||||
cachedTypes[cachedTypes.length - i - 1] = myTypeParameters[i].getType();
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class PsiImmediateClassType extends PsiClassType {
|
||||
return myClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiSubstitutor getSubstitutor() {
|
||||
return mySubstitutor;
|
||||
@@ -118,7 +119,7 @@ public class PsiImmediateClassType extends PsiClassType {
|
||||
lst.add(substituted);
|
||||
}
|
||||
}
|
||||
return lst.toArray(new PsiType[lst.size()]);
|
||||
return lst.toArray(createArray(lst.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,6 +134,7 @@ public class PsiImmediateClassType extends PsiClassType {
|
||||
return JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory().createType(myClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
if (myPresentableText == null) {
|
||||
@@ -143,6 +145,7 @@ public class PsiImmediateClassType extends PsiClassType {
|
||||
return myPresentableText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getCanonicalText() {
|
||||
if (myCanonicalText == null) {
|
||||
@@ -154,6 +157,7 @@ public class PsiImmediateClassType extends PsiClassType {
|
||||
return myCanonicalText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getInternalCanonicalText() {
|
||||
if (myInternalCanonicalText == null) {
|
||||
@@ -251,7 +255,7 @@ public class PsiImmediateClassType extends PsiClassType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsToText(String text) {
|
||||
public boolean equalsToText(@NotNull String text) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory();
|
||||
final PsiType patternType;
|
||||
try {
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo
|
||||
types.add(PsiType.NULL);
|
||||
}
|
||||
}
|
||||
methodSignature = MethodSignatureUtil.createMethodSignature(name, types.toArray(new PsiType[types.size()]),
|
||||
methodSignature = MethodSignatureUtil.createMethodSignature(name, types.toArray(PsiType.createArray(types.size())),
|
||||
PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY,
|
||||
name.equals(scope.getName()));
|
||||
}
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class GraphInferencePolicy extends ProcessCandidateParameterTypeInference
|
||||
protected PsiType[] getExpressionTypes(PsiExpressionList argumentList) {
|
||||
if (argumentList != null) {
|
||||
final PsiExpression[] expressions = argumentList.getExpressions();
|
||||
final PsiType[] types = new PsiType[expressions.length];
|
||||
final PsiType[] types = PsiType.createArray(expressions.length);
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
if (i != exprIdx) {
|
||||
types[i] = expressions[i].getType();
|
||||
|
||||
+33
-34
@@ -27,7 +27,6 @@ import com.intellij.openapi.util.RecursionGuard;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
@@ -57,36 +56,36 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
@NotNull PsiSubstitutor partialSubstitutor,
|
||||
final PsiElement parent,
|
||||
@NotNull ParameterTypeInferencePolicy policy) {
|
||||
PsiType[] paramTypes = new PsiType[arguments.length];
|
||||
PsiType[] argTypes = new PsiType[arguments.length];
|
||||
if (parameters.length > 0) {
|
||||
for (int j = 0; j < argTypes.length; j++) {
|
||||
final PsiExpression argument = arguments[j];
|
||||
if (argument == null) continue;
|
||||
if (argument instanceof PsiMethodCallExpression && PsiResolveHelper.ourGuard.currentStack().contains(argument)) continue;
|
||||
PsiType[] paramTypes = PsiType.createArray(arguments.length);
|
||||
PsiType[] argTypes = PsiType.createArray(arguments.length);
|
||||
if (parameters.length > 0) {
|
||||
for (int j = 0; j < argTypes.length; j++) {
|
||||
final PsiExpression argument = arguments[j];
|
||||
if (argument == null) continue;
|
||||
if (argument instanceof PsiMethodCallExpression && PsiResolveHelper.ourGuard.currentStack().contains(argument)) continue;
|
||||
|
||||
final RecursionGuard.StackStamp stackStamp = PsiDiamondType.ourDiamondGuard.markStack();
|
||||
argTypes[j] = argument.getType();
|
||||
if (!stackStamp.mayCacheNow()) {
|
||||
argTypes[j] = null;
|
||||
continue;
|
||||
}
|
||||
final RecursionGuard.StackStamp stackStamp = PsiDiamondType.ourDiamondGuard.markStack();
|
||||
argTypes[j] = argument.getType();
|
||||
if (!stackStamp.mayCacheNow()) {
|
||||
argTypes[j] = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
final PsiParameter parameter = parameters[Math.min(j, parameters.length - 1)];
|
||||
if (j >= parameters.length && !parameter.isVarArgs()) break;
|
||||
paramTypes[j] = parameter.getType();
|
||||
if (paramTypes[j] instanceof PsiEllipsisType) {
|
||||
paramTypes[j] = ((PsiEllipsisType)paramTypes[j]).getComponentType();
|
||||
if (arguments.length == parameters.length &&
|
||||
argTypes[j] instanceof PsiArrayType &&
|
||||
!(((PsiArrayType)argTypes[j]).getComponentType() instanceof PsiPrimitiveType)) {
|
||||
argTypes[j] = ((PsiArrayType)argTypes[j]).getComponentType();
|
||||
final PsiParameter parameter = parameters[Math.min(j, parameters.length - 1)];
|
||||
if (j >= parameters.length && !parameter.isVarArgs()) break;
|
||||
paramTypes[j] = parameter.getType();
|
||||
if (paramTypes[j] instanceof PsiEllipsisType) {
|
||||
paramTypes[j] = ((PsiEllipsisType)paramTypes[j]).getComponentType();
|
||||
if (arguments.length == parameters.length &&
|
||||
argTypes[j] instanceof PsiArrayType &&
|
||||
!(((PsiArrayType)argTypes[j]).getComponentType() instanceof PsiPrimitiveType)) {
|
||||
argTypes[j] = ((PsiArrayType)argTypes[j]).getComponentType();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return inferTypeForMethodTypeParameterInner(typeParameter, paramTypes, argTypes, partialSubstitutor, parent, policy);
|
||||
}
|
||||
return inferTypeForMethodTypeParameterInner(typeParameter, paramTypes, argTypes, partialSubstitutor, parent, policy);
|
||||
}
|
||||
|
||||
private Pair<PsiType, ConstraintType> inferTypeForMethodTypeParameterInner(@NotNull PsiTypeParameter typeParameter,
|
||||
@NotNull PsiType[] paramTypes,
|
||||
@@ -255,7 +254,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
@NotNull PsiElement parent,
|
||||
@NotNull ParameterTypeInferencePolicy policy,
|
||||
@NotNull LanguageLevel languageLevel) {
|
||||
PsiType[] substitutions = new PsiType[typeParameters.length];
|
||||
PsiType[] substitutions = PsiType.createArray(typeParameters.length);
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<PsiType, ConstraintType>[] constraints = new Pair[typeParameters.length];
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
@@ -307,7 +306,6 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +332,8 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
constraint = inferMethodTypeParameterFromParent(typeParameter, partialSubstitutor, parent, policy);
|
||||
}
|
||||
else if (constraint.getSecond() == ConstraintType.SUBTYPE) {
|
||||
Pair<PsiType, ConstraintType> otherConstraint = inferMethodTypeParameterFromParent(typeParameter, partialSubstitutor, parent, policy);
|
||||
Pair<PsiType, ConstraintType> otherConstraint =
|
||||
inferMethodTypeParameterFromParent(typeParameter, partialSubstitutor, parent, policy);
|
||||
if (otherConstraint != null) {
|
||||
if (otherConstraint.getSecond() == ConstraintType.EQUALS || otherConstraint.getSecond() == ConstraintType.SUPERTYPE) {
|
||||
constraint = otherConstraint;
|
||||
@@ -586,7 +585,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
if (functionalInterfaceMethod != null) {
|
||||
final PsiSubstitutor subst = LambdaUtil.getSubstitutor(functionalInterfaceMethod, resolveResult);
|
||||
final PsiParameter[] methodParameters = functionalInterfaceMethod.getParameterList().getParameters();
|
||||
PsiType[] methodParamTypes = new PsiType[methodParameters.length];
|
||||
PsiType[] methodParamTypes = PsiType.createArray(methodParameters.length);
|
||||
for (int i = 0; i < methodParameters.length; i++) {
|
||||
methodParamTypes[i] = GenericsUtil.eliminateWildcards(subst.substitute(methodParameters[i].getType()));
|
||||
}
|
||||
@@ -595,7 +594,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
final PsiType[] args = new PsiType[methodParameters.length];
|
||||
final PsiType[] args = PsiType.createArray(methodParameters.length);
|
||||
Map<PsiMethodReferenceExpression,PsiType> map = PsiMethodReferenceUtil.ourRefs.get();
|
||||
if (map == null) {
|
||||
map = new HashMap<PsiMethodReferenceExpression, PsiType>();
|
||||
@@ -744,7 +743,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
PsiMethod method, PsiLambdaExpression lambdaExpression) {
|
||||
final PsiParameter[] parameters = lambdaExpression.getParameterList().getParameters();
|
||||
if (parameters.length == 0) return null;
|
||||
final PsiType[] lambdaArgs = new PsiType[parameters.length];
|
||||
final PsiType[] lambdaArgs = PsiType.createArray(parameters.length);
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
if (parameter.getTypeElement() == null) {
|
||||
@@ -754,7 +753,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
}
|
||||
|
||||
final PsiParameter[] methodParameters = method.getParameterList().getParameters();
|
||||
PsiType[] methodParamTypes = new PsiType[methodParameters.length];
|
||||
PsiType[] methodParamTypes = PsiType.createArray(methodParameters.length);
|
||||
for (int i = 0; i < methodParameters.length; i++) {
|
||||
methodParamTypes[i] = GenericsUtil.eliminateWildcards(subst.substitute(methodParameters[i].getType()));
|
||||
}
|
||||
@@ -764,7 +763,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
private static PsiType intersectAllExtends(PsiTypeParameter typeParam, PsiType arg) {
|
||||
if (arg == null) return null;
|
||||
PsiClassType[] superTypes = typeParam.getSuperTypes();
|
||||
PsiType[] erasureTypes = new PsiType[superTypes.length];
|
||||
PsiType[] erasureTypes = PsiType.createArray(superTypes.length);
|
||||
for (int i = 0; i < superTypes.length; i++) {
|
||||
erasureTypes[i] = TypeConversionUtil.erasure(superTypes[i]);
|
||||
}
|
||||
@@ -1084,7 +1083,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
|
||||
|
||||
PsiType[] superTypes = typeParameter.getSuperTypes();
|
||||
if (superTypes.length == 0) return null;
|
||||
final PsiType[] types = new PsiType[superTypes.length];
|
||||
final PsiType[] types = PsiType.createArray(superTypes.length);
|
||||
for (int i = 0; i < superTypes.length; i++) {
|
||||
PsiType superType = substitutor.substitute(superTypes[i]);
|
||||
if (superType instanceof PsiClassType && ((PsiClassType)superType).isRaw()) {
|
||||
|
||||
+1
-1
@@ -315,7 +315,7 @@ public class InferenceSession {
|
||||
if (argumentList != null) {
|
||||
final PsiExpression[] expressions = argumentList.getExpressions();
|
||||
final int idx = LambdaUtil.getLambdaIdx(argumentList, context);
|
||||
final PsiType[] types = new PsiType[expressions.length];
|
||||
final PsiType[] types = PsiType.createArray(expressions.length);
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
if (i != idx) {
|
||||
types[i] = expressions[i].getType();
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -42,7 +42,7 @@ public class PsiExpressionListImpl extends CompositePsiElement implements PsiExp
|
||||
@NotNull
|
||||
public PsiType[] getExpressionTypes() {
|
||||
PsiExpression[] expressions = getExpressions();
|
||||
PsiType[] types = new PsiType[expressions.length];
|
||||
PsiType[] types = PsiType.createArray(expressions.length);
|
||||
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
types[i] = expressions[i].getType();
|
||||
|
||||
+3
-3
@@ -454,8 +454,8 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
final PsiSubstitutor classSubstitutor2 = info2.getSubstitutor();
|
||||
|
||||
final int max = Math.max(params1.length, params2.length);
|
||||
PsiType[] types1 = new PsiType[max];
|
||||
PsiType[] types2 = new PsiType[max];
|
||||
PsiType[] types1 = PsiType.createArray(max);
|
||||
PsiType[] types2 = PsiType.createArray(max);
|
||||
final boolean varargsPosition = applicabilityLevel == MethodCandidateInfo.ApplicabilityLevel.VARARGS;
|
||||
for (int i = 0; i < max; i++) {
|
||||
ProgressManager.checkCanceled();
|
||||
@@ -642,7 +642,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
}
|
||||
|
||||
private static PsiType[] typesAtSite(PsiType[] types1, PsiSubstitutor siteSubstitutor1) {
|
||||
final PsiType[] types = new PsiType[types1.length];
|
||||
final PsiType[] types = PsiType.createArray(types1.length);
|
||||
for (int i = 0; i < types1.length; i++) {
|
||||
types[i] = siteSubstitutor1.substitute(types1[i]);
|
||||
}
|
||||
|
||||
+2
-1
@@ -326,7 +326,8 @@ public class UnnecessaryBoxingInspection extends BaseInspection {
|
||||
if (containingClass == null) {
|
||||
return false;
|
||||
}
|
||||
final PsiType[] types = new PsiType[expressions.length];
|
||||
final PsiType[] types = PsiType.createArray(expressions.length);
|
||||
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
final PsiExpression expression = expressions[i];
|
||||
final PsiType type = expression.getType();
|
||||
|
||||
+1
-1
@@ -285,7 +285,7 @@ public class UnnecessaryUnboxingInspection extends BaseInspection {
|
||||
if (containingClass == null) {
|
||||
return false;
|
||||
}
|
||||
final PsiType[] types = new PsiType[expressions.length];
|
||||
final PsiType[] types = PsiType.createArray(expressions.length);
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
final PsiExpression expression = expressions[i];
|
||||
final PsiType type = expression.getType();
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public class MethodCallUtils {
|
||||
}
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(expression.getProject());
|
||||
final PsiElementFactory factory = psiFacade.getElementFactory();
|
||||
final PsiType[] parameterTypes = new PsiType[parameterTypeStrings.length];
|
||||
final PsiType[] parameterTypes = PsiType.createArray(parameterTypeStrings.length);
|
||||
final GlobalSearchScope scope = expression.getResolveScope();
|
||||
for (int i = 0; i < parameterTypeStrings.length; i++) {
|
||||
final String parameterTypeString = parameterTypeStrings[i];
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -187,7 +187,7 @@ public class MethodUtils {
|
||||
final PsiElementFactory factory = psiFacade.getElementFactory();
|
||||
try {
|
||||
if (parameterTypeStrings != null) {
|
||||
final PsiType[] parameterTypes = new PsiType[parameterTypeStrings.length];
|
||||
final PsiType[] parameterTypes = PsiType.createArray(parameterTypeStrings.length);
|
||||
for (int i = 0; i < parameterTypeStrings.length; i++) {
|
||||
final String parameterTypeString = parameterTypeStrings[i];
|
||||
parameterTypes[i] = factory.createTypeFromText(parameterTypeString, method);
|
||||
|
||||
@@ -207,7 +207,7 @@ public class GroovyAnnotator extends GroovyElementVisitor {
|
||||
|
||||
if (typeElement instanceof GrDisjunctionTypeElement) {
|
||||
final GrTypeElement[] elements = ((GrDisjunctionTypeElement)typeElement).getTypeElements();
|
||||
PsiType[] types = new PsiType[elements.length];
|
||||
PsiType[] types = PsiType.createArray(elements.length);
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
types[i] = elements[i].getType();
|
||||
}
|
||||
@@ -1426,6 +1426,7 @@ public class GroovyAnnotator extends GroovyElementVisitor {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitAnnotation(GrAnnotation annotation) {
|
||||
final GrCodeReferenceElement ref = annotation.getClassReference();
|
||||
final PsiElement resolved = ref.resolve();
|
||||
@@ -2092,7 +2093,7 @@ public class GroovyAnnotator extends GroovyElementVisitor {
|
||||
String packageName = "<default package>";
|
||||
if (file instanceof GroovyFile) {
|
||||
final String name = ((GroovyFile)file).getPackageName();
|
||||
if (name.length() > 0) packageName = name;
|
||||
if (!name.isEmpty()) packageName = name;
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
+1
-1
@@ -197,7 +197,7 @@ public class QuickfixUtil {
|
||||
for (PsiType type : PsiUtil.getArgumentTypes(referenceExpression, false)) {
|
||||
unboxedTypes.add(TypesUtil.unboxPrimitiveTypeWrapperAndEraseGenerics(type));
|
||||
}
|
||||
final PsiType[] types = unboxedTypes.toArray(new PsiType[unboxedTypes.size()]);
|
||||
final PsiType[] types = unboxedTypes.toArray(PsiType.createArray(unboxedTypes.size()));
|
||||
final String[] names = getMethodArgumentsNames(referenceExpression.getProject(), types);
|
||||
final List<ParamInfo> infos = swapArgumentsAndTypes(names, types);
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -87,12 +87,12 @@ public class ClosureDescriptor extends LightElement implements PsiElement {
|
||||
}
|
||||
final boolean isConstructor = Boolean.TRUE.equals(myMethod.get("constructor"));
|
||||
final MethodSignature signature = MethodSignatureUtil
|
||||
.createMethodSignature(name, types.toArray(new PsiType[types.size()]), method.getTypeParameters(), PsiSubstitutor.EMPTY, isConstructor);
|
||||
.createMethodSignature(name, types.toArray(PsiType.createArray(types.size())), method.getTypeParameters(), PsiSubstitutor.EMPTY, isConstructor);
|
||||
final GrClosureSignature closureSignature = GrClosureSignatureUtil.createSignature(signature);
|
||||
|
||||
if (method instanceof ClsMethodImpl) method = ((ClsMethodImpl)method).getSourceMirrorMethod();
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
final PsiType[] typeArray = new PsiType[parameters.length];
|
||||
final PsiType[] typeArray = PsiType.createArray(parameters.length);
|
||||
ContainerUtil.map(parameters, new Function<PsiParameter, PsiType>() {
|
||||
@Override
|
||||
public PsiType fun(PsiParameter parameter) {
|
||||
|
||||
+6
-1
@@ -53,10 +53,12 @@ public class GrDocMethodParamsImpl extends GroovyDocPsiElementImpl implements Gr
|
||||
return "GrDocMethodParameterList";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(GroovyElementVisitor visitor) {
|
||||
visitor.visitDocMethodParameterList(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType[] getParameterTypes() {
|
||||
ArrayList<PsiType> types = new ArrayList<PsiType>();
|
||||
PsiManagerEx manager = getManager();
|
||||
@@ -73,9 +75,10 @@ public class GrDocMethodParamsImpl extends GroovyDocPsiElementImpl implements Gr
|
||||
types.add(null);
|
||||
}
|
||||
}
|
||||
return types.toArray(new PsiType[types.size()]);
|
||||
return types.toArray(PsiType.createArray(types.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrDocMethodParameter[] getParameters() {
|
||||
List<GrDocMethodParameter> result = new ArrayList<GrDocMethodParameter>();
|
||||
for (PsiElement cur = getFirstChild(); cur != null; cur = cur.getNextSibling()) {
|
||||
@@ -84,6 +87,7 @@ public class GrDocMethodParamsImpl extends GroovyDocPsiElementImpl implements Gr
|
||||
return result.toArray(new GrDocMethodParameter[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiElement getLeftParen() {
|
||||
ASTNode paren = getNode().findChildByType(GroovyDocTokenTypes.mGDOC_TAG_VALUE_LPAREN);
|
||||
@@ -91,6 +95,7 @@ public class GrDocMethodParamsImpl extends GroovyDocPsiElementImpl implements Gr
|
||||
return paren.getPsi();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiElement getRightParen() {
|
||||
ASTNode paren = getNode().findChildByType(GroovyDocTokenTypes.mGDOC_TAG_VALUE_RPAREN);
|
||||
|
||||
+12
-2
@@ -62,6 +62,7 @@ import java.util.*;
|
||||
public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabActionSupport<GroovyPsiElement, Object, GroovyPsiElement> {
|
||||
private static final Logger LOG = Logger.getInstance(GroovyParameterInfoHandler.class);
|
||||
|
||||
@Override
|
||||
public boolean couldShowInLookup() {
|
||||
return true;
|
||||
}
|
||||
@@ -75,6 +76,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object[] getParametersForLookup(LookupElement item, ParameterInfoContext context) {
|
||||
List<? extends PsiElement> elements = JavaCompletionUtil.getAllPsiElements(item);
|
||||
|
||||
@@ -91,6 +93,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getParametersForDocumentation(Object resolveResult, ParameterInfoContext context) {
|
||||
if (resolveResult instanceof GroovyResolveResult) {
|
||||
final PsiElement element = ((GroovyResolveResult)resolveResult).getElement();
|
||||
@@ -102,10 +105,12 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroovyPsiElement findElementForParameterInfo(@NotNull CreateParameterInfoContext context) {
|
||||
return findAnchorElement(context.getEditor().getCaretModel().getOffset(), context.getFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroovyPsiElement findElementForUpdatingParameterInfo(@NotNull UpdateParameterInfoContext context) {
|
||||
return findAnchorElement(context.getEditor().getCaretModel().getOffset(), context.getFile());
|
||||
}
|
||||
@@ -131,6 +136,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void showParameterInfo(@NotNull GroovyPsiElement place, @NotNull CreateParameterInfoContext context) {
|
||||
GroovyResolveResult[] variants = ResolveUtil.getCallVariants(place);
|
||||
@@ -210,6 +216,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return resolveResult.isInvokedOnProperty() || resolveResult.getElement() instanceof PsiVariable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateParameterInfo(@NotNull GroovyPsiElement place, @NotNull UpdateParameterInfoContext context) {
|
||||
final PsiElement parameterOwner = context.getParameterOwner();
|
||||
if (parameterOwner != place) {
|
||||
@@ -243,7 +250,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
final PsiMethod method = (PsiMethod)namedElement;
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
parameters = updateConstructorParams(method, parameters, context.getParameterOwner());
|
||||
parameterTypes = new PsiType[parameters.length];
|
||||
parameterTypes = PsiType.createArray(parameters.length);
|
||||
for (int j = 0; j < parameters.length; j++) {
|
||||
parameterTypes[j] = parameters[j].getType();
|
||||
}
|
||||
@@ -254,7 +261,7 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
else if (objects[i] instanceof GrClosureSignature) {
|
||||
final GrClosureSignature signature = (GrClosureSignature)objects[i];
|
||||
argTypes = PsiUtil.getArgumentTypes(place, false);
|
||||
parameterTypes = new PsiType[signature.getParameterCount()];
|
||||
parameterTypes = PsiType.createArray(signature.getParameterCount());
|
||||
int j = 0;
|
||||
for (GrClosureParameter parameter : signature.getParameters()) {
|
||||
parameterTypes[j++] = parameter.getType();
|
||||
@@ -310,14 +317,17 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return element != null && element.getNode().getElementType() == GroovyTokenTypes.mCOMMA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameterCloseChars() {
|
||||
return ",){}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tracksParameterIndex() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUI(Object o, @NotNull ParameterInfoUIContext context) {
|
||||
CodeInsightSettings settings = CodeInsightSettings.getInstance();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -132,7 +132,7 @@ public class DFAType {
|
||||
|
||||
@Nullable
|
||||
public PsiType getResultType() {
|
||||
if (mixins.size() == 0) return primary;
|
||||
if (mixins.isEmpty()) return primary;
|
||||
|
||||
List<PsiType> types = new ArrayList<PsiType>();
|
||||
if (primary != null) {
|
||||
@@ -143,8 +143,8 @@ public class DFAType {
|
||||
types.add(mixin.myType);
|
||||
}
|
||||
}
|
||||
if (types.size() == 0) return null;
|
||||
return PsiIntersectionType.createIntersection(types.toArray(new PsiType[types.size()]));
|
||||
if (types.isEmpty()) return null;
|
||||
return PsiIntersectionType.createIntersection(types.toArray(PsiType.createArray(types.size())));
|
||||
}
|
||||
|
||||
public static DFAType create(@Nullable PsiType type) {
|
||||
|
||||
+18
-2
@@ -43,6 +43,7 @@ public abstract class GrLiteralClassType extends PsiClassType {
|
||||
@NotNull
|
||||
protected abstract String getJavaClassName();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ClassResolveResult resolveGenerics() {
|
||||
final PsiClass myBaseClass = resolve();
|
||||
@@ -50,31 +51,39 @@ public abstract class GrLiteralClassType extends PsiClassType {
|
||||
|
||||
return new ClassResolveResult() {
|
||||
|
||||
@Override
|
||||
public PsiClass getElement() {
|
||||
return myBaseClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiSubstitutor getSubstitutor() {
|
||||
return substitutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPackagePrefixPackageReference() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccessible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStaticsScopeCorrect() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiElement getCurrentFileResolveScope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidResult() {
|
||||
return isStaticsScopeCorrect() && isAccessible();
|
||||
}
|
||||
@@ -90,7 +99,7 @@ public abstract class GrLiteralClassType extends PsiClassType {
|
||||
return PsiSubstitutor.EMPTY.putAll(myBaseClass, typeArgs);
|
||||
}
|
||||
else {
|
||||
return PsiSubstitutor.EMPTY.putAll(myBaseClass, new PsiType[typeParams.length]);
|
||||
return PsiSubstitutor.EMPTY.putAll(myBaseClass, createArray(typeParams.length));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -102,6 +111,7 @@ public abstract class GrLiteralClassType extends PsiClassType {
|
||||
@NotNull
|
||||
public abstract String getClassName() ;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getPresentableText() {
|
||||
String name = getClassName();
|
||||
@@ -116,6 +126,7 @@ public abstract class GrLiteralClassType extends PsiClassType {
|
||||
}, ", ") + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getCanonicalText() {
|
||||
String name = getJavaClassName();
|
||||
@@ -131,6 +142,7 @@ public abstract class GrLiteralClassType extends PsiClassType {
|
||||
return name + "<" + StringUtil.join(params, f, ", ") + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public LanguageLevel getLanguageLevel() {
|
||||
return myLanguageLevel;
|
||||
@@ -141,20 +153,24 @@ public abstract class GrLiteralClassType extends PsiClassType {
|
||||
return myScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiClass resolve() {
|
||||
return myGroovyPsiManager.findClassWithCache(getJavaClassName(), getResolveScope());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClassType rawType() {
|
||||
return myGroovyPsiManager.createTypeByFQClassName(getJavaClassName(), myScope);
|
||||
}
|
||||
|
||||
public boolean equalsToText(@NonNls String text) {
|
||||
@Override
|
||||
public boolean equalsToText(@NotNull @NonNls String text) {
|
||||
return text != null && text.equals(getJavaClassName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GlobalSearchScope getResolveScope() {
|
||||
return myScope;
|
||||
|
||||
@@ -87,6 +87,7 @@ public class GrMapType extends GrLiteralClassType {
|
||||
return myJavaClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getClassName() {
|
||||
return StringUtil.getShortName(myJavaClassName);
|
||||
@@ -110,7 +111,7 @@ public class GrMapType extends GrLiteralClassType {
|
||||
result.add(entry.first);
|
||||
}
|
||||
result.remove(null);
|
||||
return result.toArray(new PsiType[result.size()]);
|
||||
return result.toArray(createArray(result.size()));
|
||||
}
|
||||
|
||||
public PsiType[] getAllValueTypes() {
|
||||
@@ -120,9 +121,10 @@ public class GrMapType extends GrLiteralClassType {
|
||||
result.add(entry.second);
|
||||
}
|
||||
result.remove(null);
|
||||
return result.toArray(new PsiType[result.size()]);
|
||||
return result.toArray(createArray(result.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiType[] getParameters() {
|
||||
final PsiType[] keyTypes = getAllKeyTypes();
|
||||
@@ -134,9 +136,11 @@ public class GrMapType extends GrLiteralClassType {
|
||||
return new PsiType[]{getLeastUpperBound(keyTypes), getLeastUpperBound(valueTypes)};
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getInternalCanonicalText() {
|
||||
if (myStringEntries.size() == 0) {
|
||||
if (myOtherEntries.size() == 0) return "[:]";
|
||||
if (myStringEntries.isEmpty()) {
|
||||
if (myOtherEntries.isEmpty()) return "[:]";
|
||||
String name = getJavaClassName();
|
||||
final PsiType[] params = getParameters();
|
||||
return name + "<" + getInternalText(params[0]) + ", " + getInternalText(params[1]) + ">";
|
||||
@@ -159,6 +163,7 @@ public class GrMapType extends GrLiteralClassType {
|
||||
return param == null ? "null" : param.getInternalCanonicalText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
for (PsiType type : myStringEntries.values()) {
|
||||
if (type != null && !type.isValid()) {
|
||||
@@ -177,6 +182,7 @@ public class GrMapType extends GrLiteralClassType {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClassType setLanguageLevel(@NotNull final LanguageLevel languageLevel) {
|
||||
return new GrMapType(myFacade, getResolveScope(), myStringEntries, myOtherEntries, languageLevel);
|
||||
@@ -189,6 +195,7 @@ public class GrMapType extends GrLiteralClassType {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableFrom(@NotNull PsiType type) {
|
||||
return type instanceof GrMapType || super.isAssignableFrom(type);
|
||||
}
|
||||
|
||||
+13
-1
@@ -41,6 +41,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiReference getReference() {
|
||||
return this;
|
||||
}
|
||||
@@ -52,6 +53,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
super.subtreeChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReferenceName() {
|
||||
PsiElement nameElement = getReferenceNameElement();
|
||||
if (nameElement != null) {
|
||||
@@ -60,10 +62,12 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getElement() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextRange getRangeInElement() {
|
||||
final PsiElement refNameElement = getReferenceNameElement();
|
||||
if (refNameElement != null) {
|
||||
@@ -73,6 +77,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
return new TextRange(0, getTextLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement handleElementRenameSimple(String newElementName) throws IncorrectOperationException {
|
||||
PsiElement nameElement = getReferenceNameElement();
|
||||
if (nameElement != null) {
|
||||
@@ -92,10 +97,12 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
|
||||
return handleElementRenameSimple(newElementName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
if (isReferenceTo(element)) return this;
|
||||
final boolean fullyQualified = isFullyQualified();
|
||||
@@ -151,6 +158,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
|
||||
public abstract boolean isFullyQualified();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiType[] getTypeArguments() {
|
||||
final GrTypeArgumentList typeArgsList = getTypeArgumentList();
|
||||
@@ -158,7 +166,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
|
||||
final GrTypeElement[] args = typeArgsList.getTypeArgumentElements();
|
||||
if (args.length == 0) return PsiType.EMPTY_ARRAY;
|
||||
PsiType[] result = new PsiType[args.length];
|
||||
PsiType[] result = PsiType.createArray(args.length);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = args[i].getType();
|
||||
}
|
||||
@@ -166,15 +174,18 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public GrTypeArgumentList getTypeArgumentList() {
|
||||
return (GrTypeArgumentList)findChildByType(GroovyElementTypes.TYPE_ARGUMENTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQualifier(@Nullable Q newQualifier) {
|
||||
PsiImplUtil.setQualifier(this, newQualifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassNameText() {
|
||||
String cachedQName = myCachedQName;
|
||||
if (cachedQName == null) {
|
||||
@@ -191,6 +202,7 @@ public abstract class GrReferenceElementImpl<Q extends PsiElement> extends Groov
|
||||
return whiteSpaceAndComments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isQualified() {
|
||||
return getQualifier() != null;
|
||||
}
|
||||
|
||||
+43
-2
@@ -86,6 +86,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiElement createReferenceNameFromText(String refName) {
|
||||
PsiFile file = createGroovyFileChecked("a." + refName);
|
||||
@@ -100,12 +101,14 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement createDocMemberReferenceNameFromText(String idText) {
|
||||
GrDocMemberReference reference = createDocMemberReferenceFromText("Foo", idText);
|
||||
LOG.assertTrue(reference != null, idText);
|
||||
return reference.getReferenceNameElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrDocMemberReference createDocMemberReferenceFromText(String className, String text) {
|
||||
PsiFile file = createGroovyFileChecked("/** @see " + className + "#" + text + " */");
|
||||
PsiElement element = file.getFirstChild();
|
||||
@@ -115,6 +118,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return PsiTreeUtil.getChildOfType(tag, GrDocMemberReference.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrDocReferenceElement createDocReferenceElementFromFQN(String qName) {
|
||||
PsiFile file = createGroovyFileChecked("/** @see " + qName + " */");
|
||||
PsiElement element = file.getFirstChild();
|
||||
@@ -124,12 +128,14 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return PsiTreeUtil.getChildOfType(tag, GrDocReferenceElement.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrCodeReferenceElement createReferenceElementFromText(String refName, final PsiElement context) {
|
||||
GroovyFile file = createGroovyFileChecked("(" + refName + ")foo", false, context);
|
||||
GrTypeElement typeElement = ((GrTypeCastExpression) file.getTopStatements()[0]).getCastTypeElement();
|
||||
return ((GrClassTypeElement) typeElement).getReferenceElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrReferenceExpression createReferenceExpressionFromText(String idText) {
|
||||
PsiFile file = createGroovyFileChecked(idText);
|
||||
final GrTopStatement[] statements = ((GroovyFileBase)file).getTopStatements();
|
||||
@@ -137,6 +143,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return (GrReferenceExpression) statements[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrReferenceExpression createReferenceExpressionFromText(String idText, PsiElement context) {
|
||||
GroovyFile file = createGroovyFileChecked(idText, false, context);
|
||||
GrTopStatement[] statements = file.getTopStatements();
|
||||
@@ -159,6 +166,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return createReferenceExpressionFromText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GrExpression createExpressionFromText(@NotNull String text, PsiElement context) {
|
||||
GroovyFile file = createGroovyFile(text, false, context);
|
||||
@@ -215,6 +223,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrVariableDeclaration createVariableDeclaration(@Nullable String[] modifiers,
|
||||
@Nullable GrExpression initializer,
|
||||
@Nullable PsiType type,
|
||||
@@ -289,6 +298,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return enumClass.getEnumConstants()[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrVariableDeclaration createFieldDeclaration(String[] modifiers,
|
||||
String identifier,
|
||||
@Nullable GrExpression initializer,
|
||||
@@ -336,6 +346,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public GrTopStatement createTopElementFromText(String text) {
|
||||
GroovyFile dummyFile = createGroovyFileChecked(text);
|
||||
@@ -344,6 +355,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return topStatements[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrClosableBlock createClosureFromText(String closureText, PsiElement context) throws IncorrectOperationException {
|
||||
GroovyFile psiFile = createGroovyFileChecked("def __hdsjfghk_sdhjfshglk_foo = " + closureText, false, context);
|
||||
final GrStatement st = psiFile.getStatements()[0];
|
||||
@@ -360,6 +372,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return (GroovyFileImpl) factory.createFileFromText(fileName, GroovyFileType.GROOVY_FILE_TYPE, text, stamp, physical);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrParameter createParameter(String name,
|
||||
@Nullable String typeText,
|
||||
@Nullable String initializer,
|
||||
@@ -375,7 +388,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
fileText.append(typeText).append(' ');
|
||||
}
|
||||
fileText.append(name);
|
||||
if (initializer != null && initializer.length() > 0) {
|
||||
if (initializer != null && !initializer.isEmpty()) {
|
||||
fileText.append(" = ").append(initializer);
|
||||
}
|
||||
fileText.append("){}");
|
||||
@@ -389,6 +402,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrCodeReferenceElement createTypeOrPackageReference(String qName) {
|
||||
try {
|
||||
final GroovyFileBase file = createGroovyFileChecked("def i = new " + qName + "()");
|
||||
@@ -403,6 +417,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrTypeDefinition createTypeDefinition(String text) throws IncorrectOperationException {
|
||||
final GroovyFileBase file = createGroovyFileChecked(text);
|
||||
final GrTypeDefinition[] classes = file.getTypeDefinitions();
|
||||
@@ -410,6 +425,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return classes[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GrTypeElement createTypeElement(String typeText, final PsiElement context) throws IncorrectOperationException {
|
||||
final GroovyFile file = createGroovyFileChecked("def " + typeText + " someVar", false, context);
|
||||
@@ -427,6 +443,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrTypeElement createTypeElement(PsiType type) throws IncorrectOperationException {
|
||||
final String typeText = getTypeText(type);
|
||||
if (typeText == null)
|
||||
@@ -440,14 +457,17 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return JavaPsiFacade.getElementFactory(myProject).createType(aClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrParenthesizedExpression createParenthesizedExpr(GrExpression expression) {
|
||||
return ((GrParenthesizedExpression) createExpressionFromText("(" + expression.getText() + ")"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement createStringLiteralForReference(String text) {
|
||||
return createLiteralFromValue(text).getFirstChild();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement createModifierFromText(String name) {
|
||||
final GroovyFileBase file = createGroovyFileChecked(name + " foo() {}");
|
||||
final GrTopLevelDefinition[] definitions = file.getTopLevelDefinitions();
|
||||
@@ -455,12 +475,14 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return definitions[0].getFirstChild().getFirstChild();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrCodeBlock createMethodBodyFromText(String text) {
|
||||
final GroovyFileBase file = createGroovyFileChecked("def foo () {" + text + "}");
|
||||
final GrMethod method = (GrMethod) file.getTopLevelDefinitions()[0];
|
||||
return method.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrVariableDeclaration createSimpleVariableDeclaration(String name, String typeText) {
|
||||
String classText;
|
||||
if (Character.isLowerCase(typeText.charAt(0))) {
|
||||
@@ -474,14 +496,17 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return (GrVariableDeclaration) body.getMemberDeclarations()[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrReferenceElement createPackageReferenceElementFromText(String newPackageName) {
|
||||
return ((GrPackageDefinition) createGroovyFileChecked("package " + newPackageName).getTopStatements()[0]).getPackageReference();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement createDotToken(String newDot) {
|
||||
return createReferenceExpressionFromText("a" + newDot + "b").getDotToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrMethod createConstructorFromText(@NotNull String constructorName,
|
||||
@Nullable String[] paramTypes,
|
||||
String[] paramNames,
|
||||
@@ -491,6 +516,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return createConstructorFromText(constructorName, text, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrMethod createConstructorFromText(String constructorName, CharSequence constructorText, @Nullable PsiElement context) {
|
||||
GroovyFile file = createGroovyFileChecked("class " + constructorName + "{" + constructorText + "}", false, context);
|
||||
GrTopLevelDefinition definition = file.getTopLevelDefinitions()[0];
|
||||
@@ -505,6 +531,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return methods[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GrMethod createMethodFromText(@NotNull String methodText, @Nullable PsiElement context) {
|
||||
GroovyFile file = createGroovyFile(methodText, false, context);
|
||||
@@ -579,17 +606,20 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
/**
|
||||
* use createGroovyFileChecked() inside GroovyPsiElementFactoryImpl instead of this method
|
||||
*/
|
||||
@Override
|
||||
public GroovyFile createGroovyFile(CharSequence idText, boolean isPhysical, @Nullable PsiElement context) {
|
||||
GroovyFileImpl file = createDummyFile(idText, isPhysical);
|
||||
file.setContext(context);
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement createWhiteSpace() {
|
||||
PsiFile dummyFile = createDummyFile(" ", false);
|
||||
return dummyFile.getFirstChild();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiElement createLineTerminator(int length) {
|
||||
|
||||
@@ -601,6 +631,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return createLineTerminator(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiElement createLineTerminator(String text) {
|
||||
PsiFile dummyFile = createGroovyFileChecked(text);
|
||||
@@ -609,6 +640,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return child;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrArgumentList createExpressionArgumentList(GrExpression... expressions) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.append("ven (");
|
||||
@@ -624,6 +656,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return (((GrMethodCallExpression) file.getChildren()[0])).getArgumentList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrNamedArgument createNamedArgument(@NotNull final String name, final GrExpression expression) {
|
||||
PsiFile file = createGroovyFileChecked("foo (" + name + ":" + expression.getText() + ")");
|
||||
assert file.getChildren()[0] != null;
|
||||
@@ -631,6 +664,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return call.getArgumentList().getNamedArguments()[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrStatement createStatementFromText(CharSequence text) {
|
||||
return createStatementFromText(text, null);
|
||||
}
|
||||
@@ -648,6 +682,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return (GrStatement)statements[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrBlockStatement createBlockStatement(@NonNls GrStatement... statements) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.append("while (true) { \n");
|
||||
@@ -660,6 +695,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return (GrBlockStatement) ((GrWhileStatement) file.getChildren()[0]).getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrMethodCallExpression createMethodCallByAppCall(GrApplicationStatement callExpr) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.append(callExpr.getInvokedExpression().getText());
|
||||
@@ -741,10 +777,12 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return sections[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrImportStatement createImportStatementFromText(@NotNull String qName, boolean isStatic, boolean isOnDemand, String alias) {
|
||||
return createImportStatement(qName, isStatic, isOnDemand, alias, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrImportStatement createImportStatementFromText(@NotNull String text) {
|
||||
PsiFile dummyFile = createGroovyFileChecked(text);
|
||||
return ((GrImportStatement) dummyFile.getFirstChild());
|
||||
@@ -825,6 +863,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrMethod createMethodFromText(String modifier, String name, @Nullable String type, String[] paramTypes, PsiElement context) {
|
||||
PsiType psiType;
|
||||
List<PsiType> res = new ArrayList<PsiType>();
|
||||
@@ -840,11 +879,12 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
res.add(psiType);
|
||||
}
|
||||
|
||||
String[] paramNames = QuickfixUtil.getMethodArgumentsNames(myProject, res.toArray(new PsiType[res.size()]));
|
||||
String[] paramNames = QuickfixUtil.getMethodArgumentsNames(myProject, res.toArray(PsiType.createArray(res.size())));
|
||||
final CharSequence text = generateMethodText(modifier, name, type, paramTypes, paramNames, null, false);
|
||||
return createMethodFromText(text.toString(), context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GrDocComment createDocCommentFromText(@NotNull String text) {
|
||||
return (GrDocComment)createGroovyFileChecked(text).getFirstChild();
|
||||
@@ -899,6 +939,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
return ((GrCall)createExpressionFromText("foo()")).getArgumentList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrArgumentList createArgumentListFromText(String argListText) {
|
||||
try {
|
||||
return ((GrCall)createExpressionFromText("foo " + argListText)).getArgumentList();
|
||||
|
||||
+7
-1
@@ -66,6 +66,7 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(GroovyElementVisitor visitor) {
|
||||
visitor.visitListOrMap(this);
|
||||
}
|
||||
@@ -100,10 +101,12 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
super.deleteChildInternal(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType getType() {
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPES_CALCULATOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMap() {
|
||||
return findChildByType(MAP_LITERAL_TOKEN_SET) != null;
|
||||
}
|
||||
@@ -118,6 +121,7 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
return findChildByType(GroovyTokenTypes.mRBRACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GrExpression[] getInitializers() {
|
||||
List<GrExpression> result = ContainerUtil.newArrayList();
|
||||
@@ -129,6 +133,7 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
return result.toArray(new GrExpression[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GrNamedArgument[] getNamedArguments() {
|
||||
List<GrNamedArgument> result = new ArrayList<GrNamedArgument>();
|
||||
@@ -183,6 +188,7 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
}
|
||||
|
||||
private static class MyTypesCalculator implements Function<GrListOrMapImpl, PsiType> {
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiType fun(GrListOrMapImpl listOrMap) {
|
||||
final GlobalSearchScope scope = listOrMap.getResolveScope();
|
||||
@@ -261,7 +267,7 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
|
||||
}
|
||||
}
|
||||
|
||||
PsiType[] result = new PsiType[initializers.length];
|
||||
PsiType[] result = PsiType.createArray(initializers.length);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = initializers[i].getType();
|
||||
}
|
||||
|
||||
+5
-5
@@ -368,7 +368,7 @@ public class GrClosureSignatureUtil {
|
||||
PsiType type;
|
||||
@Nullable Arg arg;
|
||||
|
||||
private ArgWrapper(PsiType type, Arg arg) {
|
||||
private ArgWrapper(PsiType type, @Nullable Arg arg) {
|
||||
this.type = type;
|
||||
this.arg = arg;
|
||||
}
|
||||
@@ -515,7 +515,7 @@ public class GrClosureSignatureUtil {
|
||||
this.context = context;
|
||||
this.params = params;
|
||||
this.args = args;
|
||||
this.types = new PsiType[args.length];
|
||||
this.types = PsiType.createArray(args.length);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
types[i] = typeComputer.fun(args[i]);
|
||||
}
|
||||
@@ -819,7 +819,7 @@ public class GrClosureSignatureUtil {
|
||||
List<PsiType> paramTypes,
|
||||
PsiTypeParameter[] typeParameters,
|
||||
PsiSubstitutor substitutor) {
|
||||
return MethodSignatureUtil.createMethodSignature(name, paramTypes.toArray(new PsiType[paramTypes.size()]), typeParameters, substitutor);
|
||||
return MethodSignatureUtil.createMethodSignature(name, paramTypes.toArray(PsiType.createArray(paramTypes.size())), typeParameters, substitutor);
|
||||
}
|
||||
|
||||
public static void generateAllMethodSignaturesByClosureSignature(@NotNull String name,
|
||||
@@ -866,7 +866,7 @@ public class GrClosureSignatureUtil {
|
||||
@Nullable
|
||||
public static PsiType getTypeByArg(ArgInfo<PsiElement> arg, PsiManager manager, GlobalSearchScope resolveScope) {
|
||||
if (arg.isMultiArg) {
|
||||
if (arg.args.size() == 0) return PsiType.getJavaLangObject(manager, resolveScope).createArrayType();
|
||||
if (arg.args.isEmpty()) return PsiType.getJavaLangObject(manager, resolveScope).createArrayType();
|
||||
PsiType leastUpperBound = null;
|
||||
PsiElement first = arg.args.get(0);
|
||||
if (first instanceof GrNamedArgument) {
|
||||
@@ -887,7 +887,7 @@ public class GrClosureSignatureUtil {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (arg.args.size() == 0) return null;
|
||||
if (arg.args.isEmpty()) return null;
|
||||
PsiElement elem = arg.args.get(0);
|
||||
if (elem instanceof GrExpression) {
|
||||
return ((GrExpression)elem).getType();
|
||||
|
||||
+2
-2
@@ -508,7 +508,7 @@ public class TypesUtil {
|
||||
if (components1.length == 0) return genNewListBy(type2, manager);
|
||||
if (components2.length == 0) return genNewListBy(type1, manager);
|
||||
|
||||
PsiType[] components3 = new PsiType[Math.min(components1.length, components2.length)];
|
||||
PsiType[] components3 = PsiType.createArray(Math.min(components1.length, components2.length));
|
||||
for (int i = 0; i < components3.length; i++) {
|
||||
PsiType c1 = components1[i];
|
||||
PsiType c2 = components2[i];
|
||||
@@ -849,7 +849,7 @@ public class TypesUtil {
|
||||
public PsiType fun(GrAnnotationMemberValue value) {
|
||||
return inferAnnotationMemberValueType(value);
|
||||
}
|
||||
}, new PsiType[initializers.length]);
|
||||
}, PsiType.createArray(initializers.length));
|
||||
return new GrTupleType(types, JavaPsiFacade.getInstance(value.getProject()), value.getResolveScope());
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -33,6 +33,7 @@ public class GrTypeArgumentListImpl extends GroovyPsiElementImpl implements GrTy
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(GroovyElementVisitor visitor) {
|
||||
visitor.visitTypeArgumentList(this);
|
||||
}
|
||||
@@ -41,6 +42,7 @@ public class GrTypeArgumentListImpl extends GroovyPsiElementImpl implements GrTy
|
||||
return "Type arguments";
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrTypeElement[] getTypeArgumentElements() {
|
||||
return findChildrenByClass(GrTypeElement.class);
|
||||
}
|
||||
@@ -50,13 +52,14 @@ public class GrTypeArgumentListImpl extends GroovyPsiElementImpl implements GrTy
|
||||
final GrTypeElement[] elements = getTypeArgumentElements();
|
||||
if (elements.length == 0) return PsiType.EMPTY_ARRAY;
|
||||
|
||||
PsiType[] result = new PsiType[elements.length];
|
||||
PsiType[] result = PsiType.createArray(elements.length);
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
result[i] = elements[i].getType();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiamond() {
|
||||
return getTypeArgumentElements().length == 0;
|
||||
}
|
||||
|
||||
+2
-2
@@ -68,13 +68,13 @@ public class GrInnerClassConstructorUtil {
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject());
|
||||
PsiClass scopeClass = PsiUtil.findEnclosingInstanceClassInScope(containingClass, place, true);
|
||||
if (scopeClass != null) {
|
||||
PsiType[] newTypes = new PsiType[types.length + 1];
|
||||
PsiType[] newTypes = PsiType.createArray(types.length + 1);
|
||||
newTypes[0] = factory.createType(scopeClass);
|
||||
System.arraycopy(types, 0, newTypes, 1, types.length);
|
||||
types = newTypes;
|
||||
}
|
||||
else if (types.length == 0 || !TypesUtil.isAssignableByMethodCallConversion(factory.createType(containingClass), types[0], place)) {
|
||||
PsiType[] newTypes = new PsiType[types.length + 1];
|
||||
PsiType[] newTypes = PsiType.createArray(types.length + 1);
|
||||
newTypes[0] = PsiType.NULL;
|
||||
System.arraycopy(types, 0, newTypes, 1, types.length);
|
||||
types = newTypes;
|
||||
|
||||
@@ -323,7 +323,7 @@ public class PsiUtil {
|
||||
}
|
||||
|
||||
if (stopAt == expression) {
|
||||
return result.toArray(new PsiType[result.size()]);
|
||||
return result.toArray(PsiType.createArray(result.size()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ public class PsiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
return result.toArray(new PsiType[result.size()]);
|
||||
return result.toArray(PsiType.createArray(result.size()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -390,8 +390,9 @@ public class PsiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterable<PsiClass> iterateSupers(final @NotNull PsiClass psiClass, final boolean includeSelf) {
|
||||
public static Iterable<PsiClass> iterateSupers(@NotNull final PsiClass psiClass, final boolean includeSelf) {
|
||||
return new Iterable<PsiClass>() {
|
||||
@Override
|
||||
public Iterator<PsiClass> iterator() {
|
||||
return new Iterator<PsiClass>() {
|
||||
TIntStack indices = new TIntStack();
|
||||
@@ -413,6 +414,7 @@ public class PsiUtil {
|
||||
pushSuper(psiClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
nextElement();
|
||||
return current != null;
|
||||
@@ -450,6 +452,7 @@ public class PsiUtil {
|
||||
indices.push(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass next() {
|
||||
nextElement();
|
||||
@@ -458,6 +461,7 @@ public class PsiUtil {
|
||||
return current;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new IllegalStateException("should not be called");
|
||||
}
|
||||
@@ -600,7 +604,7 @@ public class PsiUtil {
|
||||
PsiClassType classType = (PsiClassType)qualifierType;
|
||||
final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
|
||||
GrExpression[] arguments = expr.getArgumentList().getExpressionArguments();
|
||||
PsiType[] argTypes = new PsiType[arguments.length];
|
||||
PsiType[] argTypes = PsiType.createArray(arguments.length);
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
PsiType argType = arguments[i].getType();
|
||||
if (argType == null) argType = TypesUtil.getJavaLangObject(expr);
|
||||
|
||||
+7
-3
@@ -93,6 +93,7 @@ public class MethodResolverProcessor extends ResolverProcessor implements GrMeth
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
|
||||
if (myStopExecuting) {
|
||||
return false;
|
||||
@@ -130,6 +131,7 @@ public class MethodResolverProcessor extends ResolverProcessor implements GrMeth
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GroovyResolveResult[] getCandidates() {
|
||||
if (!myAllVariants && super.hasCandidates()) {
|
||||
@@ -152,7 +154,7 @@ public class MethodResolverProcessor extends ResolverProcessor implements GrMeth
|
||||
result.add(candidate);
|
||||
}
|
||||
}
|
||||
if (result.size() > 0) return result;
|
||||
if (!result.isEmpty()) return result;
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@@ -234,7 +236,7 @@ public class MethodResolverProcessor extends ResolverProcessor implements GrMeth
|
||||
final PsiParameter[] plusParameters = method.getParameterList().getParameters();
|
||||
final PsiParameter[] defParameters = another.getParameterList().getParameters();
|
||||
|
||||
final PsiType[] paramTypes = new PsiType[plusParameters.length];
|
||||
final PsiType[] paramTypes = PsiType.createArray(plusParameters.length);
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
paramTypes[i] = eliminateOneMethodInterfaces(plusParameters[i], defParameters, i);
|
||||
|
||||
@@ -274,7 +276,7 @@ public class MethodResolverProcessor extends ResolverProcessor implements GrMeth
|
||||
method1 = ((GrGdkMethod)method1).getStaticMethod();
|
||||
method2 = ((GrGdkMethod)method2).getStaticMethod();
|
||||
if (myArgumentTypes != null) {
|
||||
argTypes = new PsiType[argTypes.length + 1];
|
||||
argTypes = PsiType.createArray(argTypes.length + 1);
|
||||
System.arraycopy(myArgumentTypes, 0, argTypes, 1, myArgumentTypes.length);
|
||||
argTypes[0] = myThisType;
|
||||
}
|
||||
@@ -349,6 +351,7 @@ public class MethodResolverProcessor extends ResolverProcessor implements GrMeth
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasCandidates() {
|
||||
return super.hasCandidates() || !myInapplicableCandidates.isEmpty();
|
||||
}
|
||||
@@ -357,6 +360,7 @@ public class MethodResolverProcessor extends ResolverProcessor implements GrMeth
|
||||
return super.hasCandidates();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiType[] getArgumentTypes() {
|
||||
return myArgumentTypes;
|
||||
|
||||
+3
-3
@@ -126,7 +126,7 @@ public class SubstitutorComputer {
|
||||
final PsiElement resolveContext = state.get(ResolverProcessor.RESOLVE_CONTEXT);
|
||||
if (method instanceof GrGdkMethod) {
|
||||
//type inference should be performed from static method
|
||||
PsiType[] newArgTypes = new PsiType[argTypes.length + 1];
|
||||
PsiType[] newArgTypes = PsiType.createArray(argTypes.length + 1);
|
||||
if (GdkMethodUtil.isInWithContext(resolveContext)) {
|
||||
newArgTypes[0] = ((GrExpression)resolveContext).getType();
|
||||
}
|
||||
@@ -163,8 +163,8 @@ public class SubstitutorComputer {
|
||||
|
||||
int max = Math.max(params.length, argTypes.length);
|
||||
|
||||
PsiType[] parameterTypes = new PsiType[max];
|
||||
PsiType[] argumentTypes = new PsiType[max];
|
||||
PsiType[] parameterTypes = PsiType.createArray(max);
|
||||
PsiType[] argumentTypes = PsiType.createArray(max);
|
||||
int i = 0;
|
||||
for (int paramIndex = 0; paramIndex < argInfos.length; paramIndex++) {
|
||||
PsiType paramType = params[paramIndex].getType();
|
||||
|
||||
+2
-2
@@ -113,7 +113,7 @@ public class TypeProvider {
|
||||
final GrParameter[] parameters = method.getParameters();
|
||||
|
||||
final TIntArrayList paramInds = new TIntArrayList(parameters.length);
|
||||
final PsiType[] types = new PsiType[parameters.length];
|
||||
final PsiType[] types = PsiType.createArray(parameters.length);
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
if (parameters[i].getTypeElementGroovy() == null) {
|
||||
paramInds.add(i);
|
||||
@@ -122,7 +122,7 @@ public class TypeProvider {
|
||||
}
|
||||
}
|
||||
|
||||
if (paramInds.size() > 0) {
|
||||
if (!paramInds.isEmpty()) {
|
||||
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, PsiSubstitutor.EMPTY);
|
||||
MethodReferencesSearch.search(method, true).forEach(new Processor<PsiReference>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user