jtulach commented on code in PR #9650:
URL: https://github.com/apache/netbeans/pull/9650#discussion_r4172268510


##########
ide/projectapi/src/org/netbeans/api/project/ProjectManager.java:
##########
@@ -141,6 +146,54 @@ public Project findProject(@NonNull final FileObject 
projectDirectory) throws IO
         }
         return impl.findProject(projectDirectory);
     }
+
+    /** Finds a project corresponding to the given directory. This method 
behaves
+     * exactly as {@link #findProject}, just instead of {@code null} it returns
+     * the <em>fallback project</em> - e.g. if the directory isn't recognized 
as a project,
+     * a <em>fallback project</em> is created and registered with the 
directory.
+     *
+     * <h2>Fallback Project</h2>
+     * <p>
+     * The <em>fallback project</em> is dummy representation of a folder on
+     * disk, but it can be extended via {@link LookupMerger} mechanism. The
+     * project uses {@code org-netbeans-modules-project-fallback} ID.
+     * </p>
+     * <p>
+     * For example its {@link Project#getLookup()} can be extended by 
registering
+     * instance of {@link LookupProvider} into
+     * {@code Projects/org-netbeans-modules-project-fallback/Lookup}
+     * configuration directory. Either via {@code layer.xml}, or annotations
+     * that generate the layer like
+     * </p>
+     * <pre>
+     * @ProjectServiceProvider(service = LookupProvider.class, projectTypes = {
+     *   @LookupProvider.Registration.ProjectType(id = 
"org-netbeans-modules-project-fallback", position = 11000)
+     * })
+     * </pre>
+     * <p>
+     * It is also possible to register {@link ActionProvider} via such a 
lookup.
+     * </p>
+     * 
+     * @param projectDirectory the project top directory
+     * @return the project (object identity may or may not vary between calls)
+     * @throws IOException if the project was recognized but could not be 
loaded
+     * @throws IllegalArgumentException if the supplied file object is null or 
not a folder
+     * @since 1.111
+     */
+    @NonNull
+    public Project findProjectOrFallback(@NonNull FileObject projectDirectory) 
throws IOException, IllegalArgumentException {
+        if (projectDirectory == null) {
+            throw new IllegalArgumentException("Attempted to pass a null 
directory to findProject"); // NOI18N
+        }
+        if (!projectDirectory.isFolder()) {
+            throw new IllegalArgumentException("Attempted to pass a 
non-directory to findProject: " + projectDirectory); // NOI18N
+        }
+        if (impl instanceof ProjectManagerImplementation.WithFallback implV2) {
+            return implV2.findProjectOrFallback(projectDirectory);
+        } else {
+            throw new IllegalArgumentException("Cannot create fallback project 
for " + projectDirectory); // NOI18N

Review Comment:
   > concerned about the exception in `ProjectManager`
   
   Which exception do you have in mind? The [NPE that could be throw 
here](https://github.com/apache/netbeans/pull/9650/changes#diff-a882af68fbc3397e8bc42d88596b191bfed99622d3520b1c3afd3e16d6efc12cR193)?
 Well, that's never going to be thrown as with `FindOptions.WITH_FALLBACK` 
argument the implementation never returns `null`. Just (as a result of 
introducing a default method for all the `FindOptions` variants) the type 
system (nor `@NonNull` & co. annotations) really can express that easily.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to