Cleanup (unneeded anonymous classes)

This commit is contained in:
Roman Shevchenko
2016-02-11 12:23:40 +01:00
parent 950c87d29c
commit b6de74f18b
3 changed files with 54 additions and 80 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -22,27 +22,19 @@ import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
abstract class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBinaryExpression {
class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBinaryExpression {
private final ClsElementImpl myParent;
private final PsiJavaToken myOperator;
private final PsiExpression myLOperand;
private final PsiJavaToken myOperation;
private final PsiExpression myROperand;
ClsBinaryExpressionImpl(@NotNull ClsElementImpl parent) {
ClsBinaryExpressionImpl(ClsElementImpl parent, PsiJavaToken sign, PsiExpression left, PsiExpression right) {
myParent = parent;
myLOperand = createLOperand();
myOperation = createOperation();
myROperand = createROperand();
myOperator = new ClsJavaTokenImpl(this, sign.getTokenType(), sign.getText());
myLOperand = ClsParsingUtil.psiToClsExpression(left, this);
myROperand = ClsParsingUtil.psiToClsExpression(right, this);
}
@NotNull
protected abstract PsiJavaToken createOperation();
@NotNull
protected abstract PsiExpression createLOperand();
@NotNull
protected abstract ClsLiteralExpressionImpl createROperand();
@Override
public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) {
buffer.append(getText());
@@ -55,13 +47,13 @@ abstract class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBina
@Override
public String getText() {
return StringUtil.join(myLOperand.getText(), " ", myOperation.getText(), " ", myROperand.getText());
return StringUtil.join(myLOperand.getText(), " ", myOperator.getText(), " ", myROperand.getText());
}
@NotNull
@Override
public PsiElement[] getChildren() {
return new PsiElement[]{myLOperand, myOperation, myROperand};
return new PsiElement[]{myLOperand, myOperator, myROperand};
}
@Override
@@ -94,13 +86,13 @@ abstract class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBina
@NotNull
@Override
public PsiJavaToken getOperationSign() {
return myOperation;
return myOperator;
}
@NotNull
@Override
public IElementType getOperationTokenType() {
return myOperation.getTokenType();
return myOperator.getTokenType();
}
@Override
@@ -123,4 +115,4 @@ abstract class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBina
public String toString() {
return "PsiBinaryExpression:" + getText();
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -117,29 +117,24 @@ public class ClsParsingUtil {
}
}
private static PsiExpression psiToClsExpression(@NotNull PsiExpression expr, @Nullable ClsElementImpl parent) {
static PsiExpression psiToClsExpression(@NotNull PsiExpression expr, @NotNull ClsElementImpl parent) {
if (expr instanceof PsiLiteralExpression) {
if (parent != null && ((ClsFileImpl)parent.getContainingFile()).isForDecompiling()) {
return new ClsLiteralExpressionImpl(parent, expr.getText(), PsiType.NULL, null);
}
return new ClsLiteralExpressionImpl(parent, expr.getText(), expr.getType(), ((PsiLiteralExpression)expr).getValue());
boolean forDecompiling = ((ClsFileImpl)parent.getContainingFile()).isForDecompiling();
PsiType type = forDecompiling ? PsiType.NULL : expr.getType();
Object value = forDecompiling ? null : ((PsiLiteralExpression)expr).getValue();
return new ClsLiteralExpressionImpl(parent, expr.getText(), type, value);
}
if (expr instanceof PsiPrefixExpression) {
final PsiPrefixExpression prefixExpr = (PsiPrefixExpression)expr;
return new ClsPrefixExpressionImpl(parent){
@NotNull
@Override
protected PsiJavaToken createOperation() {
return new ClsJavaTokenImpl(this, prefixExpr.getOperationTokenType(), prefixExpr.getOperationSign().getText());
}
@NotNull
@Override
protected PsiExpression createOperand() {
return psiToClsExpression(prefixExpr.getOperand(), this);
}
};
if (expr instanceof PsiPrefixExpression) {
PsiJavaToken sign = ((PsiPrefixExpression)expr).getOperationSign();
PsiExpression operand = ((PsiPrefixExpression)expr).getOperand();
if (operand == null) {
LOG.error("Invalid prefix expression: " + expr + " [" + expr.getText() + "]");
return null;
}
return new ClsPrefixExpressionImpl(parent, sign, operand);
}
if (expr instanceof PsiClassObjectAccessExpression) {
String exprText = expr.getText();
if (StringUtil.endsWith(exprText, ".class")) {
@@ -147,36 +142,28 @@ public class ClsParsingUtil {
return new ClsClassObjectAccessExpressionImpl(parent, classText);
}
}
if (expr instanceof PsiReferenceExpression) {
return new ClsReferenceExpressionImpl(parent, (PsiReferenceExpression)expr);
}
if (expr instanceof PsiBinaryExpression) {
final PsiBinaryExpression binaryExpr = (PsiBinaryExpression)expr;
return new ClsBinaryExpressionImpl(parent){
@NotNull
@Override
protected PsiJavaToken createOperation() {
return new ClsJavaTokenImpl(this, binaryExpr.getOperationTokenType(), binaryExpr.getOperationSign().getText());
}
@NotNull
@Override
protected PsiExpression createLOperand() {
return psiToClsExpression(binaryExpr.getLOperand(), this);
}
@NotNull
@Override
protected ClsLiteralExpressionImpl createROperand() {
return (ClsLiteralExpressionImpl)psiToClsExpression(binaryExpr.getROperand(), this);
}
};
PsiJavaToken sign = ((PsiBinaryExpression)expr).getOperationSign();
PsiExpression left = ((PsiBinaryExpression)expr).getLOperand();
PsiExpression right = ((PsiBinaryExpression)expr).getROperand();
if (right == null) {
LOG.error("Invalid binary expression: " + expr + " [" + expr.getText() + "]");
return null;
}
return new ClsBinaryExpressionImpl(parent, sign, left, right);
}
if (parent != null && ((ClsFileImpl)parent.getContainingFile()).isForDecompiling()) {
if (((ClsFileImpl)parent.getContainingFile()).isForDecompiling()) {
return new ClsLiteralExpressionImpl(parent, expr.getText(), PsiType.NULL, null);
}
final PsiConstantEvaluationHelper evaluator = JavaPsiFacade.getInstance(expr.getProject()).getConstantEvaluationHelper();
final Object value = evaluator.computeConstantExpression(expr);
PsiConstantEvaluationHelper evaluator = JavaPsiFacade.getInstance(expr.getProject()).getConstantEvaluationHelper();
Object value = evaluator.computeConstantExpression(expr);
if (value != null) {
return new ClsLiteralExpressionImpl(parent, expr.getText(), expr.getType(), value);
}
@@ -217,4 +204,4 @@ public class ClsParsingUtil {
return null;
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -22,22 +22,17 @@ import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
abstract class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPrefixExpression {
class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPrefixExpression {
private final ClsElementImpl myParent;
private final PsiJavaToken myOperation;
private final PsiJavaToken myOperator;
private final PsiExpression myOperand;
ClsPrefixExpressionImpl(ClsElementImpl parent) {
ClsPrefixExpressionImpl(ClsElementImpl parent, PsiJavaToken sign, PsiExpression operand) {
myParent = parent;
myOperation = createOperation();
myOperand = createOperand();
myOperator = new ClsJavaTokenImpl(this, sign.getTokenType(), sign.getText());
myOperand = ClsParsingUtil.psiToClsExpression(operand, this);
}
@NotNull
protected abstract PsiExpression createOperand();
@NotNull
protected abstract PsiJavaToken createOperation();
@NotNull
@Override
public PsiExpression getOperand() {
@@ -47,13 +42,13 @@ abstract class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPref
@NotNull
@Override
public PsiJavaToken getOperationSign() {
return myOperation;
return myOperator;
}
@NotNull
@Override
public IElementType getOperationTokenType() {
return myOperation.getTokenType();
return myOperator.getTokenType();
}
@Override
@@ -69,12 +64,12 @@ abstract class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPref
@NotNull
@Override
public PsiElement[] getChildren() {
return new PsiElement[]{myOperation, myOperand};
return new PsiElement[]{myOperator, myOperand};
}
@Override
public String getText() {
return StringUtil.join(myOperation.getText(), myOperand.getText());
return StringUtil.join(myOperator.getText(), myOperand.getText());
}
@Override
@@ -101,4 +96,4 @@ abstract class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPref
public String toString() {
return "PsiPrefixExpression:" + getText();
}
}
}