Search in sources :

Example 1 with WordOccurrence

use of com.intellij.lang.cacheBuilder.WordOccurrence in project intellij-community by JetBrains.

the class FormWordsScanner method processWords.

@Override
public void processWords(CharSequence fileText, final Processor<WordOccurrence> processor) {
    super.processWords(fileText, processor);
    try {
        LwRootContainer container = Utils.getRootContainer(fileText.toString(), null);
        String className = container.getClassToBind();
        if (className != null) {
            processClassAndPackagesNames(className, processor);
        }
        FormEditingUtil.iterate(container, new FormEditingUtil.ComponentVisitor() {

            WordOccurrence occurence;

            public boolean visit(IComponent iComponent) {
                String componentClassName = iComponent.getComponentClassName();
                processClassAndPackagesNames(componentClassName, processor);
                final String binding = iComponent.getBinding();
                if (binding != null) {
                    if (occurence == null)
                        occurence = new WordOccurrence(binding, 0, binding.length(), WordOccurrence.Kind.FOREIGN_LANGUAGE);
                    else
                        occurence.init(binding, 0, binding.length(), WordOccurrence.Kind.FOREIGN_LANGUAGE);
                    processor.process(occurence);
                }
                return true;
            }
        });
    } catch (AlienFormFileException | JDOMParseException | UnexpectedFormElementException ex) {
    // ignore
    } catch (Exception e) {
        LOG.error("Error indexing form file", e);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) WordOccurrence(com.intellij.lang.cacheBuilder.WordOccurrence) IComponent(com.intellij.uiDesigner.lw.IComponent) AlienFormFileException(com.intellij.uiDesigner.compiler.AlienFormFileException) LwRootContainer(com.intellij.uiDesigner.lw.LwRootContainer) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) UnexpectedFormElementException(com.intellij.uiDesigner.compiler.UnexpectedFormElementException) AlienFormFileException(com.intellij.uiDesigner.compiler.AlienFormFileException) JDOMParseException(org.jdom.input.JDOMParseException) UnexpectedFormElementException(com.intellij.uiDesigner.compiler.UnexpectedFormElementException)

Example 2 with WordOccurrence

use of com.intellij.lang.cacheBuilder.WordOccurrence in project smali by JesusFreke.

the class SmaliWordScanner method processWords.

@Override
public void processWords(CharSequence fileText, Processor<WordOccurrence> processor) {
    SmaliLexer lexer = new SmaliLexer();
    lexer.start(fileText);
    IElementType type = lexer.getTokenType();
    while (type != null) {
        if (type == SmaliTokens.CLASS_DESCRIPTOR) {
            processClassDescriptor(fileText, lexer.getTokenStart(), lexer.getTokenEnd(), processor);
        } else if (MEMBER_NAME_TOKENS.contains(type)) {
            processor.process(new WordOccurrence(fileText, lexer.getTokenStart(), lexer.getTokenEnd(), Kind.CODE));
        } else if (type == SmaliTokens.PARAM_LIST_OR_ID_PRIMITIVE_TYPE) {
            int tokenStart = lexer.getTokenStart();
            while (type == SmaliTokens.PARAM_LIST_OR_ID_PRIMITIVE_TYPE) {
                lexer.advance();
                type = lexer.getTokenType();
            }
            int tokenEnd = lexer.getTokenStart();
            processor.process(new WordOccurrence(fileText, tokenStart, tokenEnd, Kind.CODE));
        }
        lexer.advance();
        type = lexer.getTokenType();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) WordOccurrence(com.intellij.lang.cacheBuilder.WordOccurrence) SmaliLexer(org.jf.smalidea.SmaliLexer)

Example 3 with WordOccurrence

use of com.intellij.lang.cacheBuilder.WordOccurrence in project smali by JesusFreke.

the class SmaliWordScanner method processClassDescriptor.

private void processClassDescriptor(CharSequence fileText, int tokenStart, int tokenEnd, @NotNull Processor<WordOccurrence> processor) {
    CharSequence tokenText = fileText.subSequence(tokenStart, tokenEnd);
    assert tokenText.charAt(0) == 'L' && tokenText.charAt(tokenText.length() - 1) == ';';
    processor.process(new WordOccurrence(fileText, tokenStart, tokenEnd, Kind.CODE));
}
Also used : WordOccurrence(com.intellij.lang.cacheBuilder.WordOccurrence)

Example 4 with WordOccurrence

use of com.intellij.lang.cacheBuilder.WordOccurrence in project intellij-community by JetBrains.

the class GroovyWordsScanner method stripWords.

private static boolean stripWords(final Processor<WordOccurrence> processor, final CharSequence tokenText, int from, int to, final WordOccurrence.Kind kind, WordOccurrence occurrence) {
    // This code seems strange but it is more effective as Character.isJavaIdentifier_xxx_ is quite costly operation due to unicode
    int index = from;
    ScanWordsLoop: while (true) {
        while (true) {
            if (index == to)
                break ScanWordsLoop;
            char c = tokenText.charAt(index);
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (Character.isJavaIdentifierStart(c) && c != '$')) {
                break;
            }
            index++;
        }
        int index1 = index;
        while (true) {
            index++;
            if (index == to)
                break;
            char c = tokenText.charAt(index);
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))
                continue;
            if (!Character.isJavaIdentifierPart(c) || c == '$')
                break;
        }
        if (occurrence == null)
            occurrence = new WordOccurrence(tokenText, index1, index, kind);
        else
            occurrence.init(tokenText, index1, index, kind);
        if (!processor.process(occurrence))
            return false;
    }
    return true;
}
Also used : WordOccurrence(com.intellij.lang.cacheBuilder.WordOccurrence)

Example 5 with WordOccurrence

use of com.intellij.lang.cacheBuilder.WordOccurrence in project intellij-community by JetBrains.

the class GroovyWordsScanner method processWords.

@Override
public void processWords(CharSequence fileText, Processor<WordOccurrence> processor) {
    myLexer.start(fileText);
    // shared occurrence
    WordOccurrence occurrence = null;
    while (myLexer.getTokenType() != null) {
        final IElementType type = myLexer.getTokenType();
        if (type == GroovyTokenTypes.mIDENT || TokenSets.KEYWORDS.contains(type)) {
            if (occurrence == null)
                occurrence = new WordOccurrence(fileText, myLexer.getTokenStart(), myLexer.getTokenEnd(), WordOccurrence.Kind.CODE);
            else
                occurrence.init(fileText, myLexer.getTokenStart(), myLexer.getTokenEnd(), WordOccurrence.Kind.CODE);
            if (!processor.process(occurrence))
                return;
        } else if (TokenSets.COMMENT_SET.contains(type)) {
            if (!stripWords(processor, fileText, myLexer.getTokenStart(), myLexer.getTokenEnd(), WordOccurrence.Kind.COMMENTS, occurrence))
                return;
        } else if (TokenSets.STRING_LITERALS.contains(type)) {
            if (!stripWords(processor, fileText, myLexer.getTokenStart(), myLexer.getTokenEnd(), WordOccurrence.Kind.LITERALS, occurrence)) {
                return;
            }
            if (type == GroovyTokenTypes.mSTRING_LITERAL) {
                if (!stripWords(processor, fileText, myLexer.getTokenStart(), myLexer.getTokenEnd(), WordOccurrence.Kind.CODE, occurrence))
                    return;
            }
        } else {
            if (!stripWords(processor, fileText, myLexer.getTokenStart(), myLexer.getTokenEnd(), null, occurrence)) {
                return;
            }
        }
        myLexer.advance();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) WordOccurrence(com.intellij.lang.cacheBuilder.WordOccurrence)

Aggregations

WordOccurrence (com.intellij.lang.cacheBuilder.WordOccurrence)6 IElementType (com.intellij.psi.tree.IElementType)2 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)1 AlienFormFileException (com.intellij.uiDesigner.compiler.AlienFormFileException)1 UnexpectedFormElementException (com.intellij.uiDesigner.compiler.UnexpectedFormElementException)1 IComponent (com.intellij.uiDesigner.lw.IComponent)1 LwRootContainer (com.intellij.uiDesigner.lw.LwRootContainer)1 JDOMParseException (org.jdom.input.JDOMParseException)1 SmaliLexer (org.jf.smalidea.SmaliLexer)1