@Override public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { if(element.getParent() instanceof JSStringTemplateExpression) { if(element.getNode().getElementType() == JSTokenTypes.STRING_TEMPLATE_PART) { // when the annotator runs in non-typescript a JSStringTemplateExpression element is never // passed as the element, so we have to resolve it manually here if(!DialectDetector.isTypeScript(element)) { element = element.getParent(); } } } if(element instanceof JSStringTemplateExpression) { if(JSGraphQLLanguageInjectionUtil.isJSGraphQLLanguageInjectionTarget(element)) { for (ASTNode astNode : element.getNode().getChildren(null)) { if (astNode.getElementType() == JSTokenTypes.STRING_TEMPLATE_PART) { final Annotation annotation = holder.createInfoAnnotation(astNode, null); annotation.setTextAttributes(RELAY_TEMPLATE); } } } } }
@Override protected boolean parseUnaryExpression() { final IElementType tokenType = builder.getTokenType(); if (tokenType == JSTokenTypes.OR) { builder.advanceLexer(); return true; } if (tokenType == EmberJSTokenTypes.ONE_TIME_BINDING) { final PsiBuilder.Marker expr = builder.mark(); builder.advanceLexer(); if (!super.parseUnaryExpression()) { builder.error(JSBundle.message("javascript.parser.message.expected.expression")); } expr.done(JSElementTypes.PREFIX_EXPRESSION); return true; } return super.parseUnaryExpression(); }
private boolean parseStringLiteral(IElementType firstToken) { final PsiBuilder.Marker mark = builder.mark(); IElementType currentToken = firstToken; StringBuilder literal = new StringBuilder(); while (currentToken == JSTokenTypes.STRING_LITERAL || currentToken == EmberJSTokenTypes.ESCAPE_SEQUENCE || currentToken == EmberJSTokenTypes.INVALID_ESCAPE_SEQUENCE) { literal.append(builder.getTokenText()); builder.advanceLexer(); currentToken = builder.getTokenType(); } mark.done(JSElementTypes.LITERAL_EXPRESSION); final String errorMessage = validateLiteralText(literal.toString()); if (errorMessage != null) { builder.error(errorMessage); } return true; }
public boolean parseInExpression() { final PsiBuilder.Marker expr = builder.mark(); if (isIdentifierToken(builder.getTokenType())) { parseExplicitIdentifier(); } else { final PsiBuilder.Marker keyValue = builder.mark(); parseKeyValue(); if (builder.getTokenType() != JSTokenTypes.IN_KEYWORD) { expr.rollbackTo(); return false; } else { keyValue.done(JSElementTypes.PARENTHESIZED_EXPRESSION); } } builder.advanceLexer(); parseExpression(); if (builder.getTokenType() == EmberJSTokenTypes.TRACK_BY_KEYWORD) { builder.advanceLexer(); parseExpression(); } expr.done(EmberJSElementTypes.REPEAT_EXPRESSION); return true; }
private void parseKeyValue() { builder.advanceLexer(); final PsiBuilder.Marker comma = builder.mark(); parseExplicitIdentifierWithError(); if (builder.getTokenType() == JSTokenTypes.COMMA) { builder.advanceLexer(); } else { builder.error(JSBundle.message("javascript.parser.message.expected.comma")); } parseExplicitIdentifierWithError(); comma.done(JSElementTypes.COMMA_EXPRESSION); if (builder.getTokenType() == JSTokenTypes.RPAR) { builder.advanceLexer(); } else { builder.error(JSBundle.message("javascript.parser.message.expected.rparen")); } }
private PsiElement moveImportToEnd(JSArrayLiteralExpression imports, JSParameterList parameters, String module, String parameter, PsiElement lastDefine, PsiElement lastParameter) { // TODO move to AMDPsiUtil if we need to reuse this in the future PsiElement lastChild = imports.getChildren()[imports.getChildren().length-1]; if(lastDefine != null) { lastChild = lastDefine; } PsiElement element = imports.addAfter(JSChangeUtil.createExpressionFromText(imports.getProject(), String.format("%s", module)).getPsi(), lastChild); imports.getNode().addLeaf(JSTokenTypes.COMMA, ",", element.getNode()); imports.getNode().addLeaf(JSTokenTypes.WHITE_SPACE, "\n", element.getNode()); PsiElement lastParameterChild = parameters.getChildren()[parameters.getChildren().length-1]; if(lastParameter != null) { lastParameterChild = lastParameter; } PsiElement parameterElement = parameters.addAfter(JSChangeUtil.createExpressionFromText(imports.getProject(), String.format("%s", parameter)).getPsi(), lastParameterChild); parameters.getNode().addLeaf(JSTokenTypes.COMMA, ",", parameterElement.getNode()); return element; }
private void parseReferenceList(final PsiBuilder builder) { final IElementType tokenType = builder.getTokenType(); EcmaScript6StatementParsing.LOGGER.assertTrue(tokenType == JSTokenTypes.EXTENDS_KEYWORD || tokenType == JSTokenTypes.IMPLEMENTS_KEYWORD); final PsiBuilder.Marker referenceList = builder.mark(); builder.advanceLexer(); if(getExpressionParsing().parseQualifiedTypeName(builder)) { while(builder.getTokenType() == JSTokenTypes.COMMA) { builder.advanceLexer(); if(!getExpressionParsing().parseQualifiedTypeName(builder)) { break; } } } referenceList.done(JSElementTypes.EXTENDS_LIST); }
@Override @RequiredReadAction public void injectLanguages(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { if(context instanceof JSSimpleLiteralExpression) { IElementType literalElementType = ((JSSimpleLiteralExpression) context).getLiteralElementType(); if(literalElementType == JSTokenTypes.REGEXP_LITERAL) { int textLength = context.getTextLength() - 1; String text = context.getText(); if(text.charAt(textLength) != '/') { textLength --; } registrar.startInjecting(RegExpLanguage.INSTANCE).addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(1, textLength)).doneInjecting(); } } }
@Override public void visitElement(PsiElement element) { if (element instanceof JSFunction) { this.visitJSFunctionDeclaration((JSFunction) element); } else if (element instanceof JSReferenceExpression) { if (element == element.getParent().getChildren()[0]) { final PsiElement firstChild = element.getParent().getFirstChild(); if (firstChild != null && firstChild.toString().indexOf(JSTokenTypes.NEW_KEYWORD.toString()) >= 0) { this.visitJSNewExpression(new JSNewExpressionImpl(element.getParent().getNode())); } } } else if (element instanceof XmlFile) { processFile((XmlFile)element); } super.visitElement(element); for (final PsiElement childElement : element.getChildren()) { childElement.accept(this); } }
private static void deleteImport(final JSImportStatement anImport) { if(!anImport.isValid()) { return; } PsiElement nextSibling = anImport.getNextSibling(); if(nextSibling instanceof PsiWhiteSpace) { // remove with the following whitespace String whitespace = nextSibling.getText(); if(whitespace.contains("]]>")) { nextSibling.replace(JSChangeUtil.createJSTreeFromText(anImport.getProject(), "]]>").getPsi()); } // don't remove trailing line break if it is an injection suffix else if(nextSibling.getNextSibling() == null || nextSibling.getNextSibling().getNode().getElementType() != JSTokenTypes.RBRACE || !(nextSibling.getParent() instanceof JSBlockStatement) || !ImportUtils.isAnonymousEventHandler((JSBlockStatement) nextSibling.getParent())) { nextSibling.delete(); } } anImport.delete(); }
protected boolean parseNewExpression(PsiBuilder builder) { ExpressionParsing.LOGGER.assertTrue(builder.getTokenType() == JSTokenTypes.NEW_KEYWORD); builder.advanceLexer(); if(builder.getTokenType() == JSTokenTypes.FUNCTION_KEYWORD) { getFunctionParsing().parseFunctionExpression(builder); return true; } if(!parseMemberExpression(builder, false)) { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.expression")); } return false; }
private void parseDefaultNsStatement(final PsiBuilder builder) { EcmaScript4StatementParsing.LOGGER.assertTrue(builder.getTokenType() == JSTokenTypes.DEFAULT_KEYWORD); final PsiBuilder.Marker marker = builder.mark(); builder.advanceLexer(); if(builder.getTokenType() == JSTokenTypes.IDENTIFIER && "xml".equals(builder.getTokenText())) { builder.advanceLexer(); if(checkMatches(builder, JSTokenTypes.NAMESPACE_KEYWORD, JavaScriptBundle.message("javascript.parser.message.expected.namespace"))) { if(checkMatches(builder, JSTokenTypes.EQ, JavaScriptBundle.message("javascript.parser.message.expected.equal"))) { getExpressionParsing().parseExpression(builder); } } } else { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.xml")); } marker.done(JSElementTypes.ASSIGNMENT_EXPRESSION); }
private boolean parseBitwiseORExpression(final PsiBuilder builder, final boolean allowIn) { PsiBuilder.Marker expr = builder.mark(); if(!parseBitwiseXORExpression(builder, allowIn)) { expr.drop(); return false; } while(builder.getTokenType() == JSTokenTypes.OR) { builder.advanceLexer(); if(!parseBitwiseXORExpression(builder, allowIn)) { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.expression")); } expr.done(JSElementTypes.BINARY_EXPRESSION); expr = expr.precede(); } expr.drop(); return true; }
@Override public void visitFunctionDeclaration(final ASTNode node) { if(type1 == JSTokenTypes.FUNCTION_KEYWORD && type2 == JSElementTypes.REFERENCE_EXPRESSION) { setSingleSpace(true); } else if(type1 == JSElementTypes.REFERENCE_EXPRESSION && type2 == JSElementTypes.PARAMETER_LIST) { setSingleSpace(mySettings.SPACE_BEFORE_METHOD_PARENTHESES); } else if(type2 == JSElementTypes.BLOCK_STATEMENT) { setBraceSpace(mySettings.SPACE_BEFORE_METHOD_LBRACE, mySettings.METHOD_BRACE_STYLE, myChild1.getTextRange()); } else if(type1 == JSElementTypes.ATTRIBUTE_LIST && type2 == JSTokenTypes.FUNCTION_KEYWORD) { setSingleSpace(true); } }
private boolean parseEqualityExpression(final PsiBuilder builder, final boolean allowIn) { PsiBuilder.Marker expr = builder.mark(); if(!parseRelationalExpression(builder, allowIn)) { expr.drop(); return false; } while(JSTokenTypes.EQUALITY_OPERATIONS.contains(builder.getTokenType())) { builder.advanceLexer(); if(!parseRelationalExpression(builder, allowIn)) { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.expression")); } expr.done(JSElementTypes.BINARY_EXPRESSION); expr = expr.precede(); } expr.drop(); return true; }
private boolean parseRelationalExpression(final PsiBuilder builder, final boolean allowIn) { PsiBuilder.Marker expr = builder.mark(); if(!parseShiftExpression(builder)) { expr.drop(); return false; } while(JSTokenTypes.RELATIONAL_OPERATIONS.contains(builder.getTokenType()) && (allowIn || builder.getTokenType() != JSTokenTypes.IN_KEYWORD)) { builder.advanceLexer(); if(!parseShiftExpression(builder)) { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.expression")); } expr.done(JSElementTypes.BINARY_EXPRESSION); expr = expr.precede(); } expr.drop(); return true; }
@Override public void visitJSPrefixExpression(JSPrefixExpression expression) { if (!this.assigned) { super.visitJSPrefixExpression(expression); final IElementType tokenType = expression.getOperationSign(); if (!(tokenType.equals(JSTokenTypes.PLUSPLUS) || tokenType.equals(JSTokenTypes.MINUSMINUS))) { return; } final JSExpression operand = expression.getExpression(); this.assigned = (VariableAccessUtil.mayEvaluateToVariable(operand, this.variable)); } }
private boolean parseIsAsExpression(final PsiBuilder builder) { PsiBuilder.Marker expr = builder.mark(); if(!parseUnaryExpression(builder)) { expr.drop(); return false; } while(builder.getTokenType() == JSTokenTypes.AS_KEYWORD || builder.getTokenType() == JSTokenTypes.IS_KEYWORD) { builder.advanceLexer(); if(!parseUnaryExpression(builder)) { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.expression")); } expr.done(JSElementTypes.BINARY_EXPRESSION); expr = expr.precede(); } expr.drop(); return true; }
private boolean parseMultiplicativeExpression(final PsiBuilder builder) { PsiBuilder.Marker expr = builder.mark(); if(!parseIsAsExpression(builder)) { expr.drop(); return false; } while(JSTokenTypes.MULTIPLICATIVE_OPERATIONS.contains(builder.getTokenType())) { builder.advanceLexer(); if(!parseUnaryExpression(builder)) { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.expression")); } expr.done(JSElementTypes.BINARY_EXPRESSION); expr = expr.precede(); } expr.drop(); return true; }
private boolean parsePostfixExpression(PsiBuilder builder) { final PsiBuilder.Marker expr = builder.mark(); if(!parseMemberExpression(builder, true)) { expr.drop(); return false; } final IElementType tokenType = builder.getTokenType(); if(tokenType == JSTokenTypes.PLUSPLUS || tokenType == JSTokenTypes.MINUSMINUS) { builder.advanceLexer(); expr.done(JSElementTypes.POSTFIX_EXPRESSION); } else { expr.drop(); } return true; }
@Override @RequiredReadAction public void visitJSLiteralExpression(JSSimpleLiteralExpression node) { super.visitJSLiteralExpression(node); if(node.getLiteralElementType() == JSTokenTypes.NUMERIC_LITERAL) { String text = node.getText(); if(StringUtil.startsWithIgnoreCase(text, "0o")) { reportFeatureUsage(node, JavaScriptFeature.OCTAL_LITERAL); } else if(StringUtil.startsWithIgnoreCase(text, "0b")) { reportFeatureUsage(node, JavaScriptFeature.BINARY_LITERAL); } } }
@Override public void visitJSArrayLiteralExpression(final JSArrayLiteralExpression node) { final PsiElement lastChild = node.getLastChild(); PsiElement child = lastChild != null ? lastChild.getPrevSibling() : null; if(child instanceof PsiWhiteSpace) { child = child.getPrevSibling(); } ASTNode childNode; if(child != null && (childNode = child.getNode()) != null && childNode.getElementType() == JSTokenTypes.COMMA) { final Annotation annotation = myHolder.createWarningAnnotation(child, JavaScriptBundle.message("javascript.validation.message.unneeded.comma")); annotation.registerFix(new RemoveASTNodeFix(childNode, "javascript.validation.message.remove.unneeded.comma.fix")); } }
@Override public boolean satisfiedBy(@NotNull PsiElement element) { if (!(element instanceof JSBinaryExpression)) { return false; } if (ErrorUtil.containsError(element)) { return false; } final JSBinaryExpression expression = (JSBinaryExpression) element; final IElementType sign = expression.getOperationSign(); if (!(sign.equals(JSTokenTypes.EQEQ) || sign.equals(JSTokenTypes.NE))) { return false; } final JSExpression lhs = expression.getLOperand(); final JSExpression rhs = expression.getROperand(); return (lhs != null && rhs != null && (BoolUtils.isBooleanLiteral(lhs) || BoolUtils.isBooleanLiteral(rhs))); }
private static List<JSExpression> determinePossibleCaseExpressions(JSExpression exp) { final JSExpression expToCheck = ParenthesesUtils.stripParentheses(exp); final List<JSExpression> out = new ArrayList<JSExpression>(10); if (expToCheck instanceof JSBinaryExpression) { final JSBinaryExpression binaryExp = (JSBinaryExpression) expToCheck; final IElementType operation = binaryExp.getOperationSign(); final JSExpression lhs = binaryExp.getLOperand(); final JSExpression rhs = binaryExp.getROperand(); if (operation.equals(JSTokenTypes.OROR)) { return determinePossibleCaseExpressions(lhs); } else if (operation.equals(JSTokenTypes.EQEQ)) { if (canBeCaseLabel(lhs) && rhs != null) { out.add(rhs); } if (canBeCaseLabel(rhs)) { out.add(lhs); } } } return out; }
private void parseCaseOrDefaultClause(final PsiBuilder builder) { final IElementType firstToken = builder.getTokenType(); final PsiBuilder.Marker clause = builder.mark(); if(firstToken != JSTokenTypes.CASE_KEYWORD && firstToken != JSTokenTypes.DEFAULT_KEYWORD) { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.catch.or.default")); } builder.advanceLexer(); if(firstToken == JSTokenTypes.CASE_KEYWORD) { getExpressionParsing().parseExpression(builder); } Parsing.checkMatches(builder, JSTokenTypes.COLON, JavaScriptBundle.message("javascript.parser.message.expected.colon")); while(true) { IElementType token = builder.getTokenType(); if(token == null || token == JSTokenTypes.CASE_KEYWORD || token == JSTokenTypes.DEFAULT_KEYWORD || token == JSTokenTypes.RBRACE) { break; } parseStatement(builder); } clause.done(JSElementTypes.CASE_CLAUSE); }
@Override public void visitJSAssignmentExpression( JSAssignmentExpression expression) { super.visitJSAssignmentExpression(expression); final JSExpression rhs = expression.getROperand(); if (rhs == null) { return; } final IElementType tokenType = expression.getOperationSign(); if (!JSTokenTypes.DIVEQ.equals(tokenType) && !JSTokenTypes.PERCEQ.equals(tokenType)) { return; } if (!isZero(rhs)) { return; } registerError(expression); }
@Override public JSStatement getFinallyStatement() { ASTNode child = getNode().getFirstChildNode(); boolean foundFinally = false; while(child != null) { final IElementType type = child.getElementType(); if(foundFinally && JSElementTypes.STATEMENTS.contains(type)) { return (JSStatement) child.getPsi(); } if(type == JSTokenTypes.FINALLY_KEYWORD) { foundFinally = true; } child = child.getTreeNext(); } return null; }
public void visitJSPrefixOrPostfixExpression(JSExpression operand, IElementType sign) { if (operand == null) { this.isConstant = false; return; } operand.accept(this); if (!this.isConstant) { return; } if (sign == JSTokenTypes.PLUS || sign == JSTokenTypes.MINUS || sign == JSTokenTypes.TILDE || sign == JSTokenTypes.EXCL) { return; } this.isConstant = false; }
private void replaceShiftWithMultiplyOrDivide(JSBinaryExpression exp) throws IncorrectOperationException { final JSExpression lhs = exp.getLOperand(); final JSExpression rhs = exp.getROperand(); final IElementType tokenType = exp.getOperationSign(); final String operatorString = ((tokenType.equals(JSTokenTypes.LTLT)) ? "*" : "/"); final String lhsText = ParenthesesUtils.getParenthesized(lhs, ParenthesesUtils.MULTIPLICATIVE_PRECENDENCE); String expString = lhsText + operatorString + ShiftUtils.getExpBase2(rhs); final JSElement parent = (JSElement) exp.getParent(); if (parent != null && parent instanceof JSExpression) { if (!(parent instanceof JSParenthesizedExpression) && ParenthesesUtils.getPrecendence((JSExpression) parent) < ParenthesesUtils.MULTIPLICATIVE_PRECENDENCE) { expString = '(' + expString + ')'; } } JSElementFactory.replaceExpression(exp, expString); }
private void parseClassNoMarker(final PsiBuilder builder, final @NotNull PsiBuilder.Marker clazz) { final IElementType tokenType = builder.getTokenType(); EcmaScript4StatementParsing.LOGGER.assertTrue(JSTokenTypes.CLASS_KEYWORD == tokenType || JSTokenTypes.INTERFACE_KEYWORD == tokenType); builder.advanceLexer(); if(!getExpressionParsing().parseQualifiedTypeName(builder)) { builder.error(JavaScriptBundle.message("javascript.parser.message.expected.typename")); } if(builder.getTokenType() == JSTokenTypes.EXTENDS_KEYWORD) { parseReferenceList(builder); } if(builder.getTokenType() == JSTokenTypes.IMPLEMENTS_KEYWORD) { parseReferenceList(builder); } parseBlockOrFunctionBody(builder, BlockType.PACKAGE_OR_CLASS_BODY); clazz.done(JSElementTypes.CLASS); }
@Override public void visitIfStatement(final ASTNode node) { if(type1 == JSTokenTypes.IF_KEYWORD && type2 == JSTokenTypes.LPAR) { setSingleSpace(mySettings.SPACE_BEFORE_IF_PARENTHESES); } else if(type1 == JSTokenTypes.LPAR || type2 == JSTokenTypes.RPAR) { setSingleSpace(mySettings.SPACE_WITHIN_IF_PARENTHESES); } else if(type1 == JSTokenTypes.RPAR && type2 == JSElementTypes.BLOCK_STATEMENT) { TextRange dependentRange = new TextRange(myParent.getStartOffset(), myChild1.getTextRange().getEndOffset()); setBraceSpace(mySettings.SPACE_BEFORE_IF_LBRACE, mySettings.BRACE_STYLE, dependentRange); } else if(type2 == JSTokenTypes.ELSE_KEYWORD) { setLineBreakSpace(mySettings.ELSE_ON_NEW_LINE); } else if(type1 == JSTokenTypes.ELSE_KEYWORD && type2 == JSElementTypes.BLOCK_STATEMENT) { setBraceSpace(mySettings.SPACE_BEFORE_ELSE_LBRACE, mySettings.BRACE_STYLE, null); } }
@Override public void visitTryStatement(final ASTNode node) { if(type1 == JSTokenTypes.TRY_KEYWORD && type2 == JSElementTypes.BLOCK_STATEMENT) { setBraceSpace(mySettings.SPACE_BEFORE_TRY_LBRACE, mySettings.BRACE_STYLE, null); } else if(type2 == JSElementTypes.CATCH_BLOCK) { setLineBreakSpace(mySettings.CATCH_ON_NEW_LINE); } else if(type2 == JSTokenTypes.FINALLY_KEYWORD) { setLineBreakSpace(mySettings.FINALLY_ON_NEW_LINE); } else if(type1 == JSTokenTypes.FINALLY_KEYWORD) { setBraceSpace(mySettings.SPACE_BEFORE_FINALLY_LBRACE, mySettings.BRACE_STYLE, null); } }
@Override public void visitWhileStatement(final ASTNode node) { if(type1 == JSTokenTypes.WHILE_KEYWORD && type2 == JSTokenTypes.LPAR) { setSingleSpace(mySettings.SPACE_BEFORE_WHILE_PARENTHESES); } else if(type1 == JSTokenTypes.RPAR && type2 == JSElementTypes.BLOCK_STATEMENT) { TextRange dependentRange = new TextRange(myParent.getStartOffset(), myChild1.getTextRange().getEndOffset()); setBraceSpace(mySettings.SPACE_BEFORE_WHILE_LBRACE, mySettings.BRACE_STYLE, dependentRange); } else if(type1 == JSTokenTypes.LPAR || type2 == JSTokenTypes.RPAR) { setSingleSpace(mySettings.SPACE_WITHIN_WHILE_PARENTHESES); } }
@Override public void visitJSPostfixExpression(JSPostfixExpression jsPostfixExpression) { final IElementType sign = jsPostfixExpression.getOperationSign(); if (!JSTokenTypes.PLUSPLUS.equals(sign) && !JSTokenTypes.MINUSMINUS.equals(sign)) { return; } final PsiElement parent = jsPostfixExpression.getParent(); if (parent == null) { return; } if (parent instanceof JSExpressionStatement ||parent instanceof JSForInStatement ||parent instanceof JSForStatement || parent instanceof JSCommaExpression) { return; } registerError(jsPostfixExpression); }
static @Nullable ASTNode findTrailingCommentInFunctionBody(final @NotNull JSFunction function) { final ASTNode block = function.getNode().findChildByType(JSElementTypes.BLOCK_STATEMENT); if(block == null) { return null; } for(ASTNode prev = block.getLastChildNode(); prev != null; prev = prev.getTreePrev()) { if(prev.getElementType() == JSElementTypes.RETURN_STATEMENT) { return block.findChildByType(JSTokenTypes.COMMENTS, prev); } else if(JSElementTypes.STATEMENTS.contains(prev.getElementType())) { break; } } return null; }
private static PsiElement findFirstDocComment(PsiElement docComment) { if(docComment.getNode().getElementType() == JSTokenTypes.END_OF_LINE_COMMENT) { while(true) { PsiElement prev = docComment.getPrevSibling(); if(prev instanceof PsiWhiteSpace) { prev = prev.getPrevSibling(); } if(prev == null) { break; } if(prev.getNode().getElementType() != JSTokenTypes.END_OF_LINE_COMMENT) { break; } docComment = prev; } } return docComment; }
private void checkExpression(IElementType tokenType, JSExpression expression) { if (!(tokenType == null || tokenType.equals(JSTokenTypes.PLUSPLUS) || tokenType.equals(JSTokenTypes.MINUSMINUS))) { return; } if (!(expression instanceof JSIndexedPropertyAccessExpression)) { return; } JSExpression arrayExpression = ((JSIndexedPropertyAccessExpression) expression).getQualifier(); while (arrayExpression instanceof JSIndexedPropertyAccessExpression) { final JSIndexedPropertyAccessExpression accessExpression = (JSIndexedPropertyAccessExpression) arrayExpression; arrayExpression = accessExpression.getQualifier(); } if (arrayExpression instanceof JSReferenceExpression) { final String referencedName = ((JSReferenceExpression) arrayExpression).getReferencedName(); // TODO maybe it's better to check ((JSReferenceExpression) arrayExpression).isReferenceTo(variable) ? this.assigned = referencedName != null && referencedName.equals(this.variable.getName()); } }
@Override public void visitDoWhileStatement(final ASTNode node) { if(type2 == JSTokenTypes.WHILE_KEYWORD) { if(mySettings.WHILE_ON_NEW_LINE) { myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } else { myResult = Spacing.createSpacing(1, 1, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } } else if(type2 == JSTokenTypes.LPAR) { setSingleSpace(mySettings.SPACE_BEFORE_WHILE_PARENTHESES); } else if(type1 == JSTokenTypes.LPAR || type2 == JSTokenTypes.RPAR) { setSingleSpace(mySettings.SPACE_WITHIN_WHILE_PARENTHESES); } }
@Override public String getInitialValueString() { final JSNamespaceDeclarationStub stub = getStub(); if(stub != null) { return stub.getInitialValueString(); } final ASTNode anchor = getNode().findChildByType(JSTokenTypes.EQ); if(anchor != null) { ASTNode node = anchor.getTreeNext(); if(node != null && node.getElementType() == JSTokenTypes.WHITE_SPACE) { node = node.getTreeNext(); } if(node != null && JavaScriptTokenSets.STRING_LITERALS.contains(node.getElementType())) { return node.getText(); } } return null; }
private static boolean canBeMadeIntoCase(JSExpression exp, JSExpression caseExpression) { final JSExpression expToCheck = ParenthesesUtils.stripParentheses(exp); if (!(expToCheck instanceof JSBinaryExpression)) { return false; } final JSBinaryExpression binaryExp = (JSBinaryExpression) expToCheck; final IElementType operation = binaryExp.getOperationSign(); final JSExpression leftOperand = binaryExp.getLOperand(); final JSExpression rightOperand = binaryExp.getROperand(); if (operation.equals(JSTokenTypes.OROR)) { return (canBeMadeIntoCase(leftOperand, caseExpression) && canBeMadeIntoCase(rightOperand, caseExpression)); } else if (operation.equals(JSTokenTypes.EQEQ)) { return ((canBeCaseLabel(leftOperand) && EquivalenceChecker.expressionsAreEquivalent(caseExpression, rightOperand)) || (canBeCaseLabel(rightOperand) && EquivalenceChecker.expressionsAreEquivalent(caseExpression, leftOperand))); } else { return false; } }