Java Code Examples for org.netbeans.api.lexer.TokenSequence#isEmpty()
The following examples show how to use
org.netbeans.api.lexer.TokenSequence#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavadocCompletionUtils.java From netbeans with Apache License 2.0 | 6 votes |
public static boolean isJavadocContext(TokenHierarchy hierarchy, int offset) { TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(hierarchy, offset); if (!movedToJavadocToken(ts, offset)) { return false; } TokenSequence<JavadocTokenId> jdts = ts.embedded(JavadocTokenId.language()); if (jdts == null) { return false; } else if (jdts.isEmpty()) { return isEmptyJavadoc(ts.token(), offset - ts.offset()); } jdts.move(offset); if (!jdts.moveNext() && !jdts.movePrevious()) { return false; } // this checks /** and */ headers return isInsideToken(jdts, offset) && !isInsideIndent(jdts.token(), offset - jdts.offset()); }
Example 2
Source File: CodeCompletionUtils.java From netbeans with Apache License 2.0 | 6 votes |
static boolean inVariableModifiers(Document doc, int caretOffset) { TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc); TokenSequence tokenSequence = tokenHierarchy.tokenSequence(); tokenSequence.move(caretOffset); tokenSequence.movePrevious(); tokenSequence.moveNext(); while (!tokenSequence.isEmpty()) { if (tokenSequence.token().id() == TplTopTokenId.T_SMARTY_OPEN_DELIMITER || tokenSequence.token().id() == TplTopTokenId.T_HTML && isDefaultOpenDelimOnPreviousPosition(doc, caretOffset)) { return false; } else if (tokenSequence.token().id() == TplTopTokenId.T_SMARTY) { if (tokenSequence.token().text().toString().contains("|")) { return true; } } tokenSequence.movePrevious(); } return false; }
Example 3
Source File: JavadocCompletionUtils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks whether Doc instance matches to its token sequence representation. * @param javadoc Doc instance of javadoc * @param ts javadoc token sequence * @return true if it is valid javadoc * * @see <a href="http://www.netbeans.org/issues/show_bug.cgi?id=139147">139147</a> */ public static boolean isInvalidDocInstance(DocCommentTree javadoc, TokenSequence<JavadocTokenId> ts) { if (javadoc == null || javadoc.getFullBody().isEmpty()) { if (!ts.isEmpty()) { ts.moveStart(); return !(ts.moveNext() && isTokenOfEmptyJavadoc(ts.token()) && ts.moveNext() == false); } } return false; }
Example 4
Source File: CustomFoldManager.java From netbeans with Apache License 2.0 | 4 votes |
private void updateFolds(TokenSequence seq, FoldHierarchyTransaction transaction) { if (seq != null && !seq.isEmpty()) { processTokenList(seq, transaction); } if (maxUpdateMarkOffset == -1) { // no updates return; } // Find the first mark to update and init the prevMark and parentMark prior the loop int index = findMarkIndex(minUpdateMarkOffset); FoldMarkInfo prevMark; FoldMarkInfo parentMark; if (index == 0) { // start from begining prevMark = null; parentMark = null; } else { prevMark = getMark(index - 1); parentMark = prevMark.getParentMark(); } // Iterate through the changed marks in the mark array int markCount = getMarkCount(); while (index < markCount) { // process the marks FoldMarkInfo mark = getMark(index); // If the mark was released then it must be removed if (mark.isReleased()) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Removing released mark at ind=" + index + ": " + mark); // NOI18N } removeMark(index); markCount--; continue; } // Update mark's status (folds, parentMark etc.) if (mark.isStartMark()) { // starting a new fold if (prevMark == null || prevMark.isStartMark()) { // new level mark.setParentMark(prevMark); // prevMark == null means root level parentMark = prevMark; } // same level => parent to the parent of the prevMark } else { // end mark if (prevMark != null) { if (prevMark.isStartMark()) { // closing nearest fold prevMark.setEndMark(mark, false, transaction); } else { // prevMark is end mark - closing its parent fold if (parentMark != null) { // mark's parent gets set as well parentMark.setEndMark(mark, false, transaction); parentMark = parentMark.getParentMark(); } else { // prevMark's parentMark is null (top level) mark.makeSolitaire(false, transaction); } } } else { // prevMark is null mark.makeSolitaire(false, transaction); } } // Set parent mark of the mark mark.setParentMark(parentMark); prevMark = mark; index++; } minUpdateMarkOffset = Integer.MAX_VALUE; maxUpdateMarkOffset = -1; if (LOG.isLoggable(Level.FINE)) { LOG.fine("MARKS DUMP:\n" + this); //NOI18N } }
Example 5
Source File: CompletionUtil.java From netbeans with Apache License 2.0 | 4 votes |
public static boolean isTokenSequenceUsable(TokenSequence tokenSequence) { return ((tokenSequence != null) && (tokenSequence.isValid()) && (! tokenSequence.isEmpty())); }
Example 6
Source File: CompletionSupport.java From netbeans with Apache License 2.0 | 4 votes |
private String getConfirmChars (JTextComponent component) { NbEditorDocument doc = (NbEditorDocument) component.getDocument (); StringBuffer buf = new StringBuffer(); int offset = component.getCaret ().getDot (); try { TokenHierarchy tokenHierarchy = TokenHierarchy.get (doc); if (doc instanceof NbEditorDocument) { ((NbEditorDocument) doc).readLock (); } try { TokenSequence sequence = tokenHierarchy.tokenSequence (); if (sequence.isEmpty()) { return ""; // NOI18N } //find most embedded token sequence on the specified offset while(true) { sequence.move (offset - 1); if (!sequence.moveNext()) { return ""; // NOI18N } TokenSequence embedded = sequence.embedded (); if (embedded == null) break; sequence = embedded; } Token token = sequence.token (); String tokenType = token.id ().name (); String mimeType = sequence.language ().mimeType (); Language l = LanguagesManager.getDefault ().getLanguage (mimeType); List<Feature> features = l.getFeatureList ().getFeatures (CompletionProviderImpl.COMPLETION, tokenType); Iterator<Feature> it = features.iterator (); while (it.hasNext ()) { Feature feature = it.next (); String confChars = (String) feature.getValue("confirmChars"); // NOI18N if (confChars != null) { buf.append(confChars); } } } finally { if (doc instanceof NbEditorDocument) ((NbEditorDocument) doc).readUnlock (); } } catch (LanguageDefinitionNotFoundException ex) { } return buf.toString(); }
Example 7
Source File: CustomFoldManager.java From netbeans with Apache License 2.0 | 4 votes |
private void updateFolds(TokenSequence seq, FoldHierarchyTransaction transaction) { if (seq != null && !seq.isEmpty()) { processTokenList(seq, transaction); } if (maxUpdateMarkOffset == -1) { // no updates return; } // Find the first mark to update and init the prevMark and parentMark prior the loop int index = findMarkIndex(minUpdateMarkOffset); FoldMarkInfo prevMark; FoldMarkInfo parentMark; if (index == 0) { // start from begining prevMark = null; parentMark = null; } else { prevMark = getMark(index - 1); parentMark = prevMark.getParentMark(); } // Iterate through the changed marks in the mark array int markCount = getMarkCount(); while (index < markCount) { // process the marks FoldMarkInfo mark = getMark(index); // If the mark was released then it must be removed if (mark.isReleased()) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Removing released mark at ind=" + index + ": " + mark); // NOI18N } removeMark(index); markCount--; continue; } // Update mark's status (folds, parentMark etc.) if (mark.isStartMark()) { // starting a new fold if (prevMark == null || prevMark.isStartMark()) { // new level mark.setParentMark(prevMark); // prevMark == null means root level parentMark = prevMark; } // same level => parent to the parent of the prevMark } else { // end mark if (prevMark != null) { if (prevMark.isStartMark()) { // closing nearest fold prevMark.setEndMark(mark, false, transaction); } else { // prevMark is end mark - closing its parent fold if (parentMark != null) { // mark's parent gets set as well parentMark.setEndMark(mark, false, transaction); parentMark = parentMark.getParentMark(); } else { // prevMark's parentMark is null (top level) mark.makeSolitaire(false, transaction); } } } else { // prevMark is null mark.makeSolitaire(false, transaction); } } // Set parent mark of the mark mark.setParentMark(parentMark); prevMark = mark; index++; } minUpdateMarkOffset = Integer.MAX_VALUE; maxUpdateMarkOffset = -1; if (LOG.isLoggable(Level.FINE)) { LOG.fine("MARKS DUMP:\n" + this); //NOI18N } }