private static Collection<String> suggestKeywords(PsiElement position) { TextRange posRange = position.getTextRange(); CupFile posFile = (CupFile) position.getContainingFile(); TextRange range = new TextRange(0, posRange.getStartOffset()); String text = range.isEmpty() ? CompletionInitializationContext.DUMMY_IDENTIFIER : range.substring(posFile.getText()); int completionOffset = posRange.getStartOffset() - range.getStartOffset(); // = posRange.getStartOffset() ... PsiFile file = PsiFileFactory.getInstance(posFile.getProject()).createFileFromText("a.cup", CupLanguage.INSTANCE, text, true, false); GeneratedParserUtilBase.CompletionState state = new GeneratedParserUtilBase.CompletionState(completionOffset) { @Nullable @Override public String convertItem(Object o) { if (o == CupTypes.IDENTIFIER) { return null; } return o.toString(); } }; file.putUserData(GeneratedParserUtilBase.COMPLETION_STATE_KEY, state); TreeUtil.ensureParsed(file.getNode()); return state.items; }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet resultSet) { PsiElement position = parameters.getPosition(); PsiElement parent = position.getParent(); PsiElement grandParent = Optional.ofNullable(parent) .map(PsiElement::getParent) .orElse(null); if (parent instanceof ElmFile || parent instanceof GeneratedParserUtilBase.DummyBlock) { addCompletionsInInvalidExpression(position, resultSet); } else if (grandParent instanceof ElmLowerCasePath) { this.addValueOrFieldCompletions((ElmLowerCaseId) parent, resultSet); } else if (grandParent instanceof ElmMixedCasePath || grandParent instanceof ElmUpperCasePath) { addTypeOrModuleCompletions(parent, resultSet); } else if (grandParent instanceof ElmExposingClause) { this.addExposedValuesCompletion((ElmExposingClause)grandParent, resultSet); } else if (parent instanceof ElmUpperCaseId) { this.addExposedValuesCompletion((ElmUpperCaseId)parent, resultSet); } else if (parent instanceof ElmLowerCaseId && grandParent instanceof ElmModuleDeclaration) { this.singleModuleValueProvider.addCompletions((ElmFile)grandParent.getContainingFile(), resultSet); } }
public CaseOfParser( GeneratedParserUtilBase.Parser header, GeneratedParserUtilBase.Parser branch, GeneratedParserUtilBase.Parser oneOrMoreSeparations ) { this.header = header; this.branch = branch; this.oneOrMoreSeparations = oneOrMoreSeparations; }
/** * Returns current position in the {@link PsiBuilder}. * * @param builder_ builder * @return current position */ public static int current_position_(PsiBuilder builder_) { try { if (GeneratedParserUtilBase.class.getMethod("current_position_", PsiBuilder.class) != null) { return GeneratedParserUtilBase.current_position_(builder_); } } catch (NoSuchMethodException ignored) { } return 0; }
/** * Checks if next token of {@link PsiBuilder} is in the given tokens list. * * @param builder_ builder * @param frameName frame name * @param tokens tokens list * @return builder is in the tokens list */ public static boolean nextTokenIs(PsiBuilder builder_, String frameName, IElementType... tokens) { try { if (GeneratedParserUtilBase.class.getMethod("nextTokenIs", PsiBuilder.class, String.class, IElementType.class) != null) { return GeneratedParserUtilBase.nextTokenIs(builder_, frameName, tokens); } } catch (NoSuchMethodException ignored) { } return true; }
/** * Checks if at the given position there is empty element. * * @param builder_ builder * @param funcName_ function name * @param prev_position_ previous position * @return empty element at the given position */ public static boolean empty_element_parsed_guard_(PsiBuilder builder_, String funcName_, int prev_position_) { try { if (GeneratedParserUtilBase.class.getMethod("nextTokenIs", PsiBuilder.class, String.class, int.class) != null) { return GeneratedParserUtilBase.empty_element_parsed_guard_(builder_, funcName_, prev_position_); } } catch (NoSuchMethodException ignored) { } return true; }
private Collection<String> suggestKeywords(@NotNull PsiElement position) { PsiFile psiFile = position.getContainingFile(); PsiElement topLevelElement = position; while(!(topLevelElement.getParent() instanceof PsiFile)) { topLevelElement = topLevelElement.getParent(); } PsiFile file = PsiFileFactory.getInstance(psiFile.getProject()).createFileFromText("a.thrift", ThriftLanguage.INSTANCE, topLevelElement.getText(), true, false); GeneratedParserUtilBase.CompletionState state = new GeneratedParserUtilBase.CompletionState(position.getTextOffset() - topLevelElement.getTextOffset()); file.putUserData(GeneratedParserUtilBase.COMPLETION_STATE_KEY, state); TreeUtil.ensureParsed(file.getNode()); return state.items; }
private Collection<String> suggestKeywords(@NotNull PsiElement position) { PsiFile psiFile = position.getContainingFile(); PsiElement topLevelElement = position; while (!(topLevelElement.getParent() instanceof PsiFile)) { topLevelElement = topLevelElement.getParent(); } PsiFile file = PsiFileFactory.getInstance(psiFile.getProject()) .createFileFromText("a.thrift", ThriftLanguage.INSTANCE, topLevelElement.getText(), true, false); GeneratedParserUtilBase.CompletionState state = new GeneratedParserUtilBase.CompletionState(position.getTextOffset() - topLevelElement.getTextOffset()); file.putUserData(GeneratedParserUtilBase.COMPLETION_STATE_KEY, state); TreeUtil.ensureParsed(file.getNode()); return state.items; }
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass") public static PsiBuilder adapt_builder_(IElementType root, PsiBuilder builder, PsiParser parser, TokenSet[] tokenSets) { PsiBuilder result = GeneratedParserUtilBase.adapt_builder_(root, builder, parser, tokenSets); ErrorState.get(result).altMode = true; return result; }
public DummyRoot(PsiElement child) { super(GeneratedParserUtilBase.DUMMY_BLOCK); this.child = child; }