lbownik commented on code in PR #5802:
URL: https://github.com/apache/netbeans/pull/5802#discussion_r1167590223


##########
java/ant.hints/src/org/netbeans/modules/ant/hints/errors/EnablePreviewAntProj.java:
##########
@@ -18,94 +18,66 @@
  */
 package org.netbeans.modules.ant.hints.errors;
 
-import com.sun.source.util.TreePath;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
-import javax.lang.model.SourceVersion;
 import org.netbeans.api.annotations.common.NonNull;
-import org.netbeans.api.java.source.CompilationInfo;
 import org.netbeans.api.project.FileOwnerQuery;
-import org.netbeans.modules.java.hints.spi.ErrorRule;
-import org.netbeans.spi.editor.hints.ChangeInfo;
-import org.netbeans.spi.editor.hints.Fix;
 import org.openide.filesystems.FileObject;
-import org.openide.util.NbBundle;
 import org.openide.util.Parameters;
 import org.netbeans.api.project.Project;
 import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.java.hints.spi.preview.PreviewEnabler;
 import org.netbeans.spi.project.support.ant.AntProjectHelper;
 import org.openide.util.EditableProperties;
 import org.openide.util.Mutex;
 import org.openide.util.MutexException;
+import org.openide.util.lookup.ServiceProvider;
 
 /**
  * Handle error rule "compiler.err.preview.feature.disabled.plural" and provide
  * the fix for Ant type project.
  *
  * @author arusinha
  */
-public class EnablePreviewAntProj implements ErrorRule<Void> {
+public class EnablePreviewAntProj implements PreviewEnabler {
 
-    private static final Set<String> ERROR_CODES = new 
HashSet<String>(Arrays.asList(
-            "compiler.err.preview.feature.disabled",          // NOI18N
-            "compiler.err.preview.feature.disabled.plural")); // NOI18N
     private static final String ENABLE_PREVIEW_FLAG = "--enable-preview";   // 
NOI18N
+    private static final String JAVAC_SOURCE = "javac.source"; // NOI18N
+    private static final String JAVAC_TARGET = "javac.target"; // NOI18N
     private static final String JAVAC_COMPILER_ARGS = "javac.compilerargs"; // 
NOI18N
     private static final String RUN_JVMARGS = "run.jvmargs"; // NOI18N
 
-    @Override
-    public Set<String> getCodes() {
-        return Collections.unmodifiableSet(ERROR_CODES);
+    private final Project prj;
+
+    public EnablePreviewAntProj(Project prj) {
+        this.prj = prj;
     }
 
     @Override
-    @NonNull
-    public List<Fix> run(CompilationInfo compilationInfo, String 
diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
+    public void enablePreview(String newSourceLevel) throws Exception {
+        new ResolveAntFix(prj).enablePreview(newSourceLevel);
+    }
 
-        if (SourceVersion.latest() != compilationInfo.getSourceVersion()) {
-            return Collections.<Fix>emptyList();
-        }
+    @ServiceProvider(service=Factory.class, position=1000)
+    public static final class FactoryImpl implements Factory {
 
-        final FileObject file = compilationInfo.getFileObject();
-        Fix fix = null;
-        if (file != null) {
+        @Override
+        public PreviewEnabler enablerFor(FileObject file) {
             final Project prj = FileOwnerQuery.getOwner(file);
 
             if (isAntProject(prj)) {
-                fix = new EnablePreviewAntProj.ResolveAntFix(prj);
+                return new EnablePreviewAntProj(prj);
             } else {
-                fix = null;
+                return null;

Review Comment:
   does it make sense to return some NullObject here ?



-- 
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