本文整理汇总了Java中com.intellij.lang.javascript.psi.JSExpression.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java JSExpression.getParent方法的具体用法?Java JSExpression.getParent怎么用?Java JSExpression.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.lang.javascript.psi.JSExpression
的用法示例。
在下文中一共展示了JSExpression.getParent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findExpressionInRange
import com.intellij.lang.javascript.psi.JSExpression; //导入方法依赖的package包/类
private static JSExpression findExpressionInRange(PsiFile file, int startOffset, int endOffset)
{
PsiElement element1 = file.findElementAt(startOffset);
PsiElement element2 = file.findElementAt(endOffset - 1);
if(element1 instanceof PsiWhiteSpace)
{
startOffset = element1.getTextRange().getEndOffset();
}
if(element2 instanceof PsiWhiteSpace)
{
endOffset = element2.getTextRange().getStartOffset();
}
JSExpression expression = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, JSExpression.class);
if(expression == null || expression.getTextRange().getEndOffset() != endOffset)
{
return null;
}
if(expression instanceof JSReferenceExpression && expression.getParent() instanceof JSCallExpression)
{
return null;
}
return expression;
}
示例2: replaceExpression
import com.intellij.lang.javascript.psi.JSExpression; //导入方法依赖的package包/类
protected static void replaceExpression(JSExpression expression,
String newExpression)
throws IncorrectOperationException {
final ASTNode fromText = JSChangeUtil.createStatementFromText(expression.getProject(), newExpression + ';');
final PsiElement element = fromText != null ? fromText.getPsi() : null;
final JSExpressionStatement expressionStatement = element instanceof JSExpressionStatement ? (JSExpressionStatement) element:null;
if (expressionStatement == null) {
return;
}
final JSExpression newExp = expressionStatement.getExpression();
final ASTNode newExpressionNode = newExp.getNode();
final ASTNode expressionNode = expression.getNode();
final PsiElement parent = expression.getParent();
final ASTNode parentNode = parent.getNode();
parentNode.replaceChild(expressionNode, newExpressionNode);
// final CodeStyleManager styleManager = manager.getCodeStyleManager();
// styleManager.reformat(newExpressionNode.getPsi());
}
示例3: replaceExpression
import com.intellij.lang.javascript.psi.JSExpression; //导入方法依赖的package包/类
public static JSExpression replaceExpression(@NotNull JSExpression expression,
@NotNull JSExpression newExpression)
throws IncorrectOperationException {
final ASTNode newExpressionNode = newExpression.getNode();
final ASTNode oldExpressionNode = expression.getNode();
final PsiElement parentNode = expression.getParent();
final ASTNode grandParentNode = parentNode.getNode();
if (grandParentNode == null || oldExpressionNode == null || newExpressionNode == null) {
return null;
}
grandParentNode.replaceChild(oldExpressionNode, newExpressionNode);
reformat(parentNode);
return (JSExpression) newExpressionNode.getPsi();
}
示例4: isNeedParenthesis
import com.intellij.lang.javascript.psi.JSExpression; //导入方法依赖的package包/类
public static boolean isNeedParenthesis(JSExpression oldExpr, JSExpression newExpr)
{
int priority = getExpressionPrecedence(newExpr);
final PsiElement parent = oldExpr.getParent();
if(!(parent instanceof JSExpression))
{
return false;
}
int parentPriority = getExpressionPrecedence((JSExpression) parent);
if(priority < parentPriority)
{
return true;
}
if(priority == parentPriority && parent instanceof JSBinaryExpression)
{
final IElementType operationSign = ((JSBinaryExpression) parent).getOperationSign();
if(oldExpr != ((JSBinaryExpression) parent).getROperand())
{
return false;
}
if(!ASSOC_OPERATIONS.contains(operationSign))
{
return true;
}
return (((JSBinaryExpression) newExpr).getOperationSign() != operationSign);
}
return false;
}
示例5: isParentBoolean
import com.intellij.lang.javascript.psi.JSExpression; //导入方法依赖的package包/类
private boolean isParentBoolean(JSExpression expression) {
final PsiElement parent = expression.getParent();
if (!(parent instanceof JSExpression)) {
return false;
}
return isBoolean((JSExpression) parent);
}