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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations