use of org.netbeans.api.annotations.common.CheckForNull in project python4nb by ebresie.
the class PythonExecutable method forProjectInternal.
@CheckForNull
private static PythonExecutable forProjectInternal(@NullAllowed Project project, boolean showCustomizer) {
if (project == null) {
return getDefault(null, showCustomizer);
}
PythonPreferences preferences = PythonSupport.forProject(project).getPreferences();
if (preferences.isDefaultPython()) {
return getDefault(project, showCustomizer);
}
String node = preferences.getPython();
ValidationResult result = new PythonPreferencesValidator().validateNode(node).getResult();
if (validateResult(result) != null) {
if (showCustomizer) {
PythonCustomizerProvider.openCustomizer(project, result);
}
return null;
}
assert node != null;
return createExecutable(node, project);
}
use of org.netbeans.api.annotations.common.CheckForNull in project python4nb by ebresie.
the class PythonFile method getContent.
/**
* Returns <b>shallow</b> copy of the content.
* <p>
* <b>WARNING:</b> Do not modify the content directly! Use {@link #setContent(List, Object)} instead!
* @return <b>shallow</b> copy of the data
* @see #setContent(List, Object)
*/
@CheckForNull
public synchronized Map<String, Object> getContent() {
initContent();
if (content != null) {
return new LinkedHashMap<>(content);
}
File file = getFile();
if (!file.isFile()) {
return null;
}
// PythonParser parser = new PythonParser();
try (Reader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
// TODO: Determine how to read in and tokenize python code
// content = (Map<String, Object>) parser.parse(reader, CONTAINER_FACTORY);
content = new LinkedHashMap<String, Object>();
// } catch (ParseException ex) {
// LOGGER.log(Level.INFO, file.getAbsolutePath(), ex);
// } catch (IOException ex) {
// LOGGER.log(Level.WARNING, file.getAbsolutePath(), ex);
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, file.getAbsolutePath(), ex);
}
if (content == null) {
return null;
}
return new LinkedHashMap<>(content);
}
use of org.netbeans.api.annotations.common.CheckForNull in project python4nb by ebresie.
the class PythonUtils method getPythonSources.
//
// @CheckForNull
// public static PackageJson getPackageJson(Lookup context) {
// return getProjectAndPackageJson(context).second();
// }
//
// @CheckForNull
// public static Project getPackageJsonProject(Lookup context) {
// return getProjectAndPackageJson(context).first();
// }
//
// public static Pair<Project, PackageJson> getProjectAndPackageJson(Lookup context) {
// Project project = context.lookup(Project.class);
// PackageJson packageJson = null;
// if (project != null) {
// // project action
// packageJson = new PackageJson(project.getProjectDirectory());
// } else {
// // package.json directly
// FileObject file = context.lookup(FileObject.class);
// if (file == null) {
// DataObject dataObject = context.lookup(DataObject.class);
// if (dataObject != null) {
// file = dataObject.getPrimaryFile();
// }
// }
// if (file != null) {
// packageJson = new PackageJson(file.getParent());
// project = FileOwnerQuery.getOwner(file);
// }
// }
// if (project == null) {
// return Pair.of(null, null);
// }
// if (packageJson == null) {
// return Pair.of(null, null);
// }
// if (!packageJson.exists()) {
// return Pair.of(null, null);
// }
// assert project != null;
// assert packageJson != null;
// return Pair.of(project, packageJson);
// }
@CheckForNull
public static File getPythonSources(Project project) {
PythonPreferences preferences = PythonSupport.forProject(project).getPreferences();
if (preferences.isDefaultPython()) {
// default python
String pythonSources = PythonOptions.getInstance().getPythonSources();
if (pythonSources != null) {
return new File(pythonSources);
}
PythonExecutable python = PythonExecutable.getDefault(project, false);
if (python == null) {
return null;
}
Version version = python.getVersion();
if (version == null) {
return null;
}
return getPythonSources(version);
}
// custom python
String pythonSources = preferences.getPythonSources();
if (pythonSources != null) {
return new File(pythonSources);
}
PythonExecutable python = PythonExecutable.forProject(project, false);
if (python == null) {
return null;
}
Version version = python.getVersion();
if (version == null) {
return null;
}
return PythonUtils.getPythonSources(project);
}
Aggregations