/* * 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. * 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; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiType; import com.intellij.psi.tree.IElementType; 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.psi.api.statements.expressions.GrOperatorExpression; import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.binaryCalculators.GrBinaryExpressionTypeCalculators; abstract public class GrOperatorExpressionImpl extends GrExpressionImpl implements GrOperatorExpression { protected GrOperatorExpressionImpl(@NotNull ASTNode node) { super(node); } @Nullable @Override public PsiType getType() { return TypeInferenceHelper.getCurrentContext().getExpressionType(this, GrBinaryExpressionTypeCalculators::computeType); } @Override @NotNull public IElementType getOperationTokenType() { return getOperationToken().getNode().getElementType(); } @Override public PsiElement getElement() { return this; } @Override public TextRange getRangeInElement() { final PsiElement token = getOperationToken(); final int offset = token.getStartOffsetInParent(); return new TextRange(offset, offset + token.getTextLength()); } @Override public PsiElement resolve() { return PsiImplUtil.extractUniqueElement(multiResolve(false)); } @Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { throw new IncorrectOperationException("assignment expression cannot be renamed"); } @Override public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { throw new IncorrectOperationException("assignment expression cannot be bound to anything"); } @Override public boolean isReferenceTo(PsiElement element) { return getManager().areElementsEquivalent(resolve(), element); } @NotNull @Override public Object[] getVariants() { return ArrayUtil.EMPTY_OBJECT_ARRAY; } @Override public boolean isSoft() { return false; } @NotNull @Override public String getCanonicalText() { return getText(); } }