/** * @param aClass * @param leaf leaf element. Is guaranteed to be a tree descendant of aClass. * @return the value that will be passed to the {@link #insert(com.intellij.psi.PsiClass, com.intellij.psi.PsiElement, boolean)} method later. */ @Override @Nullable public PsiElement findInsertionAnchor(@NotNull PsiClass aClass, @NotNull PsiElement leaf) { PsiElement element = leaf; while (element.getParent() != aClass) { element = element.getParent(); } PsiElement lBrace = aClass.getLBrace(); if (lBrace == null) { return null; } PsiElement rBrace = aClass.getRBrace(); if (!GenerateMembersUtil.isChildInRange(element, lBrace.getNextSibling(), rBrace)) { return null; } PsiElement prev = leaf.getPrevSibling(); if (prev != null && prev.getNode() != null && prev.getNode().getElementType() == JavaTokenType.END_OF_LINE_COMMENT) { element = leaf.getNextSibling(); } return element; }
@Nullable public PsiBuilder.Marker parseCodeBlockDeep(final PsiBuilder builder, final boolean parseUntilEof) { if (builder.getTokenType() != JavaTokenType.LBRACE) return null; final PsiBuilder.Marker codeBlock = builder.mark(); builder.advanceLexer(); parseStatements(builder, parseUntilEof ? BraceMode.TILL_LAST : BraceMode.TILL_FIRST); final boolean greedyBlock = !expectOrError(builder, JavaTokenType.RBRACE, "expected.rbrace"); builder.getTokenType(); // eat spaces done(codeBlock, JavaElementType.CODE_BLOCK); if (greedyBlock) { codeBlock.setCustomEdgeTokenBinders(null, WhitespacesBinders.GREEDY_RIGHT_BINDER); } return codeBlock; }
public boolean satisfiedBy(PsiElement element) { if (!(element instanceof PsiJavaToken)) { return false; } final PsiJavaToken token = (PsiJavaToken)element; final IElementType tokenType = token.getTokenType(); if (!JavaTokenType.DO_KEYWORD.equals(tokenType)) { return false; } final PsiElement parent = element.getParent(); if (!(parent instanceof PsiDoWhileStatement)) { return false; } final PsiDoWhileStatement doWhileStatement = (PsiDoWhileStatement)parent; return !(doWhileStatement.getCondition() == null || doWhileStatement.getBody() == null); }
@NotNull private PsiBuilder.Marker parseForStatement(final PsiBuilder builder) { final PsiBuilder.Marker statement = builder.mark(); builder.advanceLexer(); if (!expect(builder, JavaTokenType.LPARENTH)) { error(builder, JavaErrorMessages.message("expected.lparen")); done(statement, JavaElementType.FOR_STATEMENT); return statement; } final PsiBuilder.Marker afterParenth = builder.mark(); final PsiBuilder.Marker param = myParser.getDeclarationParser().parseParameter(builder, false, false); if (param == null || exprType(param) != JavaElementType.PARAMETER || builder.getTokenType() != JavaTokenType.COLON) { afterParenth.rollbackTo(); return parseForLoopFromInitialization(builder, statement); } else { afterParenth.drop(); return parseForEachFromColon(builder, statement); } }
private void parseExpressionOrExpressionList(final PsiBuilder builder) { final PsiBuilder.Marker expr = myParser.getExpressionParser().parse(builder); if (expr == null) return; final PsiBuilder.Marker expressionStatement; if (builder.getTokenType() != JavaTokenType.COMMA) { expressionStatement = expr.precede(); done(expressionStatement, JavaElementType.EXPRESSION_STATEMENT); } else { final PsiBuilder.Marker expressionList = expr.precede(); expressionStatement = expressionList.precede(); do { builder.advanceLexer(); final PsiBuilder.Marker nextExpression = myParser.getExpressionParser().parse(builder); if (nextExpression == null) { error(builder, JavaErrorMessages.message("expected.expression")); } } while (builder.getTokenType() == JavaTokenType.COMMA); done(expressionList, JavaElementType.EXPRESSION_LIST); done(expressionStatement, JavaElementType.EXPRESSION_LIST_STATEMENT); } }
@NotNull private PsiBuilder.Marker parseForEachFromColon(PsiBuilder builder, PsiBuilder.Marker statement) { builder.advanceLexer(); final PsiBuilder.Marker expr = myParser.getExpressionParser().parse(builder); if (expr == null) { error(builder, JavaErrorMessages.message("expected.expression")); } if (expect(builder, JavaTokenType.RPARENTH)) { final PsiBuilder.Marker bodyStatement = parseStatement(builder); if (bodyStatement == null) { error(builder, JavaErrorMessages.message("expected.statement")); } } else { error(builder, JavaErrorMessages.message("expected.rparen")); } done(statement, JavaElementType.FOREACH_STATEMENT); return statement; }
@NotNull private PsiBuilder.Marker parseDoWhileStatement(final PsiBuilder builder) { final PsiBuilder.Marker statement = builder.mark(); builder.advanceLexer(); final PsiBuilder.Marker body = parseStatement(builder); if (body == null) { error(builder, JavaErrorMessages.message("expected.statement")); done(statement, JavaElementType.DO_WHILE_STATEMENT); return statement; } if (!expect(builder, JavaTokenType.WHILE_KEYWORD)) { error(builder, JavaErrorMessages.message("expected.while")); done(statement, JavaElementType.DO_WHILE_STATEMENT); return statement; } if (parseExpressionInParenth(builder)) { semicolon(builder); } done(statement, JavaElementType.DO_WHILE_STATEMENT); return statement; }
@Nullable private PsiBuilder.Marker parseSwitchLabelStatement(final PsiBuilder builder) { final PsiBuilder.Marker statement = builder.mark(); final boolean isCase = builder.getTokenType() == JavaTokenType.CASE_KEYWORD; builder.advanceLexer(); if (isCase) { final PsiBuilder.Marker expr = myParser.getExpressionParser().parse(builder); if (expr == null) { statement.rollbackTo(); return null; } } expectOrError(builder, JavaTokenType.COLON, "expected.colon"); done(statement, JavaElementType.SWITCH_LABEL_STATEMENT); return statement; }
@NotNull private PsiBuilder.Marker parseAssertStatement(final PsiBuilder builder) { final PsiBuilder.Marker statement = builder.mark(); builder.advanceLexer(); final PsiBuilder.Marker expr = myParser.getExpressionParser().parse(builder); if (expr == null) { error(builder, JavaErrorMessages.message("expected.boolean.expression")); done(statement, JavaElementType.ASSERT_STATEMENT); return statement; } if (expect(builder, JavaTokenType.COLON)) { final PsiBuilder.Marker expr2 = myParser.getExpressionParser().parse(builder); if (expr2 == null) { error(builder, JavaErrorMessages.message("expected.expression")); done(statement, JavaElementType.ASSERT_STATEMENT); return statement; } } semicolon(builder); done(statement, JavaElementType.ASSERT_STATEMENT); return statement; }
private boolean parseExpressionInParenth(final PsiBuilder builder) { if (!expect(builder, JavaTokenType.LPARENTH)) { error(builder, JavaErrorMessages.message("expected.lparen")); return false; } final PsiBuilder.Marker beforeExpr = builder.mark(); final PsiBuilder.Marker expr = myParser.getExpressionParser().parse(builder); if (expr == null || builder.getTokenType() == JavaTokenType.SEMICOLON) { beforeExpr.rollbackTo(); error(builder, JavaErrorMessages.message("expected.expression")); if (builder.getTokenType() != JavaTokenType.RPARENTH) { return false; } } else { beforeExpr.drop(); if (builder.getTokenType() != JavaTokenType.RPARENTH) { error(builder, JavaErrorMessages.message("expected.rparen")); return false; } } builder.advanceLexer(); return true; }
@Nullable public PsiBuilder.Marker parsePackageStatement(final PsiBuilder builder) { final PsiBuilder.Marker statement = builder.mark(); if (!expect(builder, JavaTokenType.PACKAGE_KEYWORD)) { final PsiBuilder.Marker modList = builder.mark(); myParser.getDeclarationParser().parseAnnotations(builder); done(modList, JavaElementType.MODIFIER_LIST); if (!expect(builder, JavaTokenType.PACKAGE_KEYWORD)) { statement.rollbackTo(); return null; } } final PsiBuilder.Marker ref = myParser.getReferenceParser().parseJavaCodeReference(builder, true, false, false, false); if (ref == null) { statement.error(JavaErrorMessages.message("expected.class.or.interface")); return null; } semicolon(builder); done(statement, JavaElementType.PACKAGE_STATEMENT); return statement; }
@Nullable private PsiBuilder.Marker parseImportStatement(final PsiBuilder builder) { if (builder.getTokenType() != JavaTokenType.IMPORT_KEYWORD) return null; final PsiBuilder.Marker statement = builder.mark(); builder.advanceLexer(); final boolean isStatic = expect(builder, JavaTokenType.STATIC_KEYWORD); final IElementType type = isStatic ? JavaElementType.IMPORT_STATIC_STATEMENT : JavaElementType.IMPORT_STATEMENT; final boolean isOk = myParser.getReferenceParser().parseImportCodeReference(builder, isStatic); if (isOk) { semicolon(builder); } done(statement, type); return statement; }
@NotNull public Block create(@NotNull final List<ASTNode> subNodes, final Wrap wrap, @Nullable final Alignment alignment) { final ArrayList<Block> subBlocks = new ArrayList<Block>(); final ASTNode firstNode = subNodes.get(0); if (firstNode.getElementType() == JavaTokenType.DOT) { AlignmentStrategy strategy = AlignmentStrategy.getNullStrategy(); Block block = newJavaBlock(firstNode, mySettings, myJavaSettings, Indent.getNoneIndent(), null, strategy); subBlocks.add(block); subNodes.remove(0); if (!subNodes.isEmpty()) { subBlocks.add(create(subNodes, wrap, null)); } return new SyntheticCodeBlock(subBlocks, alignment, mySettings, myJavaSettings, Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS), wrap); } return new SyntheticCodeBlock(createJavaBlocks(subNodes), alignment, mySettings, myJavaSettings, Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS), null); }
@Nullable public PsiBuilder.Marker parseTypeParameter(final PsiBuilder builder) { final PsiBuilder.Marker param = builder.mark(); myParser.getDeclarationParser().parseAnnotations(builder); if (isKeywordAny(builder)) { dummy(builder); } final boolean wild = expect(builder, JavaTokenType.QUEST); if (!wild && !expect(builder, JavaTokenType.IDENTIFIER)) { param.rollbackTo(); return null; } parseReferenceList(builder, JavaTokenType.EXTENDS_KEYWORD, JavaElementType.EXTENDS_BOUND_LIST, JavaTokenType.AND); if (!wild) { param.done(JavaElementType.TYPE_PARAMETER); } else { param.error(JavaErrorMessages.message("wildcard.not.expected")); } return param; }
private void parseEnumConstants(final PsiBuilder builder) { while (builder.getTokenType() != null) { if (expect(builder, JavaTokenType.SEMICOLON)) { return; } if (builder.getTokenType() == JavaTokenType.PRIVATE_KEYWORD || builder.getTokenType() == JavaTokenType.PROTECTED_KEYWORD) { error(builder, JavaErrorMessages.message("expected.semicolon")); return; } final PsiBuilder.Marker enumConstant = parseEnumConstant(builder); if (enumConstant == null) { error(builder, JavaErrorMessages.message("expected.identifier")); } if (!expect(builder, JavaTokenType.COMMA)) { if (builder.getTokenType() != null && builder.getTokenType() != JavaTokenType.SEMICOLON) { error(builder, JavaErrorMessages.message("expected.comma.or.semicolon")); return; } } } }
@NotNull public PsiBuilder.Marker parseAnnotationValue(final PsiBuilder builder) { PsiBuilder.Marker result; final IElementType tokenType = builder.getTokenType(); if (tokenType == JavaTokenType.AT) { result = parseAnnotation(builder); } else if (tokenType == JavaTokenType.LBRACE) { result = parseAnnotationArrayInitializer(builder); } else { result = myParser.getExpressionParser().parseConditional(builder); } if (result == null) { result = builder.mark(); result.error(JavaErrorMessages.message("expected.value")); } return result; }
public void testDrop() throws Exception { myBuilder = createBuilder("package"); final PsiBuilder.Marker fileMarker = myBuilder.mark(); assertEquals("package", myBuilder.getTokenText()); assertEquals(JavaTokenType.PACKAGE_KEYWORD, myBuilder.getTokenType()); final PsiBuilder.Marker packageStatementMarker = myBuilder.mark(); myBuilder.advanceLexer(); assertTrue(myBuilder.eof()); packageStatementMarker.drop(); fileMarker.done(JavaStubElementTypes.JAVA_FILE); ASTNode fileNode = myBuilder.getTreeBuilt(); assertNotNull(fileNode); assertEquals("package", fileNode.getText()); assertSame(fileNode.getFirstChildNode(), fileNode.getLastChildNode()); ASTNode leaf = fileNode.getFirstChildNode(); assertNotNull(leaf); assertEquals(JavaTokenType.PACKAGE_KEYWORD, leaf.getElementType()); assertEquals("package", leaf.getText()); assertNull(leaf.getFirstChildNode()); }
@Override public PsiNameValuePairStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { String name = null; String value = null; List<LighterASTNode> children = tree.getChildren(node); for (LighterASTNode child : children) { if (child.getTokenType() == JavaTokenType.IDENTIFIER) { name = RecordUtil.intern(tree.getCharTable(), child); } else if (child.getTokenType() == JavaElementType.LITERAL_EXPRESSION) { value = RecordUtil.intern(tree.getCharTable(), tree.getChildren(child).get(0)); value = StringUtil.unquoteString(value); } } return new PsiNameValuePairStubImpl(parentStub, StringRef.fromString(name), StringRef.fromString(value)); }
@Override public PsiImportStatementStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { boolean isOnDemand = false; String refText = null; for (LighterASTNode child : tree.getChildren(node)) { IElementType type = child.getTokenType(); if (type == JavaElementType.JAVA_CODE_REFERENCE || type == JavaElementType.IMPORT_STATIC_REFERENCE) { refText = JavaSourceUtil.getReferenceText(tree, child); } else if (type == JavaTokenType.ASTERISK) { isOnDemand = true; } } byte flags = PsiImportStatementStubImpl.packFlags(isOnDemand, node.getTokenType() == JavaElementType.IMPORT_STATIC_STATEMENT); return new PsiImportStatementStubImpl(parentStub, refText, flags); }
public static boolean isDeprecatedByAnnotation(@NotNull LighterAST tree, @NotNull LighterASTNode modList) { for (final LighterASTNode child : tree.getChildren(modList)) { if (child.getTokenType() == JavaElementType.ANNOTATION) { final LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, child, JavaElementType.JAVA_CODE_REFERENCE); if (ref != null) { final LighterASTNode id = LightTreeUtil.firstChildOfType(tree, ref, JavaTokenType.IDENTIFIER); if (id != null) { final String name = intern(tree.getCharTable(), id); if (DEPRECATED_ANNOTATION_NAME.equals(name)) return true; } } } } return false; }
public boolean satisfiedBy(PsiElement element) { if (!(element instanceof PsiComment)) { return false; } if (element instanceof PsiDocComment) { return false; } final PsiComment comment = (PsiComment)element; final IElementType type = comment.getTokenType(); if (!JavaTokenType.END_OF_LINE_COMMENT.equals(type)) { return false; } final String text = comment.getText(); final Matcher matcher = NO_INSPECTION_PATTERN.matcher(text); return !matcher.matches(); }
@Override public int getChildRole(final ASTNode child) { LOG.assertTrue(child.getTreeParent() == this); final IElementType elType = child.getElementType(); if (elType == JavaElementType.TYPE_PARAMETER) { return ChildRole.TYPE_PARAMETER_IN_LIST; } else if (elType == JavaTokenType.COMMA) { return ChildRole.COMMA; } else if (elType == JavaTokenType.LT) { return ChildRole.LT_IN_TYPE_LIST; } else if (elType == JavaTokenType.GT) { return ChildRole.GT_IN_TYPE_LIST; } else { return ChildRoleBase.NONE; } }
@Override public void tokenize(@NotNull PsiLiteralExpression element, TokenConsumer consumer) { PsiLiteralExpressionImpl literalExpression = (PsiLiteralExpressionImpl)element; if (literalExpression.getLiteralElementType() != JavaTokenType.STRING_LITERAL) return; // not a string literal String text = literalExpression.getInnerText(); if (StringUtil.isEmpty(text) || text.length() <= 2) { // optimisation to avoid expensive injection check return; } if (InjectedLanguageUtil.hasInjections(literalExpression)) return; final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class); if (listOwner != null && AnnotationUtil.isAnnotated(listOwner, Collections.singleton(AnnotationUtil.NON_NLS), false, false)) { return; } if (!text.contains("\\")) { consumer.consumeToken(element, PlainTextSplitter.getInstance()); } else { processTextWithEscapeSequences(element, text, consumer); } }
@Override public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) { List<TextRange> result = new ArrayList<TextRange>(); result.addAll(expandToWholeLine(editorText, e.getTextRange(), false)); PsiTypeCastExpression expression = (PsiTypeCastExpression)e; PsiElement[] children = expression.getChildren(); PsiElement lParen = null; PsiElement rParen = null; for (PsiElement child : children) { if (child instanceof PsiJavaToken) { PsiJavaToken token = (PsiJavaToken)child; if (token.getTokenType() == JavaTokenType.LPARENTH) lParen = token; if (token.getTokenType() == JavaTokenType.RPARENTH) rParen = token; } } if (lParen != null && rParen != null) { result.addAll(expandToWholeLine(editorText, new TextRange(lParen.getTextRange().getStartOffset(), rParen.getTextRange().getEndOffset()), false)); } return result; }
@Override protected List<Block> buildChildren() { final ArrayList<Block> result = new ArrayList<Block>(); ASTNode child = myNode.getFirstChildNode(); Indent currentIndent = getLabelIndent(); Wrap currentWrap = null; while (child != null) { if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0){ result.add(createJavaBlock(child, mySettings, myJavaSettings, currentIndent, currentWrap, AlignmentStrategy.getNullStrategy())); if (child.getElementType() == JavaTokenType.COLON) { currentIndent = Indent.getNoneIndent(); currentWrap =Wrap.createWrap(WrapType.ALWAYS, true); } } child = child.getTreeNext(); } return result; }
@Override public ASTNode findChildByRole(int role) { LOG.assertTrue(ChildRole.isUnique(role)); if (role == ChildRole.MODIFIER_LIST) { return findChildByType(JavaElementType.MODIFIER_LIST); } else if (role == ChildRole.NAME) { return findChildByType(JavaTokenType.IDENTIFIER); } else if (role == ChildRole.TYPE) { return findChildByType(JavaElementType.TYPE); } else { return null; } }
@Override public int getChildRole(ASTNode child) { LOG.assertTrue(child.getTreeParent() == this); IElementType i = child.getElementType(); if (i == JavaElementType.MODIFIER_LIST) { return ChildRole.MODIFIER_LIST; } else if (i == JavaElementType.TYPE) { return getChildRole(child, ChildRole.TYPE); } else if (i == JavaTokenType.IDENTIFIER) { return getChildRole(child, ChildRole.NAME); } else { return ChildRoleBase.NONE; } }
public boolean satisfiedBy(PsiElement element) { if (!(element instanceof PsiComment)) { return false; } if (element instanceof PsiDocComment) { return false; } final PsiComment comment = (PsiComment)element; final IElementType type = comment.getTokenType(); if (!JavaTokenType.C_STYLE_COMMENT.equals(type)) { return false; } final PsiElement sibling = PsiTreeUtil.nextLeaf(comment); if (!(sibling instanceof PsiWhiteSpace)) { return false; } final String whitespaceText = sibling.getText(); return whitespaceText.indexOf((int)'\n') >= 0 || whitespaceText.indexOf((int)'\r') >= 0; }
@NotNull private List<ChainedCallChunk> splitMethodCallOnChunksByDots(@NotNull List<ASTNode> nodes) { List<ChainedCallChunk> result = new ArrayList<ChainedCallChunk>(); List<ASTNode> current = new ArrayList<ASTNode>(); for (ASTNode node : nodes) { if (node.getElementType() == JavaTokenType.DOT || node.getPsi() instanceof PsiComment) { result.add(new ChainedCallChunk(current)); current = new ArrayList<ASTNode>(); } current.add(node); } result.add(new ChainedCallChunk(current)); return result; }
@Override public int getChildRole(ASTNode child) { LOG.assertTrue(child.getTreeParent() == this); IElementType i = child.getElementType(); if (i == JavaTokenType.EXTENDS_KEYWORD) { return ChildRole.EXTENDS_KEYWORD; } else if (i == JavaTokenType.COMMA) { return ChildRole.COMMA; } else if (i == JavaElementType.JAVA_CODE_REFERENCE) { return ChildRole.REFERENCE_IN_LIST; } else { return ChildRoleBase.NONE; } }
@Override public ASTNode findChildByRole(int role){ LOG.assertTrue(ChildRole.isUnique(role)); switch(role){ default: return null; case ChildRole.DOC_COMMENT: return PsiImplUtil.findDocComment(this); case ChildRole.NAME: return findChildByType(JavaTokenType.IDENTIFIER); case ChildRole.ARGUMENT_LIST: return findChildByType(EXPRESSION_LIST); case ChildRole.ANONYMOUS_CLASS: return findChildByType(ENUM_CONSTANT_INITIALIZER); case ChildRole.MODIFIER_LIST: return findChildByType(JavaElementType.MODIFIER_LIST); } }
@Override public ASTNode findChildByRole(int role){ LOG.assertTrue(ChildRole.isUnique(role)); switch(role){ default: return null; case ChildRole.IMPORT_KEYWORD: return getFirstChildNode(); case ChildRole.IMPORT_ON_DEMAND_DOT: return findChildByType(JavaTokenType.DOT); case ChildRole.IMPORT_ON_DEMAND_ASTERISK: return findChildByType(JavaTokenType.ASTERISK); case ChildRole.CLOSING_SEMICOLON: return TreeUtil.findChildBackward(this, JavaTokenType.SEMICOLON); } }
@Override public int getChildRole(ASTNode child) { LOG.assertTrue(child.getTreeParent() == this); IElementType i = child.getElementType(); if (i == JavaTokenType.IMPORT_KEYWORD) { return ChildRole.IMPORT_KEYWORD; } else if (i == JavaElementType.JAVA_CODE_REFERENCE) { return ChildRole.IMPORT_REFERENCE; } else if (i == JavaTokenType.DOT) { return ChildRole.IMPORT_ON_DEMAND_DOT; } else if (i == JavaTokenType.ASTERISK) { return ChildRole.IMPORT_ON_DEMAND_ASTERISK; } else if (i == JavaTokenType.SEMICOLON) { return ChildRole.CLOSING_SEMICOLON; } else { return ChildRoleBase.NONE; } }
@Override public void deleteChildInternal(@NotNull ASTNode child) { if (child.getElementType() == JavaElementType.JAVA_CODE_REFERENCE){ ASTNode next = PsiImplUtil.skipWhitespaceAndComments(child.getTreeNext()); if (next != null && next.getElementType() == JavaTokenType.COMMA){ deleteChildInternal(next); } else{ ASTNode prev = PsiImplUtil.skipWhitespaceAndCommentsBack(child.getTreePrev()); if (prev != null){ if (prev.getElementType() == JavaTokenType.COMMA || prev.getElementType() == getKeywordType() ){ deleteChildInternal(prev); } } } } super.deleteChildInternal(child); }
@Override public int getChildRole(ASTNode child) { LOG.assertTrue(child.getTreeParent() == this); IElementType i = child.getElementType(); if (i == JavaTokenType.THROWS_KEYWORD) { return ChildRole.THROWS_KEYWORD; } else if (i == JavaTokenType.COMMA) { return ChildRole.COMMA; } else if (i == JavaElementType.JAVA_CODE_REFERENCE) { return ChildRole.REFERENCE_IN_LIST; } else { return ChildRoleBase.NONE; } }
@Override public void advance() { final IElementType tokenType = myDelegate.getTokenType(); if (tokenType == JavaTokenType.IDENTIFIER || tokenType == JavaTokenType.LONG_LITERAL || tokenType == JavaTokenType.INTEGER_LITERAL || tokenType == JavaTokenType.CHARACTER_LITERAL || tokenType == JavaTokenType.ARROW || tokenType == JavaTokenType.DOUBLE_COLON) { addOccurrenceInToken(UsageSearchContext.IN_CODE); } else if (tokenType == JavaTokenType.STRING_LITERAL) { scanWordsInToken(UsageSearchContext.IN_STRINGS | UsageSearchContext.IN_FOREIGN_LANGUAGES, false, true); } else if (ElementType.JAVA_COMMENT_BIT_SET.contains(tokenType)) { scanWordsInToken(UsageSearchContext.IN_COMMENTS, false, false); advanceTodoItemCountsInToken(); } else if (!ourSkipWordsScanSet.contains(tokenType)) { scanWordsInToken(UsageSearchContext.IN_PLAIN_TEXT, false, false); } myDelegate.advance(); }
private void restoreOtherInequalities(Fact removedFact, Collection<DfaMemoryStateImpl> mergedGroup, DfaMemoryStateImpl state) { Set<DfaConstValue> inequalitiesToRestore = null; for (DfaMemoryStateImpl member : mergedGroup) { LinkedHashSet<Fact> memberFacts = getFacts(member); if (memberFacts.contains(removedFact)) { Set<DfaConstValue> otherInequalities = getOtherInequalities(removedFact, memberFacts, member); if (inequalitiesToRestore == null) { inequalitiesToRestore = otherInequalities; } else { inequalitiesToRestore.retainAll(otherInequalities); } } } if (inequalitiesToRestore != null) { DfaRelationValue.Factory relationFactory = state.getFactory().getRelationFactory(); for (DfaConstValue toRestore : inequalitiesToRestore) { state.applyCondition(relationFactory.createRelation(removedFact.myVar, toRestore, JavaTokenType.EQEQ, true)); } } }
public boolean satisfiedBy(PsiElement element) { if (!(element instanceof PsiJavaToken)) { return false; } final PsiJavaToken token = (PsiJavaToken)element; if (token.getTokenType() != JavaTokenType.IF_KEYWORD) { return false; } final PsiElement parent = element.getParent(); if (!(parent instanceof PsiIfStatement)) { return false; } final PsiIfStatement statement = (PsiIfStatement)parent; if (ErrorUtil.containsError(statement)) { return false; } return SwitchUtils.getSwitchExpression(statement, 0) != null; }
@NotNull private PsiBuilder.Marker parseIfStatement(final PsiBuilder builder) { final PsiBuilder.Marker statement = builder.mark(); builder.advanceLexer(); if (!parseExpressionInParenth(builder)) { done(statement, JavaElementType.IF_STATEMENT); return statement; } final PsiBuilder.Marker thenStatement = parseStatement(builder); if (thenStatement == null) { error(builder, JavaErrorMessages.message("expected.statement")); done(statement, JavaElementType.IF_STATEMENT); return statement; } if (!expect(builder, JavaTokenType.ELSE_KEYWORD)) { done(statement, JavaElementType.IF_STATEMENT); return statement; } final PsiBuilder.Marker elseStatement = parseStatement(builder); if (elseStatement == null) { error(builder, JavaErrorMessages.message("expected.statement")); } done(statement, JavaElementType.IF_STATEMENT); return statement; }
@NotNull private PsiBuilder.Marker parseForLoopFromInitialization(final PsiBuilder builder, final PsiBuilder.Marker statement) { final PsiBuilder.Marker init = parseStatement(builder); if (init == null){ error(builder, JavaErrorMessages.message("expected.statement")); if (!expect(builder, JavaTokenType.RPARENTH)) { done(statement, JavaElementType.FOR_STATEMENT); return statement; } } else { myParser.getExpressionParser().parse(builder); if (!expect(builder, JavaTokenType.SEMICOLON)) { error(builder, JavaErrorMessages.message("expected.semicolon")); if (!expect(builder, JavaTokenType.RPARENTH)) { done(statement, JavaElementType.FOR_STATEMENT); return statement; } } else { parseExpressionOrExpressionList(builder); if (!expect(builder, JavaTokenType.RPARENTH)) { error(builder, JavaErrorMessages.message("expected.rparen")); done(statement, JavaElementType.FOR_STATEMENT); return statement; } } } final PsiBuilder.Marker bodyStatement = parseStatement(builder); if (bodyStatement == null) { error(builder, JavaErrorMessages.message("expected.statement")); } done(statement, JavaElementType.FOR_STATEMENT); return statement; }