@Override protected boolean isStableFormattingStartToken( Token<JspTokenId> token, JoinedTokenSequence<JspTokenId> ts) { return token.id() == JspTokenId.SYMBOL2 && (token.text().toString().equals("<%") || token.text().toString().equals("<%=") || token.text().toString().equals("<%!")); }
void checkQtObject(Token<CppTokenId> token) { if (!isQtObject) { isQtObject = token.id() == IDENTIFIER && CharSequenceUtilities.equals(token.text(), "Q_OBJECT"); // NOI18N } }
@Override protected boolean isPreservedLine( Token<JspTokenId> token, IndenterContextData<JspTokenId> context) { String text = token.text().toString().trim(); if (token.id() == JspTokenId.COMMENT) { if (!text.startsWith("<%--") && !text.startsWith("--%>")) { return true; } } return false; }
private String getFunctionalTplTokenId(Token<TplTopTokenId> token) { TokenHierarchy<CharSequence> th = TokenHierarchy.create(token.text(), TplTokenId.language()); TokenSequence<TplTokenId> sequence = th.tokenSequence(TplTokenId.language()); while (sequence.moveNext()) { if (sequence.token().id() == TplTokenId.WHITESPACE) { continue; } else { return sequence.token().toString(); } } return ""; }
@SuppressWarnings("empty-statement") private DeclarationLocation findUrl(PythonParserResult info, Document doc, int lexOffset) { TokenSequence<?> ts = PythonLexerUtils.getPythonSequence((BaseDocument) doc, lexOffset); if (ts == null) { return DeclarationLocation.NONE; } ts.move(lexOffset); if (!ts.moveNext() && !ts.movePrevious()) { return DeclarationLocation.NONE; } Token<?> token = ts.token(); TokenSequence<?> embedded = ts.embedded(); if (embedded != null) { ts = embedded; embedded.move(lexOffset); if (!embedded.moveNext() && !embedded.movePrevious()) { return DeclarationLocation.NONE; } token = embedded.token(); } // Is this a comment? If so, possibly do rdoc-method reference jump if ((token != null) && (token.id() == PythonStringTokenId.URL)) { // TODO - use findLinkedMethod String method = token.text().toString(); if (method.startsWith("www.")) { // NOI18N method = "http://" + method; // NOI18N } // A URL such as http://netbeans.org - try to open it in a browser! try { URL url = new URL(method); return new DeclarationLocation(url); } catch (MalformedURLException mue) { // URL is from user source... don't complain with exception dialogs etc. ; } } return DeclarationLocation.NONE; }
public boolean verifyState(Document doc, int offset) { TokenHierarchy hi = TokenHierarchy.get(doc); TokenSequence<HTMLTokenId> ts = hi.tokenSequence(HTMLTokenId.language()); if (ts != null) { ts.move(offset); ts.moveNext(); Token<HTMLTokenId> tok = ts.token(); int newOffset = ts.offset(); String matcherText = tok.text().toString(); Matcher m = MY_SPECIAL_PATTERN.matcher(matcherText); if (m.matches()) { target = m.group(1); int idx = matcherText.indexOf(target); targetStart = newOffset + idx; targetEnd = targetStart + target.length(); return true; } } return false; }
private static CharSequence dumpTokens(TokenSequence<?> seq) { seq.moveStart(); StringBuilder builder = new StringBuilder(); Token<?> token = null; while (seq.moveNext()) { if (token != null) { builder.append('\n'); } token = seq.token(); builder.append(token.id()); PartType part = token.partType(); if (part != PartType.COMPLETE) { builder.append(' '); builder.append(token.partType()); } builder.append(' '); builder.append('\''); builder.append(token.text()); builder.append('\''); } return builder; }
private DeclarationLocation findImport(PythonParserResult info, int lexOffset, BaseDocument doc) { TokenSequence<? extends PythonTokenId> ts = PythonLexerUtils.getPositionedSequence(doc, lexOffset); if (ts == null) { return DeclarationLocation.NONE; } if (ts.offset() == lexOffset) { // We're looking at the offset to the RIGHT of the caret // and here I care about what's on the left if (!ts.movePrevious()) { return DeclarationLocation.NONE; } } Token<? extends PythonTokenId> token = ts.token(); if (token == null) { return DeclarationLocation.NONE; } TokenId id = token.id(); String moduleName = null; while (true) { if (id == PythonTokenId.IDENTIFIER || id.primaryCategory().equals(PythonLexer.KEYWORD_CAT)) { // Possibly inside the import string String tokenText = token.text().toString(); if (moduleName == null) { moduleName = tokenText; } else { moduleName = tokenText + "." + moduleName; } } else if (id != PythonTokenId.DOT) { break; } if (!ts.movePrevious()) { return DeclarationLocation.NONE; } token = ts.token(); id = token.id(); } if (id != PythonTokenId.ERROR && id != PythonTokenId.NEWLINE && id != PythonTokenId.WHITESPACE) { return DeclarationLocation.NONE; } if (!ts.movePrevious()) { return DeclarationLocation.NONE; } token = ts.token(); id = token.id(); if (id != PythonTokenId.IMPORT) { return DeclarationLocation.NONE; } if (moduleName == null) { return DeclarationLocation.NONE; } if (id == PythonTokenId.IMPORT || id == PythonTokenId.FROM) { if (id == PythonTokenId.IMPORT && ts.movePrevious() && ts.token().id() == PythonTokenId.WHITESPACE && ts.movePrevious()) { // See if this was "from foo import bar" such that we really should // be listing symbols inside the foo library token = ts.token(); id = token.id(); String library = null; while (true) { if (id == PythonTokenId.IDENTIFIER || id.primaryCategory().equals(PythonLexer.KEYWORD_CAT)) { // Possibly inside the import string String tokenText = token.text().toString(); if (library == null) { library = tokenText; } else { library = tokenText + "." + library; } } else if (id != PythonTokenId.DOT) { break; } if (!ts.movePrevious()) { return DeclarationLocation.NONE; } token = ts.token(); id = token.id(); } if (library != null) { if (id == PythonTokenId.WHITESPACE && ts.movePrevious() && ts.token().id() == PythonTokenId.FROM) { return findImport(info, library, moduleName); } } } return findImport(info, moduleName, null); } return DeclarationLocation.NONE; }
@Override protected boolean isEndTagClosingSymbol(Token<JspTokenId> token) { return token.id() == JspTokenId.SYMBOL && (token.text().toString().equals("/>") || token.text().toString().equals("%>")); }
@Override protected boolean isEndTagSymbol(Token<JspTokenId> token) { return token.id() == JspTokenId.SYMBOL && token.text().toString().equals(">"); }
@Override protected boolean isStartTagClosingSymbol(Token<JspTokenId> token) { return token.id() == JspTokenId.SYMBOL && token.text().toString().equals("</"); }
@Override protected boolean isStartTagSymbol(Token<JspTokenId> token) { return token.id() == JspTokenId.SYMBOL && (token.text().toString().equals("<") || token.text().toString().equals("<%@")); }
@Override protected boolean isWhiteSpaceToken(Token<JspTokenId> token) { return token.id() == JspTokenId.WHITESPACE || (token.id() == JspTokenId.TEXT && token.text().toString().trim().length() == 0); }
@Override protected boolean isForeignLanguageEndToken( Token<JspTokenId> token, JoinedTokenSequence<JspTokenId> ts) { return token.id() == JspTokenId.SYMBOL2 && token.text().toString().equals("%>"); }
@SuppressWarnings("unchecked") @Override protected LanguageEmbedding embedding( Token<HTMLTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) { if (LOG) { LOGGER.log( Level.FINE, String.format( "HTMLTokenId$Language<HTMLTokenId>.embedding(...) called on removed token with %s token id. LanguagePath: %s", token.id(), languagePath), new IllegalStateException()); // NOI18N } String mimeType = null; switch (token.id()) { // BEGIN TOR MODIFICATIONS case VALUE_JAVASCRIPT: mimeType = JAVASCRIPT_MIMETYPE; if (mimeType != null) { Language lang = Language.find(mimeType); if (lang == null) { return null; // no language found } else { // TODO: // XXX Don't handle JavaScript for non-quoted attributes // (Or use separate state so I can do 0,0 as offsets there // Marek: AFAIK value of the onSomething methods is always javascript // so having the attribute unqouted doesn't make much sense - the html spec // allows only a-zA-Z characters in unqouted values so I belive // it is not possible to write reasonable js code - it ususally // contains some whitespaces, brackets, quotations etc. PartType ptype = token.partType(); int startSkipLength = ptype == PartType.COMPLETE || ptype == PartType.START ? 1 : 0; int endSkipLength = ptype == PartType.COMPLETE || ptype == PartType.END ? 1 : 0; // do not join css code sections in attribute value between each other, // only token parts inside one value return LanguageEmbedding.create( lang, startSkipLength, endSkipLength, (ptype == PartType.END || ptype == PartType.COMPLETE) ? false : true); } } break; // END TOR MODIFICATIONS case VALUE_CSS: mimeType = STYLE_MIMETYPE; if (mimeType != null) { Language lang = Language.find(mimeType); if (lang == null) { return null; // no language found } else { PartType ptype = token.partType(); if (token.isRemoved()) { // strange, but sometimes the embedding is requested on removed token which has // null image return null; } char firstChar = token.text().charAt(0); boolean quoted = firstChar == '\'' || firstChar == '"'; int startSkipLength = quoted && (ptype == PartType.COMPLETE || ptype == PartType.START) ? 1 : 0; int endSkipLength = quoted && (ptype == PartType.COMPLETE || ptype == PartType.END) ? 1 : 0; // do not join css code sections in attribute value between each other, // only token parts inside one value return LanguageEmbedding.create( lang, startSkipLength, endSkipLength, (ptype == PartType.END || ptype == PartType.COMPLETE) ? false : true); } } break; case SCRIPT: mimeType = JAVASCRIPT_MIMETYPE; break; case STYLE: mimeType = STYLE_MIMETYPE; break; } if (mimeType != null) { Language lang = Language.find(mimeType); if (lang == null) { return null; // no language found } else { return LanguageEmbedding.create(lang, 0, 0, true); } } return null; }
boolean isSlots(Token<CppTokenId> token) { return token.id() == IDENTIFIER && CharSequenceUtilities.equals(token.text(), "slots"); // NOI18N }