dead code

This commit is contained in:
Max Medvedev
2013-09-20 17:35:31 +04:00
parent a712f87da8
commit 732cafd6d6
6 changed files with 0 additions and 446 deletions
@@ -1,8 +0,0 @@
package org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions;
/**
* @author ilyas
*/
public interface GrSuperReferenceExpression extends GrThisSuperReferenceExpression {
}
@@ -1,8 +0,0 @@
package org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions;
/**
* @author ilyas
*/
public interface GrThisReferenceExpression extends GrThisSuperReferenceExpression {
}
@@ -1,34 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPolyVariantReference;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.GrQualifiedReference;
/**
* @author Maxim.Medvedev
*/
public interface GrThisSuperReferenceExpression extends GrExpression, PsiPolyVariantReference, GrQualifiedReference<GrReferenceExpression> {
@NotNull
@Override
PsiElement getReferenceNameElement();
@NotNull
@Override
String getReferenceName();
}
@@ -1,118 +0,0 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions;
import com.intellij.lang.ASTNode;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.NullableFunction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSuperReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper;
import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil;
/**
* @author ilyas
*/
public class GrSuperReferenceExpressionImpl extends GrThisSuperReferenceExpressionBase implements GrSuperReferenceExpression {
private static final NullableFunction<GrSuperReferenceExpressionImpl, PsiType> TYPE_CALCULATOR =
new NullableFunction<GrSuperReferenceExpressionImpl, PsiType>() {
@Override
public PsiType fun(GrSuperReferenceExpressionImpl ref) {
final GrReferenceExpression qualifier = ref.getQualifier();
if (qualifier == null) {
GroovyPsiElement context = PsiTreeUtil.getParentOfType(ref, GrTypeDefinition.class, GroovyFileBase.class);
if (context instanceof GrTypeDefinition) {
final PsiClass superClass = ((GrTypeDefinition)context).getSuperClass();
if (superClass != null) {
return JavaPsiFacade.getInstance(ref.getProject()).getElementFactory().createType(superClass);
}
}
else if (context instanceof GroovyFileBase) {
PsiClass scriptClass = ((GroovyFileBase)context).getScriptClass();
if (scriptClass != null) {
PsiClass superClass = scriptClass.getSuperClass();
if (superClass != null) {
return JavaPsiFacade.getInstance(ref.getProject()).getElementFactory().createType(superClass);
}
}
return GrClassImplUtil.getGroovyObjectType(ref);
}
}
else {
final PsiElement resolved = qualifier.resolve();
if (resolved instanceof PsiClass) {
return ref.getSuperType((PsiClass)resolved);
}
}
return null;
}
};
public GrSuperReferenceExpressionImpl(@NotNull ASTNode node) {
super(node);
}
public void accept(GroovyElementVisitor visitor) {
}
public String toString() {
return "'super' reference expression";
}
public PsiType getType() {
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
}
@Nullable
private PsiType getSuperType(PsiClass aClass) {
if (aClass.isInterface()) {
return PsiType.getJavaLangObject(getManager(), getResolveScope());
}
if (aClass instanceof GrAnonymousClassDefinition) {
final PsiClassType baseClassType = ((GrAnonymousClassDefinition)aClass).getBaseClassType();
final PsiClass psiClass = baseClassType.resolve();
if (psiClass != null && !psiClass.isInterface()) {
return baseClassType;
}
return PsiType.getJavaLangObject(getManager(), getResolveScope());
}
if (CommonClassNames.JAVA_LANG_OBJECT.equals(aClass.getQualifiedName())) return null;
PsiClassType[] superTypes = aClass.getExtendsListTypes();
if (superTypes.length == 0) {
return PsiType.getJavaLangObject(getManager(), getResolveScope());
}
return superTypes[0];
}
@Override
public String getReferenceName() {
return "super";
}
}
@@ -1,131 +0,0 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions;
import com.intellij.lang.ASTNode;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.NullableFunction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrThisReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper;
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
import org.jetbrains.plugins.groovy.lang.psi.util.StaticChecker;
/**
* @author ilyas
*/
public class GrThisReferenceExpressionImpl extends GrThisSuperReferenceExpressionBase implements GrThisReferenceExpression {
private static final NullableFunction<GrThisReferenceExpressionImpl, PsiType> TYPE_CALCULATOR =
new NullableFunction<GrThisReferenceExpressionImpl, PsiType>() {
@Override
public PsiType fun(GrThisReferenceExpressionImpl ref) {
if (ref.getQualifier() == null) {
return resolveNonQualified(ref);
}
else {
return resolveQualified(ref);
}
}
@Nullable
private PsiType resolveQualified(GrThisReferenceExpressionImpl ref) {
GrReferenceExpression qualifier = ref.getQualifier();
assert qualifier != null;
final PsiElement resolved = qualifier.resolve();
try {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(ref.getProject());
if (resolved instanceof PsiClass) {
return factory.createType((PsiClass)resolved);
}
else {
return factory.createTypeFromText(qualifier.getText(), ref);
}
}
catch (IncorrectOperationException e) {
return null;
}
}
@Nullable
private PsiType resolveNonQualified(GrThisReferenceExpressionImpl ref) {
PsiClass context = PsiUtil.getContextClass(ref);
if (context != null) {
return ref.createType(context);
}
else {
return null;
}
}
};
public GrThisReferenceExpressionImpl(@NotNull ASTNode node) {
super(node);
}
public void accept(GroovyElementVisitor visitor) {
}
public String toString() {
return "'this' reference expression";
}
public PsiType getType() {
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, TYPE_CALCULATOR);
}
private PsiType createType(@NotNull PsiClass context) {
final JavaPsiFacade facade = JavaPsiFacade.getInstance(context.getProject());
PsiElementFactory elementFactory = facade.getElementFactory();
if (!StaticChecker.isInStaticContext(this)) return elementFactory.createType(context);
//create instance of java.lang.Class<CurrentClass>
if (context instanceof PsiAnonymousClass) {
final PsiClassType type = ((PsiAnonymousClass)context).getBaseClassType();
final PsiClass aClass = facade.findClass(CommonClassNames.JAVA_LANG_CLASS, context.getResolveScope());
if (aClass != null) {
return elementFactory.createType(aClass, type);
}
else {
return elementFactory.createTypeFromText(CommonClassNames.JAVA_LANG_CLASS + "<" + type.getCanonicalText() + ">", this);
}
}
return elementFactory.createTypeFromText(CommonClassNames.JAVA_LANG_CLASS + "<" + context.getName() + ">", this);
}
@NotNull
@Override
public String getReferenceName() {
return "this";
}
@Override
protected PsiElement resolveInner() {
final PsiElement resolved = super.resolveInner();
if (resolved != null) return resolved;
final GrReferenceExpression qualifier = getQualifier();
if (qualifier != null) {
return qualifier.resolve();
}
return PsiUtil.getContextClass(this);
}
}
@@ -1,147 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.ResolveResult;
import com.intellij.psi.impl.source.resolve.ResolveCache;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrThisSuperReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper;
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl;
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
/**
* @author Maxim.Medvedev
*/
public abstract class GrThisSuperReferenceExpressionBase extends GrExpressionImpl implements GrThisSuperReferenceExpression {
private static final OurResolver OUR_RESOLVER = new OurResolver();
public GrThisSuperReferenceExpressionBase(ASTNode node) {
super(node);
}
@Nullable
public GrReferenceExpression getQualifier() {
return (GrReferenceExpression)findChildByType(GroovyElementTypes.REFERENCE_EXPRESSION);
}
@Override
public void setQualifier(@Nullable GrReferenceExpression newQualifier) {
PsiImplUtil.setQualifier(this, newQualifier);
}
@NotNull
@Override
public PsiElement getReferenceNameElement() {
return getLastChild();
}
@Override
public boolean isQualified() {
return getQualifier() != null;
}
@Override
public PsiElement getElement() {
return this;
}
@Override
public TextRange getRangeInElement() {
final PsiElement token = findNotNullChildByType(TokenSet.create(GroovyTokenTypes.kTHIS, GroovyTokenTypes.kSUPER));
return TextRange.from(token.getStartOffsetInParent(), token.getTextLength());
}
@Override
public PsiElement resolve() {
final ResolveResult[] results = TypeInferenceHelper.getCurrentContext().multiResolve(this, false, OUR_RESOLVER);
if (results.length == 1) return results[0].getElement();
return null;
}
@Nullable
protected PsiElement resolveInner() {
final PsiElement parent = getParent();
if (parent instanceof GrConstructorInvocation) {
return ((GrConstructorInvocation)parent).resolveMethod();
}
return null;
}
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
return this;
}
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
return this;
}
public boolean isReferenceTo(PsiElement element) {
return getManager().areElementsEquivalent(element, resolve());
}
@NotNull
public Object[] getVariants() {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
public boolean isSoft() {
return false;
}
@Override
public PsiReference getReference() {
return this;
}
@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode) {
final PsiElement parent = getParent();
if (parent instanceof GrConstructorInvocation) {
return ((GrConstructorInvocation)parent).multiResolve(incompleteCode);
}
return ResolveResult.EMPTY_ARRAY;
}
@NotNull
@Override
public String getCanonicalText() {
return getReferenceName();
}
static class OurResolver implements ResolveCache.PolyVariantResolver<GrThisSuperReferenceExpressionBase> {
@NotNull
@Override
public ResolveResult[] resolve(@NotNull GrThisSuperReferenceExpressionBase ref, boolean incompleteCode) {
final PsiElement resolved = ref.resolveInner();
if (resolved == null) return ResolveResult.EMPTY_ARRAY;
return new GroovyResolveResult[]{new GroovyResolveResultImpl(resolved, true)};
}
}
}