本文整理汇总了Java中org.antlr.v4.runtime.misc.Utils.join方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.join方法的具体用法?Java Utils.join怎么用?Java Utils.join使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.misc.Utils
的用法示例。
在下文中一共展示了Utils.join方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
@Override
public String toString() {
return Utils.join(syntaxErrors.iterator(), "\n");
}
示例2: toString
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
@Override
public String toString() {
return Utils.join(syntaxErrors.iterator(), "\n");
}
示例3: toString
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
@Override
public String toString() {
return Utils.join(Arrays.asList(opnds).iterator(), "&&");
}
示例4: actionPerformed
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
LOG.info("actionPerformed GenerateLexerRulesForLiteralsAction");
final Project project = e.getProject();
final PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
if (psiFile == null) {
return;
}
String inputText = psiFile.getText();
ParsingResult results = ParsingUtils.parseANTLRGrammar(inputText);
final Parser parser = results.parser;
final ParseTree tree = results.tree;
Collection<ParseTree> literalNodes = XPath.findAll(tree, "//ruleBlock//STRING_LITERAL", parser);
LinkedHashMap<String, String> lexerRules = new LinkedHashMap<String, String>();
for (ParseTree node : literalNodes) {
String literal = node.getText();
String ruleText = String.format("%s : %s ;",
RefactorUtils.getLexerRuleNameFromLiteral(literal), literal);
lexerRules.put(literal, ruleText);
}
// remove those already defined
String lexerRulesXPath = "//lexerRule";
String treePattern = "<TOKEN_REF> : <STRING_LITERAL>;";
ParseTreePattern p = parser.compileParseTreePattern(treePattern, ANTLRv4Parser.RULE_lexerRule);
List<ParseTreeMatch> matches = p.findAll(tree, lexerRulesXPath);
for (ParseTreeMatch match : matches) {
ParseTree lit = match.get("STRING_LITERAL");
if (lexerRules.containsKey(lit.getText())) { // we have rule for this literal already
lexerRules.remove(lit.getText());
}
}
final LiteralChooser chooser =
new LiteralChooser(project, new ArrayList<String>(lexerRules.values()));
chooser.show();
List<String> selectedElements = chooser.getSelectedElements();
// chooser disposed automatically.
final Editor editor = e.getData(PlatformDataKeys.EDITOR);
final Document doc = editor.getDocument();
final CommonTokenStream tokens = (CommonTokenStream) parser.getTokenStream();
// System.out.println(selectedElements);
if (selectedElements != null) {
String text = doc.getText();
int cursorOffset = editor.getCaretModel().getOffset();
// make sure it's not in middle of rule; put between.
// System.out.println("offset "+cursorOffset);
Collection<ParseTree> allRuleNodes = XPath.findAll(tree, "//ruleSpec", parser);
for (ParseTree r : allRuleNodes) {
Interval extent = r.getSourceInterval(); // token indexes
int start = tokens.get(extent.a).getStartIndex();
int stop = tokens.get(extent.b).getStopIndex();
// System.out.println("rule "+r.getChild(0).getText()+": "+start+".."+stop);
if (cursorOffset < start) {
// before this rule, so must be between previous and this one
cursorOffset = start; // put right before this rule
break;
}
else if (cursorOffset >= start && cursorOffset <= stop) {
// cursor in this rule
cursorOffset = stop + 2; // put right before this rule (after newline)
if (cursorOffset >= text.length()) {
cursorOffset = text.length();
}
break;
}
}
String allRules = Utils.join(selectedElements.iterator(), "\n");
text =
text.substring(0, cursorOffset) +
"\n" + allRules + "\n" +
text.substring(cursorOffset, text.length());
MyPsiUtils.replacePsiFileFromText(project, psiFile, text);
}
}
示例5: showParseRegion
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
/**
* Show tokens/region associated with parse tree parent of this token
* if the alt-key is down and mouse movement occurs.
*/
public void showParseRegion(EditorMouseEvent event, Editor editor,
PreviewState previewState, int offset) {
Token tokenUnderCursor = ParsingUtils.getTokenUnderCursor(previewState, offset);
if ( tokenUnderCursor==null ) {
return;
}
ParseTree tree = previewState.parsingResult.tree;
TerminalNode nodeWithToken =
(TerminalNode) ParsingUtils.getParseTreeNodeWithToken(tree, tokenUnderCursor);
if ( nodeWithToken==null ) {
// hidden token
return;
}
PreviewParser parser = (PreviewParser) previewState.parsingResult.parser;
CommonTokenStream tokenStream = (CommonTokenStream) parser.getInputStream();
ParserRuleContext parent = (ParserRuleContext) nodeWithToken.getParent();
Interval tokenInterval = parent.getSourceInterval();
Token startToken = tokenStream.get(tokenInterval.a);
Token stopToken = tokenStream.get(tokenInterval.b);
Interval sourceInterval =
Interval.of(startToken.getStartIndex(), stopToken.getStopIndex()+1);
// int ruleIndex = parent.getRuleIndex();
// String ruleName = parser.getRuleNames()[ruleIndex];
// System.out.println("parent " + ruleName + " region " + sourceInterval);
List<String> stack = parser.getRuleInvocationStack(parent);
Collections.reverse(stack);
if ( stack.size()>MAX_STACK_DISPLAY ) {
// collapse contiguous dups to handle left-recursive stacks
List<Pair<String, Integer>> smaller = new ArrayList<Pair<String, Integer>>();
int last = 0;
smaller.add(new Pair<String, Integer>(stack.get(0), 1)); // init to having first element, count of 1
for (int i = 1; i<stack.size(); i++) {
String s = stack.get(i);
if ( smaller.get(last).a.equals(s) ) {
smaller.set(last, new Pair<String, Integer>(s, smaller.get(last).b+1));
}
else {
smaller.add(new Pair<String, Integer>(s, 1));
last++;
}
}
stack = new ArrayList<String>();
for (int i = 0; i<smaller.size(); i++) {
Pair<String, Integer> pair = smaller.get(i);
if ( pair.b>1 ) {
stack.add(pair.a+"^"+pair.b);
}
else {
stack.add(pair.a);
}
}
}
String stackS = Utils.join(stack.toArray(), "\n");
highlightAndOfferHint(editor, offset, sourceInterval,
JBColor.BLUE, EffectType.ROUNDED_BOX, stackS);
// Code for a balloon.
// JBPopupFactory popupFactory = JBPopupFactory.getInstance();
// BalloonBuilder builder =
// popupFactory.createHtmlTextBalloonBuilder(Utils.join(stack.toArray(), "<br>"),
// MessageType.INFO, null);
// builder.setHideOnClickOutside(true);
// Balloon balloon = builder.createBalloon();
// MouseEvent mouseEvent = event.getMouseEvent();
// Point point = mouseEvent.getPoint();
// point.translate(10, -15);
// RelativePoint where = new RelativePoint(mouseEvent.getComponent(), point);
// balloon.show(where, Balloon.Position.above);
}
示例6: showTooltips
import org.antlr.v4.runtime.misc.Utils; //导入方法依赖的package包/类
/**
* Display syntax errors, hints in tooltips if under the cursor
*/
public static void showTooltips(EditorMouseEvent event, Editor editor,
@NotNull PreviewState previewState, int offset) {
if ( previewState.parsingResult==null ) return; // no results?
// Turn off any tooltips if none under the cursor
// find the highlighter associated with this offset
List<RangeHighlighter> highlightersAtOffset = MyActionUtils.getRangeHighlightersAtOffset(editor, offset);
if ( highlightersAtOffset.size()==0 ) {
return;
}
List<String> msgList = new ArrayList<String>();
boolean foundDecisionEvent = false;
for (int i = 0; i<highlightersAtOffset.size(); i++) {
RangeHighlighter r = highlightersAtOffset.get(i);
DecisionEventInfo eventInfo = r.getUserData(ProfilerPanel.DECISION_EVENT_INFO_KEY);
String msg;
if ( eventInfo!=null ) {
// TODO: move decision event stuff to profiler?
if ( eventInfo instanceof AmbiguityInfo ) {
msg = "Ambiguous upon alts "+eventInfo.configs.getAlts().toString();
}
else if ( eventInfo instanceof ContextSensitivityInfo ) {
msg = "Context-sensitive";
}
else if ( eventInfo instanceof LookaheadEventInfo ) {
int k = eventInfo.stopIndex-eventInfo.startIndex+1;
msg = "Deepest lookahead k="+k;
}
else if ( eventInfo instanceof PredicateEvalInfo ) {
PredicateEvalInfo evalInfo = (PredicateEvalInfo) eventInfo;
msg = ProfilerPanel.getSemanticContextDisplayString(evalInfo,
previewState,
evalInfo.semctx, evalInfo.predictedAlt,
evalInfo.evalResult);
msg = msg+(!evalInfo.fullCtx ? " (DFA)" : "");
}
else {
msg = "Unknown decision event: "+eventInfo;
}
foundDecisionEvent = true;
}
else {
// error tool tips
SyntaxError errorUnderCursor = r.getUserData(SYNTAX_ERROR);
msg = getErrorDisplayString(errorUnderCursor);
if ( msg.length()>MAX_HINT_WIDTH ) {
msg = msg.substring(0, MAX_HINT_WIDTH)+"...";
}
if ( msg.indexOf('<')>=0 ) {
msg = msg.replaceAll("<", "<");
}
}
msgList.add(msg);
}
String combinedMsg = Utils.join(msgList.iterator(), "\n");
HintManagerImpl hintMgr = (HintManagerImpl) HintManager.getInstance();
if ( foundDecisionEvent ) {
showDecisionEventToolTip(editor, offset, hintMgr, combinedMsg.toString());
}
else {
showPreviewEditorErrorToolTip(editor, offset, hintMgr, combinedMsg.toString());
}
}