Search in sources :

Example 6 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 7 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 8 with Nullable

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

the class MorfologikMultiSpeller method getPlainTextDictSpellerOrNull.

@Nullable
private MorfologikSpeller getPlainTextDictSpellerOrNull(BufferedReader plainTextReader, String dictPath, int maxEditDistance) throws IOException {
    List<byte[]> lines = getLines(plainTextReader);
    if (lines.isEmpty()) {
        return null;
    }
    Dictionary dictionary = getDictionary(lines, dictPath);
    return new MorfologikSpeller(dictionary, maxEditDistance);
}
Also used : Dictionary(morfologik.stemming.Dictionary) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with Nullable

use of org.jetbrains.annotations.Nullable in project gitblit by gitblit.

the class BugtraqConfig method getBaseConfig.

// Utils ==================================================================
@Nullable
private static Config getBaseConfig(@NotNull Repository repository, @NotNull String configFileName) throws IOException, ConfigInvalidException {
    final Config baseConfig;
    if (repository.isBare()) {
        // read bugtraq config directly from the repository
        String content = null;
        RevWalk rw = new RevWalk(repository);
        TreeWalk tw = new TreeWalk(repository);
        tw.setFilter(PathFilterGroup.createFromStrings(configFileName));
        try {
            final Ref ref = repository.getRef(Constants.HEAD);
            if (ref == null) {
                return null;
            }
            ObjectId headId = ref.getTarget().getObjectId();
            if (headId == null || ObjectId.zeroId().equals(headId)) {
                return null;
            }
            RevCommit commit = rw.parseCommit(headId);
            RevTree tree = commit.getTree();
            tw.reset(tree);
            while (tw.next()) {
                ObjectId entid = tw.getObjectId(0);
                FileMode entmode = tw.getFileMode(0);
                if (FileMode.REGULAR_FILE == entmode) {
                    ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
                    content = new String(ldr.getCachedBytes(), commit.getEncoding());
                    break;
                }
            }
        } finally {
            rw.dispose();
            tw.close();
        }
        if (content == null) {
            // config not found
            baseConfig = null;
        } else {
            // parse the config
            Config config = new Config();
            config.fromText(content);
            baseConfig = config;
        }
    } else {
        // read bugtraq config from work tree
        final File baseFile = new File(repository.getWorkTree(), configFileName);
        if (baseFile.isFile()) {
            FileBasedConfig fileConfig = new FileBasedConfig(baseFile, repository.getFS());
            fileConfig.load();
            baseConfig = fileConfig;
        } else {
            baseConfig = null;
        }
    }
    return baseConfig;
}
Also used : FileMode(org.eclipse.jgit.lib.FileMode) Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) Config(org.eclipse.jgit.lib.Config) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) RevWalk(org.eclipse.jgit.revwalk.RevWalk) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) File(java.io.File) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with Nullable

use of org.jetbrains.annotations.Nullable in project gitblit by gitblit.

the class BugtraqConfig method read.

// Static =================================================================
@Nullable
public static BugtraqConfig read(@NotNull Repository repository) throws IOException, ConfigInvalidException {
    Config baseConfig = getBaseConfig(repository, DOT_GIT_BUGTRAQ);
    if (baseConfig == null) {
        baseConfig = getBaseConfig(repository, DOT_TGITCONFIG);
    }
    final Set<String> allNames = new HashSet<String>();
    final Config config;
    try {
        config = repository.getConfig();
    } catch (RuntimeException ex) {
        final Throwable cause = ex.getCause();
        if (cause instanceof IOException) {
            throw (IOException) cause;
        }
        throw ex;
    }
    if (getString(null, URL, config, baseConfig) != null) {
        allNames.add(null);
    } else {
        allNames.addAll(config.getSubsections(BUGTRAQ));
        if (baseConfig != null) {
            allNames.addAll(baseConfig.getSubsections(BUGTRAQ));
        }
    }
    final List<BugtraqEntry> entries = new ArrayList<BugtraqEntry>();
    for (String name : allNames) {
        final String url = getString(name, URL, config, baseConfig);
        if (url == null) {
            continue;
        }
        final String enabled = getString(name, ENABLED, config, baseConfig);
        if (enabled != null && !"true".equals(enabled)) {
            continue;
        }
        String idRegex = getString(name, LOG_REGEX, config, baseConfig);
        if (idRegex == null) {
            return null;
        }
        String filterRegex = getString(name, LOG_FILTERREGEX, config, baseConfig);
        final String linkRegex = getString(name, LOG_LINKREGEX, config, baseConfig);
        if (filterRegex == null && linkRegex == null) {
            final String[] split = idRegex.split("\n", Integer.MAX_VALUE);
            if (split.length == 2) {
                // Compatibility with TortoiseGit
                filterRegex = split[0];
                idRegex = split[1];
            } else {
                // Backwards compatibility with specification version < 0.3
                final List<String> logIdRegexs = new ArrayList<String>();
                for (int index = 1; index < Integer.MAX_VALUE; index++) {
                    final String logIdRegexN = getString(name, LOG_REGEX + index, config, baseConfig);
                    if (logIdRegexN == null) {
                        break;
                    }
                    logIdRegexs.add(logIdRegexN);
                }
                if (logIdRegexs.size() > 1) {
                    throw new ConfigInvalidException("More than three " + LOG_REGEX + " entries found. This is not supported anymore since bugtraq version 0.3, use " + LOG_FILTERREGEX + " and " + LOG_LINKREGEX + " instead.");
                } else if (logIdRegexs.size() == 1) {
                    filterRegex = idRegex;
                    idRegex = logIdRegexs.get(0);
                }
            }
        }
        final String linkText = getString(name, LOG_LINKTEXT, config, baseConfig);
        entries.add(new BugtraqEntry(url, idRegex, linkRegex, filterRegex, linkText));
    }
    if (entries.isEmpty()) {
        return null;
    }
    return new BugtraqConfig(entries);
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Config(org.eclipse.jgit.lib.Config) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)4694 VirtualFile (com.intellij.openapi.vfs.VirtualFile)812 PsiElement (com.intellij.psi.PsiElement)485 File (java.io.File)405 Project (com.intellij.openapi.project.Project)396 PsiFile (com.intellij.psi.PsiFile)320 NotNull (org.jetbrains.annotations.NotNull)259 IOException (java.io.IOException)247 Module (com.intellij.openapi.module.Module)227 ArrayList (java.util.ArrayList)178 TextRange (com.intellij.openapi.util.TextRange)156 Document (com.intellij.openapi.editor.Document)124 List (java.util.List)116 ASTNode (com.intellij.lang.ASTNode)105 IElementType (com.intellij.psi.tree.IElementType)103 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)102 XmlTag (com.intellij.psi.xml.XmlTag)96 Editor (com.intellij.openapi.editor.Editor)94 Element (org.jdom.Element)93 XmlFile (com.intellij.psi.xml.XmlFile)78