當前位置: 首頁>>代碼示例>>Java>>正文


Java JSExpressionStatement類代碼示例

本文整理匯總了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());
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:21,代碼來源:InspectionJSFix.java

示例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);
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:19,代碼來源:ConditionalUtils.java

示例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);
      }
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:25,代碼來源:JSExtractIncrementIntention.java

示例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;
}
 
開發者ID:consulo,項目名稱:consulo-nodejs,代碼行數:34,代碼來源:MochaPsiElementUtil.java

示例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'"));
}
 
開發者ID:cefolger,項目名稱:needsmoredojo,代碼行數:10,代碼來源:TestUtilToClassConverter.java

示例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"));
}
 
開發者ID:cefolger,項目名稱:needsmoredojo,代碼行數:10,代碼來源:TestUtilToClassConverter.java

示例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());
		}
	});
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:36,代碼來源:JavaScriptKeywordCompletionContributor.java

示例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();
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:10,代碼來源:JSImplementationTextSelectioner.java

示例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();
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:38,代碼來源:CreateClassDialog.java

示例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);
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:16,代碼來源:ObjectAllocationIgnoredJSInspection.java

示例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);
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:14,代碼來源:DebuggerStatementJSInspection.java

示例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));
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:16,代碼來源:ConditionalUtils.java

示例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;
    }
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:33,代碼來源:ConditionalUtils.java

示例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 + ';');
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:14,代碼來源:ConditionalUtils.java

示例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));
}
 
開發者ID:consulo,項目名稱:consulo-javascript,代碼行數:31,代碼來源:JSReplaceIfWithConditionalIntention.java


注:本文中的com.intellij.lang.javascript.psi.JSExpressionStatement類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。