[jboss-svn-commits] JBL Code SVN: r35810 - in labs/jbossrules/trunk/drools-ide-common/src: main/java/org/drools/ide/common/assistant and 10 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Nov 1 00:27:37 EDT 2010
Author: lucazamador
Date: 2010-11-01 00:27:36 -0400 (Mon, 01 Nov 2010)
New Revision: 35810
Added:
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleRefactorAssistant.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleSuggestionAssistant.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/AbstractParserEngine.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DRLParserEngine.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DSLParserEngine.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/RuleRefactorInfo.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLContentTypeEnum.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLRuleRefactorInfo.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleBasicContentInfo.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleDRLContentInfo.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleLineContentInfo.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/dsl/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/dsl/DSLRuleRefactorInfo.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/AssistantOption.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/RenameAssistantOption.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/ReplaceAssistantOption.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleAssistantProcessor.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleRefactorProcessor.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DRLRefactorProcessor.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DSLRefactorProcessor.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/AbstractRuleRefactor.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DRLRuleRefactor.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DSLRuleRefactor.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/FixImport.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableBinding.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableOption.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableRename.java
labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/
labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLAssistantTest.java
labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLParserEngineTest.java
labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DSLParserEngineTest.java
labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/FixImportTest.java
labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableBindingTest.java
labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableRenameTest.java
Log:
JBRULES-2765 move drools-assistant into drools-ide-common
- assistant code moved into ide-common
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleRefactorAssistant.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleRefactorAssistant.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleRefactorAssistant.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,21 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant;
+
+public interface RuleRefactorAssistant {
+ public String bindPatternToVariable(String backText);
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleRefactorAssistant.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleSuggestionAssistant.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleSuggestionAssistant.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleSuggestionAssistant.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,21 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant;
+
+public interface RuleSuggestionAssistant {
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/RuleSuggestionAssistant.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/AbstractParserEngine.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/AbstractParserEngine.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/AbstractParserEngine.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,33 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.engine;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+
+public abstract class AbstractParserEngine {
+
+ protected RuleRefactorInfo ruleRefactorInfo;
+ protected Pattern pattern;
+ protected Matcher matcher;
+ protected String rule;
+
+ public abstract RuleRefactorInfo parse();
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/AbstractParserEngine.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DRLParserEngine.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DRLParserEngine.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DRLParserEngine.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,149 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.engine;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+import org.drools.ide.common.assistant.info.drl.DRLContentTypeEnum;
+import org.drools.ide.common.assistant.info.drl.DRLRuleRefactorInfo;
+import org.drools.ide.common.assistant.info.drl.RuleLineContentInfo;
+
+/**
+ * A simple DRL parser implemented with regular expressions to get the offset of rule components
+ *
+ * @author lucas
+ *
+ */
+public class DRLParserEngine extends AbstractParserEngine {
+
+ private static final String RULE_DECLARATION = "(rule|RULE)";
+ private static final String PACKAGE_DECLARATION = "(package|PACKAGE)";
+ private static final String IMPORT_DECLARATION = "(import|IMPORT)";
+ private static final String GLOBAL_DECLARATION = "(global|GLOBAL)";
+ private static final String RULE_WHEN_DECLARATION = "(when|WHEN)";
+ private static final String RULE_THEN_DECLARATION = "(then|THEN)";
+ private static final String RULE_END_DECLARATION = "(end|END)";
+
+ private static final String OPTIONAL_TAB = "[\t]*";
+
+ private static final String FULLY_QUALIFIED_NAME = "[\\w\\.]*";
+ private static final String ONE_OR_MORE_SPACES = "[\\s]+";
+ private static final String RULE_NAME = "\"[\\s\\w]*\"";
+
+ // Regulars expressions to match DRL Rule
+ private static final String PACKAGE_PATTERN = PACKAGE_DECLARATION + ONE_OR_MORE_SPACES + FULLY_QUALIFIED_NAME + ";?"; // OK
+ private static final String IMPORT_PATTERN = IMPORT_DECLARATION + ONE_OR_MORE_SPACES + FULLY_QUALIFIED_NAME + ";"; // OK
+ private static final String GLOBAL_PATTERN = GLOBAL_DECLARATION + ONE_OR_MORE_SPACES + FULLY_QUALIFIED_NAME + ONE_OR_MORE_SPACES + "[\\w]*" + ONE_OR_MORE_SPACES + ""; // OK
+
+ private static final String RULE_NAME_PATTERN = RULE_DECLARATION + ONE_OR_MORE_SPACES + RULE_NAME;
+ private static final String RULE_LHS_PATTERN = "[\\t\\s]*" + RULE_WHEN_DECLARATION + ONE_OR_MORE_SPACES + OPTIONAL_TAB + "[\\w\\W]*" + "(?=" + RULE_THEN_DECLARATION + ")";
+ private static final String RULE_RHS_PATTERN = "[\\t\\s]*" + RULE_THEN_DECLARATION + ONE_OR_MORE_SPACES + "[\\w\\W]*" + RULE_END_DECLARATION;
+
+ private static final Pattern rulePattern = Pattern.compile("rule.+?end\\s*$", Pattern.MULTILINE | Pattern.DOTALL);
+
+ public DRLParserEngine(String rule) {
+ this.ruleRefactorInfo = new DRLRuleRefactorInfo();
+ this.rule = rule;
+ }
+
+ public RuleRefactorInfo parse() {
+ detectPackage(rule);
+ detectGlobals(rule);
+ detectImports(rule);
+ detectRules(rule);
+ return ruleRefactorInfo;
+ }
+
+ private void detectPackage(CharSequence rule) {
+ pattern = Pattern.compile(PACKAGE_PATTERN);
+ matcher = pattern.matcher(rule);
+ if (matcher.find())
+ ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.PACKAGE, matcher.start(), matcher.group());
+ }
+
+ private void detectImports(CharSequence rule) {
+ pattern = Pattern.compile(IMPORT_PATTERN);
+ matcher = pattern.matcher(rule);
+ while (matcher.find())
+ ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.IMPORT, matcher.start(), matcher.group());
+ }
+
+ private void detectGlobals(CharSequence rule) {
+ pattern = Pattern.compile(GLOBAL_PATTERN);
+ matcher = pattern.matcher(rule);
+ while (matcher.find())
+ ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.GLOBAL, matcher.start(), matcher.group());
+ }
+
+ private void detectRules(CharSequence rule) {
+ Matcher ruleMatcher = rulePattern.matcher(rule);
+ while (ruleMatcher.find()) {
+ for( int position = 0; position < ruleMatcher.groupCount()+1; position++ ){
+ String value = ruleMatcher.group(position);
+ int offset = ruleMatcher.start();
+ String ruleName = detectRuleName(value);
+ List<RuleLineContentInfo> lhs = detectLHS(value, offset);
+ List<RuleLineContentInfo> rhs = detectRHS(value, offset);
+ ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.RULE, offset, value, ruleName, lhs, rhs);
+ }
+ }
+ }
+
+ private String detectRuleName(CharSequence rule) {
+ pattern = Pattern.compile(RULE_NAME_PATTERN);
+ matcher = pattern.matcher(rule);
+ if (matcher.find())
+ return matcher.group();
+ return null;
+ }
+
+ private List<RuleLineContentInfo> detectLHS(CharSequence rule, int ruleOffset) {
+ pattern = Pattern.compile(RULE_LHS_PATTERN);
+ matcher = pattern.matcher(rule);
+ if (matcher.find()) {
+ return detectLines(matcher.group(), matcher.start() + ruleOffset, DRLContentTypeEnum.RULE_LHS_LINE);
+ }
+ return null;
+ }
+
+ private List<RuleLineContentInfo> detectRHS(CharSequence rule, int ruleOffset) {
+ pattern = Pattern.compile(RULE_RHS_PATTERN);
+ matcher = pattern.matcher(rule);
+ if (matcher.find())
+ return detectLines(matcher.group(), matcher.start() + ruleOffset, DRLContentTypeEnum.RULE_RHS_LINE);
+ return null;
+ }
+
+ private List<RuleLineContentInfo> detectLines(CharSequence rule, int lineOffset, DRLContentTypeEnum type) {
+ List<RuleLineContentInfo> ruleLines = new ArrayList<RuleLineContentInfo>();
+ pattern = Pattern.compile(".*");
+ matcher = pattern.matcher(rule);
+ while (matcher.find()) {
+ if (matcher.start()!=matcher.end()) {
+ if (matcher.group().trim().length() > 0) {
+ ruleLines.add(new RuleLineContentInfo(matcher.start()+lineOffset, matcher.group(), type));
+ }
+ }
+ }
+ return ruleLines;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DRLParserEngine.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DSLParserEngine.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DSLParserEngine.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DSLParserEngine.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,59 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.engine;
+
+import java.util.regex.Pattern;
+
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+import org.drools.ide.common.assistant.info.dsl.DSLRuleRefactorInfo;
+
+public class DSLParserEngine extends AbstractParserEngine {
+
+ private static final String WHEN_PATTERN = "(\\[when\\]|\\[consequence\\]).*";
+ private static final String THEN_PATTERN = "\\[then\\].*";
+
+
+ public DSLParserEngine(String rule) {
+ this.ruleRefactorInfo = new DSLRuleRefactorInfo();
+ this.rule = rule;
+ }
+
+ @Override
+ public RuleRefactorInfo parse() {
+ detectWHEN();
+ detectTHEN();
+ return ruleRefactorInfo;
+ }
+
+
+ private void detectWHEN() {
+ pattern = Pattern.compile(WHEN_PATTERN);
+ matcher = pattern.matcher(rule);
+ System.out.println("--------------when--------------");
+ while (matcher.find())
+ System.out.println(matcher.group() + "\n\tstart at index " + matcher.start());
+ }
+
+ private void detectTHEN() {
+ pattern = Pattern.compile(THEN_PATTERN);
+ matcher = pattern.matcher(rule);
+ System.out.println("--------------then--------------");
+ while (matcher.find())
+ System.out.println(matcher.group() + "\n\tstart at index " + matcher.start());
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/engine/DSLParserEngine.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/RuleRefactorInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/RuleRefactorInfo.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/RuleRefactorInfo.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,24 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.info;
+
+
+public interface RuleRefactorInfo {
+
+// public AbstractRuleBasicContentInfo getContentAt(int offset);
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/RuleRefactorInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLContentTypeEnum.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLContentTypeEnum.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLContentTypeEnum.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.info.drl;
+
+public enum DRLContentTypeEnum {
+
+ PACKAGE,
+ IMPORT,
+ GLOBAL,
+ RULE,
+ RULE_LHS_LINE,
+ RULE_RHS_LINE;
+
+ DRLContentTypeEnum() {
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLContentTypeEnum.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLRuleRefactorInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLRuleRefactorInfo.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLRuleRefactorInfo.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,96 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.info.drl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+
+public class DRLRuleRefactorInfo implements RuleRefactorInfo {
+
+ private Map<Integer, RuleBasicContentInfo> contents;
+
+ public DRLRuleRefactorInfo() {
+ contents = new TreeMap<Integer, RuleBasicContentInfo>();
+ }
+
+ public void addContent(DRLContentTypeEnum type, Integer offset, String content) {
+ this.contents.put(offset, new RuleBasicContentInfo(offset, content, type));
+ }
+
+ public void addContent(DRLContentTypeEnum type, int offset, String content, String ruleName, List<RuleLineContentInfo> lhs, List<RuleLineContentInfo> rhs) {
+ RuleDRLContentInfo contentInfo = new RuleDRLContentInfo(offset, content, type, ruleName, lhs, rhs);
+ for (RuleLineContentInfo ruleLine : contentInfo.getLHSRuleLines())
+ ruleLine.setRule(contentInfo);
+ for (RuleLineContentInfo ruleLine : contentInfo.getRHSRuleLines())
+ ruleLine.setRule(contentInfo);
+ this.contents.put(offset, contentInfo);
+ }
+
+ public RuleBasicContentInfo getContentAt(int offset) {
+ if (contents.containsKey(offset))
+ return contents.get(offset);
+ int previousKey = 0;
+ for (Integer key : contents.keySet()) {
+ if (key > offset) {
+ RuleBasicContentInfo info = contents.get(previousKey);
+ if ((previousKey + info.getContentLength()) >= offset) {
+ if (info.getType().equals(DRLContentTypeEnum.RULE))
+ return searchInsideTheRule(offset, (RuleDRLContentInfo) info);
+ return info;
+ }
+ return null;
+ }
+ previousKey = key;
+ }
+ RuleBasicContentInfo info = contents.get(previousKey);
+ if (info.getType().equals(DRLContentTypeEnum.RULE))
+ return searchInsideTheRule(offset, (RuleDRLContentInfo) info);
+ return (info.getContentLength() + previousKey > offset)?info:null;
+ }
+
+ private RuleBasicContentInfo searchInsideTheRule(int offset, RuleDRLContentInfo info) {
+ // search if inside the rulename
+ if (offset <= info.getRuleNameLength() + info.getOffset())
+ return null;
+ // search in LHS
+ for(RuleLineContentInfo ruleLine : info.getLHSRuleLines()) {
+ if (offset <= ruleLine.getOffset() + ruleLine.getContentLength())
+ return ruleLine;
+ }
+ // search in RHS
+ for(RuleLineContentInfo ruleLine : info.getRHSRuleLines()) {
+ if (offset <= ruleLine.getOffset() + ruleLine.getContentLength())
+ return ruleLine;
+ }
+ return null;
+ }
+
+ public List<RuleBasicContentInfo> getImports() {
+ List<RuleBasicContentInfo> imports = new ArrayList<RuleBasicContentInfo>();
+ for (Integer key : contents.keySet()) {
+ RuleBasicContentInfo info = contents.get(key);
+ if (info.getType().equals(DRLContentTypeEnum.IMPORT))
+ imports.add(info);
+ }
+ return imports;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/DRLRuleRefactorInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleBasicContentInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleBasicContentInfo.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleBasicContentInfo.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.info.drl;
+
+public class RuleBasicContentInfo {
+
+ private Integer offset;
+ private String content;
+ private DRLContentTypeEnum type;
+
+ public RuleBasicContentInfo(Integer offset, String content, DRLContentTypeEnum type) {
+ this.offset = offset;
+ this.content = content;
+ this.type = type;
+ }
+ public Integer getOffset() {
+ return offset;
+ }
+ public String getContent() {
+ return content;
+ }
+ public int getContentLength() {
+ return content.length();
+ }
+ public DRLContentTypeEnum getType() {
+ return type;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleBasicContentInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleDRLContentInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleDRLContentInfo.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleDRLContentInfo.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,69 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.info.drl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RuleDRLContentInfo extends RuleBasicContentInfo {
+
+ private String ruleName;
+ private List<RuleLineContentInfo> lhs;
+ private List<RuleLineContentInfo> rhs;
+
+ public RuleDRLContentInfo(Integer offset, String content, DRLContentTypeEnum type, String ruleName, List<RuleLineContentInfo> lhs, List<RuleLineContentInfo> rhs) {
+ super(offset, content, type);
+ this.setRuleName(ruleName);
+ this.lhs = lhs;
+ this.rhs = rhs;
+ }
+
+ public void setRuleName(String ruleName) {
+ this.ruleName = ruleName;
+ }
+
+ public String getRuleName() {
+ return ruleName;
+ }
+
+ public Integer getRuleNameLength() {
+ return ruleName.length();
+ }
+
+ public void addLHSRuleLine(RuleLineContentInfo ruleLine) {
+ this.lhs.add(ruleLine);
+ }
+
+ public List<RuleLineContentInfo> getLHSRuleLines() {
+ return lhs;
+ }
+
+ public void addRHSRuleLine(RuleLineContentInfo ruleLine) {
+ this.rhs.add(ruleLine);
+ }
+
+ public List<RuleLineContentInfo> getRHSRuleLines() {
+ return rhs;
+ }
+
+ public List<RuleLineContentInfo> getAllLines() {
+ List<RuleLineContentInfo> all = new ArrayList<RuleLineContentInfo>(lhs);
+ all.addAll(rhs);
+ return all;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleDRLContentInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleLineContentInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleLineContentInfo.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleLineContentInfo.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.info.drl;
+
+public class RuleLineContentInfo extends RuleBasicContentInfo {
+
+ private RuleDRLContentInfo rule;
+
+ public RuleLineContentInfo(Integer offset, String content, DRLContentTypeEnum type) {
+ super(offset, content, type);
+ }
+
+ public void setRule(RuleDRLContentInfo rule) {
+ this.rule = rule;
+ }
+
+ public RuleDRLContentInfo getRule() {
+ return rule;
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/drl/RuleLineContentInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/dsl/DSLRuleRefactorInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/dsl/DSLRuleRefactorInfo.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/dsl/DSLRuleRefactorInfo.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.info.dsl;
+
+import java.util.List;
+
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+
+public class DSLRuleRefactorInfo implements RuleRefactorInfo {
+
+ private List<String> when;
+ private List<String> then;
+
+ public List<String> getWhen() {
+ return when;
+ }
+ public void setWhen(List<String> when) {
+ this.when = when;
+ }
+ public List<String> getThen() {
+ return then;
+ }
+ public void setThen(List<String> then) {
+ this.then = then;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/info/dsl/DSLRuleRefactorInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/AssistantOption.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/AssistantOption.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/AssistantOption.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,67 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.option;
+
+public abstract class AssistantOption {
+
+ public static enum ACTION {RENAME, REPLACE};
+
+ protected String display;
+ protected String content;
+ protected Integer length;
+ protected Integer offset;
+ protected Integer position;
+ protected ACTION type;
+
+ public String getDisplay() {
+ return display;
+ }
+ public void setDisplay(String display) {
+ this.display = display;
+ }
+ public String getContent() {
+ return content;
+ }
+ public void setContent(String content) {
+ this.content = content;
+ }
+ public Integer getLength() {
+ return length;
+ }
+ public void setLength(Integer length) {
+ this.length = length;
+ }
+ public Integer getOffset() {
+ return offset;
+ }
+ public void setOffset(Integer offset) {
+ this.offset = offset;
+ }
+ public void setPosition(Integer position) {
+ this.position = position;
+ }
+ public Integer getPosition() {
+ return position;
+ }
+ public void setType(ACTION type) {
+ this.type = type;
+ }
+ public ACTION getType() {
+ return type;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/AssistantOption.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/RenameAssistantOption.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/RenameAssistantOption.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/RenameAssistantOption.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,39 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.option;
+
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+
+public class RenameAssistantOption extends AssistantOption {
+
+ private RuleBasicContentInfo contentInfo;
+
+ public RenameAssistantOption(String display, String content, RuleBasicContentInfo contentInfo, Integer position) {
+ this.display = display;
+ this.content = content;
+ this.contentInfo = contentInfo;
+ this.offset = position;
+ // FIXME: weird assignation
+ this.position = position;
+ this.type = ACTION.RENAME;
+ }
+
+ public RuleBasicContentInfo getContentInfo() {
+ return contentInfo;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/RenameAssistantOption.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/ReplaceAssistantOption.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/ReplaceAssistantOption.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/ReplaceAssistantOption.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.option;
+
+public class ReplaceAssistantOption extends AssistantOption {
+
+ public ReplaceAssistantOption(String display, String content, Integer offset, Integer length, Integer position) {
+ this.display = display;
+ this.content = content;
+ this.offset = offset;
+ this.length = length;
+ this.position = position;
+ this.type = ACTION.REPLACE;
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/option/ReplaceAssistantOption.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleAssistantProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleAssistantProcessor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleAssistantProcessor.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,27 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.processor;
+
+import java.util.List;
+
+import org.drools.ide.common.assistant.option.AssistantOption;
+
+public abstract class AbstractRuleAssistantProcessor {
+
+ public abstract List<AssistantOption> getRuleAssistant(String text, Integer offset);
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleAssistantProcessor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleRefactorProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleRefactorProcessor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleRefactorProcessor.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.processor;
+
+import org.drools.ide.common.assistant.engine.AbstractParserEngine;
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+import org.drools.ide.common.assistant.refactor.AbstractRuleRefactor;
+
+public abstract class AbstractRuleRefactorProcessor extends AbstractRuleAssistantProcessor {
+
+ protected AbstractRuleRefactor ruleRefactorEngine;
+ protected AbstractParserEngine ruleParserEngine;
+
+ protected abstract RuleRefactorInfo generateRuleRefactorInfo(String text);
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/AbstractRuleRefactorProcessor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DRLRefactorProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DRLRefactorProcessor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DRLRefactorProcessor.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.processor;
+
+import java.util.List;
+
+import org.drools.ide.common.assistant.engine.DRLParserEngine;
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+import org.drools.ide.common.assistant.option.AssistantOption;
+import org.drools.ide.common.assistant.option.RenameAssistantOption;
+import org.drools.ide.common.assistant.refactor.DRLRuleRefactor;
+import org.drools.ide.common.assistant.refactor.drl.VariableRename;
+
+public class DRLRefactorProcessor extends AbstractRuleRefactorProcessor {
+
+ private static DRLRefactorProcessor instance;
+
+ @Override
+ public List<AssistantOption> getRuleAssistant(String text, Integer offset) {
+ RuleRefactorInfo ruleRefactorInfo = generateRuleRefactorInfo(text);
+ ruleRefactorEngine = new DRLRuleRefactor(ruleRefactorInfo);
+ return ruleRefactorEngine.execute(offset);
+ }
+
+ @Override
+ protected RuleRefactorInfo generateRuleRefactorInfo(String text) {
+ ruleParserEngine = new DRLParserEngine(text);
+ RuleRefactorInfo info = ruleParserEngine.parse();
+ return info;
+ }
+
+ public AssistantOption executeVariableRename(RenameAssistantOption assistantOption, String newVariableName) {
+ return VariableRename.execute(assistantOption, newVariableName);
+ }
+
+
+ public static DRLRefactorProcessor getInstance() {
+ if (instance==null)
+ instance = new DRLRefactorProcessor();
+ return instance;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DRLRefactorProcessor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DSLRefactorProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DSLRefactorProcessor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DSLRefactorProcessor.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.processor;
+
+import java.util.List;
+
+import org.drools.ide.common.assistant.engine.DSLParserEngine;
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+import org.drools.ide.common.assistant.option.AssistantOption;
+import org.drools.ide.common.assistant.refactor.DSLRuleRefactor;
+
+public class DSLRefactorProcessor extends AbstractRuleRefactorProcessor {
+
+ @Override
+ public List<AssistantOption> getRuleAssistant(String text, Integer offset) {
+ RuleRefactorInfo ruleRefactorInfo = this.generateRuleRefactorInfo(text);
+ ruleRefactorEngine = new DSLRuleRefactor(ruleRefactorInfo);
+ return ruleRefactorEngine.execute(offset);
+ }
+
+ @Override
+ protected RuleRefactorInfo generateRuleRefactorInfo(String text) {
+ ruleParserEngine = new DSLParserEngine(text);
+ return ruleParserEngine.parse();
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/processor/DSLRefactorProcessor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/AbstractRuleRefactor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/AbstractRuleRefactor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/AbstractRuleRefactor.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,40 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.refactor;
+
+import java.util.List;
+
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+import org.drools.ide.common.assistant.option.AssistantOption;
+
+public abstract class AbstractRuleRefactor {
+
+ protected RuleRefactorInfo ruleRefactorInfo;
+ protected List<AssistantOption> options;
+ protected AssistantOption option;
+ protected int offset;
+
+ public abstract List<AssistantOption> execute(int offset);
+
+ protected abstract AssistantOption bindVariable(RuleBasicContentInfo contentInfo);
+
+ protected abstract AssistantOption fixImports(RuleBasicContentInfo contentInfo);
+
+ protected abstract AssistantOption renameVariable(RuleBasicContentInfo contentInfo);
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/AbstractRuleRefactor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DRLRuleRefactor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DRLRuleRefactor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DRLRuleRefactor.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,89 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.refactor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+import org.drools.ide.common.assistant.info.drl.DRLContentTypeEnum;
+import org.drools.ide.common.assistant.info.drl.DRLRuleRefactorInfo;
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+import org.drools.ide.common.assistant.option.AssistantOption;
+import org.drools.ide.common.assistant.option.RenameAssistantOption;
+import org.drools.ide.common.assistant.option.ReplaceAssistantOption;
+import org.drools.ide.common.assistant.refactor.drl.FixImport;
+import org.drools.ide.common.assistant.refactor.drl.VariableBinding;
+import org.drools.ide.common.assistant.refactor.drl.VariableRename;
+
+public class DRLRuleRefactor extends AbstractRuleRefactor {
+
+ public DRLRuleRefactor(RuleRefactorInfo refactorInfo) {
+ this.ruleRefactorInfo = refactorInfo;
+ this.options = new ArrayList<AssistantOption>();
+ }
+
+ @Override
+ public List<AssistantOption> execute(int offset) {
+ this.offset = offset;
+ RuleBasicContentInfo contentInfo = ((DRLRuleRefactorInfo)ruleRefactorInfo).getContentAt(offset);
+ if (contentInfo==null)
+ return this.options;
+ if ((option = this.bindVariable(contentInfo))!=null)
+ this.options.add(option);
+ if ((option = this.fixImports(contentInfo))!=null)
+ this.options.add(option);
+ if ((option = this.renameVariable(contentInfo))!=null)
+ this.options.add(option);
+ return this.options;
+ }
+
+ @Override
+ protected AssistantOption bindVariable(RuleBasicContentInfo contentInfo) {
+ if (contentInfo==null) return null;
+ if (!contentInfo.getType().equals(DRLContentTypeEnum.RULE_LHS_LINE))
+ return null;
+ String response = VariableBinding.execute(contentInfo, offset-contentInfo.getOffset());
+ if (response.equals(contentInfo.getContent()))
+ return null;
+ return new ReplaceAssistantOption("assign to variable", response, contentInfo.getOffset(), contentInfo.getContentLength(), offset);
+ }
+
+ @Override
+ protected AssistantOption fixImports(RuleBasicContentInfo contentInfo) {
+ if (contentInfo==null) return null;
+ if (!contentInfo.getType().equals(DRLContentTypeEnum.RULE_LHS_LINE) &&
+ !contentInfo.getType().equals(DRLContentTypeEnum.RULE_RHS_LINE))
+ return null;
+ List<RuleBasicContentInfo> imports = ((DRLRuleRefactorInfo)ruleRefactorInfo).getImports();
+ FixImport.execute(contentInfo, imports);
+ return null;
+ }
+
+ @Override
+ protected AssistantOption renameVariable(RuleBasicContentInfo contentInfo) {
+ if (contentInfo==null) return null;
+ if (!contentInfo.getType().equals(DRLContentTypeEnum.RULE_LHS_LINE) &&
+ !contentInfo.getType().equals(DRLContentTypeEnum.RULE_RHS_LINE))
+ return null;
+ String variable;
+ if ((variable = VariableRename.isPossible(contentInfo, offset-contentInfo.getOffset()))!=null)
+ return new RenameAssistantOption("rename variable", variable, contentInfo, contentInfo.getOffset());
+ return null;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DRLRuleRefactor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DSLRuleRefactor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DSLRuleRefactor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DSLRuleRefactor.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.refactor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.ide.common.assistant.info.RuleRefactorInfo;
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+import org.drools.ide.common.assistant.option.AssistantOption;
+import org.drools.ide.common.assistant.option.ReplaceAssistantOption;
+
+public class DSLRuleRefactor extends AbstractRuleRefactor {
+
+ private List<AssistantOption> options;
+
+ public DSLRuleRefactor(RuleRefactorInfo ruleRefactorInfo) {
+ this.ruleRefactorInfo = ruleRefactorInfo;
+ this.options = new ArrayList<AssistantOption>();
+ }
+
+ @Override
+ public List<AssistantOption> execute(int offset) {
+ if ((option = this.bindVariable(null))!=null)
+ this.options.add(option);
+ if ((option = this.fixImports(null))!=null)
+ this.options.add(option);
+ return this.options;
+ }
+
+ @Override
+ protected ReplaceAssistantOption bindVariable(RuleBasicContentInfo contentInfo) {
+ return null;
+ }
+
+ @Override
+ protected ReplaceAssistantOption fixImports(RuleBasicContentInfo contentInfo) {
+ return null;
+ }
+
+ @Override
+ protected ReplaceAssistantOption renameVariable(RuleBasicContentInfo contentInfo) {
+ return null;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/DSLRuleRefactor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/FixImport.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/FixImport.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/FixImport.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.refactor.drl;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+import org.drools.ide.common.assistant.info.drl.RuleDRLContentInfo;
+import org.drools.ide.common.assistant.info.drl.RuleLineContentInfo;
+
+public class FixImport {
+
+ private static final String CLASS_PATTERN = "[\\s\\t:,]+[a-zA-Z]*\\(";
+
+ private static final String[] KEYWORDS = {"new", "update", "insert"};
+
+ private static final Pattern pattern = Pattern.compile(CLASS_PATTERN);
+ private static Matcher matcher;
+
+ private static List<String> classes = new ArrayList<String>();
+ private static List<String> classloaderClasses = new ArrayList<String>();
+
+ // detect all the Class Name and compare with the current imports
+ // how detect the Classes loaded into the ClassLoader?
+ public static void execute(RuleBasicContentInfo contentInfo, List<RuleBasicContentInfo> imports) {
+ classloaderClasses.clear();
+ classes.clear();
+ RuleDRLContentInfo ruleInfo = ((RuleLineContentInfo)contentInfo).getRule();
+ String rule = "";
+ for (RuleLineContentInfo ruleLineContentInfo : ruleInfo.getLHSRuleLines())
+ rule = rule.concat(ruleLineContentInfo.getContent() + "\n");
+ for (RuleLineContentInfo ruleLineContentInfo : ruleInfo.getRHSRuleLines())
+ rule = rule.concat(ruleLineContentInfo.getContent() + "\n");
+ matcher = pattern.matcher(rule);
+ String className;
+ while (matcher.find()) {
+ className = matcher.group().replaceAll(":", "").replaceAll("\\(", "").replaceAll("\\t", "").replaceAll("\\n", "").trim();
+ addClass(className);
+ }
+ hookClassLoader(ClassLoader.getSystemClassLoader());
+ }
+
+ private static void addClass(String className) {
+ for (int i = 0; i < KEYWORDS.length; i++)
+ if (KEYWORDS[i].equals(className))
+ return;
+ if (!classes.contains(className))
+ classes.add(className);
+ }
+
+ private static void hookClassLoader(ClassLoader currLoader) {
+ try {
+ Field field = ClassLoader.class.getDeclaredField ("classes");
+ field.setAccessible(true);
+ Vector<?> currClasses = (Vector<?>)field.get( currLoader );
+ for (int position = 0; position < currClasses.size(); position++) {
+ Class<?> object = (Class<?>) currClasses.get(position);
+ if (!classloaderClasses.contains(object.getCanonicalName()))
+ classloaderClasses.add(object.getCanonicalName());
+ }
+ }
+ catch ( java.lang.Exception ex ) {
+ System.out.println( "Can't hook " + currLoader + ": " + ex );
+ }
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/FixImport.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableBinding.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableBinding.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableBinding.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,115 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.refactor.drl;
+
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+
+
+public class VariableBinding extends VariableOption {
+
+ private static final String DEFAULT_VARIABLE_NAME = "$default";
+
+ public static String execute(RuleBasicContentInfo contentInfo, int offset) {
+ detectCurrentVariables(contentInfo);
+ return execute(contentInfo.getContent(), offset);
+ }
+
+ public static String execute(String line, int offset) {
+ if (offset > line.length())
+ return line;
+ int position;
+ for (position = offset-1; position >= 0; position--) {
+ if (line.charAt(position)==' ' || line.charAt(position)=='(' || line.charAt(position)=='\t' || line.charAt(position)==',') {
+ String left = line.substring(0, position+1);
+ String right = line.substring(position+1, line.length());
+ if (!VariableBinding.isVariableOrParameter(right, left) && !VariableBinding.hasVariableAssigned(left)) {
+ return left + getVariableName(right) + right;
+ }
+ return line;
+ }
+ }
+ // search to the right the first : before ( and ,
+ for (position = 0; position < line.length(); position++) {
+ if (line.charAt(position)==':') {
+ return line;
+ }
+ if (line.charAt(position)=='(' || line.charAt(position)==',') {
+ return getVariableName(line) + line;
+ }
+ }
+ return line;
+ }
+
+ // detect if already has an assigned variable or is the right side of the comparator parameter
+ private static boolean isVariableOrParameter(String right, String left) {
+ int position;
+ for (position = 0; position <= right.length()-1; position++) {
+ if (right.charAt(position)==',' || right.charAt(position)=='(') {
+ break;
+ }
+ if (right.charAt(position)==':') {
+ return true;
+ }
+ }
+ for (position = left.length()-1; position >=0; position--) {
+ if (left.charAt(position)=='>' || left.charAt(position)=='<' || left.charAt(position)=='=') {
+ return true;
+ }
+ if (left.charAt(position)==',') {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ private static String getVariableName(String right) {
+ for (int position = 0; position < right.length(); position++) {
+ if (right.charAt(position)=='(' || right.charAt(position)==')' || right.charAt(position)==',' ||
+ right.charAt(position)=='<' || right.charAt(position)=='>' || right.charAt(position)=='=') {
+ String varname = "$" + right.substring(0, position).toLowerCase().trim();
+ return generateVariableName(varname);
+ }
+ }
+ return DEFAULT_VARIABLE_NAME;
+ }
+
+ private static boolean hasVariableAssigned(String line) {
+ for (int position = line.length()-1; position >=0; position--) {
+ if (line.charAt(position)==':') {
+ return true;
+ }
+ if (line.charAt(position)==',' || line.charAt(position)=='(') {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ private static String generateVariableName(String varname) {
+ if (!existsVariableWithSameName(varname)) {
+ return varname + " : ";
+ }
+ // generate a pseudo-random variable name
+ for (int count=1; count <= 100; count++) {
+ if (!existsVariableWithSameName(varname+count)) {
+ return varname+count + " : ";
+ }
+ }
+ return varname;
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableBinding.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableOption.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableOption.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableOption.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.refactor.drl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+import org.drools.ide.common.assistant.info.drl.RuleLineContentInfo;
+
+public abstract class VariableOption {
+
+ private static final String VARIABLE_PATTERN = "[\\$\\d\\w]*\\s*:";
+ private static final Pattern pattern = Pattern.compile(VARIABLE_PATTERN);
+ private static List<String> variables = new ArrayList<String>();
+ private static Matcher matcher;
+
+ protected static void detectCurrentVariables(RuleBasicContentInfo contentInfo) {
+ variables.clear();
+ String lhs = "";
+ List<RuleLineContentInfo> ruleLines = ((RuleLineContentInfo)contentInfo).getRule().getLHSRuleLines();
+ for (RuleLineContentInfo ruleLineContentInfo : ruleLines)
+ lhs = lhs.concat(ruleLineContentInfo.getContent());
+ matcher = pattern.matcher(lhs);
+ String varname;
+ while (matcher.find()) {
+ varname = matcher.group().replace(":", "").trim();
+ addVariableName(varname);
+ }
+ }
+
+ protected static boolean existsVariableWithSameName(String varname) {
+ return variables.contains(varname);
+ }
+
+ private static void addVariableName(String variableName) {
+ if (!variables.contains(variableName))
+ variables.add(variableName);
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableOption.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableRename.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableRename.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableRename.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,130 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant.refactor.drl;
+
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+import org.drools.ide.common.assistant.info.drl.RuleDRLContentInfo;
+import org.drools.ide.common.assistant.info.drl.RuleLineContentInfo;
+import org.drools.ide.common.assistant.option.AssistantOption;
+import org.drools.ide.common.assistant.option.RenameAssistantOption;
+
+public class VariableRename extends VariableOption {
+
+ public static AssistantOption execute(RenameAssistantOption assistantOption, String newVariableName) {
+ detectCurrentVariables(assistantOption.getContentInfo());
+ if (existsVariableWithSameName(newVariableName))
+ return null;
+ RuleDRLContentInfo ruleDRLContentInfo = ((RuleLineContentInfo)assistantOption.getContentInfo()).getRule();
+ String rule = getAllRuleLines(ruleDRLContentInfo);
+ Integer offset = getOffsetFirstLine(ruleDRLContentInfo);
+ String content = replaceAllVariables(rule, assistantOption.getContent(), newVariableName);
+ assistantOption.setContent(content);
+ assistantOption.setOffset(offset);
+ assistantOption.setLength(rule.length());
+ return assistantOption;
+ }
+
+ public static String isPossible(RuleBasicContentInfo contentInfo, int offset) {
+ String line = contentInfo.getContent();
+ int offsetStart = detectVariableOffsetStart(line, offset);
+ if (offsetStart==-1)
+ return null;
+ String right = line.substring(offsetStart);
+ String variableName = detectVariableToReplace(right);
+ if (variableName==null)
+ return null;
+ RuleDRLContentInfo ruleContentInfo = ((RuleLineContentInfo)contentInfo).getRule();
+ String allRule = getAllRuleLines(ruleContentInfo);
+ return hasMoreVariableToReplace(allRule, variableName)?variableName:null;
+ }
+
+ private static Integer getOffsetFirstLine(RuleDRLContentInfo ruleContentInfo) {
+ List<RuleLineContentInfo> lhsLines = ruleContentInfo.getLHSRuleLines();
+ return lhsLines.get(0).getOffset();
+ }
+
+ private static String getAllRuleLines(RuleDRLContentInfo ruleContentInfo) {
+ String rule = "";
+ for (RuleLineContentInfo ruleLine : ruleContentInfo.getAllLines()) {
+ rule = rule.concat(ruleLine.getContent())+"\n";
+ }
+ return rule.substring(0, rule.length()-1);
+ }
+
+ private static boolean hasMoreVariableToReplace(String line, String variableName) {
+ variableName = createPatternToFoundAndReplace(variableName);
+ Pattern pattern = Pattern.compile(variableName+"\\b");
+ Matcher matcher = pattern.matcher(line);
+ int variableCount = 0;
+ while (matcher.find()) {
+ variableCount++;
+ }
+ return variableCount > 1;
+ }
+
+ private static String detectVariableToReplace(String right) {
+ for (int position = 0; position < right.length(); position++) {
+ if (right.charAt(position)==':' || right.charAt(position)=='.' || right.charAt(position)==')') {
+ return right.substring(0, position).trim();
+ }
+ if (right.charAt(position)==',' || right.charAt(position)=='(') {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ private static String createPatternToFoundAndReplace(String varname) {
+ for (int position = 0; position < varname.length(); position++) {
+ if (varname.charAt(position)=='$') {
+ return varname.substring(0, position) + "\\$" + varname.substring(position+1, varname.length());
+ }
+ }
+ return varname;
+ }
+
+ private static String replaceAllVariables(String rule, String variableName, String newVariableName) {
+ newVariableName = createPatternToFoundAndReplace(newVariableName);
+ variableName = createPatternToFoundAndReplace(variableName);
+ if(variableName.charAt(0)=='$' || variableName.charAt(0)=='\\') {
+ return rule.replaceAll("\\B("+variableName+")\\b", newVariableName);
+ }
+ rule = rule.replaceAll("\\b"+variableName+"\\s*\\:\\s*", newVariableName + " :");
+ rule = rule.replaceAll("\\b"+variableName+"\\.", newVariableName + ".");
+ rule = rule.replaceAll("\\b"+variableName+"\\s*\\,\\s*", newVariableName + " , ");
+ rule = rule.replaceAll("([^:\\s]\\s*)"+variableName+"(\\s*)(?=\\))", "$1" + newVariableName + "$2");
+ rule = rule.replaceAll("\\b"+variableName+"\\s*\\+\\s*", newVariableName + " + ");
+ return rule;
+ }
+
+ private static int detectVariableOffsetStart(String line, int offset) {
+ for (int position = offset; position > 0; position--) {
+ if (line.charAt(position)==',' || line.charAt(position)=='(') {
+ return position+1;
+ }
+ if (line.charAt(position)==':' || line.charAt(position)=='.') {
+ return -1;
+ }
+ }
+ return 0;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/assistant/refactor/drl/VariableRename.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLAssistantTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLAssistantTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLAssistantTest.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,92 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant;
+
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.drools.ide.common.assistant.option.AssistantOption;
+import org.drools.ide.common.assistant.option.ReplaceAssistantOption;
+import org.drools.ide.common.assistant.processor.AbstractRuleAssistantProcessor;
+import org.drools.ide.common.assistant.processor.DRLRefactorProcessor;
+
+public class DRLAssistantTest extends TestCase {
+
+ private AbstractRuleAssistantProcessor ruleAssistant;
+ private String rule;
+
+ @Override
+ protected void setUp() throws Exception {
+ ruleAssistant = new DRLRefactorProcessor();
+ rule = "package org.drools.assistant.test;\n\n";
+ rule += "import org.drools.assistant.test.model.Company;\n";
+ rule += "IMPORT org.drools.assistant.test.model.Employee;\n\n";
+ rule += "import function org.drools.assistant.model.Class1.anotherFunction \n";
+ rule += "import function org.drools.assistant.model.Class1.mathFunction \n";
+ rule += "global org.drools.assistant.test.model.Class2 results \n";
+ rule += "GLOBAL org.drools.assistant.test.model.Class3 current\n";
+ rule += "expander help-expander.dsl\n";
+ rule += "query \"all clients\"\n";
+ rule += " result : Clients()\n";
+ rule += "end\n";
+ rule += "query \"new query\"\n";
+ rule += " objects : Clients()\n";
+ rule += "end\n";
+ rule += "function String hello(String name) {\n";
+ rule += " return \"Hello \"+name+\"!\";\n";
+ rule += "}\n";
+ rule += "function String helloWithAge(String name, Integer age) {\n";
+ rule += " return \"Hello2 \"+name+\"! \" + age;\n";
+ rule += "}\n";
+ rule += "rule \"My Test Rule\"\n";
+ rule += "when\n";
+ rule += " $employee : Employee($company : company, $company1 : oldcompany, $age : age > 80, salary > 400)\n";
+ rule += " $result : Company(company==$company, retireAge <= $age)\n";
+ rule += "then\n";
+ rule += " System.out.println(\"can retire\")\n";
+ rule += "end\n";
+ rule += "rule \"My Second Rule\"\n";
+ rule += "when\n";
+ rule += " Driver(licence = 1234, $name : name)\n";
+ rule += " $car : Car(company : $company, ownerLicense == licence, year == 2009)\n";
+ rule += "then\n";
+ rule += " System.out.println(\"licence 1234 has a new car\")\n";
+ rule += "end\n";
+ }
+
+ public void testAssignSalaryFieldToVariable() throws Exception {
+ List<AssistantOption> options = ruleAssistant.getRuleAssistant(rule, 780);
+ assertEquals(options.size(), 1);
+ ReplaceAssistantOption assistantOption = (ReplaceAssistantOption) options.get(0);
+ Assert.assertEquals("\t$employee : Employee($company : company, $company1 : oldcompany, $age : age > 80, salary $ : > 400)", assistantOption.getContent());
+ }
+
+ public void testDontAssignFieldInsideRHS() throws Exception {
+ List<AssistantOption> options = ruleAssistant.getRuleAssistant(rule, 840);
+ assertEquals(options.size(), 0);
+ }
+
+ public void testAssignLicenseFromSecondRule() throws Exception {
+ List<AssistantOption> options = ruleAssistant.getRuleAssistant(rule, 930);
+ assertEquals(options.size(), 1);
+ ReplaceAssistantOption assistantOption = (ReplaceAssistantOption) options.get(0);
+ Assert.assertEquals("\tDriver($licence : licence = 1234, $name : name)", assistantOption.getContent());
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLAssistantTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLParserEngineTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLParserEngineTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLParserEngineTest.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,143 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.drools.ide.common.assistant.engine.DRLParserEngine;
+import org.drools.ide.common.assistant.info.drl.DRLContentTypeEnum;
+import org.drools.ide.common.assistant.info.drl.DRLRuleRefactorInfo;
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+import org.drools.ide.common.assistant.info.drl.RuleLineContentInfo;
+
+public class DRLParserEngineTest extends TestCase {
+
+ private String rule;
+ private DRLParserEngine engine;
+ private DRLRuleRefactorInfo info;
+
+ @Override
+ protected void setUp() throws Exception {
+ rule = "package org.drools.assistant.test;\n\n";
+ rule += "import org.drools.assistant.test.model.Company;\n";
+ rule += "import org.drools.assistant.test.model.Employee;\n\n";
+ rule += "import function org.drools.assistant.model.Class1.anotherFunction \n";
+ rule += "import function org.drools.assistant.model.Class1.mathFunction \n";
+ rule += "global org.drools.assistant.test.model.Class2 results \n";
+ rule += "global org.drools.assistant.test.model.Class3 current\n";
+ rule += "expander help-expander.dsl\n";
+ rule += "query \"all clients\"\n";
+ rule += " result : Clients()\n";
+ rule += "end\n";
+ rule += "query \"new query\"\n";
+ rule += " objects : Clients()\n";
+ rule += "end\n";
+ rule += "function String hello(String name) {\n";
+ rule += " return \"Hello \"+name+\"!\";\n";
+ rule += "}\n";
+ rule += "function String helloWithAge(String name, Integer age) {\n";
+ rule += " return \"Hello2 \"+name+\"! \" + age;\n";
+ rule += "}\n";
+ rule += "rule \"My Test Rule\"\n";
+ rule += "when\n";
+ rule += " $employee : Employee($company : company, $age : age > 80, salary > 400)\n";
+ rule += " $result : Company(company == $company, retireAge <= $age)\n";
+ rule += "then\n";
+ rule += " System.out.println(\"can retire\")\n";
+ rule += "end\n";
+
+ engine = new DRLParserEngine(rule);
+
+ }
+
+ public void testExecuteEngine() {
+ info = (DRLRuleRefactorInfo) engine.parse();
+ RuleBasicContentInfo content = info.getContentAt(123);
+ Assert.assertEquals(true, content!=null);
+ }
+
+ public void testImport() {
+ info = (DRLRuleRefactorInfo) engine.parse();
+ RuleBasicContentInfo content = info.getContentAt(9);
+ Assert.assertEquals(true, content!=null);
+ }
+
+ public void testNothingInteresting() {
+ info = (DRLRuleRefactorInfo) engine.parse();
+ RuleBasicContentInfo content = info.getContentAt(199);
+ Assert.assertEquals(true, content==null);
+ }
+
+ public void testInsideTheRuleName() {
+ info = (DRLRuleRefactorInfo) engine.parse();
+ RuleBasicContentInfo content = info.getContentAt(670);
+ Assert.assertEquals(true, content==null);
+ }
+
+ public void testInsideLHSRule() {
+ info = (DRLRuleRefactorInfo) engine.parse();
+ RuleBasicContentInfo content = info.getContentAt(790);
+ Assert.assertEquals(true, content!=null);
+ }
+
+ public void testInsideRHSRule() {
+ info = (DRLRuleRefactorInfo) engine.parse();
+ RuleBasicContentInfo content = info.getContentAt(830);
+ Assert.assertEquals(true, content!=null);
+ }
+
+ public void testSampleDRL() {
+ rule = "package com.sample\n\n";
+ rule += "import com.sample.DroolsTest.Message;\n";
+ rule += "import com.sample.Prueba;\n\n";
+ rule += "\trule \"Hello World\"\n";
+ rule += "\twhen\n";
+ rule += "\t\tm : Message( status == Message.HELLO, myMessage : message )\n";
+ rule += "\t\tPrueba()\n";
+ rule += "\tthen\n";
+ rule += "\t\tSystem.out.println( myMessage );\n";
+ rule += "\t\tm.setMessage( \"Goodbye cruel world\" );\n";
+ rule += "\t\tm.setStatus( Message.GOODBYE );\n";
+ rule += "\t\tupdate( m );\n";
+ rule += "end\n";
+ rule += "rule \"GoodBye World\"\n";
+ rule += "\twhen\n";
+ rule += "\t\tm : Message( status == Message.GOODBYE, myMessage : message )\n";
+ rule += "\t\tPrueba()\n";
+ rule += "\tthen\n";
+ rule += "\t\tSystem.out.println( myMessage );\n";
+ rule += "\t\tm.setMessage( \"Bon Giorno\" );\n";
+ rule += "end";
+
+ engine = new DRLParserEngine(rule);
+ info = (DRLRuleRefactorInfo) engine.parse();
+ RuleBasicContentInfo content = info.getContentAt(173);
+
+ Assert.assertEquals(true, content!=null);
+ Assert.assertEquals(DRLContentTypeEnum.RULE_LHS_LINE, content.getType());
+ Assert.assertEquals("rule \"Hello World\"", ((RuleLineContentInfo)content).getRule().getRuleName());
+ Assert.assertEquals("\t\tPrueba()", content.getContent());
+
+ content = info.getContentAt(343);
+ Assert.assertEquals(true, content!=null);
+ Assert.assertEquals(DRLContentTypeEnum.RULE_LHS_LINE, content.getType());
+ Assert.assertEquals("rule \"GoodBye World\"", ((RuleLineContentInfo)content).getRule().getRuleName());
+ Assert.assertEquals("\twhen", content.getContent());
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DRLParserEngineTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DSLParserEngineTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DSLParserEngineTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DSLParserEngineTest.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,46 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant;
+
+import junit.framework.TestCase;
+
+import org.drools.ide.common.assistant.engine.DSLParserEngine;
+
+public class DSLParserEngineTest extends TestCase {
+
+ DSLParserEngine dslParserEngine;
+ private String rule;
+
+ @Override
+ protected void setUp() throws Exception {
+ rule = "#This is a starter DSL to show off some of the features. Make sure you change it to be what you need !.\n" +
+ "[when]There is an Instance with field of \"{value}\"=i: Instance(field==\"{value}\")\n" +
+ "[when]Instance is at least {number} and field is \"{value}\"=i: Instance(number > {number}, location==\"{value}\")\n" +
+ "[then]Log : \"{message}\"=System.out.println(\"{message}\");\n" +
+ "[then]Set field of instance to \"{value}\"=i.setField(\"{value}\");\n" +
+ "[then]Create instance : \"{value}\"=insert(new Instance(\"{value}\"));\n" +
+ "[when]There is no current Instance with field : \"{value}\"=not Instance(field == \"{value}\")\n" +
+ "[then]Report error : \"{error}\"=System.err.println(\"{error}\");\n" +
+ "[then]Retract the fact : '{variable}'=retract({variable}); //this would retract bound variable {variable}\n";
+
+ dslParserEngine = new DSLParserEngine(rule);
+ }
+
+ public void testExecute() {
+// dslParserEngine.parse();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/DSLParserEngineTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/FixImportTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/FixImportTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/FixImportTest.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant;
+
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.drools.ide.common.assistant.option.AssistantOption;
+import org.drools.ide.common.assistant.option.ReplaceAssistantOption;
+import org.drools.ide.common.assistant.processor.AbstractRuleAssistantProcessor;
+import org.drools.ide.common.assistant.processor.DRLRefactorProcessor;
+
+public class FixImportTest extends TestCase {
+
+ private AbstractRuleAssistantProcessor ruleAssistant;
+ private String rule;
+
+ protected void setUp() throws Exception {
+ ruleAssistant = new DRLRefactorProcessor();
+ rule = "package com.sample\n\n" +
+ "import com.sample.DroolsTest.Message;\n" +
+ "rule \"Hello World\"\n" +
+ "\twhen\n" +
+ "\t\tm : Message( status == Message.HELLO, myMessage : message )\n" +
+ "\t\tPrueba()\n" +
+ "\tthen\n" +
+ "\t\tSystem.out.println( myMessage );\n" +
+ "\t\tm.setMessage( \"Goodbye cruel world\" );\n" +
+ "\t\tm.setStatus( Message.GOODBYE );\n" +
+ "\t\tupdate( m );\n" +
+ "end";
+ }
+
+ public void testFirstTest() {
+ List<AssistantOption> options = ruleAssistant.getRuleAssistant(rule, 150);
+ assertEquals(1, options.size());
+ ReplaceAssistantOption assistantOption = (ReplaceAssistantOption) options.get(0);
+ Assert.assertEquals("\t\t$prueba : Prueba()", assistantOption.getContent());
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/FixImportTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableBindingTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableBindingTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableBindingTest.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,114 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.ide.common.assistant;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.drools.ide.common.assistant.refactor.drl.VariableBinding;
+
+public class VariableBindingTest extends TestCase {
+
+ private String line;
+ private String response;
+
+ @Override
+ protected void setUp() throws Exception {
+ line = "\tEmployee($company : company, $age : age > 80, salary > 400)";
+ }
+
+ public void testFieldWithVariableAssignedTest1() {
+ response = VariableBinding.execute(line, 24);
+ Assert.assertEquals(true, response.equals(line));
+ }
+
+ public void testClassNameWithoutVariableAssigned() {
+ response = VariableBinding.execute(line, 4);
+ Assert.assertEquals(false, response.equals(line));
+ }
+
+ public void testFieldWithVariableAssignedTest2() {
+ response = VariableBinding.execute(line, 39);
+ Assert.assertEquals(true, response.equals(line));
+ }
+
+ public void testAssignVariableInsideTheComparator() {
+ response = VariableBinding.execute(line, 50);
+ Assert.assertEquals(false, response.equals(line));
+ }
+
+ public void testInsideFieldComparator() {
+ response = VariableBinding.execute(line, 58);
+ Assert.assertEquals(true, response.equals(line));
+ }
+
+ public void testComplexLineTestMustAssign() {
+ line = "$ma20 : Double() from accumulate( $r2:ClosePrice(close, this != $r1, this after [0ms,20ms] $r1) , average ( $value ))";
+ response = VariableBinding.execute(line, 53);
+ Assert.assertEquals(false, response.equals(line));
+ }
+
+ public void testComplexLineTestDontMustAssign() {
+ line = "$ma20 : Double() from accumulate( $r2:ClosePrice($close : close, this != $r1, this after [0ms,20ms] $r1) , average ( $value ))";
+ response = VariableBinding.execute(line, 61);
+ Assert.assertEquals(true, response.equals(line));
+ }
+
+ public void testComplexLineClosePriceMustAssign() {
+ line = "$ma20 : Double() from accumulate( ClosePrice($close : close, this != $r1, this after [0ms,20ms] $r1) , average ( $value ))";
+ response = VariableBinding.execute(line, 43);
+ Assert.assertEquals(false, response.equals(line));
+ }
+
+ public void testComplexLineClosePriceDontMustAssign() {
+ line = "$ma20 : Double() from accumulate( $cp : ClosePrice($close : close, this != $r1, this after [0ms,20ms] $r1) , average ( $value ))";
+ response = VariableBinding.execute(line, 36);
+ Assert.assertEquals(true, response.equals(line));
+ }
+
+// public void testThisDontWorks() {
+// line = "$ma20 : Double() from accumulate( $r2:ClosePrice($close : close, this != $r1, this after [0ms,20ms] $r1) , average ( $value ))";
+// response = VariableBinding.execute(line, 121);
+// System.out.println(response);
+// Assert.assertEquals(true, response.equals(line));
+// }
+
+ public void testSampleDRL() {
+ line = "\t\tMessage( status == Message.HELLO, myMessage : message )\n";
+ response = VariableBinding.execute(line, 3);
+ Assert.assertEquals(false, response.equals(line));
+ }
+
+ public void testWithoutSpacesOrTab() {
+ line = "Message( status == Message.HELLO, myMessage : message )\n";
+ response = VariableBinding.execute(line, 0);
+ Assert.assertEquals(false, response.equals(line));
+ }
+
+ public void testWithoutSpacesOrTabButWithVariableAssigned() {
+ line = "m : Message( status == Message.HELLO, myMessage : message )\n";
+ response = VariableBinding.execute(line, 1);
+ Assert.assertEquals(true, response.equals(line));
+ }
+
+ public void testWithoutSpaceOnLeftOfField() {
+ line = "m : Message( status == Message.HELLO,message )\n";
+ response = VariableBinding.execute(line, 37);
+ Assert.assertEquals(false, response.equals(line));
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableBindingTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableRenameTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableRenameTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableRenameTest.java 2010-11-01 04:27:36 UTC (rev 35810)
@@ -0,0 +1,52 @@
+package org.drools.ide.common.assistant;
+
+import junit.framework.TestCase;
+
+import org.drools.ide.common.assistant.engine.DRLParserEngine;
+import org.drools.ide.common.assistant.info.drl.DRLRuleRefactorInfo;
+import org.drools.ide.common.assistant.info.drl.RuleBasicContentInfo;
+import org.drools.ide.common.assistant.option.AssistantOption;
+import org.drools.ide.common.assistant.option.RenameAssistantOption;
+import org.drools.ide.common.assistant.refactor.drl.VariableRename;
+
+public class VariableRenameTest extends TestCase {
+
+ private DRLParserEngine engine;
+ private DRLRuleRefactorInfo info;
+
+ public void test() {
+ String rule = "package com.sample\n\n";
+ rule += "import com.sample.DroolsTest.Message;\n\n";
+ rule += "rule \"Hello World\"\n";
+ rule += " when\n";
+ rule += " m : Message( $status : status == Message.HELLO, message :message )\n";
+ rule += " $m2 : Message( message2 :message )";
+ rule += " then\n";
+ rule += " System.out.println( message ); \n";
+ rule += " System.out.println(message ); \n";
+ rule += " System.out.println( message); \n";
+ rule += " System.out.println(message); \n";
+ rule += " $m.setMessage( \"Goodbye cruel world\", message);\n";
+ rule += " $m.setMessage( \"Goodbye cruel world\" +message);\n";
+ rule += " $m.setMessage( \"Goodbye cruel world\" + message );\n";
+ rule += " $m.setStatus( Message.GOODBYE );\n";
+ rule += " update( $m ) ;\n";
+ rule += "end";
+
+ engine = new DRLParserEngine(rule);
+ info = (DRLRuleRefactorInfo) engine.parse();
+ RuleBasicContentInfo content = info.getContentAt(87);
+
+ RenameAssistantOption assistantOption = new RenameAssistantOption("rename variable", "message", content, 87);
+
+ AssistantOption result = VariableRename.execute(assistantOption, "msg");
+
+ assertTrue(result.getContent().contains("m : Message( $status : status == Message.HELLO, msg :message )"));
+ assertTrue(result.getContent().contains("System.out.println( msg );"));
+ assertTrue(result.getContent().contains("System.out.println(msg );"));
+ assertTrue(result.getContent().contains("System.out.println( msg);"));
+ assertTrue(result.getContent().contains("$m.setMessage( \"Goodbye cruel world\" + msg );"));
+
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/ide/common/assistant/VariableRenameTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list