Search in sources :

Example 11 with CheckForNull

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);
}
Also used : PythonPreferencesValidator(org.apache.netbeans.modules.python4nb.preferences.PythonPreferencesValidator) PythonPreferences(org.apache.netbeans.modules.python4nb.preferences.PythonPreferences) ValidationResult(org.apache.netbeans.modules.python4nb.util.ValidationResult) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Example 12 with CheckForNull

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileObject(org.openide.filesystems.FileObject) DataObject(org.openide.loaders.DataObject) WatchedFile(org.netbeans.modules.web.clientproject.api.util.WatchedFile) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException) LinkedHashMap(java.util.LinkedHashMap) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Example 13 with CheckForNull

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);
}
Also used : PythonExecutable(org.apache.netbeans.modules.python4nb.exec.PythonExecutable) Version(org.apache.netbeans.modules.python4nb.util.Version) PythonPreferences(org.apache.netbeans.modules.python4nb.preferences.PythonPreferences) File(java.io.File) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Aggregations

CheckForNull (org.netbeans.api.annotations.common.CheckForNull)13 File (java.io.File)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 KeyStroke (javax.swing.KeyStroke)2 PythonPreferences (org.apache.netbeans.modules.python4nb.preferences.PythonPreferences)2 ValidationResult (org.apache.netbeans.modules.python4nb.util.ValidationResult)2 OperationException (org.netbeans.api.autoupdate.OperationException)2 DelegatingSearchInfo (org.netbeans.api.search.provider.impl.DelegatingSearchInfo)2 ModuleInstallerSupport (org.netbeans.modules.autoupdate.ui.ModuleInstallerSupport)2 SearchInfoDefinition (org.netbeans.spi.search.SearchInfoDefinition)2 FileObject (org.openide.filesystems.FileObject)2 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedReader (java.io.BufferedReader)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 FieldPosition (java.text.FieldPosition)1 Format (java.text.Format)1 ParsePosition (java.text.ParsePosition)1