use of org.jetbrains.annotations.Nullable in project pysonar2 by yinwang0.
the class Analyzer method loadModule.
@Nullable
public Type loadModule(@NotNull List<Name> name, @NotNull State state) {
if (name.isEmpty()) {
return null;
}
String qname = makeQname(name);
Type mt = getBuiltinModule(qname);
if (mt != null) {
state.insert(name.get(0).id, new Url(Builtins.LIBRARY_URL + mt.table.path + ".html"), mt, Binding.Kind.SCOPE);
return mt;
}
// If there are more than one segment
// load the packages first
Type prev = null;
String startPath = locateModule(name.get(0).id);
if (startPath == null) {
return null;
}
File path = new File(startPath);
for (int i = 0; i < name.size(); i++) {
path = new File(path, name.get(i).id);
File initFile = new File($.joinPath(path, "__init__.py").getPath());
if (initFile.exists()) {
Type mod = loadFile(initFile.getPath());
if (mod == null) {
return null;
}
Binding binding = Binding.createFileBinding(name.get(i).id, initFile.getPath(), mod);
if (prev != null) {
prev.table.update(name.get(i).id, binding);
} else {
state.update(name.get(i).id, binding);
}
Analyzer.self.putRef(name.get(i), binding);
prev = mod;
} else if (i == name.size() - 1) {
File startFile = new File(path + Globals.FILE_SUFFIX);
if (startFile.exists()) {
Type mod = loadFile(startFile.getPath());
if (mod == null) {
return null;
}
Binding binding = Binding.createFileBinding(name.get(i).id, startFile.getPath(), mod);
if (prev != null) {
prev.table.update(name.get(i).id, binding);
} else {
state.update(name.get(i).id, binding);
}
Analyzer.self.putRef(name.get(i), binding);
prev = mod;
} else {
return null;
}
}
}
return prev;
}
use of org.jetbrains.annotations.Nullable in project pysonar2 by yinwang0.
the class AstCache method getAST.
/**
* Returns the syntax tree for {@code path}. May find and/or create a
* cached copy in the mem cache or the disk cache.
*
* @param path absolute path to a source file
* @return the AST, or {@code null} if the parse failed for any reason
*/
@Nullable
public Node getAST(@NotNull String path) {
// Cache stores null value if the parse failed.
if (cache.containsKey(path)) {
return cache.get(path);
}
// Might be cached on disk but not in memory.
Node node = getSerializedModule(path);
if (node != null) {
LOG.log(Level.FINE, "reusing " + path);
cache.put(path, node);
return node;
}
node = null;
try {
LOG.log(Level.FINE, "parsing " + path);
node = parser.parseFile(path);
} finally {
// may be null
cache.put(path, node);
}
if (node != null) {
serialize(node);
}
return node;
}
use of org.jetbrains.annotations.Nullable in project pysonar2 by yinwang0.
the class Parser method startInterpreter.
@Nullable
public Process startInterpreter(String pythonExe) {
Process p;
try {
ProcessBuilder builder = new ProcessBuilder(pythonExe, "-i", jsonizer);
builder.redirectErrorStream(true);
builder.redirectOutput(new File(parserLog + "-" + (logCount++)));
builder.environment().remove("PYTHONPATH");
p = builder.start();
} catch (Exception e) {
$.msg("Failed to start: " + pythonExe);
return null;
}
return p;
}
use of org.jetbrains.annotations.Nullable in project pysonar2 by yinwang0.
the class Parser method parseFileInner.
@Nullable
public Node parseFileInner(String filename, @NotNull Process pythonProcess) {
// _.msg("parsing: " + filename);
File exchange = new File(exchangeFile);
File marker = new File(endMark);
cleanTemp();
String s1 = $.escapeWindowsPath(filename);
String s2 = $.escapeWindowsPath(exchangeFile);
String s3 = $.escapeWindowsPath(endMark);
String dumpCommand = "parse_dump('" + s1 + "', '" + s2 + "', '" + s3 + "')";
if (!sendCommand(dumpCommand, pythonProcess)) {
cleanTemp();
return null;
}
long waitStart = System.currentTimeMillis();
while (!marker.exists()) {
if (System.currentTimeMillis() - waitStart > TIMEOUT) {
Analyzer.self.failedToParse.add(filename);
cleanTemp();
startPythonProcesses();
return null;
}
try {
Thread.sleep(1);
} catch (Exception e) {
cleanTemp();
return null;
}
}
String json = $.readFile(exchangeFile);
if (json != null) {
cleanTemp();
Map<String, Object> map = gson.fromJson(json, Map.class);
return convert(map);
} else {
cleanTemp();
return null;
}
}
use of org.jetbrains.annotations.Nullable in project intellij-plugins by StepicOrg.
the class StepikModuleType method modifySettingsStep.
@Nullable
@Override
public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep, @NotNull ModuleBuilder moduleBuilder) {
JTextField nameField = settingsStep.getModuleNameField();
if (nameField != null) {
CourseModuleBuilder courseModuleBuilder = (CourseModuleBuilder) moduleBuilder;
StudyObject studyObject = courseModuleBuilder.getWizardStep().getSelectedStudyObject();
String projectDirectory = settingsStep.getContext().getProjectFileDirectory();
String projectName = ProjectWizardUtils.getProjectDefaultName(projectDirectory, studyObject);
nameField.setText(projectName);
}
return null;
}
Aggregations