本文整理汇总了Java中com.intellij.lang.javascript.psi.JSExpressionStatement类的典型用法代码示例。如果您正苦于以下问题:Java JSExpressionStatement类的具体用法?Java JSExpressionStatement怎么用?Java JSExpressionStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSExpressionStatement类属于com.intellij.lang.javascript.psi包,在下文中一共展示了JSExpressionStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceExpression
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的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());
}
示例2: replaceSimplifiableImplicitAssignment
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
public static void replaceSimplifiableImplicitAssignment(JSIfStatement statement, boolean negated)
throws IncorrectOperationException {
final JSElement prevStatement = (JSElement) JSElementFactory.getNonWhiteSpaceSibling(statement, false);
final JSExpression condition = statement.getCondition();
final String conditionText = (negated ? BoolUtils.getNegatedExpressionText(condition) : condition.getText());
final JSExpressionStatement assignmentStatement = (JSExpressionStatement) ConditionalUtils.stripBraces(statement.getThen());
final JSAssignmentExpression assignmentExpression = (JSAssignmentExpression) assignmentStatement.getExpression();
final IElementType operator = assignmentExpression.getOperationSign();
final String operand = BinaryOperatorUtils.getOperatorText(operator);
final JSExpression lhs = assignmentExpression.getLOperand();
final String lhsText = lhs.getText();
JSElementFactory.replaceStatement(statement, lhsText + operand + conditionText + ';');
assert (prevStatement != null);
JSElementFactory.removeElement(prevStatement);
}
示例3: satisfiedBy
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
@Override
public boolean satisfiedBy(@NotNull PsiElement element) {
if (!ExpressionUtil.isIncrementDecrementExpression(element)) {
return false;
}
if (ErrorUtil.containsError(element)) {
return false;
}
final PsiElement parent = element.getParent();
if (parent instanceof JSExpressionStatement) {
return false;
}
final JSStatement containingStatement = TreeUtil.getParentOfType(element, JSStatement.class);
if (element instanceof JSPostfixExpression &&
(containingStatement instanceof JSReturnStatement ||
containingStatement instanceof JSThrowStatement)) {
return false;
}
return (containingStatement != null);
}
示例4: containsTestsInFiles
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
public static boolean containsTestsInFiles(JSFile file)
{
JSSourceElement[] statements = file.getStatements();
for(JSSourceElement statement : statements)
{
if(statement instanceof JSExpressionStatement)
{
JSExpression expression = ((JSExpressionStatement) statement).getExpression();
if(expression instanceof JSCallExpression)
{
JSExpression methodExpression = ((JSCallExpression) expression).getMethodExpression();
if(methodExpression instanceof JSReferenceExpression)
{
JSExpression qualifier = ((JSReferenceExpression) methodExpression).getQualifier();
if(qualifier != null)
{
continue;
}
String referencedName = ((JSReferenceExpression) methodExpression).getReferencedName();
if("describe".equals(referencedName))
{
JSArgumentList argumentList = ((JSCallExpression) expression).getArgumentList();
if(argumentList != null && argumentList.getArguments().length == 2)
{
return true;
}
}
}
}
}
}
return false;
}
示例5: testPropertyIsGenerated
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
@Test
public void testPropertyIsGenerated()
{
List<JSExpressionStatement> methods = new ArrayList<JSExpressionStatement>();
methods.add(new MockJSExpressionStatement(new MockJSAssignmentExpression("util.", "property", "'value'")));
String result = converter.buildUtilPatternString(null, new JSExpression[0], methods, "util");
assertTrue(result.contains("property: 'value'"));
}
示例6: indexPropertyIsConverted
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
@Test
public void indexPropertyIsConverted()
{
List<JSExpressionStatement> methods = new ArrayList<JSExpressionStatement>();
methods.add(new MockJSExpressionStatement(new MockJSAssignmentExpression(new MockJSDefinitionExpressionWithIndexedProperty("util", "'-test-'"), "value")));
String result = converter.buildUtilPatternString(null, new JSExpression[0], methods, "util");
assertTrue(result.contains("-test-': value"));
}
示例7: JavaScriptKeywordCompletionContributor
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
public JavaScriptKeywordCompletionContributor()
{
extend(CompletionType.BASIC, StandardPatterns.psiElement().withParent(JSReferenceExpression.class), new CompletionProvider()
{
@RequiredReadAction
@Override
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result)
{
PsiElement position = parameters.getPosition();
JSReferenceExpression parent = (JSReferenceExpression) position.getParent();
if(parent.getQualifier() != null)
{
return;
}
boolean parentIsStatement = parent.getParent() instanceof JSExpressionStatement;
LookupElementBuilder functionKeyword = LookupElementBuilder.create("function");
functionKeyword = functionKeyword.bold();
if(parentIsStatement)
{
functionKeyword = functionKeyword.withInsertHandler(SpaceInsertHandler.INSTANCE);
}
else
{
functionKeyword = functionKeyword.withInsertHandler(ParenthesesInsertHandler.getInstance(false));
functionKeyword = functionKeyword.withPresentableText("function()");
}
result.addElement(functionKeyword);
result.addElement(LookupElementBuilder.create("var").withInsertHandler(SpaceInsertHandler.INSTANCE).bold());
}
});
}
示例8: getTextEndOffset
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
@Override
public int getTextEndOffset(@NotNull PsiElement element)
{
if(element instanceof JSDefinitionExpression)
{
element = PsiTreeUtil.getParentOfType(element, JSExpressionStatement.class);
}
return element.getTextRange().getEndOffset();
}
示例9: CreateClassDialog
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
protected CreateClassDialog(final Project project, String className, String packageName, boolean isInterface)
{
super(project, false);
setTitle(JavaScriptBundle.message(isInterface ? "create.interface.dialog.title" : "create.class.dialog.title"));
setModal(true);
myPackageName.getDocument().addDocumentListener(new DocumentAdapter()
{
@Override
protected void textChanged(final DocumentEvent e)
{
String text = getPackageName();
boolean enabled;
if(text.length() == 0)
{
enabled = true;
}
else
{
ASTNode node = JSChangeUtil.createJSTreeFromText(project, text);
PsiElement elt;
enabled = node != null &&
(elt = node.getPsi()) instanceof JSExpressionStatement &&
(elt = ((JSExpressionStatement) elt).getExpression()) instanceof JSReferenceExpression &&
((JSReferenceExpression) elt).getReferencedName() != null &&
elt.textMatches(text);
}
getOKAction().setEnabled(enabled);
}
});
myClassName.setText(className);
myPackageName.setText(packageName);
init();
}
示例10: visitJSExpressionStatement
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
@Override public void visitJSExpressionStatement(
@NotNull JSExpressionStatement statement) {
super.visitJSExpressionStatement(statement);
if (!(statement.getExpression()instanceof JSNewExpression)) {
return;
}
final JSNewExpression newExpression =
(JSNewExpression) statement.getExpression();
final JSExpression methodExpression =
newExpression.getMethodExpression();
if (methodExpression == null) {
return;
}
registerError(methodExpression);
}
示例11: visitJSExpressionStatement
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
@Override public void visitJSExpressionStatement(JSExpressionStatement jsExpressionStatement) {
super.visitJSExpressionStatement(jsExpressionStatement);
final JSExpression expression = jsExpressionStatement.getExpression();
if (!(expression instanceof JSReferenceExpression)) {
return;
}
@NonNls final String text = expression.getText();
if (!"debugger".equals(text)) {
return;
}
registerError(expression);
}
示例12: isAssignment
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
public static boolean isAssignment(JSStatement statement, String value) {
if (statement == null || !(statement instanceof JSExpressionStatement)) {
return false;
}
final JSExpression expression = ((JSExpressionStatement) statement).getExpression();
if (!(expression instanceof JSAssignmentExpression)) {
return false;
}
final JSExpression rhs = ((JSAssignmentExpression) expression).getROperand();
return (rhs != null && rhs.getText().equals(value));
}
示例13: isSimplifiableAssignment
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
public static boolean isSimplifiableAssignment(JSIfStatement ifStatement, boolean negated) {
final JSStatement thenBranch = ConditionalUtils.stripBraces(ifStatement.getThen());
final JSStatement elseBranch = ConditionalUtils.stripBraces(ifStatement.getElse());
final boolean isAssignment;
if (negated) {
isAssignment = (ConditionalUtils.isAssignment(thenBranch, BoolUtils.FALSE) &&
ConditionalUtils.isAssignment(elseBranch, BoolUtils.TRUE));
} else {
isAssignment = (ConditionalUtils.isAssignment(thenBranch, BoolUtils.TRUE) &&
ConditionalUtils.isAssignment(elseBranch, BoolUtils.FALSE));
}
if (isAssignment) {
final JSAssignmentExpression thenExpression = (JSAssignmentExpression) ((JSExpressionStatement) thenBranch).getExpression();
final JSAssignmentExpression elseExpression = (JSAssignmentExpression) ((JSExpressionStatement) elseBranch).getExpression();
final IElementType thenSign = thenExpression.getOperationSign();
final IElementType elseSign = elseExpression.getOperationSign();
if (!thenSign.equals(elseSign)) {
return false;
}
final JSExpression thenLhs = thenExpression.getLOperand();
final JSExpression elseLhs = elseExpression.getLOperand();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs, elseLhs);
} else {
return false;
}
}
示例14: replaceSimplifiableAssignment
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
public static void replaceSimplifiableAssignment(JSIfStatement statement, boolean negated)
throws IncorrectOperationException {
final JSExpression condition = statement.getCondition();
final String conditionText = (negated ? BoolUtils.getNegatedExpressionText(condition) : condition.getText());
final JSExpressionStatement assignmentStatement = (JSExpressionStatement) ConditionalUtils.stripBraces(statement.getThen());
final JSAssignmentExpression assignmentExpression = (JSAssignmentExpression) assignmentStatement.getExpression();
final IElementType operator = assignmentExpression.getOperationSign();
final String operand = BinaryOperatorUtils.getOperatorText(operator);
final JSExpression lhs = assignmentExpression.getLOperand();
final String lhsText = lhs.getText();
JSElementFactory.replaceStatement(statement, lhsText + operand + conditionText + ';');
}
示例15: getAssignmentReplacement
import com.intellij.lang.javascript.psi.JSExpressionStatement; //导入依赖的package包/类
private static void getAssignmentReplacement(StringBuilder buffer, JSIfStatement ifStatement) {
final JSExpression condition = ifStatement.getCondition();
final JSExpressionStatement thenBranch = (JSExpressionStatement) ConditionalUtils.stripBraces(ifStatement.getThen());
final JSAssignmentExpression thenAssign = (JSAssignmentExpression) thenBranch.getExpression();
final JSExpression thenRhs = thenAssign.getROperand();
final String operator = BinaryOperatorUtils.getOperatorText(thenAssign.getOperationSign());
final JSStatement elseBranch = ifStatement.getElse();
assert (thenRhs != null);
buffer.append(thenAssign.getLOperand().getText())
.append(operator)
.append(ParenthesesUtils.getParenthesized(condition, ParenthesesUtils.CONDITIONAL_PRECENDENCE))
.append(TERNARY_QUESTION)
.append(ParenthesesUtils.getParenthesized(thenRhs, ParenthesesUtils.CONDITIONAL_PRECENDENCE))
.append(TERNARY_SEMICOLON);
if (elseBranch instanceof JSIfStatement) {
getAssignmentReplacement(buffer, (JSIfStatement) elseBranch);
return;
}
final JSExpressionStatement strippedElseBranch = (JSExpressionStatement) ConditionalUtils.stripBraces(elseBranch);
final JSAssignmentExpression elseAssign = (JSAssignmentExpression) strippedElseBranch.getExpression();
final JSExpression elseRhs = elseAssign.getROperand();
assert (elseRhs != null);
buffer.append(ParenthesesUtils.getParenthesized(elseRhs, ParenthesesUtils.CONDITIONAL_PRECENDENCE));
}