Search in sources :

Example 26 with Nullable

use of org.jetbrains.annotations.Nullable in project jadx by skylot.

the class ConstStorage method getConstField.

@Nullable
public FieldNode getConstField(ClassNode cls, Object value, boolean searchGlobal) {
    DexNode dex = cls.dex();
    if (value instanceof Integer) {
        String str = resourcesNames.get(value);
        if (str != null) {
            return new ResRefField(dex, str.replace('/', '.'));
        }
    }
    if (!replaceEnabled) {
        return null;
    }
    boolean foundInGlobal = globalValues.contains(value);
    if (foundInGlobal && !searchGlobal) {
        return null;
    }
    ClassNode current = cls;
    while (current != null) {
        Values classValues = classes.get(current);
        if (classValues != null) {
            FieldNode field = classValues.get(value);
            if (field != null) {
                if (foundInGlobal) {
                    return null;
                }
                return field;
            }
        }
        ClassInfo parentClass = current.getClassInfo().getParentClass();
        if (parentClass == null) {
            break;
        }
        current = dex.resolveClass(parentClass);
    }
    if (searchGlobal) {
        return globalValues.get(value);
    }
    return null;
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) DexNode(jadx.core.dex.nodes.DexNode) ResRefField(jadx.core.dex.nodes.ResRefField) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with Nullable

use of org.jetbrains.annotations.Nullable in project jadx by skylot.

the class Deobfuscator method getFieldAlias.

@Nullable
public String getFieldAlias(FieldNode field) {
    FieldInfo fieldInfo = field.getFieldInfo();
    String alias = fldMap.get(fieldInfo);
    if (alias != null) {
        return alias;
    }
    alias = deobfPresets.getForFld(fieldInfo);
    if (alias != null) {
        fldMap.put(fieldInfo, alias);
        return alias;
    }
    if (shouldRename(field.getName())) {
        return makeFieldAlias(field);
    }
    return null;
}
Also used : FieldInfo(jadx.core.dex.info.FieldInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with Nullable

use of org.jetbrains.annotations.Nullable in project jadx by skylot.

the class TabbedPane method makeContentPanel.

@Nullable
private ContentPanel makeContentPanel(JNode node) {
    if (node instanceof JResource) {
        JResource res = (JResource) node;
        ResourceFile resFile = res.getResFile();
        if (resFile != null) {
            if (resFile.getType() == ResourceType.IMG) {
                return new ImagePanel(this, res);
            }
        } else {
            return null;
        }
    }
    return new CodePanel(this, node);
}
Also used : ResourceFile(jadx.api.ResourceFile) JResource(jadx.gui.treemodel.JResource) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with Nullable

use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.

the class CompoundTagger method doGuessCompoundTag.

@Nullable
private List<AnalyzedToken> doGuessCompoundTag(String word) {
    int dashIdx = word.lastIndexOf('-');
    if (dashIdx == 0 || dashIdx == word.length() - 1)
        return null;
    int firstDashIdx = word.indexOf('-');
    if (dashIdx != firstDashIdx)
        return null;
    String leftWord = word.substring(0, dashIdx);
    String rightWord = word.substring(dashIdx + 1);
    // авіа..., авто... пишуться разом
    if (LEFT_INVALID.contains(leftWord.toLowerCase()))
        return null;
    // wrong: пів-качана
    if (leftWord.equalsIgnoreCase("пів") && Character.isLowerCase(rightWord.charAt(0)))
        return null;
    List<TaggedWord> leftWdList = tagAsIsAndWithLowerCase(leftWord);
    if (rightPartsWithLeftTagMap.containsKey(rightWord)) {
        if (leftWdList.isEmpty())
            return null;
        Pattern leftTagRegex = rightPartsWithLeftTagMap.get(rightWord);
        List<AnalyzedToken> leftAnalyzedTokens = ukrainianTagger.asAnalyzedTokenListForTaggedWordsInternal(leftWord, leftWdList);
        List<AnalyzedToken> newAnalyzedTokens = new ArrayList<>(leftAnalyzedTokens.size());
        // ignore хто-то
        if (rightWord.equals("то") && LemmaHelper.hasLemma(leftAnalyzedTokens, Arrays.asList("хто", "що", "чи")))
            return null;
        for (AnalyzedToken analyzedToken : leftAnalyzedTokens) {
            String posTag = analyzedToken.getPOSTag();
            if (posTag != null && (leftWord.equals("дуже") && posTag.contains("adv")) || (leftTagRegex.matcher(posTag).matches())) {
                newAnalyzedTokens.add(new AnalyzedToken(word, posTag, analyzedToken.getLemma()));
            }
        }
        return newAnalyzedTokens.isEmpty() ? null : newAnalyzedTokens;
    }
    if (UkrainianTagger.NUMBER.matcher(leftWord).matches()) {
        List<AnalyzedToken> newAnalyzedTokens = new ArrayList<>();
        // e.g. 101-го
        if (NUMR_ENDING_MAP.containsKey(rightWord)) {
            List<String> tags = NUMR_ENDING_MAP.get(rightWord);
            for (String tag : tags) {
                // TODO: shall it be numr or adj?
                newAnalyzedTokens.add(new AnalyzedToken(word, IPOSTag.adj.getText() + tag + ":&numr", leftWord + "-" + "й"));
            }
        } else {
            List<TaggedWord> rightWdList = wordTagger.tag(rightWord);
            if (rightWdList.isEmpty())
                return null;
            List<AnalyzedToken> rightAnalyzedTokens = ukrainianTagger.asAnalyzedTokenListForTaggedWordsInternal(rightWord, rightWdList);
            // e.g. 100-річному
            for (AnalyzedToken analyzedToken : rightAnalyzedTokens) {
                if (analyzedToken.getPOSTag().startsWith(IPOSTag.adj.getText())) {
                    newAnalyzedTokens.add(new AnalyzedToken(word, analyzedToken.getPOSTag(), leftWord + "-" + analyzedToken.getLemma()));
                }
            }
        }
        return newAnalyzedTokens.isEmpty() ? null : newAnalyzedTokens;
    }
    if (leftWord.equalsIgnoreCase("по") && rightWord.endsWith("ськи")) {
        rightWord += "й";
    }
    List<TaggedWord> rightWdList = wordTagger.tag(rightWord);
    if (rightWdList.isEmpty())
        return null;
    List<AnalyzedToken> rightAnalyzedTokens = ukrainianTagger.asAnalyzedTokenListForTaggedWordsInternal(rightWord, rightWdList);
    if (leftWord.equalsIgnoreCase("по")) {
        if (rightWord.endsWith("ому")) {
            return poAdvMatch(word, rightAnalyzedTokens, ADJ_TAG_FOR_PO_ADV_MIS);
        } else if (rightWord.endsWith("ський")) {
            return poAdvMatch(word, rightAnalyzedTokens, ADJ_TAG_FOR_PO_ADV_NAZ);
        }
        return null;
    }
    // exclude: Малишко-це, відносини-коли
    List<AnalyzedToken> leftAnalyzedTokens = ukrainianTagger.asAnalyzedTokenListForTaggedWordsInternal(leftWord, leftWdList);
    if (!leftWord.equalsIgnoreCase(rightWord) && PosTagHelper.hasPosTag(rightAnalyzedTokens, "(part|conj).*|.*:&pron.*") && !(PosTagHelper.hasPosTag(leftAnalyzedTokens, "numr.*") && PosTagHelper.hasPosTag(rightAnalyzedTokens, "numr.*")))
        return null;
    if (Character.isUpperCase(rightWord.charAt(0))) {
        if (word.startsWith("пів-")) {
            List<AnalyzedToken> newAnalyzedTokens = new ArrayList<>(rightAnalyzedTokens.size());
            for (AnalyzedToken rightAnalyzedToken : rightAnalyzedTokens) {
                String rightPosTag = rightAnalyzedToken.getPOSTag();
                if (rightPosTag == null)
                    continue;
                if (NOUN_SING_V_ROD_REGEX.matcher(rightPosTag).matches()) {
                    for (String vid : PosTagHelper.VIDMINKY_MAP.keySet()) {
                        if (vid.equals("v_kly"))
                            continue;
                        String posTag = rightPosTag.replace("v_rod", vid);
                        newAnalyzedTokens.add(new AnalyzedToken(word, posTag, word));
                    }
                }
            }
            return newAnalyzedTokens;
        } else {
            // we don't want Нью-Париж
            return null;
        }
    }
    if (dashPrefixes.contains(leftWord) || dashPrefixes.contains(leftWord.toLowerCase()) || DASH_PREFIX_LAT_PATTERN.matcher(leftWord).matches()) {
        return getNvPrefixNounMatch(word, rightAnalyzedTokens, leftWord);
    }
    if (Character.isUpperCase(leftWord.charAt(0)) && cityAvenue.contains(rightWord)) {
        if (leftWdList.isEmpty())
            return null;
        return cityAvenueMatch(word, leftAnalyzedTokens);
    }
    if (!PosTagHelper.hasPosTag(leftAnalyzedTokens, "intj.*")) {
        String noDashWord = word.replace("-", "");
        List<TaggedWord> noDashWordList = tagAsIsAndWithLowerCase(noDashWord);
        List<AnalyzedToken> noDashAnalyzedTokens = ukrainianTagger.asAnalyzedTokenListForTaggedWordsInternal(noDashWord, noDashWordList);
        if (!noDashAnalyzedTokens.isEmpty())
            return null;
    }
    if (!leftWdList.isEmpty()) {
        List<AnalyzedToken> tagMatch = tagMatch(word, leftAnalyzedTokens, rightAnalyzedTokens);
        if (tagMatch != null) {
            return tagMatch;
        }
    }
    if (LEFT_O_ADJ_INVALID.contains(leftWord.toLowerCase()))
        return null;
    if (O_ADJ_PATTERN.matcher(leftWord).matches()) {
        return oAdjMatch(word, rightAnalyzedTokens, leftWord);
    }
    debug_compound_unknown_write(word);
    return null;
}
Also used : Pattern(java.util.regex.Pattern) TaggedWord(org.languagetool.tagging.TaggedWord) AnalyzedToken(org.languagetool.AnalyzedToken) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with Nullable

use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.

the class Main method getLanguage.

/**
   * Checks the language under the cursor. Used for opening the configuration dialog.
   * @return the language under the visible cursor
   */
@Nullable
private Language getLanguage() {
    XComponent xComponent = getXComponent();
    Locale charLocale;
    XPropertySet xCursorProps;
    try {
        XModel model = UnoRuntime.queryInterface(XModel.class, xComponent);
        XTextViewCursorSupplier xViewCursorSupplier = UnoRuntime.queryInterface(XTextViewCursorSupplier.class, model.getCurrentController());
        XTextViewCursor xCursor = xViewCursorSupplier.getViewCursor();
        if (xCursor.isCollapsed()) {
            // no text selection
            xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, xCursor);
        } else {
            // text is selected, need to create another cursor
            // as multiple languages can occur here - we care only
            // about character under the cursor, which might be wrong
            // but it applies only to the checking dialog to be removed
            xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, xCursor.getText().createTextCursorByRange(xCursor.getStart()));
        }
        // Thus we check the text itself:
        if (new KhmerDetector().isThisLanguage(xCursor.getText().getString())) {
            return Languages.getLanguageForShortCode("km");
        }
        if (new TamilDetector().isThisLanguage(xCursor.getText().getString())) {
            return Languages.getLanguageForShortCode("ta");
        }
        Object obj = xCursorProps.getPropertyValue("CharLocale");
        if (obj == null) {
            return Languages.getLanguageForShortCode("en-US");
        }
        charLocale = (Locale) obj;
        boolean langIsSupported = false;
        for (Language element : Languages.get()) {
            if (charLocale.Language.equalsIgnoreCase(LIBREOFFICE_SPECIAL_LANGUAGE_TAG) && element.getShortCodeWithCountryAndVariant().equalsIgnoreCase(charLocale.Variant)) {
                langIsSupported = true;
                break;
            }
            if (element.getShortCode().equals(charLocale.Language)) {
                langIsSupported = true;
                break;
            }
        }
        if (!langIsSupported) {
            String message = Tools.i18n(MESSAGES, "language_not_supported", charLocale.Language);
            JOptionPane.showMessageDialog(null, message);
            return null;
        }
    } catch (Throwable t) {
        showError(t);
        return null;
    }
    return getLanguage(charLocale);
}
Also used : XModel(com.sun.star.frame.XModel) XPropertySet(com.sun.star.beans.XPropertySet) XTextViewCursorSupplier(com.sun.star.text.XTextViewCursorSupplier) Language(org.languagetool.Language) XTextViewCursor(com.sun.star.text.XTextViewCursor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)4642 VirtualFile (com.intellij.openapi.vfs.VirtualFile)810 PsiElement (com.intellij.psi.PsiElement)485 File (java.io.File)399 Project (com.intellij.openapi.project.Project)396 PsiFile (com.intellij.psi.PsiFile)319 NotNull (org.jetbrains.annotations.NotNull)257 IOException (java.io.IOException)243 Module (com.intellij.openapi.module.Module)227 ArrayList (java.util.ArrayList)169 TextRange (com.intellij.openapi.util.TextRange)156 Document (com.intellij.openapi.editor.Document)124 List (java.util.List)111 ASTNode (com.intellij.lang.ASTNode)105 IElementType (com.intellij.psi.tree.IElementType)103 XmlTag (com.intellij.psi.xml.XmlTag)96 Editor (com.intellij.openapi.editor.Editor)94 Element (org.jdom.Element)93 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)86 XmlFile (com.intellij.psi.xml.XmlFile)78