Commits

Jan Lahoda committed 62046c4

Let the (marks based) API clients compute their own ErrorDescription and Fixes.

  • Participants
  • Parent commits e7bdef2
  • Branches marks

Comments (0)

Files changed (6)

api/src/org/netbeans/modules/jackpot30/impl/MessageImpl.java

         this.text = text;
     }
 
+    @Override
+    public String toString() {
+        return "[" + kind + ":" + text + "]";
+    }
+
 }

api/src/org/netbeans/modules/jackpot30/impl/hints/HintsInvoker.java

 import org.netbeans.modules.jackpot30.spi.Hacks;
 import org.netbeans.modules.jackpot30.spi.HintContext;
 import org.netbeans.modules.jackpot30.spi.HintDescription;
-import org.netbeans.modules.jackpot30.spi.HintDescription.Acceptor;
 import org.netbeans.modules.jackpot30.spi.HintDescription.Condition;
 import org.netbeans.modules.jackpot30.spi.HintDescription.CustomCondition;
 import org.netbeans.modules.jackpot30.spi.HintDescription.DeclarativeFixDescription;
+import org.netbeans.modules.jackpot30.spi.HintDescription.ErrorDescriptionAcceptor;
+import org.netbeans.modules.jackpot30.spi.HintDescription.FixAcceptor;
 import org.netbeans.modules.jackpot30.spi.HintDescription.Literal;
 import org.netbeans.modules.jackpot30.spi.HintDescription.MarkCondition;
 import org.netbeans.modules.jackpot30.spi.HintDescription.MarksWorker;
 import org.netbeans.modules.jackpot30.spi.HintDescription.Value;
 import org.netbeans.modules.jackpot30.spi.HintMetadata;
 import org.netbeans.modules.jackpot30.spi.HintMetadata.HintSeverity;
-import org.netbeans.modules.jackpot30.spi.JavaFix;
-import org.netbeans.modules.jackpot30.spi.support.ErrorDescriptionFactory;
 import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
 import org.netbeans.spi.editor.hints.Fix;
+import org.netbeans.spi.editor.hints.Severity;
 import org.openide.util.Exceptions;
 
 /**
                                 HintContext fixContext = new HintContext(workerContext);
 
                                 fixContext.enterScope();
-                                fixData.add(new FixEvaluationData(fixContext, new LinkedList<Condition>(fd.marks), fd.acceptor, fd.fix));
+                                fixData.add(new FixEvaluationData(fixContext, new LinkedList<Condition>(fd.marks), fd.acceptor));
                             }
 
                             HintEvaluationData data = new HintEvaluationData(workerContext, hd, new LinkedList<Condition>(mw.marks), mw.acceptor, fixData);
                     if (res == null) continue;
 
                     if (res) {
-                        if (fed.acceptor.accept(fed.ctx)) {
-                            Fix fix = JavaFix.rewriteFix(fed.ctx.getInfo(), "XXX: todo", fed.ctx.getPath(), fed.fix, fed.ctx.getVariables(), fed.ctx.getMultiVariables(), fed.ctx.getVariableNames(), Collections.<String, TypeMirror>emptyMap()/*XXX*/ /*XXX: , imports*/);
+                        Fix fix = fed.acceptor.accept(fed.ctx);
 
+                        if (fix != null) {
                             hed.createdFixes.add(fix);
                         }
                     } else {
                 }
 
                 if (hed.fixDescriptions.isEmpty()) {
-                    if (hed.acceptor.accept(hed.ctx)) {
-                        //XXX: @SuppressWarnings!
-                        ErrorDescription ed = ErrorDescriptionFactory.forName(hed.ctx, hed.ctx.getPath(), hed.hd.getMetadata().displayName, hed.createdFixes.toArray(new Fix[0]));
+                    //XXX: @SuppressWarnings!
+                    ErrorDescription ed = hed.acceptor.accept(hed.ctx);
 
+                    ed = ErrorDescriptionFactory.createErrorDescription(ed.getSeverity(), ed.getDescription(), hed.createdFixes, ed.getFile(), ed.getRange().getBegin().getOffset(), ed.getRange().getEnd().getOffset());
+
+                    if (ed != null) {
                         merge(errors, hed.hd, ed);
                     }
                     it.remove();
         public final HintContext ctx;
         public final HintDescription hd;
         public final List<Condition> marks;
-        public final Acceptor acceptor;
+        public final ErrorDescriptionAcceptor acceptor;
         public final List<FixEvaluationData> fixDescriptions;
         public final List<Fix> createdFixes = new LinkedList<Fix>();
-        public HintEvaluationData(HintContext ctx, HintDescription hd, List<Condition> marks, Acceptor acceptor, List<FixEvaluationData> fixDescriptions) {
+        public HintEvaluationData(HintContext ctx, HintDescription hd, List<Condition> marks, ErrorDescriptionAcceptor acceptor, List<FixEvaluationData> fixDescriptions) {
             this.ctx = ctx;
             this.hd = hd;
             this.marks = marks;
     private static final class FixEvaluationData {
         public final HintContext ctx;
         public final List<Condition> marks;
-        public final Acceptor acceptor;
-        public final String fix;
-        public FixEvaluationData(HintContext ctx, List<Condition> marks, Acceptor acceptor, String fix) {
+        public final FixAcceptor acceptor;
+        public FixEvaluationData(HintContext ctx, List<Condition> marks, FixAcceptor acceptor) {
             this.ctx = ctx;
             this.marks = marks;
             this.acceptor = acceptor;
-            this.fix = fix;
         }
     }
 

api/src/org/netbeans/modules/jackpot30/spi/HintDescription.java

 import java.util.Map;
 import java.util.Set;
 import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.Fix;
 import org.openide.util.Parameters;
 
 /**
 
     }
 
-    public static interface Acceptor {
-        public boolean accept(HintContext ctx);
+    public static interface ErrorDescriptionAcceptor {
+        public ErrorDescription accept(HintContext ctx);
+    }
+
+    public static interface FixAcceptor {
+        public Fix accept(HintContext ctx);
     }
 
     //XXX: should be a method on the factory:
     public static final class MarksWorker implements Worker {
 
         public final List<Condition> marks;
-        public final Acceptor acceptor;
+        public final ErrorDescriptionAcceptor acceptor;
         public final List<DeclarativeFixDescription> fixes;
 
-        public MarksWorker(List<Condition> marks, Acceptor acceptor, List<DeclarativeFixDescription> fixes) {
+        public MarksWorker(List<Condition> marks, ErrorDescriptionAcceptor acceptor, List<DeclarativeFixDescription> fixes) {
             this.marks = marks;
             this.acceptor = acceptor;
             this.fixes = fixes;
     //XXX: should be a method on the factory:
     public static final class DeclarativeFixDescription {
         public final List<Condition> marks;
-        public final Acceptor acceptor;
-        public final String fix;
+        public final FixAcceptor acceptor;
 
-        public DeclarativeFixDescription(List<Condition> marks, Acceptor acceptor, String fix) {
+        public DeclarativeFixDescription(List<Condition> marks, FixAcceptor acceptor) {
             this.marks = marks;
             this.acceptor = acceptor;
-            this.fix = fix;
         }
 
     }

api/test/unit/src/org/netbeans/modules/jackpot30/impl/hints/MarkEvaluationTest.java

 import org.netbeans.modules.jackpot30.impl.RulesManager;
 import org.netbeans.modules.jackpot30.spi.HintContext;
 import org.netbeans.modules.jackpot30.spi.HintDescription;
-import org.netbeans.modules.jackpot30.spi.HintDescription.Acceptor;
 import org.netbeans.modules.jackpot30.spi.HintDescription.Condition;
 import org.netbeans.modules.jackpot30.spi.HintDescription.DeclarativeFixDescription;
+import org.netbeans.modules.jackpot30.spi.HintDescription.ErrorDescriptionAcceptor;
+import org.netbeans.modules.jackpot30.spi.HintDescription.FixAcceptor;
 import org.netbeans.modules.jackpot30.spi.HintDescription.MarkCondition;
 import org.netbeans.modules.jackpot30.spi.HintDescription.MarksWorker;
 import org.netbeans.modules.jackpot30.spi.HintDescription.PatternDescription;
 import org.netbeans.modules.jackpot30.spi.HintDescriptionFactory;
 import org.netbeans.modules.jackpot30.spi.HintMetadata;
 import org.netbeans.modules.jackpot30.spi.HintMetadata.HintSeverity;
+import org.netbeans.modules.jackpot30.spi.JavaFix;
+import org.netbeans.modules.jackpot30.spi.support.ErrorDescriptionFactory;
 import org.netbeans.modules.java.hints.infrastructure.TreeRuleTestBase;
 import org.netbeans.spi.editor.hints.ErrorDescription;
 import org.netbeans.spi.editor.hints.Fix;
         List<Condition> globalConditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$_", "mark_var"), HintDescription.Operator.ASSIGN, new Selector("$var")));
         List<Condition> fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.EQUALS, new Selector("$var")));
         List<Condition> fix2Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.NOT_EQUALS, new Selector("$var")));
-        DeclarativeFixDescription f1 = new DeclarativeFixDescription(fix1Conditions, TRUE, "if ($var != $c) $then;");
-        DeclarativeFixDescription f2 = new DeclarativeFixDescription(fix2Conditions, TRUE, "if ($c == $var) $then;");
+        DeclarativeFixDescription f1 = new DeclarativeFixDescription(fix1Conditions, new FixAcceptorImpl("if ($var != $c) $then;"));
+        DeclarativeFixDescription f2 = new DeclarativeFixDescription(fix2Conditions, new FixAcceptorImpl("if ($c == $var) $then;"));
         currentHint = HintDescriptionFactory.create().setMetadata(prepareMetadata("A"))
                                                      .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
-                                                     .setWorker(new MarksWorker(globalConditions, new AcceptorImpl(), Arrays.asList(f1, f2)))
+                                                     .setWorker(new MarksWorker(globalConditions, new ErrorDescriptionAcceptorImpl("A"), Arrays.asList(f1, f2)))
                                                      .produce();
 
     }
         List<Condition> fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "impossible"), HintDescription.Operator.EQUALS, new Selector("$var")),
                                                                   new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.ASSIGN, new Selector("$var")));
         List<Condition> fix2Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$_", "mark_var"), HintDescription.Operator.NOT_EQUALS, new Selector("$var")));
-        DeclarativeFixDescription f1 = new DeclarativeFixDescription(fix1Conditions, TRUE, "if ($var != $c) $then;");
-        DeclarativeFixDescription f2 = new DeclarativeFixDescription(fix2Conditions, TRUE, "if ($c == $var) $then;");
+        DeclarativeFixDescription f1 = new DeclarativeFixDescription(fix1Conditions, new FixAcceptorImpl("if ($var != $c) $then;"));
+        DeclarativeFixDescription f2 = new DeclarativeFixDescription(fix2Conditions, new FixAcceptorImpl("if ($c == $var) $then;"));
         currentHint = HintDescriptionFactory.create().setMetadata(prepareMetadata("A"))
                                                      .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
-                                                     .setWorker(new MarksWorker(globalConditions, new AcceptorImpl(), Arrays.asList(f1, f2)))
+                                                     .setWorker(new MarksWorker(globalConditions, new ErrorDescriptionAcceptorImpl("A"), Arrays.asList(f1, f2)))
                                                      .produce();
         
         performFixTest("test/Test.java",
         List<Condition> hint2GlobalConditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "impossible"), HintDescription.Operator.EQUALS, new Selector("$var")),
                                                                          new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.ASSIGN, new Selector("$var")));
         List<Condition> hint1Fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$_", "mark_var"), HintDescription.Operator.NOT_EQUALS, new Selector("$var")));
-        DeclarativeFixDescription h1f1 = new DeclarativeFixDescription(hint1Fix1Conditions, TRUE, "if ($c == $var) $then;");
+        DeclarativeFixDescription h1f1 = new DeclarativeFixDescription(hint1Fix1Conditions, new FixAcceptorImpl("if ($c == $var) $then;"));
         HintDescription hint1 = HintDescriptionFactory.create().setMetadata(prepareMetadata("A"))
                                                                .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
-                                                               .setWorker(new MarksWorker(hint1GlobalConditions, new AcceptorImpl(), Arrays.asList(h1f1)))
+                                                               .setWorker(new MarksWorker(hint1GlobalConditions, new ErrorDescriptionAcceptorImpl("A"), Arrays.asList(h1f1)))
                                                                .produce();
         HintDescription hint2 = HintDescriptionFactory.create().setMetadata(prepareMetadata("B"))
                                                                .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
-                                                               .setWorker(new MarksWorker(hint2GlobalConditions, new AcceptorImpl(), Collections.<DeclarativeFixDescription>emptyList()))
+                                                               .setWorker(new MarksWorker(hint2GlobalConditions, new ErrorDescriptionAcceptorImpl("B"), Collections.<DeclarativeFixDescription>emptyList()))
                                                                .produce();
 
         currentHints = Arrays.asList(hint1, hint2);
         List<Condition> hint2GlobalConditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "impossible"), HintDescription.Operator.EQUALS, new Selector("$var")));
         List<Condition> hint1Fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$_", "mark_var"), HintDescription.Operator.NOT_EQUALS, new Selector("$var")));
         List<Condition> hint2Fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.ASSIGN, new Selector("$var")));
-        DeclarativeFixDescription h1f1 = new DeclarativeFixDescription(hint1Fix1Conditions, TRUE, "if ($c == $var) $then;");
-        DeclarativeFixDescription h2f1 = new DeclarativeFixDescription(hint2Fix1Conditions, TRUE, "if ($var != $c) $then;");
+        DeclarativeFixDescription h1f1 = new DeclarativeFixDescription(hint1Fix1Conditions, new FixAcceptorImpl("if ($c == $var) $then;"));
+        DeclarativeFixDescription h2f1 = new DeclarativeFixDescription(hint2Fix1Conditions, new FixAcceptorImpl("if ($var != $c) $then;"));
         HintDescription hint1 = HintDescriptionFactory.create().setMetadata(prepareMetadata("A"))
                                                                .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
-                                                               .setWorker(new MarksWorker(hint1GlobalConditions, new AcceptorImpl(), Arrays.asList(h1f1)))
+                                                               .setWorker(new MarksWorker(hint1GlobalConditions, new ErrorDescriptionAcceptorImpl("A"), Arrays.asList(h1f1)))
                                                                .produce();
         HintDescription hint2 = HintDescriptionFactory.create().setMetadata(prepareMetadata("B"))
                                                                .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
-                                                               .setWorker(new MarksWorker(hint2GlobalConditions, new AcceptorImpl(), Arrays.asList(h2f1)))
+                                                               .setWorker(new MarksWorker(hint2GlobalConditions, new ErrorDescriptionAcceptorImpl("B"), Arrays.asList(h2f1)))
                                                                .produce();
 
         currentHints = Arrays.asList(hint1, hint2);
     @Override
     public void testNoHintsForSimpleInitialize() throws Exception {}
 
-    private static final Acceptor TRUE = new AcceptorImpl();
+    private static final class ErrorDescriptionAcceptorImpl implements ErrorDescriptionAcceptor {
+        private final String displayName;
+        public ErrorDescriptionAcceptorImpl(String displayName) {
+            this.displayName = displayName;
+        }
+        public ErrorDescription accept(HintContext ctx) {
+            return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName);
+        }
+    };
     
-    private static final class AcceptorImpl implements Acceptor {
-        public boolean accept(HintContext ctx) { return true; }
+    private static final class FixAcceptorImpl implements FixAcceptor {
+        private final String to;
+        public FixAcceptorImpl(String to) {
+            this.to = to;
+        }
+        public Fix accept(HintContext ctx) {
+            return JavaFix.rewriteFix(ctx, "FixImpl", ctx.getPath(), to);
+        }
     }
 }

file/src/org/netbeans/modules/jackpot30/file/DeclarativeHintRegistry.java

 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import org.netbeans.modules.jackpot30.file.DeclarativeHintsParser.FixTextDescription;
 import org.netbeans.modules.jackpot30.file.DeclarativeHintsParser.HintTextDescription;
 import org.netbeans.modules.jackpot30.file.DeclarativeHintsParser.Result;
-import org.netbeans.modules.jackpot30.file.conditionapi.Context;
 import org.netbeans.modules.jackpot30.spi.ClassPathBasedHintProvider;
 import org.netbeans.modules.jackpot30.spi.HintContext;
 import org.netbeans.modules.jackpot30.spi.HintContext.MessageKind;
 import org.netbeans.modules.jackpot30.spi.HintDescription;
-import org.netbeans.modules.jackpot30.spi.HintDescription.Acceptor;
 import org.netbeans.modules.jackpot30.spi.HintDescription.AdditionalQueryConstraints;
 import org.netbeans.modules.jackpot30.spi.HintDescription.Condition;
 import org.netbeans.modules.jackpot30.spi.HintDescription.DeclarativeFixDescription;
+import org.netbeans.modules.jackpot30.spi.HintDescription.ErrorDescriptionAcceptor;
+import org.netbeans.modules.jackpot30.spi.HintDescription.FixAcceptor;
 import org.netbeans.modules.jackpot30.spi.HintDescription.PatternDescription;
 import org.netbeans.modules.jackpot30.spi.HintDescriptionFactory;
 import org.netbeans.modules.jackpot30.spi.HintMetadata;
 import org.netbeans.modules.jackpot30.spi.HintMetadata.HintSeverity;
 import org.netbeans.modules.jackpot30.spi.HintProvider;
+import org.netbeans.modules.jackpot30.spi.JavaFix;
+import org.netbeans.modules.jackpot30.spi.support.ErrorDescriptionFactory;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.Fix;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileStateInvalidException;
 import org.openide.filesystems.FileUtil;
 
                 //XXX:
 //                fixes.add(DeclarativeFix.create(fixDisplayName, spec.substring(fixRange[0], fixRange[1]), fix.conditions, options));
-                fixes.add(new DeclarativeFixDescription(fix.conditions, new HintsFixAcceptor(fix.conditions, fix.options), spec.substring(fixRange[0], fixRange[1])));
+                fixes.add(new DeclarativeFixDescription(fix.conditions, new HintsFixAcceptor(fix.displayName, spec.substring(fixRange[0], fixRange[1]), fix.options, imports)));
             }
 
             HintMetadata currentMeta = meta;
 
             //XXX:
 //            f = f.setWorker(new DeclarativeHintsWorker(displayName, hint.conditions, imports, fixes, options, primarySuppressWarningsKey));
-            f = f.setWorker(new HintDescription.MarksWorker(hint.conditions, new HintsFixAcceptor(hint.conditions, hint.options), fixes));
+            f = f.setWorker(new HintDescription.MarksWorker(hint.conditions, new HintsAcceptor(displayName), fixes));
             f = f.setMetadata(currentMeta);
             f = f.setAdditionalConstraints(new AdditionalQueryConstraints(new HashSet<String>(constraints.values())));
 
         }
     }
     
-    private static final class HintsFixAcceptor implements Acceptor {
+    private static final class HintsFixAcceptor implements FixAcceptor {
 
-        private final List<Condition> conditions;
+        private final String displayName;
+        private final String pattern;
         private final Map<String, String> options;
+        private final String imports;
 
-        public HintsFixAcceptor(List<Condition> conditions, Map<String, String> options) {
-            this.conditions = conditions;
+        public HintsFixAcceptor(String displayName, String pattern, Map<String, String> options, String imports) {
+            this.displayName = displayName;
+            this.pattern = pattern;
             this.options = options;
+            this.imports = imports;
         }
 
-        public boolean accept(HintContext ctx) {
-//            for (Condition c : conditions) {
-//                if (!c.holds(ctx)) {
-//                    return false;
-//                }
-//            }
-
+        public Fix accept(HintContext ctx) {
             reportErrorWarning(ctx, options);
 
-            return true;
+            TokenSequence<DeclarativeHintTokenId> ts = TokenHierarchy.create(pattern,
+                                                                             false,
+                                                                             DeclarativeHintTokenId.language(),
+                                                                             EnumSet.of(DeclarativeHintTokenId.BLOCK_COMMENT,
+                                                                                        DeclarativeHintTokenId.LINE_COMMENT,
+                                                                                        DeclarativeHintTokenId.WHITESPACE),
+                                                                             null).tokenSequence(DeclarativeHintTokenId.language());
+
+            boolean empty = !ts.moveNext();
+
+            if (empty) {
+                if (   (   !options.containsKey(DeclarativeHintsOptions.OPTION_ERROR)
+                        && !options.containsKey(DeclarativeHintsOptions.OPTION_WARNING))
+                    || options.containsKey(DeclarativeHintsOptions.OPTION_REMOVE_FROM_PARENT)) {
+                    return JavaFix.removeFromParent(ctx, ctx.getPath());
+                }
+
+                //not realizing empty fixes
+                return null;
+            } else {
+                return JavaFix.rewriteFix(ctx.getInfo(),
+                                          displayName,
+                                          ctx.getPath(),
+                                          pattern,
+                                          ctx.getVariables(),
+                                          ctx.getMultiVariables(),
+                                          ctx.getVariableNames(),
+                                          ctx.getConstraints(),
+                                          options,
+                                          imports);
+            }
         }
     }
 
+    private static final class HintsAcceptor implements ErrorDescriptionAcceptor {
+
+        private final String displayName;
+
+        public HintsAcceptor(String displayName) {
+            this.displayName = displayName;
+        }
+
+        public ErrorDescription accept(HintContext ctx) {
+            return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName);
+        }
+    }
 }

file/src/org/netbeans/modules/jackpot30/file/DeclarativeHintsWorker.java

-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2008-2011 Sun Microsystems, Inc. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License.  When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- *
- * Contributor(s):
- *
- * Portions Copyrighted 2008-2011 Sun Microsystems, Inc.
- */
-
-package org.netbeans.modules.jackpot30.file;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import org.netbeans.api.lexer.TokenHierarchy;
-import org.netbeans.api.lexer.TokenSequence;
-//import org.netbeans.modules.jackpot30.file.DeclarativeCondition.Otherwise;
-import org.netbeans.modules.jackpot30.file.conditionapi.Context;
-import org.netbeans.modules.jackpot30.spi.HintContext;
-import org.netbeans.modules.jackpot30.spi.HintContext.MessageKind;
-import org.netbeans.modules.jackpot30.spi.HintDescription.Worker;
-import org.netbeans.modules.jackpot30.spi.JavaFix;
-import org.netbeans.modules.jackpot30.spi.support.ErrorDescriptionFactory;
-//import org.netbeans.modules.java.hints.spi.support.FixFactory;
-import org.netbeans.spi.editor.hints.ErrorDescription;
-import org.netbeans.spi.editor.hints.Fix;
-
-/**
- *
- * @author Jan Lahoda
- */
-class DeclarativeHintsWorker implements Worker {
-
-    private final String displayName;
-    private final List<DeclarativeCondition> conditions;
-    private final String imports;
-    private final List<DeclarativeFix> fixes;
-    private final Map<String, String> options;
-    private final String primarySuppressWarningsKey;
-
-    public DeclarativeHintsWorker(String displayName, List<DeclarativeCondition> conditions, String imports, List<DeclarativeFix> fixes, Map<String, String> options, String primarySuppressWarningsKey) {
-        this.displayName = displayName;
-        this.conditions = conditions;
-        this.imports = imports;
-        this.fixes = fixes;
-        this.options = options;
-        this.primarySuppressWarningsKey = primarySuppressWarningsKey;
-    }
-
-    //for tests:
-    String getDisplayName() {
-        return displayName;
-    }
-
-    //for tests:
-    List<DeclarativeFix> getFixes() {
-        return fixes;
-    }
-
-    public Collection<? extends ErrorDescription> createErrors(HintContext ctx) {
-//        Context context = new Context(ctx);
-//
-//        context.enterScope();
-//
-//        for (DeclarativeCondition c : conditions) {
-//            if (!c.holds(context)) {
-//                return null;
-//            }
-//        }
-//
-//        List<Fix> editorFixes = new LinkedList<Fix>();
-//
-//        OUTER: for (DeclarativeFix fix : fixes) {
-//            context.enterScope();
-//
-//            try {
-//                for (DeclarativeCondition c : fix.getConditions()) {
-//                    if (c instanceof Otherwise) {
-//                        if (editorFixes.isEmpty()) {
-//                            continue;
-//                        } else {
-//                            continue OUTER;
-//                        }
-//                    }
-//                    if (!c.holds(context)) {
-//                        continue OUTER;
-//                    }
-//                }
-//
-//                reportErrorWarning(ctx, fix.getOptions());
-//
-//                TokenSequence<DeclarativeHintTokenId> ts = TokenHierarchy.create(fix.getPattern(),
-//                                                                                 false,
-//                                                                                 DeclarativeHintTokenId.language(),
-//                                                                                 EnumSet.of(DeclarativeHintTokenId.BLOCK_COMMENT,
-//                                                                                            DeclarativeHintTokenId.LINE_COMMENT,
-//                                                                                            DeclarativeHintTokenId.WHITESPACE),
-//                                                                                 null).tokenSequence(DeclarativeHintTokenId.language());
-//
-//                boolean empty = !ts.moveNext();
-//
-//                if (empty) {
-//                    if (   (   !fix.getOptions().containsKey(DeclarativeHintsOptions.OPTION_ERROR)
-//                            && !fix.getOptions().containsKey(DeclarativeHintsOptions.OPTION_WARNING))
-//                        || fix.getOptions().containsKey(DeclarativeHintsOptions.OPTION_REMOVE_FROM_PARENT)) {
-//                        editorFixes.add(JavaFix.removeFromParent(ctx, ctx.getPath()));
-//                    }
-//                    //not realizing empty fixes
-//                } else {
-//                    editorFixes.add(JavaFix.rewriteFix(ctx.getInfo(),
-//                                                       fix.getDisplayName(),
-//                                                       ctx.getPath(),
-//                                                       fix.getPattern(),
-//                                                       ctx.getVariables(),
-//                                                       ctx.getMultiVariables(),
-//                                                       ctx.getVariableNames(),
-//                                                       ctx.getConstraints(),
-//                                                       fix.getOptions(),
-//                                                       imports));
-//                }
-//            } finally {
-//                context.leaveScope();
-//            }
-//        }
-//
-//        context.leaveScope();
-//
-////        if (primarySuppressWarningsKey != null && primarySuppressWarningsKey.length() > 0) {
-////            editorFixes.addAll(FixFactory.createSuppressWarnings(ctx.getInfo(), ctx.getPath(), primarySuppressWarningsKey));
-////        }
-//
-//        ErrorDescription ed = ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName, editorFixes.toArray(new Fix[0]));
-//
-//        if (ed == null) {
-//            return null;
-//        }
-//
-//        return Collections.singletonList(ed);
-
-        throw new IllegalStateException();
-    }
-
-    private static void reportErrorWarning(HintContext ctx, Map<String, String> options) {
-        String errorText = options.get("error");
-
-        if (errorText != null)  {
-            ctx.reportMessage(MessageKind.ERROR, errorText);
-        }
-
-        String warningText = options.get("warning");
-
-        if (warningText != null)  {
-            ctx.reportMessage(MessageKind.WARNING, warningText);
-        }
-    }
-
-}