diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java index 7913e923b5f6..0c2358a8472d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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,37 +22,26 @@ import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; -public class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBinaryExpression { +abstract class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBinaryExpression { private final ClsElementImpl myParent; private final PsiExpression myLOperand; private final PsiJavaToken myOperation; private final PsiExpression myROperand; - public ClsBinaryExpressionImpl(ClsElementImpl parent, - ClsLiteralExpressionImpl lOperand, - ClsJavaTokenImpl operation, - ClsLiteralExpressionImpl rOperand) { + ClsBinaryExpressionImpl(@NotNull ClsElementImpl parent) { myParent = parent; - myLOperand = lOperand; - myOperation = operation; - myROperand = rOperand; - lOperand.setParent(this); - operation.setParent(this); - rOperand.setParent(this); + myLOperand = createLOperand(); + myOperation = createOperation(); + myROperand = createROperand(); } - public ClsBinaryExpressionImpl(ClsElementImpl parent, - ClsPrefixExpressionImpl lOperand, - ClsJavaTokenImpl operation, - ClsLiteralExpressionImpl rOperand) { - myParent = parent; - myLOperand = lOperand; - myOperation = operation; - myROperand = rOperand; - lOperand.setParent(this); - operation.setParent(this); - rOperand.setParent(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) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocTagImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocTagImpl.java index 1588e835b9fe..c49d281c65a4 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocTagImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocTagImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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 @@ class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag { private final ClsDocCommentImpl myDocComment; private final PsiElement myNameElement; - public ClsDocTagImpl(ClsDocCommentImpl docComment, @NonNls String name) { + ClsDocTagImpl(ClsDocCommentImpl docComment, @NonNls String name) { myDocComment = docComment; myNameElement = new NameElement(this, name); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaTokenImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaTokenImpl.java index b2b676d08ac7..f871789cdcf9 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaTokenImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaTokenImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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,29 +15,28 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.psi.*; +import com.intellij.psi.JavaElementVisitor; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.PsiJavaToken; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; -public class ClsJavaTokenImpl extends ClsElementImpl implements PsiJavaToken { - private ClsElementImpl myParent; - private final IElementType myTokenType; +class ClsJavaTokenImpl extends ClsElementImpl implements PsiJavaToken { + private final ClsElementImpl myParent; + private final short myTokenTypeIndex; private final String myTokenText; - public ClsJavaTokenImpl(ClsElementImpl parent, IElementType tokenType, String tokenText) { + ClsJavaTokenImpl(ClsElementImpl parent, @NotNull IElementType tokenType, @NotNull String tokenText) { myParent = parent; - myTokenType = tokenType; + myTokenTypeIndex = tokenType.getIndex(); myTokenText = tokenText; } - void setParent(ClsElementImpl parent) { - myParent = parent; - } - @Override public IElementType getTokenType() { - return myTokenType; + return IElementType.find(myTokenTypeIndex); } @Override @@ -63,7 +62,7 @@ public class ClsJavaTokenImpl extends ClsElementImpl implements PsiJavaToken { @Override public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { - setMirrorCheckingType(element, myTokenType); + setMirrorCheckingType(element, getTokenType()); } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsLiteralExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsLiteralExpressionImpl.java index 6fb730d2fba6..c8a37f8bf7d2 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsLiteralExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsLiteralExpressionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -20,23 +20,19 @@ import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.impl.source.tree.TreeElement; import org.jetbrains.annotations.NotNull; -public class ClsLiteralExpressionImpl extends ClsElementImpl implements PsiLiteralExpression { - private ClsElementImpl myParent; +class ClsLiteralExpressionImpl extends ClsElementImpl implements PsiLiteralExpression { + private final ClsElementImpl myParent; private final String myText; private final PsiType myType; private final Object myValue; - public ClsLiteralExpressionImpl(ClsElementImpl parent, String text, PsiType type, Object value) { + ClsLiteralExpressionImpl(ClsElementImpl parent, String text, PsiType type, Object value) { myParent = parent; myText = text; myType = type; myValue = value; } - void setParent(ClsElementImpl parent) { - myParent = parent; - } - @Override public PsiType getType() { return myType; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java index e04e934b9f57..dad701d931df 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -43,7 +43,6 @@ import javax.swing.*; public class ClsParameterImpl extends ClsRepositoryPsiElement implements PsiParameter { private final NotNullLazyValue myType; - private volatile String myName; private volatile String myMirrorName; public ClsParameterImpl(@NotNull PsiParameterStub stub) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParsingUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParsingUtil.java index 6f7be2592990..ce5719f4e13c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParsingUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParsingUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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,20 +117,28 @@ public class ClsParsingUtil { } } - private static PsiExpression psiToClsExpression(PsiExpression expr, @Nullable ClsElementImpl parent) { + private static PsiExpression psiToClsExpression(@NotNull PsiExpression expr, @Nullable ClsElementImpl parent) { if (expr instanceof PsiLiteralExpression) { if (parent != null && ((ClsFileImpl)parent.getContainingFile()).isForDecompiling()) { return new ClsLiteralExpressionImpl(parent, expr.getText(), PsiType.NULL, null); } - else { - return new ClsLiteralExpressionImpl(parent, expr.getText(), expr.getType(), ((PsiLiteralExpression)expr).getValue()); - } + return new ClsLiteralExpressionImpl(parent, expr.getText(), expr.getType(), ((PsiLiteralExpression)expr).getValue()); } if (expr instanceof PsiPrefixExpression) { - PsiPrefixExpression prefixExpr = (PsiPrefixExpression)expr; - ClsJavaTokenImpl operation = new ClsJavaTokenImpl(null, prefixExpr.getOperationTokenType(), prefixExpr.getOperationSign().getText()); - ClsLiteralExpressionImpl literal = (ClsLiteralExpressionImpl)psiToClsExpression(prefixExpr.getOperand(), null); - return new ClsPrefixExpressionImpl(parent, operation, literal); + 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 PsiClassObjectAccessExpression) { String exprText = expr.getText(); @@ -143,26 +151,34 @@ public class ClsParsingUtil { return new ClsReferenceExpressionImpl(parent, (PsiReferenceExpression)expr); } if (expr instanceof PsiBinaryExpression) { - PsiBinaryExpression binaryExpr = (PsiBinaryExpression)expr; - PsiExpression lOperand = psiToClsExpression(binaryExpr.getLOperand(), null); - ClsJavaTokenImpl operation = new ClsJavaTokenImpl(null, binaryExpr.getOperationTokenType(), binaryExpr.getOperationSign().getText()); - PsiExpression rOperand = psiToClsExpression(binaryExpr.getROperand(), null); - if (lOperand instanceof ClsLiteralExpressionImpl) { - return new ClsBinaryExpressionImpl(parent, (ClsLiteralExpressionImpl)lOperand, operation, (ClsLiteralExpressionImpl)rOperand); - } - else if (lOperand instanceof ClsPrefixExpressionImpl) { - return new ClsBinaryExpressionImpl(parent, (ClsPrefixExpressionImpl)lOperand, operation, (ClsLiteralExpressionImpl)rOperand); - } + 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); + } + }; } - else { - if (parent != null && ((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); - if (value != null) { - return new ClsLiteralExpressionImpl(parent, expr.getText(), expr.getType(), value); - } + if (parent != null && ((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); + if (value != null) { + return new ClsLiteralExpressionImpl(parent, expr.getText(), expr.getType(), value); } LOG.error("Unable to compute expression value: " + expr + " [" + expr.getText() + "]"); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsPrefixExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsPrefixExpressionImpl.java index 854945a62e10..1aed2f87373b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsPrefixExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsPrefixExpressionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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,21 @@ import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; -public class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPrefixExpression { - private ClsElementImpl myParent; +abstract class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPrefixExpression { + private final ClsElementImpl myParent; private final PsiJavaToken myOperation; private final PsiExpression myOperand; - public ClsPrefixExpressionImpl(ClsElementImpl parent, ClsJavaTokenImpl operation, ClsLiteralExpressionImpl operand) { + ClsPrefixExpressionImpl(ClsElementImpl parent) { myParent = parent; - myOperation = operation; - myOperand = operand; - operation.setParent(this); - operand.setParent(this); + myOperation = createOperation(); + myOperand = createOperand(); } - void setParent(ClsElementImpl parent) { - myParent = parent; - } + @NotNull + protected abstract PsiExpression createOperand(); + @NotNull + protected abstract PsiJavaToken createOperation(); @NotNull @Override