Let the (marks based) API clients compute their own ErrorDescription and Fixes.
1.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/MessageImpl.java Sun Mar 06 14:37:09 2011 +0100
1.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/MessageImpl.java Sun Mar 06 17:38:53 2011 +0100
1.3 @@ -55,4 +55,9 @@
1.4 this.text = text;
1.5 }
1.6
1.7 + @Override
1.8 + public String toString() {
1.9 + return "[" + kind + ":" + text + "]";
1.10 + }
1.11 +
1.12 }
2.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/hints/HintsInvoker.java Sun Mar 06 14:37:09 2011 +0100
2.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/hints/HintsInvoker.java Sun Mar 06 17:38:53 2011 +0100
2.3 @@ -84,10 +84,11 @@
2.4 import org.netbeans.modules.jackpot30.spi.Hacks;
2.5 import org.netbeans.modules.jackpot30.spi.HintContext;
2.6 import org.netbeans.modules.jackpot30.spi.HintDescription;
2.7 -import org.netbeans.modules.jackpot30.spi.HintDescription.Acceptor;
2.8 import org.netbeans.modules.jackpot30.spi.HintDescription.Condition;
2.9 import org.netbeans.modules.jackpot30.spi.HintDescription.CustomCondition;
2.10 import org.netbeans.modules.jackpot30.spi.HintDescription.DeclarativeFixDescription;
2.11 +import org.netbeans.modules.jackpot30.spi.HintDescription.ErrorDescriptionAcceptor;
2.12 +import org.netbeans.modules.jackpot30.spi.HintDescription.FixAcceptor;
2.13 import org.netbeans.modules.jackpot30.spi.HintDescription.Literal;
2.14 import org.netbeans.modules.jackpot30.spi.HintDescription.MarkCondition;
2.15 import org.netbeans.modules.jackpot30.spi.HintDescription.MarksWorker;
2.16 @@ -98,10 +99,10 @@
2.17 import org.netbeans.modules.jackpot30.spi.HintDescription.Value;
2.18 import org.netbeans.modules.jackpot30.spi.HintMetadata;
2.19 import org.netbeans.modules.jackpot30.spi.HintMetadata.HintSeverity;
2.20 -import org.netbeans.modules.jackpot30.spi.JavaFix;
2.21 -import org.netbeans.modules.jackpot30.spi.support.ErrorDescriptionFactory;
2.22 import org.netbeans.spi.editor.hints.ErrorDescription;
2.23 +import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
2.24 import org.netbeans.spi.editor.hints.Fix;
2.25 +import org.netbeans.spi.editor.hints.Severity;
2.26 import org.openide.util.Exceptions;
2.27
2.28 /**
2.29 @@ -470,7 +471,7 @@
2.30 HintContext fixContext = new HintContext(workerContext);
2.31
2.32 fixContext.enterScope();
2.33 - fixData.add(new FixEvaluationData(fixContext, new LinkedList<Condition>(fd.marks), fd.acceptor, fd.fix));
2.34 + fixData.add(new FixEvaluationData(fixContext, new LinkedList<Condition>(fd.marks), fd.acceptor));
2.35 }
2.36
2.37 HintEvaluationData data = new HintEvaluationData(workerContext, hd, new LinkedList<Condition>(mw.marks), mw.acceptor, fixData);
2.38 @@ -538,9 +539,9 @@
2.39 if (res == null) continue;
2.40
2.41 if (res) {
2.42 - if (fed.acceptor.accept(fed.ctx)) {
2.43 - 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*/);
2.44 + Fix fix = fed.acceptor.accept(fed.ctx);
2.45
2.46 + if (fix != null) {
2.47 hed.createdFixes.add(fix);
2.48 }
2.49 } else {
2.50 @@ -556,10 +557,12 @@
2.51 }
2.52
2.53 if (hed.fixDescriptions.isEmpty()) {
2.54 - if (hed.acceptor.accept(hed.ctx)) {
2.55 - //XXX: @SuppressWarnings!
2.56 - ErrorDescription ed = ErrorDescriptionFactory.forName(hed.ctx, hed.ctx.getPath(), hed.hd.getMetadata().displayName, hed.createdFixes.toArray(new Fix[0]));
2.57 + //XXX: @SuppressWarnings!
2.58 + ErrorDescription ed = hed.acceptor.accept(hed.ctx);
2.59
2.60 + ed = ErrorDescriptionFactory.createErrorDescription(ed.getSeverity(), ed.getDescription(), hed.createdFixes, ed.getFile(), ed.getRange().getBegin().getOffset(), ed.getRange().getEnd().getOffset());
2.61 +
2.62 + if (ed != null) {
2.63 merge(errors, hed.hd, ed);
2.64 }
2.65 it.remove();
2.66 @@ -1098,10 +1101,10 @@
2.67 public final HintContext ctx;
2.68 public final HintDescription hd;
2.69 public final List<Condition> marks;
2.70 - public final Acceptor acceptor;
2.71 + public final ErrorDescriptionAcceptor acceptor;
2.72 public final List<FixEvaluationData> fixDescriptions;
2.73 public final List<Fix> createdFixes = new LinkedList<Fix>();
2.74 - public HintEvaluationData(HintContext ctx, HintDescription hd, List<Condition> marks, Acceptor acceptor, List<FixEvaluationData> fixDescriptions) {
2.75 + public HintEvaluationData(HintContext ctx, HintDescription hd, List<Condition> marks, ErrorDescriptionAcceptor acceptor, List<FixEvaluationData> fixDescriptions) {
2.76 this.ctx = ctx;
2.77 this.hd = hd;
2.78 this.marks = marks;
2.79 @@ -1113,13 +1116,11 @@
2.80 private static final class FixEvaluationData {
2.81 public final HintContext ctx;
2.82 public final List<Condition> marks;
2.83 - public final Acceptor acceptor;
2.84 - public final String fix;
2.85 - public FixEvaluationData(HintContext ctx, List<Condition> marks, Acceptor acceptor, String fix) {
2.86 + public final FixAcceptor acceptor;
2.87 + public FixEvaluationData(HintContext ctx, List<Condition> marks, FixAcceptor acceptor) {
2.88 this.ctx = ctx;
2.89 this.marks = marks;
2.90 this.acceptor = acceptor;
2.91 - this.fix = fix;
2.92 }
2.93 }
2.94
3.1 --- a/api/src/org/netbeans/modules/jackpot30/spi/HintDescription.java Sun Mar 06 14:37:09 2011 +0100
3.2 +++ b/api/src/org/netbeans/modules/jackpot30/spi/HintDescription.java Sun Mar 06 17:38:53 2011 +0100
3.3 @@ -49,6 +49,7 @@
3.4 import java.util.Map;
3.5 import java.util.Set;
3.6 import org.netbeans.spi.editor.hints.ErrorDescription;
3.7 +import org.netbeans.spi.editor.hints.Fix;
3.8 import org.openide.util.Parameters;
3.9
3.10 /**
3.11 @@ -253,18 +254,22 @@
3.12
3.13 }
3.14
3.15 - public static interface Acceptor {
3.16 - public boolean accept(HintContext ctx);
3.17 + public static interface ErrorDescriptionAcceptor {
3.18 + public ErrorDescription accept(HintContext ctx);
3.19 + }
3.20 +
3.21 + public static interface FixAcceptor {
3.22 + public Fix accept(HintContext ctx);
3.23 }
3.24
3.25 //XXX: should be a method on the factory:
3.26 public static final class MarksWorker implements Worker {
3.27
3.28 public final List<Condition> marks;
3.29 - public final Acceptor acceptor;
3.30 + public final ErrorDescriptionAcceptor acceptor;
3.31 public final List<DeclarativeFixDescription> fixes;
3.32
3.33 - public MarksWorker(List<Condition> marks, Acceptor acceptor, List<DeclarativeFixDescription> fixes) {
3.34 + public MarksWorker(List<Condition> marks, ErrorDescriptionAcceptor acceptor, List<DeclarativeFixDescription> fixes) {
3.35 this.marks = marks;
3.36 this.acceptor = acceptor;
3.37 this.fixes = fixes;
3.38 @@ -279,13 +284,11 @@
3.39 //XXX: should be a method on the factory:
3.40 public static final class DeclarativeFixDescription {
3.41 public final List<Condition> marks;
3.42 - public final Acceptor acceptor;
3.43 - public final String fix;
3.44 + public final FixAcceptor acceptor;
3.45
3.46 - public DeclarativeFixDescription(List<Condition> marks, Acceptor acceptor, String fix) {
3.47 + public DeclarativeFixDescription(List<Condition> marks, FixAcceptor acceptor) {
3.48 this.marks = marks;
3.49 this.acceptor = acceptor;
3.50 - this.fix = fix;
3.51 }
3.52
3.53 }
4.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/hints/MarkEvaluationTest.java Sun Mar 06 14:37:09 2011 +0100
4.2 +++ b/api/test/unit/src/org/netbeans/modules/jackpot30/impl/hints/MarkEvaluationTest.java Sun Mar 06 17:38:53 2011 +0100
4.3 @@ -55,9 +55,10 @@
4.4 import org.netbeans.modules.jackpot30.impl.RulesManager;
4.5 import org.netbeans.modules.jackpot30.spi.HintContext;
4.6 import org.netbeans.modules.jackpot30.spi.HintDescription;
4.7 -import org.netbeans.modules.jackpot30.spi.HintDescription.Acceptor;
4.8 import org.netbeans.modules.jackpot30.spi.HintDescription.Condition;
4.9 import org.netbeans.modules.jackpot30.spi.HintDescription.DeclarativeFixDescription;
4.10 +import org.netbeans.modules.jackpot30.spi.HintDescription.ErrorDescriptionAcceptor;
4.11 +import org.netbeans.modules.jackpot30.spi.HintDescription.FixAcceptor;
4.12 import org.netbeans.modules.jackpot30.spi.HintDescription.MarkCondition;
4.13 import org.netbeans.modules.jackpot30.spi.HintDescription.MarksWorker;
4.14 import org.netbeans.modules.jackpot30.spi.HintDescription.PatternDescription;
4.15 @@ -65,6 +66,8 @@
4.16 import org.netbeans.modules.jackpot30.spi.HintDescriptionFactory;
4.17 import org.netbeans.modules.jackpot30.spi.HintMetadata;
4.18 import org.netbeans.modules.jackpot30.spi.HintMetadata.HintSeverity;
4.19 +import org.netbeans.modules.jackpot30.spi.JavaFix;
4.20 +import org.netbeans.modules.jackpot30.spi.support.ErrorDescriptionFactory;
4.21 import org.netbeans.modules.java.hints.infrastructure.TreeRuleTestBase;
4.22 import org.netbeans.spi.editor.hints.ErrorDescription;
4.23 import org.netbeans.spi.editor.hints.Fix;
4.24 @@ -95,11 +98,11 @@
4.25 List<Condition> globalConditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$_", "mark_var"), HintDescription.Operator.ASSIGN, new Selector("$var")));
4.26 List<Condition> fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.EQUALS, new Selector("$var")));
4.27 List<Condition> fix2Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.NOT_EQUALS, new Selector("$var")));
4.28 - DeclarativeFixDescription f1 = new DeclarativeFixDescription(fix1Conditions, TRUE, "if ($var != $c) $then;");
4.29 - DeclarativeFixDescription f2 = new DeclarativeFixDescription(fix2Conditions, TRUE, "if ($c == $var) $then;");
4.30 + DeclarativeFixDescription f1 = new DeclarativeFixDescription(fix1Conditions, new FixAcceptorImpl("if ($var != $c) $then;"));
4.31 + DeclarativeFixDescription f2 = new DeclarativeFixDescription(fix2Conditions, new FixAcceptorImpl("if ($c == $var) $then;"));
4.32 currentHint = HintDescriptionFactory.create().setMetadata(prepareMetadata("A"))
4.33 .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
4.34 - .setWorker(new MarksWorker(globalConditions, new AcceptorImpl(), Arrays.asList(f1, f2)))
4.35 + .setWorker(new MarksWorker(globalConditions, new ErrorDescriptionAcceptorImpl("A"), Arrays.asList(f1, f2)))
4.36 .produce();
4.37
4.38 }
4.39 @@ -196,11 +199,11 @@
4.40 List<Condition> fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "impossible"), HintDescription.Operator.EQUALS, new Selector("$var")),
4.41 new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.ASSIGN, new Selector("$var")));
4.42 List<Condition> fix2Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$_", "mark_var"), HintDescription.Operator.NOT_EQUALS, new Selector("$var")));
4.43 - DeclarativeFixDescription f1 = new DeclarativeFixDescription(fix1Conditions, TRUE, "if ($var != $c) $then;");
4.44 - DeclarativeFixDescription f2 = new DeclarativeFixDescription(fix2Conditions, TRUE, "if ($c == $var) $then;");
4.45 + DeclarativeFixDescription f1 = new DeclarativeFixDescription(fix1Conditions, new FixAcceptorImpl("if ($var != $c) $then;"));
4.46 + DeclarativeFixDescription f2 = new DeclarativeFixDescription(fix2Conditions, new FixAcceptorImpl("if ($c == $var) $then;"));
4.47 currentHint = HintDescriptionFactory.create().setMetadata(prepareMetadata("A"))
4.48 .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
4.49 - .setWorker(new MarksWorker(globalConditions, new AcceptorImpl(), Arrays.asList(f1, f2)))
4.50 + .setWorker(new MarksWorker(globalConditions, new ErrorDescriptionAcceptorImpl("A"), Arrays.asList(f1, f2)))
4.51 .produce();
4.52
4.53 performFixTest("test/Test.java",
4.54 @@ -233,14 +236,14 @@
4.55 List<Condition> hint2GlobalConditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "impossible"), HintDescription.Operator.EQUALS, new Selector("$var")),
4.56 new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.ASSIGN, new Selector("$var")));
4.57 List<Condition> hint1Fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$_", "mark_var"), HintDescription.Operator.NOT_EQUALS, new Selector("$var")));
4.58 - DeclarativeFixDescription h1f1 = new DeclarativeFixDescription(hint1Fix1Conditions, TRUE, "if ($c == $var) $then;");
4.59 + DeclarativeFixDescription h1f1 = new DeclarativeFixDescription(hint1Fix1Conditions, new FixAcceptorImpl("if ($c == $var) $then;"));
4.60 HintDescription hint1 = HintDescriptionFactory.create().setMetadata(prepareMetadata("A"))
4.61 .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
4.62 - .setWorker(new MarksWorker(hint1GlobalConditions, new AcceptorImpl(), Arrays.asList(h1f1)))
4.63 + .setWorker(new MarksWorker(hint1GlobalConditions, new ErrorDescriptionAcceptorImpl("A"), Arrays.asList(h1f1)))
4.64 .produce();
4.65 HintDescription hint2 = HintDescriptionFactory.create().setMetadata(prepareMetadata("B"))
4.66 .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
4.67 - .setWorker(new MarksWorker(hint2GlobalConditions, new AcceptorImpl(), Collections.<DeclarativeFixDescription>emptyList()))
4.68 + .setWorker(new MarksWorker(hint2GlobalConditions, new ErrorDescriptionAcceptorImpl("B"), Collections.<DeclarativeFixDescription>emptyList()))
4.69 .produce();
4.70
4.71 currentHints = Arrays.asList(hint1, hint2);
4.72 @@ -275,15 +278,15 @@
4.73 List<Condition> hint2GlobalConditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "impossible"), HintDescription.Operator.EQUALS, new Selector("$var")));
4.74 List<Condition> hint1Fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$_", "mark_var"), HintDescription.Operator.NOT_EQUALS, new Selector("$var")));
4.75 List<Condition> hint2Fix1Conditions = Arrays.<Condition>asList(new MarkCondition(new Selector("$then", "mark_var"), HintDescription.Operator.ASSIGN, new Selector("$var")));
4.76 - DeclarativeFixDescription h1f1 = new DeclarativeFixDescription(hint1Fix1Conditions, TRUE, "if ($c == $var) $then;");
4.77 - DeclarativeFixDescription h2f1 = new DeclarativeFixDescription(hint2Fix1Conditions, TRUE, "if ($var != $c) $then;");
4.78 + DeclarativeFixDescription h1f1 = new DeclarativeFixDescription(hint1Fix1Conditions, new FixAcceptorImpl("if ($c == $var) $then;"));
4.79 + DeclarativeFixDescription h2f1 = new DeclarativeFixDescription(hint2Fix1Conditions, new FixAcceptorImpl("if ($var != $c) $then;"));
4.80 HintDescription hint1 = HintDescriptionFactory.create().setMetadata(prepareMetadata("A"))
4.81 .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
4.82 - .setWorker(new MarksWorker(hint1GlobalConditions, new AcceptorImpl(), Arrays.asList(h1f1)))
4.83 + .setWorker(new MarksWorker(hint1GlobalConditions, new ErrorDescriptionAcceptorImpl("A"), Arrays.asList(h1f1)))
4.84 .produce();
4.85 HintDescription hint2 = HintDescriptionFactory.create().setMetadata(prepareMetadata("B"))
4.86 .setTriggerPattern(PatternDescription.create("if ($var == $c) $then;"))
4.87 - .setWorker(new MarksWorker(hint2GlobalConditions, new AcceptorImpl(), Arrays.asList(h2f1)))
4.88 + .setWorker(new MarksWorker(hint2GlobalConditions, new ErrorDescriptionAcceptorImpl("B"), Arrays.asList(h2f1)))
4.89 .produce();
4.90
4.91 currentHints = Arrays.asList(hint1, hint2);
4.92 @@ -353,9 +356,23 @@
4.93 @Override
4.94 public void testNoHintsForSimpleInitialize() throws Exception {}
4.95
4.96 - private static final Acceptor TRUE = new AcceptorImpl();
4.97 + private static final class ErrorDescriptionAcceptorImpl implements ErrorDescriptionAcceptor {
4.98 + private final String displayName;
4.99 + public ErrorDescriptionAcceptorImpl(String displayName) {
4.100 + this.displayName = displayName;
4.101 + }
4.102 + public ErrorDescription accept(HintContext ctx) {
4.103 + return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName);
4.104 + }
4.105 + };
4.106
4.107 - private static final class AcceptorImpl implements Acceptor {
4.108 - public boolean accept(HintContext ctx) { return true; }
4.109 + private static final class FixAcceptorImpl implements FixAcceptor {
4.110 + private final String to;
4.111 + public FixAcceptorImpl(String to) {
4.112 + this.to = to;
4.113 + }
4.114 + public Fix accept(HintContext ctx) {
4.115 + return JavaFix.rewriteFix(ctx, "FixImpl", ctx.getPath(), to);
4.116 + }
4.117 }
4.118 }
4.119 \ No newline at end of file
5.1 --- a/file/src/org/netbeans/modules/jackpot30/file/DeclarativeHintRegistry.java Sun Mar 06 14:37:09 2011 +0100
5.2 +++ b/file/src/org/netbeans/modules/jackpot30/file/DeclarativeHintRegistry.java Sun Mar 06 17:38:53 2011 +0100
5.3 @@ -44,6 +44,7 @@
5.4 import java.util.Arrays;
5.5 import java.util.Collection;
5.6 import java.util.Collections;
5.7 +import java.util.EnumSet;
5.8 import java.util.HashMap;
5.9 import java.util.HashSet;
5.10 import java.util.LinkedHashMap;
5.11 @@ -65,20 +66,24 @@
5.12 import org.netbeans.modules.jackpot30.file.DeclarativeHintsParser.FixTextDescription;
5.13 import org.netbeans.modules.jackpot30.file.DeclarativeHintsParser.HintTextDescription;
5.14 import org.netbeans.modules.jackpot30.file.DeclarativeHintsParser.Result;
5.15 -import org.netbeans.modules.jackpot30.file.conditionapi.Context;
5.16 import org.netbeans.modules.jackpot30.spi.ClassPathBasedHintProvider;
5.17 import org.netbeans.modules.jackpot30.spi.HintContext;
5.18 import org.netbeans.modules.jackpot30.spi.HintContext.MessageKind;
5.19 import org.netbeans.modules.jackpot30.spi.HintDescription;
5.20 -import org.netbeans.modules.jackpot30.spi.HintDescription.Acceptor;
5.21 import org.netbeans.modules.jackpot30.spi.HintDescription.AdditionalQueryConstraints;
5.22 import org.netbeans.modules.jackpot30.spi.HintDescription.Condition;
5.23 import org.netbeans.modules.jackpot30.spi.HintDescription.DeclarativeFixDescription;
5.24 +import org.netbeans.modules.jackpot30.spi.HintDescription.ErrorDescriptionAcceptor;
5.25 +import org.netbeans.modules.jackpot30.spi.HintDescription.FixAcceptor;
5.26 import org.netbeans.modules.jackpot30.spi.HintDescription.PatternDescription;
5.27 import org.netbeans.modules.jackpot30.spi.HintDescriptionFactory;
5.28 import org.netbeans.modules.jackpot30.spi.HintMetadata;
5.29 import org.netbeans.modules.jackpot30.spi.HintMetadata.HintSeverity;
5.30 import org.netbeans.modules.jackpot30.spi.HintProvider;
5.31 +import org.netbeans.modules.jackpot30.spi.JavaFix;
5.32 +import org.netbeans.modules.jackpot30.spi.support.ErrorDescriptionFactory;
5.33 +import org.netbeans.spi.editor.hints.ErrorDescription;
5.34 +import org.netbeans.spi.editor.hints.Fix;
5.35 import org.openide.filesystems.FileObject;
5.36 import org.openide.filesystems.FileStateInvalidException;
5.37 import org.openide.filesystems.FileUtil;
5.38 @@ -277,7 +282,7 @@
5.39
5.40 //XXX:
5.41 // fixes.add(DeclarativeFix.create(fixDisplayName, spec.substring(fixRange[0], fixRange[1]), fix.conditions, options));
5.42 - fixes.add(new DeclarativeFixDescription(fix.conditions, new HintsFixAcceptor(fix.conditions, fix.options), spec.substring(fixRange[0], fixRange[1])));
5.43 + fixes.add(new DeclarativeFixDescription(fix.conditions, new HintsFixAcceptor(fix.displayName, spec.substring(fixRange[0], fixRange[1]), fix.options, imports)));
5.44 }
5.45
5.46 HintMetadata currentMeta = meta;
5.47 @@ -307,7 +312,7 @@
5.48
5.49 //XXX:
5.50 // f = f.setWorker(new DeclarativeHintsWorker(displayName, hint.conditions, imports, fixes, options, primarySuppressWarningsKey));
5.51 - f = f.setWorker(new HintDescription.MarksWorker(hint.conditions, new HintsFixAcceptor(hint.conditions, hint.options), fixes));
5.52 + f = f.setWorker(new HintDescription.MarksWorker(hint.conditions, new HintsAcceptor(displayName), fixes));
5.53 f = f.setMetadata(currentMeta);
5.54 f = f.setAdditionalConstraints(new AdditionalQueryConstraints(new HashSet<String>(constraints.values())));
5.55
5.56 @@ -389,27 +394,67 @@
5.57 }
5.58 }
5.59
5.60 - private static final class HintsFixAcceptor implements Acceptor {
5.61 + private static final class HintsFixAcceptor implements FixAcceptor {
5.62
5.63 - private final List<Condition> conditions;
5.64 + private final String displayName;
5.65 + private final String pattern;
5.66 private final Map<String, String> options;
5.67 + private final String imports;
5.68
5.69 - public HintsFixAcceptor(List<Condition> conditions, Map<String, String> options) {
5.70 - this.conditions = conditions;
5.71 + public HintsFixAcceptor(String displayName, String pattern, Map<String, String> options, String imports) {
5.72 + this.displayName = displayName;
5.73 + this.pattern = pattern;
5.74 this.options = options;
5.75 + this.imports = imports;
5.76 }
5.77
5.78 - public boolean accept(HintContext ctx) {
5.79 -// for (Condition c : conditions) {
5.80 -// if (!c.holds(ctx)) {
5.81 -// return false;
5.82 -// }
5.83 -// }
5.84 -
5.85 + public Fix accept(HintContext ctx) {
5.86 reportErrorWarning(ctx, options);
5.87
5.88 - return true;
5.89 + TokenSequence<DeclarativeHintTokenId> ts = TokenHierarchy.create(pattern,
5.90 + false,
5.91 + DeclarativeHintTokenId.language(),
5.92 + EnumSet.of(DeclarativeHintTokenId.BLOCK_COMMENT,
5.93 + DeclarativeHintTokenId.LINE_COMMENT,
5.94 + DeclarativeHintTokenId.WHITESPACE),
5.95 + null).tokenSequence(DeclarativeHintTokenId.language());
5.96 +
5.97 + boolean empty = !ts.moveNext();
5.98 +
5.99 + if (empty) {
5.100 + if ( ( !options.containsKey(DeclarativeHintsOptions.OPTION_ERROR)
5.101 + && !options.containsKey(DeclarativeHintsOptions.OPTION_WARNING))
5.102 + || options.containsKey(DeclarativeHintsOptions.OPTION_REMOVE_FROM_PARENT)) {
5.103 + return JavaFix.removeFromParent(ctx, ctx.getPath());
5.104 + }
5.105 +
5.106 + //not realizing empty fixes
5.107 + return null;
5.108 + } else {
5.109 + return JavaFix.rewriteFix(ctx.getInfo(),
5.110 + displayName,
5.111 + ctx.getPath(),
5.112 + pattern,
5.113 + ctx.getVariables(),
5.114 + ctx.getMultiVariables(),
5.115 + ctx.getVariableNames(),
5.116 + ctx.getConstraints(),
5.117 + options,
5.118 + imports);
5.119 + }
5.120 }
5.121 }
5.122
5.123 + private static final class HintsAcceptor implements ErrorDescriptionAcceptor {
5.124 +
5.125 + private final String displayName;
5.126 +
5.127 + public HintsAcceptor(String displayName) {
5.128 + this.displayName = displayName;
5.129 + }
5.130 +
5.131 + public ErrorDescription accept(HintContext ctx) {
5.132 + return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName);
5.133 + }
5.134 + }
5.135 }
6.1 --- a/file/src/org/netbeans/modules/jackpot30/file/DeclarativeHintsWorker.java Sun Mar 06 14:37:09 2011 +0100
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,190 +0,0 @@
6.4 -/*
6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6.6 - *
6.7 - * Copyright 2008-2011 Sun Microsystems, Inc. All rights reserved.
6.8 - *
6.9 - * The contents of this file are subject to the terms of either the GNU
6.10 - * General Public License Version 2 only ("GPL") or the Common
6.11 - * Development and Distribution License("CDDL") (collectively, the
6.12 - * "License"). You may not use this file except in compliance with the
6.13 - * License. You can obtain a copy of the License at
6.14 - * http://www.netbeans.org/cddl-gplv2.html
6.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
6.16 - * specific language governing permissions and limitations under the
6.17 - * License. When distributing the software, include this License Header
6.18 - * Notice in each file and include the License file at
6.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
6.20 - * particular file as subject to the "Classpath" exception as provided
6.21 - * by Sun in the GPL Version 2 section of the License file that
6.22 - * accompanied this code. If applicable, add the following below the
6.23 - * License Header, with the fields enclosed by brackets [] replaced by
6.24 - * your own identifying information:
6.25 - * "Portions Copyrighted [year] [name of copyright owner]"
6.26 - *
6.27 - * If you wish your version of this file to be governed by only the CDDL
6.28 - * or only the GPL Version 2, indicate your decision by adding
6.29 - * "[Contributor] elects to include this software in this distribution
6.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
6.31 - * single choice of license, a recipient has the option to distribute
6.32 - * your version of this file under either the CDDL, the GPL Version 2 or
6.33 - * to extend the choice of license to its licensees as provided above.
6.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
6.35 - * Version 2 license, then the option applies only if the new code is
6.36 - * made subject to such option by the copyright holder.
6.37 - *
6.38 - * Contributor(s):
6.39 - *
6.40 - * Portions Copyrighted 2008-2011 Sun Microsystems, Inc.
6.41 - */
6.42 -
6.43 -package org.netbeans.modules.jackpot30.file;
6.44 -
6.45 -import java.util.Collection;
6.46 -import java.util.Collections;
6.47 -import java.util.EnumSet;
6.48 -import java.util.LinkedList;
6.49 -import java.util.List;
6.50 -import java.util.Map;
6.51 -import org.netbeans.api.lexer.TokenHierarchy;
6.52 -import org.netbeans.api.lexer.TokenSequence;
6.53 -//import org.netbeans.modules.jackpot30.file.DeclarativeCondition.Otherwise;
6.54 -import org.netbeans.modules.jackpot30.file.conditionapi.Context;
6.55 -import org.netbeans.modules.jackpot30.spi.HintContext;
6.56 -import org.netbeans.modules.jackpot30.spi.HintContext.MessageKind;
6.57 -import org.netbeans.modules.jackpot30.spi.HintDescription.Worker;
6.58 -import org.netbeans.modules.jackpot30.spi.JavaFix;
6.59 -import org.netbeans.modules.jackpot30.spi.support.ErrorDescriptionFactory;
6.60 -//import org.netbeans.modules.java.hints.spi.support.FixFactory;
6.61 -import org.netbeans.spi.editor.hints.ErrorDescription;
6.62 -import org.netbeans.spi.editor.hints.Fix;
6.63 -
6.64 -/**
6.65 - *
6.66 - * @author Jan Lahoda
6.67 - */
6.68 -class DeclarativeHintsWorker implements Worker {
6.69 -
6.70 - private final String displayName;
6.71 - private final List<DeclarativeCondition> conditions;
6.72 - private final String imports;
6.73 - private final List<DeclarativeFix> fixes;
6.74 - private final Map<String, String> options;
6.75 - private final String primarySuppressWarningsKey;
6.76 -
6.77 - public DeclarativeHintsWorker(String displayName, List<DeclarativeCondition> conditions, String imports, List<DeclarativeFix> fixes, Map<String, String> options, String primarySuppressWarningsKey) {
6.78 - this.displayName = displayName;
6.79 - this.conditions = conditions;
6.80 - this.imports = imports;
6.81 - this.fixes = fixes;
6.82 - this.options = options;
6.83 - this.primarySuppressWarningsKey = primarySuppressWarningsKey;
6.84 - }
6.85 -
6.86 - //for tests:
6.87 - String getDisplayName() {
6.88 - return displayName;
6.89 - }
6.90 -
6.91 - //for tests:
6.92 - List<DeclarativeFix> getFixes() {
6.93 - return fixes;
6.94 - }
6.95 -
6.96 - public Collection<? extends ErrorDescription> createErrors(HintContext ctx) {
6.97 -// Context context = new Context(ctx);
6.98 -//
6.99 -// context.enterScope();
6.100 -//
6.101 -// for (DeclarativeCondition c : conditions) {
6.102 -// if (!c.holds(context)) {
6.103 -// return null;
6.104 -// }
6.105 -// }
6.106 -//
6.107 -// List<Fix> editorFixes = new LinkedList<Fix>();
6.108 -//
6.109 -// OUTER: for (DeclarativeFix fix : fixes) {
6.110 -// context.enterScope();
6.111 -//
6.112 -// try {
6.113 -// for (DeclarativeCondition c : fix.getConditions()) {
6.114 -// if (c instanceof Otherwise) {
6.115 -// if (editorFixes.isEmpty()) {
6.116 -// continue;
6.117 -// } else {
6.118 -// continue OUTER;
6.119 -// }
6.120 -// }
6.121 -// if (!c.holds(context)) {
6.122 -// continue OUTER;
6.123 -// }
6.124 -// }
6.125 -//
6.126 -// reportErrorWarning(ctx, fix.getOptions());
6.127 -//
6.128 -// TokenSequence<DeclarativeHintTokenId> ts = TokenHierarchy.create(fix.getPattern(),
6.129 -// false,
6.130 -// DeclarativeHintTokenId.language(),
6.131 -// EnumSet.of(DeclarativeHintTokenId.BLOCK_COMMENT,
6.132 -// DeclarativeHintTokenId.LINE_COMMENT,
6.133 -// DeclarativeHintTokenId.WHITESPACE),
6.134 -// null).tokenSequence(DeclarativeHintTokenId.language());
6.135 -//
6.136 -// boolean empty = !ts.moveNext();
6.137 -//
6.138 -// if (empty) {
6.139 -// if ( ( !fix.getOptions().containsKey(DeclarativeHintsOptions.OPTION_ERROR)
6.140 -// && !fix.getOptions().containsKey(DeclarativeHintsOptions.OPTION_WARNING))
6.141 -// || fix.getOptions().containsKey(DeclarativeHintsOptions.OPTION_REMOVE_FROM_PARENT)) {
6.142 -// editorFixes.add(JavaFix.removeFromParent(ctx, ctx.getPath()));
6.143 -// }
6.144 -// //not realizing empty fixes
6.145 -// } else {
6.146 -// editorFixes.add(JavaFix.rewriteFix(ctx.getInfo(),
6.147 -// fix.getDisplayName(),
6.148 -// ctx.getPath(),
6.149 -// fix.getPattern(),
6.150 -// ctx.getVariables(),
6.151 -// ctx.getMultiVariables(),
6.152 -// ctx.getVariableNames(),
6.153 -// ctx.getConstraints(),
6.154 -// fix.getOptions(),
6.155 -// imports));
6.156 -// }
6.157 -// } finally {
6.158 -// context.leaveScope();
6.159 -// }
6.160 -// }
6.161 -//
6.162 -// context.leaveScope();
6.163 -//
6.164 -//// if (primarySuppressWarningsKey != null && primarySuppressWarningsKey.length() > 0) {
6.165 -//// editorFixes.addAll(FixFactory.createSuppressWarnings(ctx.getInfo(), ctx.getPath(), primarySuppressWarningsKey));
6.166 -//// }
6.167 -//
6.168 -// ErrorDescription ed = ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName, editorFixes.toArray(new Fix[0]));
6.169 -//
6.170 -// if (ed == null) {
6.171 -// return null;
6.172 -// }
6.173 -//
6.174 -// return Collections.singletonList(ed);
6.175 -
6.176 - throw new IllegalStateException();
6.177 - }
6.178 -
6.179 - private static void reportErrorWarning(HintContext ctx, Map<String, String> options) {
6.180 - String errorText = options.get("error");
6.181 -
6.182 - if (errorText != null) {
6.183 - ctx.reportMessage(MessageKind.ERROR, errorText);
6.184 - }
6.185 -
6.186 - String warningText = options.get("warning");
6.187 -
6.188 - if (warningText != null) {
6.189 - ctx.reportMessage(MessageKind.WARNING, warningText);
6.190 - }
6.191 - }
6.192 -
6.193 -}