mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (dead code; readability; typos; annotations)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -27,32 +28,6 @@ public class PsiCapturedWildcardType extends PsiType {
|
||||
@NotNull private final PsiElement myContext;
|
||||
@Nullable private final PsiTypeParameter myParameter;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof PsiCapturedWildcardType)) return false;
|
||||
final PsiCapturedWildcardType captured = (PsiCapturedWildcardType)o;
|
||||
if (!myContext.equals(captured.myContext) ||
|
||||
!myExistential.equals(captured.myExistential)) return false;
|
||||
|
||||
if (myContext instanceof PsiReferenceExpression) {
|
||||
if (myParameter != null ? !myParameter.equals(captured.myParameter) : captured.myParameter != null) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myExistential.hashCode() + 31 * myContext.hashCode();
|
||||
}
|
||||
|
||||
private PsiCapturedWildcardType(@NotNull PsiWildcardType existential, @NotNull PsiElement context, @Nullable PsiTypeParameter parameter) {
|
||||
super(PsiAnnotation.EMPTY_ARRAY);//todo
|
||||
myExistential = existential;
|
||||
myContext = context;
|
||||
myParameter = parameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiCapturedWildcardType create(@NotNull PsiWildcardType existential, @NotNull PsiElement context) {
|
||||
return create(existential, context, null);
|
||||
@@ -61,10 +36,40 @@ public class PsiCapturedWildcardType extends PsiType {
|
||||
@NotNull
|
||||
public static PsiCapturedWildcardType create(@NotNull PsiWildcardType existential,
|
||||
@NotNull PsiElement context,
|
||||
PsiTypeParameter parameter) {
|
||||
@Nullable PsiTypeParameter parameter) {
|
||||
return new PsiCapturedWildcardType(existential, context, parameter);
|
||||
}
|
||||
|
||||
private PsiCapturedWildcardType(@NotNull PsiWildcardType existential, @NotNull PsiElement context, @Nullable PsiTypeParameter parameter) {
|
||||
super(PsiAnnotation.EMPTY_ARRAY);
|
||||
myExistential = existential;
|
||||
myContext = context;
|
||||
myParameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof PsiCapturedWildcardType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiCapturedWildcardType captured = (PsiCapturedWildcardType)o;
|
||||
if (!myContext.equals(captured.myContext) || !myExistential.equals(captured.myExistential)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (myContext instanceof PsiReferenceExpression && !Comparing.equal(myParameter, captured.myParameter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myExistential.hashCode() + 31 * myContext.hashCode();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
@@ -80,7 +85,6 @@ public class PsiCapturedWildcardType extends PsiType {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getInternalCanonicalText() {
|
||||
//noinspection HardCodedStringLiteral
|
||||
return "capture<" + myExistential.getInternalCanonicalText() + '>';
|
||||
}
|
||||
|
||||
@@ -99,6 +103,7 @@ public class PsiCapturedWildcardType extends PsiType {
|
||||
return visitor.visitCapturedWildcardType(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GlobalSearchScope getResolveScope() {
|
||||
return myExistential.getResolveScope();
|
||||
@@ -119,10 +124,11 @@ public class PsiCapturedWildcardType extends PsiType {
|
||||
if (myExistential.isExtends()) {
|
||||
return bound;
|
||||
}
|
||||
else if (bound instanceof PsiCapturedWildcardType) {
|
||||
return PsiWildcardType.createSuper(myContext.getManager(), ((PsiCapturedWildcardType)bound).getUpperBound());
|
||||
}
|
||||
else {
|
||||
return bound instanceof PsiCapturedWildcardType
|
||||
? PsiWildcardType.createSuper(myContext.getManager(), ((PsiCapturedWildcardType)bound).getUpperBound())
|
||||
: PsiType.getJavaLangObject(myContext.getManager(), getResolveScope());
|
||||
return PsiType.getJavaLangObject(myContext.getManager(), getResolveScope());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.RecursionGuard;
|
||||
import com.intellij.openapi.util.RecursionManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -74,24 +73,17 @@ public abstract class PsiDiamondType extends PsiType {
|
||||
|
||||
private final List<PsiType> myInferredTypes = new ArrayList<PsiType>();
|
||||
private String myErrorMessage;
|
||||
|
||||
private String myNewExpressionPresentableText;
|
||||
private Project myProject;
|
||||
|
||||
public DiamondInferenceResult() {
|
||||
}
|
||||
public DiamondInferenceResult() { }
|
||||
|
||||
public DiamondInferenceResult(String expressionPresentableText, Project project) {
|
||||
public DiamondInferenceResult(String expressionPresentableText) {
|
||||
myNewExpressionPresentableText = expressionPresentableText;
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiType[] getTypes() {
|
||||
if (myErrorMessage != null) {
|
||||
return PsiType.EMPTY_ARRAY;
|
||||
}
|
||||
return myInferredTypes.toArray(createArray(myInferredTypes.size()));
|
||||
return myErrorMessage == null ? myInferredTypes.toArray(createArray(myInferredTypes.size())) : PsiType.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,48 +105,12 @@ public abstract class PsiDiamondType extends PsiType {
|
||||
if (myErrorMessage != null) return;
|
||||
if (psiType == null) {
|
||||
myErrorMessage = "Cannot infer type arguments for " + myNewExpressionPresentableText;
|
||||
} /*else if (!isValid(psiType)) {
|
||||
myErrorMessage = "Cannot infer type arguments for " +
|
||||
myNewExpressionPresentableText + " because type " + psiType.getPresentableText() + " inferred is not allowed in current context";
|
||||
}*/ else {
|
||||
}
|
||||
else {
|
||||
myInferredTypes.add(psiType);
|
||||
}
|
||||
}
|
||||
|
||||
private static Boolean isValid(PsiType type) {
|
||||
return type.accept(new PsiTypeVisitor<Boolean>() {
|
||||
@Override
|
||||
public Boolean visitType(PsiType type) {
|
||||
return !(type instanceof PsiIntersectionType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitCapturedWildcardType(PsiCapturedWildcardType capturedWildcardType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitWildcardType(PsiWildcardType wildcardType) {
|
||||
final PsiType bound = wildcardType.getBound();
|
||||
if (bound != null) {
|
||||
if (bound instanceof PsiIntersectionType) return false;
|
||||
return bound.accept(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitClassType(PsiClassType classType) {
|
||||
for (PsiType psiType : classType.getParameters()) {
|
||||
if (!psiType.accept(this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,13 +38,14 @@ import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: Jul 30, 2010
|
||||
* @author anna
|
||||
* @since Jul 30, 2010
|
||||
*/
|
||||
public class PsiDiamondTypeImpl extends PsiDiamondType {
|
||||
private static final Logger LOG = Logger.getInstance("#" + PsiDiamondTypeImpl.class.getName());
|
||||
|
||||
private final PsiManager myManager;
|
||||
private final PsiTypeElement myTypeElement;
|
||||
private static final Logger LOG = Logger.getInstance("#" + PsiDiamondTypeImpl.class.getName());
|
||||
|
||||
public PsiDiamondTypeImpl(PsiManager manager, PsiTypeElement psiTypeElement) {
|
||||
super(PsiAnnotation.EMPTY_ARRAY);
|
||||
@@ -77,7 +78,7 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
|
||||
|
||||
@Override
|
||||
public boolean equalsToText(@NotNull @NonNls String text) {
|
||||
return text != null && text.isEmpty();
|
||||
return text.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,6 +86,7 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
|
||||
return visitor.visitDiamondType(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GlobalSearchScope getResolveScope() {
|
||||
return GlobalSearchScope.allScope(myManager.getProject());
|
||||
@@ -145,7 +147,7 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
|
||||
return null;
|
||||
}
|
||||
staticFactoryRef.set(staticFactory);
|
||||
|
||||
|
||||
return inferTypeParametersForStaticFactory(staticFactory, newExpression, context);
|
||||
}
|
||||
});
|
||||
@@ -161,8 +163,7 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
|
||||
final PsiTypeParameter[] classParameters = psiClass.getTypeParameters();
|
||||
final PsiJavaCodeReferenceElement classOrAnonymousClassReference = newExpression.getClassOrAnonymousClassReference();
|
||||
LOG.assertTrue(classOrAnonymousClassReference != null);
|
||||
final DiamondInferenceResult
|
||||
result = new DiamondInferenceResult(classOrAnonymousClassReference.getReferenceName() + "<>", newExpression.getProject());
|
||||
final DiamondInferenceResult result = new DiamondInferenceResult(classOrAnonymousClassReference.getReferenceName() + "<>");
|
||||
for (PsiTypeParameter parameter : parameters) {
|
||||
for (PsiTypeParameter classParameter : classParameters) {
|
||||
if (Comparing.strEqual(classParameter.getName(), parameter.getName())) {
|
||||
@@ -246,7 +247,7 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
|
||||
} else if (reference != null && qualifier == null && containingClass.getContainingClass() != null) {
|
||||
qualifiedName = null;
|
||||
}
|
||||
|
||||
|
||||
buf.append(qualifiedName != null ? qualifiedName : containingClass.getName());
|
||||
final PsiTypeParameter[] parameters = containingClass.getTypeParameters();
|
||||
buf.append("<");
|
||||
@@ -341,8 +342,8 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
|
||||
public Boolean visitClassType(PsiClassType classType) {
|
||||
for (PsiType psiType : classType.getParameters()) {
|
||||
if (psiType != null) {
|
||||
final Boolean typaParamFound = psiType.accept(this);
|
||||
if (typaParamFound != null && typaParamFound) return true;
|
||||
final Boolean typeParamFound = psiType.accept(this);
|
||||
if (typeParamFound != null && typeParamFound) return true;
|
||||
}
|
||||
}
|
||||
final PsiClass aClass = PsiUtil.resolveClassInType(classType);
|
||||
|
||||
Reference in New Issue
Block a user