[jboss-svn-commits] JBL Code SVN: r13689 - in labs/jbossrules/trunk: drools-compiler and 32 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 20 19:24:56 EDT 2007
Author: pombredanne
Date: 2007-07-20 19:24:55 -0400 (Fri, 20 Jul 2007)
New Revision: 13689
Added:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELRuleClassBuilder.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java
labs/jbossrules/trunk/m2_repo/org/mvel/mvel14/1.2pre5.4.r727/
labs/jbossrules/trunk/m2_repo/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar
Removed:
labs/jbossrules/trunk/drools-compiler/build.properties
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java
labs/jbossrules/trunk/m2_repo/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar
Modified:
labs/jbossrules/trunk/drools-compiler/.classpath
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/RuleDescr.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java
labs/jbossrules/trunk/drools-core/
labs/jbossrules/trunk/drools-core/.classpath
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELConsequence.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
labs/jbossrules/trunk/drools-decisiontables/.classpath
labs/jbossrules/trunk/drools-eclipse/
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-feature/feature.xml
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/META-INF/MANIFEST.MF
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/build.properties
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/help/
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/lib/
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DRLInfo.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/VariableWrapper.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugModelPresentation.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DroolsLineBreakpointAdapter.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/Keywords.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupDirector.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupParticipant.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/.classpath
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/IncompleteParsingTest.java
labs/jbossrules/trunk/drools-jbrms/.classpath
labs/jbossrules/trunk/drools-jbrms/src/test/resources/RepoBinPackage.pkg
labs/jbossrules/trunk/drools-jsr94/
labs/jbossrules/trunk/drools-jsr94/.classpath
labs/jbossrules/trunk/drools-repository/
labs/jbossrules/trunk/drools-server/
labs/jbossrules/trunk/pom.xml
Log:
Merged branch mvel-tooling-2007-06-30 back in trunk @ 13682. JBRULES-989 and JBRULES-990
Modified: labs/jbossrules/trunk/drools-compiler/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-compiler/.classpath 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-compiler/.classpath 2007-07-20 23:24:55 UTC (rev 13689)
@@ -12,7 +12,7 @@
<classpathentry kind="src" path="/drools-core"/>
<classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
<classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5/mvel14-1.2pre5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar"/>
<classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
<classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
</classpath>
\ No newline at end of file
Deleted: labs/jbossrules/trunk/drools-compiler/build.properties
===================================================================
--- labs/jbossrules/trunk/drools-compiler/build.properties 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-compiler/build.properties 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,19 +0,0 @@
-bin.includes = META-INF/,\
- icons/,\
- lib/,\
- drools-compiler.jar
-src.includes = META-INF/,\
- build.properties,\
- .classpath,\
- .project,\
- icons/
-jars.compile.order = drools-compiler.jar
-source.drools-compiler.jar = src/main/java/
-output.drools-compiler.jar = target/classes/
-jars.extra.classpath = lib/antlr-2.7.6.jar,\
- lib/antlr3-3.0ea7.jar,\
- lib/commons-lang-2.1.jar,\
- lib/commons-logging-api-1.0.4.jar,\
- lib/jci-SNAPSHOT-378493.jar,\
- lib/jdtcore-3.1.0.jar,\
- lib/stringtemplate-2.2-20060301.jar
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -28,6 +28,8 @@
*
*/
public interface Dialect {
+ String getId();
+
void init(PackageBuilder builder);
// this is needed because some dialects use other dialects
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/RuleDescr.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/RuleDescr.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/RuleDescr.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -2,13 +2,13 @@
/*
* Copyright 2005 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.
@@ -20,10 +20,10 @@
import java.util.Collections;
import java.util.List;
+import org.drools.compiler.Dialect;
+
public class RuleDescr extends BaseDescr {
- /**
- *
- */
+
private static final long serialVersionUID = 400L;
private String name;
private String documentation;
@@ -38,11 +38,15 @@
private String className;
+ //MVEL: Compiler change
+ private Dialect dialect;
+
public RuleDescr(final String name) {
this( name,
"" );
}
+
public RuleDescr(final String ruleName,
final String documentation) {
this.name = ruleName;
@@ -51,7 +55,7 @@
public String getName() {
return this.name;
- }
+ }
public String getSalience() {
return salience;
@@ -125,4 +129,12 @@
public int getConsequencePattern() {
return this.consequencePattern;
}
+
+ public void setDialect(Dialect dialect) {
+ this.dialect = dialect;
+ }
+
+ public Dialect getDialect() {
+ return this.dialect;
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -19,7 +19,6 @@
import org.drools.commons.jci.readers.ResourceReader;
import org.drools.compiler.Dialect;
import org.drools.compiler.PackageBuilder;
-import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.compiler.RuleError;
import org.drools.compiler.PackageBuilder.ErrorHandler;
import org.drools.compiler.PackageBuilder.FunctionErrorHandler;
@@ -59,11 +58,14 @@
import org.drools.rule.builder.SalienceBuilder;
import org.drools.rule.builder.dialect.mvel.MVELFromBuilder;
import org.drools.rule.builder.dialect.mvel.MVELSalienceBuilder;
+import org.drools.util.StringUtils;
public class JavaDialect
implements
Dialect {
+ public static final String ID = "JavaDialect";
+
private final static String EXPRESSION_DIALECT_NAME = "MVEL";
// builders
private final PatternBuilder pattern = new PatternBuilder();
@@ -78,7 +80,7 @@
private final MVELFromBuilder from = new MVELFromBuilder();
private final JavaFunctionBuilder function = new JavaFunctionBuilder();
- //
+ //
private KnowledgeHelperFixer knowledgeHelperFixer;
private DeclarationTypeFixer typeFixer;
private JavaExprAnalyzer analyzer;
@@ -90,10 +92,9 @@
private List generatedClassList;
private MemoryResourceReader src;
private PackageStore packageStoreWrapper;
- private Map lineMappings;
private Map errorHandlers;
private List results;
- // the class name for the rule
+ // the class name for the rule
private String ruleClass;
private TypeResolver typeResolver;
@@ -105,7 +106,7 @@
public JavaDialect() {
}
-
+
public void init(PackageBuilder builder) {
this.pkg = builder.getPackage();
this.configuration = (JavaDialectConfiguration) builder.getPackageBuilderConfiguration().getDialectConfiguration( "java" );
@@ -172,7 +173,9 @@
}
public void init(final Package pkg) {
+
this.pkg = pkg;
+ //TODO Consider lazy init for these as they might have been initialized from the constructor and maybe used meanwhile
this.errorHandlers = new HashMap();
this.results = new ArrayList();
@@ -182,8 +185,6 @@
this.packageStoreWrapper = new PackageStore( pkg.getPackageCompilationData(),
this.results );
-
- this.lineMappings = pkg.getPackageCompilationData().getLineMappings();
}
public void init(final RuleDescr ruleDescr) {
@@ -191,7 +192,8 @@
ruleDescr.getName(),
"java",
this.src );
- ruleDescr.setClassName( ucFirst( ruleClassName ) );
+ ruleDescr.setClassName( StringUtils.ucFirst( ruleClassName ) );
+ ruleDescr.setDialect( this );
}
public void setRuleClass(final String ruleClass) {
@@ -226,7 +228,6 @@
result = this.analyzer.analyzeBlock( text,
new Set[]{context.getDeclarationResolver().getDeclarations().keySet(), context.getPkg().getGlobals().keySet()} );
} catch ( final Exception e ) {
- e.printStackTrace();
context.getErrors().add( new RuleError( context.getRule(),
descr,
null,
@@ -337,9 +338,9 @@
final CompilationProblem err = result.getErrors()[i];
final ErrorHandler handler = (ErrorHandler) this.errorHandlers.get( err.getFileName() );
-// if ( handler instanceof RuleErrorHandler ) {
-// final RuleErrorHandler rh = (RuleErrorHandler) handler;
-// }
+ if ( handler instanceof RuleErrorHandler ) {
+ final RuleErrorHandler rh = (RuleErrorHandler) handler;
+ }
handler.addError( err );
}
@@ -368,7 +369,7 @@
* It will not actually call the compiler
*/
public void addRule(final RuleBuildContext context) {
- // return if there is no ruleclass name;
+ // return if there is no ruleclass name;
if ( this.ruleClass == null ) {
return;
}
@@ -397,7 +398,6 @@
}
final String text = (String) context.getInvokers().get( className );
- //System.out.println( className + ":\n" + text );
final BaseDescr descr = (BaseDescr) context.getDescrLookups().get( className );
addClassCompileTask( className,
descr,
@@ -410,24 +410,26 @@
}
// setup the line mappins for this rule
- final String name = this.pkg.getName() + "." + ucFirst( ruleDescr.getClassName() );
+ final String name = this.pkg.getName() + "." + StringUtils.ucFirst( ruleDescr.getClassName() );
final LineMappings mapping = new LineMappings( name );
mapping.setStartLine( ruleDescr.getConsequenceLine() );
mapping.setOffset( ruleDescr.getConsequenceOffset() );
- this.lineMappings.put( name,
- mapping );
+
+ context.getPkg().getPackageCompilationData().getLineMappings().put( name,
+ mapping );
+
}
public void addFunction(final FunctionDescr functionDescr,
final TypeResolver typeResolver) {
- final String functionClassName = this.pkg.getName() + "." + ucFirst( functionDescr.getName() );
+ final String functionClassName = this.pkg.getName() + "." + StringUtils.ucFirst( functionDescr.getName() );
this.pkg.addFunction( functionDescr.getName() );
final String functionSrc = getFunctionBuilder().build( this.pkg,
functionDescr,
typeResolver,
- this.lineMappings,
+ pkg.getPackageCompilationData().getLineMappings(),
this.results );
addClassCompileTask( functionClassName,
@@ -440,15 +442,15 @@
final LineMappings mapping = new LineMappings( functionClassName );
mapping.setStartLine( functionDescr.getLine() );
mapping.setOffset( functionDescr.getOffset() );
- this.lineMappings.put( functionClassName,
+ pkg.getPackageCompilationData().getLineMappings().put( functionClassName,
mapping );
}
- /**
- * This adds a compile "task" for when the compiler of
+ /**
+ * This adds a compile "task" for when the compiler of
* semantics (JCI) is called later on with compileAll()\
* which actually does the compiling.
- * The ErrorHandler is required to map the errors back to the
+ * The ErrorHandler is required to map the errors back to the
* element that caused it.
*/
private void addClassCompileTask(final String className,
@@ -482,16 +484,16 @@
case JavaDialectConfiguration.ECLIPSE :
default : {
this.compiler = JavaCompilerFactory.getInstance().createCompiler( "eclipse" );
- JavaCompilerSettings settings = this.compiler.createDefaultSettings();
-
+ JavaCompilerSettings settings = this.compiler.createDefaultSettings();
+
String lngLevel = this.configuration.getJavaLanguageLevel();
settings.setTargetVersion( lngLevel );
-
+
if ( lngLevel == "1.4" ) {
// 1.5 is the minimum for source langauge level, so we can use static imports.
lngLevel = "1.5";
}
-
+
settings.setSourceVersion( lngLevel );
break;
}
@@ -512,13 +514,15 @@
/**
* Takes a given name and makes sure that its legal and doesn't already exist. If the file exists it increases counter appender untill it is unique.
- *
+ *
+ * TODO: move out to shared utility class
+ *
* @param packageName
* @param name
* @param ext
* @return
*/
- private String getUniqueLegalName(final String packageName,
+ public static String getUniqueLegalName(final String packageName,
final String name,
final String ext,
final ResourceReader src) {
@@ -535,7 +539,8 @@
final String fileName = packageName.replaceAll( "\\.",
"/" ) + newName + "_" + counter + ext;
- exists = src.isAvailable( fileName );
+ //MVEL:test null to Fix failing test on org.drools.rule.builder.dialect.mvel.MVELConsequenceBuilderTest.testImperativeCodeError()
+ exists = src != null && src.isAvailable( fileName );
}
// we have duplicate file names so append counter
if ( counter >= 0 ) {
@@ -545,8 +550,7 @@
return newName;
}
- private String ucFirst(final String name) {
- return name.toUpperCase().charAt( 0 ) + name.substring( 1 );
+ public String getId() {
+ return ID;
}
-
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -13,9 +13,11 @@
import org.drools.rule.builder.RuleBuildContext;
import org.drools.spi.KnowledgeHelper;
import org.mvel.ASTNode;
-import org.mvel.MVEL;
+import org.mvel.CompiledExpression;
+import org.mvel.ExpressionCompiler;
import org.mvel.Macro;
import org.mvel.MacroProcessor;
+import org.mvel.ParserContext;
import org.mvel.ast.WithNode;
import org.mvel.integration.Interceptor;
import org.mvel.integration.VariableResolverFactory;
@@ -67,14 +69,36 @@
try {
MVELDialect dialect = (MVELDialect) context.getDialect();
+
final DroolsMVELFactory factory = new DroolsMVELFactory( context.getDeclarationResolver().getDeclarations(),
null,
context.getPkg().getGlobals() );
+
factory.setNextFactory( dialect.getClassImportResolverFactory() );
MacroProcessor macroProcessor = new MacroProcessor();
macroProcessor.setMacros( macros );
+ //MVEL: Compiler change (commented after incomming changes from r13267 port
+// String pkg = "";
+// if (context.getPkg()!= null && context.getPkg().getName()!= null
+// && context.getPkg().getName().length()>0) {
+// pkg = context.getPkg().getName()+".";
+// }
+// String sourceFile = pkg + context.getRuleDescr().getClassName();
+//
+// ParserContext parserContext = new ParserContext();
+// parserContext.setImports(dialect.getClassImportResolverFactory().getImportedClasses());
+//
+// parserContext.setInterceptors(this.interceptors);
+// parserContext.setSourceFile(sourceFile);
+// parserContext.setDebugSymbols( true );
+//
+// ExpressionCompiler parser = new ExpressionCompiler(macroProcessor.parse( delimitExpressions( (String) context.getRuleDescr().getConsequence() )));
+// CompiledExpression cExpr = parser.compile();
+//
+// final Serializable expr = cExpr;
+
String text = macroProcessor.parse( delimitExpressions( (String) context.getRuleDescr().getConsequence() ) );
Dialect.AnalysisResult analysis = dialect.analyzeBlock( context,
@@ -103,7 +127,7 @@
* Allows newlines to demarcate expressions, as per MVEL command line.
* If expression spans multiple lines (ie inside an unbalanced bracket) then
* it is left alone.
- * Uses character based iteration which is at least an order of magnitude faster then a single
+ * Uses character based iteration which is at least an order of magnitude faster then a single
* simple regex.
*/
public String delimitExpressions(String s) {
@@ -152,4 +176,5 @@
return result.toString();
}
-}
+ }
+
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -14,10 +14,10 @@
import org.drools.base.TypeResolver;
import org.drools.base.mvel.DroolsMVELFactory;
import org.drools.base.mvel.DroolsMVELKnowledgeHelper;
+import org.drools.commons.jci.readers.MemoryResourceReader;
import org.drools.compiler.Dialect;
import org.drools.compiler.ImportError;
import org.drools.compiler.PackageBuilder;
-import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.compiler.RuleError;
import org.drools.lang.descr.AccumulateDescr;
import org.drools.lang.descr.AndDescr;
@@ -32,6 +32,7 @@
import org.drools.lang.descr.QueryDescr;
import org.drools.lang.descr.RuleDescr;
import org.drools.rule.Declaration;
+import org.drools.rule.LineMappings;
import org.drools.rule.Package;
import org.drools.rule.builder.AccumulateBuilder;
import org.drools.rule.builder.ConsequenceBuilder;
@@ -45,8 +46,10 @@
import org.drools.rule.builder.RuleClassBuilder;
import org.drools.rule.builder.RuleConditionBuilder;
import org.drools.rule.builder.SalienceBuilder;
+import org.drools.rule.builder.dialect.java.JavaDialect;
import org.drools.spi.DeclarationScopeResolver;
import org.drools.spi.KnowledgeHelper;
+import org.drools.util.StringUtils;
import org.mvel.ASTNode;
import org.mvel.AbstractParser;
import org.mvel.ExpressionCompiler;
@@ -61,8 +64,12 @@
implements
Dialect {
+ public final static String ID = "MVELDialect";
+
private final static String EXPRESSION_DIALECT_NAME = "MVEL";
+ private final MVELRuleClassBuilder rule = new MVELRuleClassBuilder();
+
private final PatternBuilder pattern = new PatternBuilder();
private final QueryBuilder query = new QueryBuilder();
private final MVELAccumulateBuilder accumulate = new MVELAccumulateBuilder();
@@ -79,12 +86,13 @@
private List results;
//private final JavaFunctionBuilder function = new JavaFunctionBuilder();
+ private MemoryResourceReader src;
+
private Package pkg;
private MVELDialectConfiguration configuration;
private TypeResolver typeResolver;
private ClassFieldExtractorCache classFieldExtractorCache;
private MVELExprAnalyzer analyzer;
-
private StaticMethodImportResolverFactory staticImportFactory;
private ClassImportResolverFactory importFactory;
@@ -170,10 +178,18 @@
public void init(Package pkg) {
this.pkg = pkg;
this.results = new ArrayList();
-
+ this.src = new MemoryResourceReader();
}
public void init(RuleDescr ruleDescr) {
+ //MVEL:test null to Fix failing test on org.drools.rule.builder.dialect.mvel.MVELConsequenceBuilderTest.testImperativeCodeError()
+ String pkgName = this.pkg == null? "": this.pkg.getName();
+ final String ruleClassName = JavaDialect.getUniqueLegalName( pkgName,
+ ruleDescr.getName(),
+ "mvel",
+ this.src );
+ ruleDescr.setClassName( StringUtils.ucFirst( ruleClassName ) );
+ ruleDescr.setDialect( this );
}
public String getExpressionDialectName() {
@@ -181,7 +197,17 @@
}
public void addRule(RuleBuildContext context) {
+ //MVEL: Compiler change
+ final RuleDescr ruleDescr = context.getRuleDescr();
+ // setup the line mappins for this rule
+ final String name = this.pkg.getName() + "." + StringUtils.ucFirst( ruleDescr.getClassName() );
+ final LineMappings mapping = new LineMappings( name );
+ mapping.setStartLine( ruleDescr.getConsequenceLine() );
+ mapping.setOffset( ruleDescr.getConsequenceOffset() );
+
+ context.getPkg().getPackageCompilationData().getLineMappings().put( name, mapping );
+
}
public void addImport(String importEntry) {
@@ -309,11 +335,12 @@
final ParserContext parserContext = new ParserContext( imports,
null,
- null );
+ context.getPkg().getName()+"."+context.getRuleDescr().getClassName() );
//this.configuration.get
parserContext.setStrictTypeEnforcement( strictMode );
+
if ( interceptors != null ) {
parserContext.setInterceptors( interceptors );
}
@@ -331,7 +358,7 @@
for ( Iterator it = list[1].iterator(); it.hasNext(); ) {
String identifier = (String) it.next();
parserContext.addInput( identifier,
- (Class) globalTypes.get( identifier ) );
+ (Class) globalTypes.get( identifier ) );
}
Map mvelVars = ((MVELAnalysisResult) analysis).getMvelVariables();
@@ -355,6 +382,10 @@
KnowledgeHelper.class );
ExpressionCompiler compiler = new ExpressionCompiler( text );
+
+ //MVEL Debugging support
+ compiler.setDebugSymbols( true );
+
Serializable expr = compiler.compile( parserContext );
return expr;
}
@@ -416,7 +447,7 @@
}
public RuleClassBuilder getRuleClassBuilder() {
- return null;
+ return rule;
}
public TypeResolver getTypeResolver() {
@@ -427,9 +458,15 @@
return this.interceptors;
}
+ public String getId() {
+ return ID;
+ }
+
public static class AssertInterceptor
implements
- Interceptor {
+ Interceptor, Serializable {
+ private static final long serialVersionUID = 400L;
+
public int doBefore(ASTNode node,
VariableResolverFactory factory) {
return 0;
@@ -445,7 +482,9 @@
public static class ModifyInterceptor
implements
- Interceptor {
+ Interceptor, Serializable {
+ private static final long serialVersionUID = 400L;
+
public int doBefore(ASTNode node,
VariableResolverFactory factory) {
Object object = ((WithNode) node).getNestedStatement().getValue( null,
@@ -466,4 +505,4 @@
return 0;
}
}
-}
+}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELRuleClassBuilder.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELRuleClassBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELRuleClassBuilder.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELRuleClassBuilder.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,26 @@
+package org.drools.rule.builder.dialect.mvel;
+
+import org.drools.lang.descr.RuleDescr;
+import org.drools.rule.builder.RuleBuildContext;
+import org.drools.rule.builder.RuleClassBuilder;
+
+public class MVELRuleClassBuilder
+ implements
+ RuleClassBuilder {
+
+ /**
+ * No real building for now.
+ * Simply to update ruleDescr.setConsequenceOffset
+ */
+ public void buildRule(RuleBuildContext context) {
+ final MVELDialect dialect = (MVELDialect) context.getDialect();
+
+ final String lineSeparator = System.getProperty( "line.separator" );
+
+ final StringBuffer buffer = new StringBuffer();
+
+ final RuleDescr ruleDescr = context.getRuleDescr();
+
+ ruleDescr.setConsequenceOffset( 0);
+ }
+}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -61,7 +61,7 @@
assertNotNull( chainedProperties.getProperty( "drools.dialect.java.compiler",
null ) );
-
+
// now check that chained properties can ignore defaults
chainedProperties = new ChainedProperties( null,
"packagebuilder.conf",
@@ -71,7 +71,7 @@
assertNull( chainedProperties.getProperty( "drools.dialect.java.compiler",
null ) );
-
+
// now check it can find defaults again.
chainedProperties = new ChainedProperties( null,
"packagebuilder.conf",
@@ -381,6 +381,11 @@
// TODO Auto-generated method stub
return null;
}
+
+ public String getId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
public static class MockEvalBuilder
Property changes on: labs/jbossrules/trunk/drools-core
___________________________________________________________________
Name: svn:ignore
- target
.metadata
.settings
.wtpmodules
*.log
*.log.*
*.ipr
*.iws
*.iml
nbproject
local
+ target
.classpath
.project
.wtpmodules
__temp_test_drools_packages
Modified: labs/jbossrules/trunk/drools-core/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-core/.classpath 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-core/.classpath 2007-07-20 23:24:55 UTC (rev 13689)
@@ -8,5 +8,5 @@
<classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
<classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5/mvel14-1.2pre5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar"/>
</classpath>
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELConsequence.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELConsequence.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELConsequence.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -5,7 +5,9 @@
import org.drools.WorkingMemory;
import org.drools.spi.Consequence;
import org.drools.spi.KnowledgeHelper;
+import org.mvel.CompiledExpression;
import org.mvel.MVEL;
+import org.mvel.MVELRuntime;
public class MVELConsequence
implements
@@ -29,8 +31,20 @@
null,
workingMemory,
null );
- MVEL.executeExpression( this.expr,
+ CompiledExpression compexpr = (CompiledExpression)this.expr;
+
+ //MVEL:for testing, we can have at least one breakpoint
+ //MVELRuntime.registerBreakpoint( compexpr.getSourceName(), 1 );
+
+ //Receive breakpoints from debugger
+ MVELDebugHandler.prepare();
+
+ //we are always debugging for now, but we should either debug or run
+ MVEL.executeDebugger( compexpr, null, this.factory);
+
+ /*MVEL.executeExpression( this.expr,
null,
- this.factory );
+ this.factory );*/
}
+
}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELDebugHandler.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,61 @@
+package org.drools.base.mvel;
+
+import org.mvel.MVELRuntime;
+import org.mvel.debug.Debugger;
+import org.mvel.debug.Frame;
+
+public final class MVELDebugHandler {
+
+ static {
+ MVELRuntime.setThreadDebugger(new MVELDebugger());
+ }
+
+ /**
+ * Notify remote debugger that runtime is ready to get latest breakpoint
+ * information
+ *
+ */
+ public static void receiveBreakpoints() {
+ }
+
+ /**
+ * This is catched by the remote debugger
+ *
+ * @param frame
+ */
+ private final static void onBreak(Frame frame) {
+ }
+
+ protected final static void registerBreakpoint(String sourceName, int lineNumber) {
+ MVELRuntime.registerBreakpoint( sourceName, lineNumber );
+ }
+
+ protected final static void clearAllBreakpoints() {
+ MVELRuntime.clearAllBreakpoints();
+ }
+
+ protected final static void removeBreakpoint(String sourceName, int lineNumber) {
+ MVELRuntime.removeBreakpoint( sourceName, lineNumber );
+ }
+
+ private static class MVELDebugger implements Debugger {
+
+ public MVELDebugger() {
+ }
+
+ public int onBreak(Frame frame) {
+ MVELDebugHandler.onBreak(frame);
+ // This call is supposed to be catched by the remote debugger
+ return 0;
+ }
+
+ }
+
+ /**
+ * Do nothing. ensures that class is loaded prior debug handler
+ */
+ public static void prepare() {
+ //do nothing
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -2,13 +2,13 @@
/*
* Copyright 2005 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.
@@ -50,12 +50,12 @@
Externalizable {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
-
- private static final ProtectionDomain PROTECTION_DOMAIN;
+ private static final ProtectionDomain PROTECTION_DOMAIN;
+
private Map invokerLookups;
private Object AST;
@@ -68,17 +68,17 @@
private transient ClassLoader parentClassLoader;
-
+
static {
PROTECTION_DOMAIN = (ProtectionDomain) AccessController.doPrivileged( new PrivilegedAction() {
public Object run() {
return PackageCompilationData.class.getProtectionDomain();
}
} );
- }
-
+ }
+
/**
- * Default constructor - for Externalizable. This should never be used by a user, as it
+ * Default constructor - for Externalizable. This should never be used by a user, as it
* will result in an invalid state for the instance.
*/
public PackageCompilationData() {
@@ -101,16 +101,16 @@
}
/**
- * Handles the write serialization of the PackageCompilationData. Patterns in Rules may reference generated data which cannot be serialized by
+ * Handles the write serialization of the PackageCompilationData. Patterns in Rules may reference generated data which cannot be serialized by
* default methods. The PackageCompilationData holds a reference to the generated bytecode. The generated bytecode must be restored before any Rules.
- *
+ *
*/
public void writeExternal(final ObjectOutput stream) throws IOException {
stream.writeObject( this.store );
stream.writeObject( this.AST );
// Rules must be restored by an ObjectInputStream that can resolve using a given ClassLoader to handle seaprately by storing as
- // a byte[]
+ // a byte[]
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final ObjectOutput out = new ObjectOutputStream( bos );
out.writeObject( this.invokerLookups );
@@ -118,10 +118,10 @@
}
/**
- * Handles the read serialization of the PackageCompilationData. Patterns in Rules may reference generated data which cannot be serialized by
+ * Handles the read serialization of the PackageCompilationData. Patterns in Rules may reference generated data which cannot be serialized by
* default methods. The PackageCompilationData holds a reference to the generated bytecode; which must be restored before any Rules.
* A custom ObjectInputStream, able to resolve classes against the bytecode, is used to restore the Rules.
- *
+ *
*/
public void readExternal(final ObjectInput stream) throws IOException,
ClassNotFoundException {
@@ -129,7 +129,7 @@
DroolsObjectInputStream droolsStream = ( DroolsObjectInputStream ) stream;
initClassLoader( droolsStream.getClassLoader() );
} else {
- initClassLoader( Thread.currentThread().getContextClassLoader() );
+ initClassLoader( Thread.currentThread().getContextClassLoader() );
}
this.store = (Map) stream.readObject();
@@ -279,15 +279,14 @@
}
public Map getLineMappings() {
+ if (this.lineMappings==null) {
+ this.lineMappings = new HashMap();
+ }
return this.lineMappings;
}
-
-// public void setLineMappings(final Map lineMappings) {
-// this.lineMappings = lineMappings;
-// }
-
+
public LineMappings getLineMappings(final String className) {
- return (LineMappings) this.lineMappings.get( className );
+ return (LineMappings) getLineMappings().get( className );
}
public Object getAST() {
@@ -300,7 +299,7 @@
/**
* Lifted and adapted from Jakarta commons-jci
- *
+ *
* @author mproctor
*
*/
@@ -330,11 +329,11 @@
}
/**
- * Javadocs recommend that this method not be overloaded. We overload this so that we can prioritise the fastFindClass
+ * Javadocs recommend that this method not be overloaded. We overload this so that we can prioritise the fastFindClass
* over method calls to parent.loadClass(name, false); and c = findBootstrapClass0(name); which the default implementation
- * would first - hence why we call it "fastFindClass" instead of standard findClass, this indicates that we give it a
+ * would first - hence why we call it "fastFindClass" instead of standard findClass, this indicates that we give it a
* higher priority than normal.
- *
+ *
*/
protected synchronized Class loadClass(final String name,
final boolean resolve) throws ClassNotFoundException {
Modified: labs/jbossrules/trunk/drools-decisiontables/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/.classpath 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-decisiontables/.classpath 2007-07-20 23:24:55 UTC (rev 13689)
@@ -15,6 +15,6 @@
<classpathentry kind="src" path="/drools-compiler"/>
<classpathentry kind="var" path="M2_REPO/jexcelapi/jxl/2.4.2/jxl-2.4.2.jar"/>
<classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5/mvel14-1.2pre5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar"/>
<classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
</classpath>
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-eclipse
___________________________________________________________________
Name: svn:ignore
+ target
repository
local-eclipse-drop-mirror
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-feature/feature.xml
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-feature/feature.xml 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-feature/feature.xml 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,27 +1,49 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<feature
- id="org.drools.eclipse.feature"
- label="JBossRules Feature"
- version="4.0.0.SNAPSHOT"
- provider-name="JBoss, Inc.">
-
- <description url="http://www.example.com/description">
- [Enter Feature Description here.]
- </description>
-
- <copyright url="http://www.example.com/copyright">
- [Enter Copyright Description here.]
- </copyright>
-
- <license url="http://www.example.com/license">
- [Enter License Description here.]
- </license>
-
- <plugin
- id="org.drools.eclipse"
- download-size="0"
- install-size="0"
- version="4.0.0.SNAPSHOT"
- unpack="false"/>
-
-</feature>
+<?xml version="1.0" encoding="UTF-8"?>
+<feature
+ id="org.drools.eclipse.feature"
+ label="JBossRules Feature"
+ version="4.0.0.SNAPSHOT"
+ provider-name="JBoss, Inc.">
+
+ <description url="http://www.example.com/description">
+ [Enter Feature Description here.]
+ </description>
+
+ <copyright url="http://www.example.com/copyright">
+ [Enter Copyright Description here.]
+ </copyright>
+
+ <license url="http://www.example.com/license">
+ [Enter License Description here.]
+ </license>
+
+ <requires>
+ <import plugin="org.eclipse.core.runtime"/>
+ <import plugin="org.eclipse.core.resources"/>
+ <import plugin="org.eclipse.debug.core"/>
+ <import plugin="org.eclipse.debug.ui"/>
+ <import plugin="org.eclipse.jdt.core"/>
+ <import plugin="org.eclipse.jdt.debug"/>
+ <import plugin="org.eclipse.jdt.debug.ui"/>
+ <import plugin="org.eclipse.jdt.launching"/>
+ <import plugin="org.eclipse.jdt.ui"/>
+ <import plugin="org.eclipse.jface.text"/>
+ <import plugin="org.eclipse.ui"/>
+ <import plugin="org.eclipse.ui.console"/>
+ <import plugin="org.eclipse.ui.editors"/>
+ <import plugin="org.eclipse.ui.forms"/>
+ <import plugin="org.eclipse.ui.ide"/>
+ <import plugin="org.eclipse.ui.views"/>
+ <import plugin="org.eclipse.ui.workbench.texteditor"/>
+ <import plugin="org.eclipse.gef"/>
+ <import plugin="com.ibm.icu"/>
+ </requires>
+
+ <plugin
+ id="org.drools.eclipse"
+ download-size="0"
+ install-size="0"
+ version="4.0.0.SNAPSHOT"
+ unpack="false"/>
+
+</feature>
Property changes on: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin
___________________________________________________________________
Name: svn:ignore
-
bin
+ bin
target
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,22 +1,21 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources"/>
- <classpathentry exported="true" kind="lib" path="lib/drools-compiler.jar" sourcepath="/drools-compiler"/>
- <classpathentry exported="true" kind="lib" path="lib/drools-core.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/drools-decisiontables.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/drools-jsr94.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/jsr94.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/junit.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/jxl.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/mvel14.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/xercesImpl.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/xml-apis.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/xpp3.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/xstream.jar"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="lib" path="lib/antlr-runtime.jar"/>
- <classpathentry kind="src" path="/drools-compiler"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry exported="true" kind="lib" path="lib/drools-compiler.jar" sourcepath="/drools-compiler"/>
+ <classpathentry exported="true" kind="lib" path="lib/drools-core.jar" sourcepath="/drools-core"/>
+ <classpathentry exported="true" kind="lib" path="lib/drools-decisiontables.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/drools-jsr94.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jsr94.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/junit.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jxl.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/mvel14.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/xercesImpl.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/xml-apis.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/xpp3.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/xstream.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/antlr-runtime.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/META-INF/MANIFEST.MF
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/META-INF/MANIFEST.MF 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/META-INF/MANIFEST.MF 2007-07-20 23:24:55 UTC (rev 13689)
@@ -27,9 +27,7 @@
com.ibm.icu
Eclipse-LazyStart: true
Eclipse-BuddyPolicy: registered
-Bundle-ClassPath:
- .,
- drools-eclipse-plugin.jar,
+Bundle-ClassPath: .,
lib/drools-compiler.jar,
lib/drools-core.jar,
lib/drools-decisiontables.jar,
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/build.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/build.properties 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/build.properties 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,21 +1,18 @@
-bin.includes = META-INF/,\
+bin.includes = .,\
+ META-INF/,\
icons/,\
plugin.xml,\
help/,\
- lib/,\
- drools-eclipse-plugin.jar,\
- .,\
-bin.excludes = lib/drools-documentation.jar
+ lib/
+bin.excludes = lib/drools-documentation.jar
src.includes = META-INF/,\
icons/,\
plugin.xml,\
help/,\
lib/,\
.project,\
- .classpath,\
- build.properties,\
- src/
-src.excludes = lib/drools-documentation.jar
+ .classpath
+src.excludes = lib/drools-documentation.jar
jars.compile.order = .
source.. = src/main/java/,\
src/main/resources/
Property changes on: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/help
___________________________________________________________________
Name: svn:ignore
+ eclipse
shared
Property changes on: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/lib
___________________________________________________________________
Name: svn:ignore
- antlr-2.7.7.jar
antlr-3.0b5.jar
drools-compiler-3.1.0-M1.jar
drools-core-3.1.0-M1.jar
drools-decisiontables-3.1.0-M1.jar
drools-jsr94-3.1.0-M1.jar
jsr94-1.1.jar
junit-3.8.1.jar
jxl-2.4.2.jar
mvel14-1.2beta15.jar
stringtemplate-3.0.jar
xercesImpl-2.4.0.jar
xml-apis-1.0.b2.jar
xpp3-1.1.3.4.O.jar
xstream-1.1.3.jar
+ antlr-2.7.7.jar
antlr-3.0b5.jar
drools-compiler-3.1.0-M1.jar
drools-core-3.1.0-M1.jar
drools-decisiontables-3.1.0-M1.jar
drools-jsr94-3.1.0-M1.jar
jsr94-1.1.jar
junit-3.8.1.jar
jxl-2.4.2.jar
mvel14-1.2beta15.jar
stringtemplate-3.0.jar
xercesImpl-2.4.0.jar
xml-apis-1.0.b2.jar
xpp3-1.1.3.4.O.jar
xstream-1.1.3.jar
*.jar
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DRLInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DRLInfo.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DRLInfo.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -5,17 +5,20 @@
import java.util.Iterator;
import java.util.List;
+import org.drools.compiler.Dialect;
import org.drools.compiler.DroolsError;
import org.drools.lang.descr.FunctionDescr;
import org.drools.lang.descr.PackageDescr;
import org.drools.lang.descr.RuleDescr;
+import org.drools.rule.LineMappings;
import org.drools.rule.Package;
+import org.drools.rule.PackageCompilationData;
public class DRLInfo {
private static final DroolsError[] EMPTY_DROOLS_ERROR_ARRAY = new DroolsError[0];
private static final List EMPTY_LIST = Collections.unmodifiableList(Collections.EMPTY_LIST);
-
+
private String sourcePathName;
private PackageDescr packageDescr;
private List parserErrors;
@@ -45,14 +48,14 @@
throw new IllegalArgumentException("Null package");
}
this.compiledPackage = compiledPackage;
- this.builderErrors =
+ this.builderErrors =
builderErrors == null ? EMPTY_DROOLS_ERROR_ARRAY : builderErrors;
}
public String getSourcePathName() {
return sourcePathName;
}
-
+
public PackageDescr getPackageDescr() {
return packageDescr;
}
@@ -60,11 +63,11 @@
public List getParserErrors() {
return parserErrors;
}
-
+
public Package getPackage() {
return compiledPackage;
}
-
+
public DroolsError[] getBuilderErrors() {
return builderErrors;
}
@@ -72,11 +75,11 @@
public String getPackageName() {
return packageDescr.getName();
}
-
+
public boolean isCompiled() {
return compiledPackage != null;
}
-
+
public RuleInfo[] getRuleInfos() {
if (ruleInfos == null) {
List ruleInfosList = new ArrayList();
@@ -89,9 +92,10 @@
}
return ruleInfos;
}
-
+
public RuleInfo getRuleInfo(int drlLineNumber) {
RuleInfo[] ruleInfos = getRuleInfos();
+
int ruleLine = -1;
RuleInfo result = null;
for (int i = 0; i < ruleInfos.length; i++) {
@@ -104,14 +108,14 @@
}
return result;
}
-
+
public class RuleInfo {
-
- private RuleDescr ruleDescr;
+
+ private final RuleDescr ruleDescr;
// cached entries
private transient String className;
private transient int consequenceJavaLineNumber = -1;
-
+
public RuleInfo(RuleDescr ruleDescr) {
if (ruleDescr == null) {
throw new IllegalArgumentException("Null ruleDescr");
@@ -119,6 +123,10 @@
this.ruleDescr = ruleDescr;
}
+ public Dialect getDialect() {
+ return ruleDescr.getDialect();
+ }
+
public String getSourcePathName() {
return DRLInfo.this.getSourcePathName();
}
@@ -147,8 +155,12 @@
if (!isCompiled()) {
throw new IllegalArgumentException("Package has not been compiled");
}
- consequenceJavaLineNumber = compiledPackage
- .getPackageCompilationData().getLineMappings(className).getOffset();
+ PackageCompilationData data = compiledPackage
+ .getPackageCompilationData();
+
+ LineMappings mappings = data.getLineMappings(className);
+ consequenceJavaLineNumber = mappings.getOffset();
+
}
return consequenceJavaLineNumber;
}
@@ -174,7 +186,7 @@
}
return functionInfos;
}
-
+
public FunctionInfo getFunctionInfo(int drlLineNumber) {
FunctionInfo[] functionInfos = getFunctionInfos();
int functionLine = -1;
@@ -189,14 +201,14 @@
}
return result;
}
-
+
public class FunctionInfo {
-
+
private FunctionDescr functionDescr;
// cached entries
private transient String className;
private transient int javaLineNumber = -1;
-
+
public FunctionInfo(FunctionDescr functionDescr) {
if (functionDescr == null) {
throw new IllegalArgumentException("Null functionDescr");
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/VariableWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/VariableWrapper.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/VariableWrapper.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -19,7 +19,9 @@
private String name;
private IJavaValue value;
-
+ private boolean isLocal = false;
+ private boolean isPublic = false;
+
public VariableWrapper(String name, IJavaValue value) {
this.name = name;
this.value = value;
@@ -38,7 +40,7 @@
}
public boolean isLocal() {
- return false;
+ return isLocal;
}
public IValue getValue() {
@@ -58,7 +60,7 @@
}
public boolean isPublic() {
- return false;
+ return isPublic;
}
public boolean isPrivate() {
@@ -135,4 +137,11 @@
return name.hashCode() + value.hashCode();
}
+ public void setLocal(boolean val) {
+ isLocal=val;
+ }
+
+ public void setPublic(boolean val) {
+ isPublic = val;
+ }
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugModelPresentation.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugModelPresentation.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugModelPresentation.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,5 +1,6 @@
package org.drools.eclipse.debug.core;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.jdt.internal.debug.ui.JDIModelPresentation;
@@ -7,8 +8,15 @@
protected String getBreakpointText(IBreakpoint breakpoint) {
if (breakpoint instanceof DroolsLineBreakpoint) {
- int lineNumber = ((DroolsLineBreakpoint) breakpoint).getDRLLineNumber();
- return breakpoint.getMarker().getResource().getName() + " [line: " + lineNumber + "]";
+ DroolsLineBreakpoint breakp = ((DroolsLineBreakpoint) breakpoint);
+ int lineNumber = breakp.getDRLLineNumber();
+ int real;
+ try {
+ real = breakp.getLineNumber();
+ } catch ( CoreException e ) {
+ return breakpoint.getMarker().getResource().getName() + " [line: " + lineNumber + "] real: NA!!";
+ }
+ return breakpoint.getMarker().getResource().getName() + " [line: " + lineNumber + "] real: "+real;
}
return super.getBreakpointText(breakpoint);
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,541 +1,891 @@
-package org.drools.eclipse.debug.core;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.drools.eclipse.DroolsEclipsePlugin;
-import org.eclipse.core.resources.IMarkerDelta;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.model.IBreakpoint;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.debug.core.model.IThread;
-import org.eclipse.jdi.TimeoutException;
-import org.eclipse.jdt.internal.debug.core.IJDIEventListener;
-import org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint;
-import org.eclipse.jdt.internal.debug.core.model.JDIDebugModelMessages;
-import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
-import org.eclipse.jdt.internal.debug.core.model.JDIThread;
-
-import com.sun.jdi.ObjectCollectedException;
-import com.sun.jdi.ThreadReference;
-import com.sun.jdi.VMDisconnectedException;
-import com.sun.jdi.VirtualMachine;
-import com.sun.jdi.event.Event;
-import com.sun.jdi.event.ThreadDeathEvent;
-import com.sun.jdi.event.ThreadStartEvent;
-import com.sun.jdi.event.VMStartEvent;
-import com.sun.jdi.request.EventRequest;
-import com.sun.jdi.request.EventRequestManager;
-
-public class DroolsDebugTarget extends JDIDebugTarget {
-
- private ArrayList fThreads;
- private ThreadStartHandler fThreadStartHandler = null;
- private boolean fSuspended = true;
-
- public DroolsDebugTarget(ILaunch launch, VirtualMachine jvm, String name, boolean supportTerminate, boolean supportDisconnect, IProcess process, boolean resume) {
- super(launch, jvm, name, supportTerminate, supportDisconnect, process, resume);
- }
-
- public void breakpointAdded(IBreakpoint breakpoint) {
- try {
- if (breakpoint instanceof DroolsLineBreakpoint) {
- ((DroolsLineBreakpoint) breakpoint).setJavaBreakpointProperties();
- // only add breakpoint if setting Java properties of DRL
- // breakpoint does not generate an error
- super.breakpointAdded(breakpoint);
- } else {
- super.breakpointAdded(breakpoint);
- }
- } catch (Throwable t) {
- // Exception will be thrown when trying to use breakpoint
- // on drl that is incorrect (cannot be parsed or compiled)
- DroolsEclipsePlugin.log(t);
- }
- }
-
- protected synchronized void initialize() {
- setThreadList(new ArrayList(5));
- super.initialize();
- }
-
- protected JDIThread createThread(ThreadReference thread) {
- JDIThread jdiThread= null;
- try {
- jdiThread= new DroolsThread(this, thread);
- } catch (ObjectCollectedException exception) {
- // ObjectCollectionException can be thrown if the thread has already
- // completed (exited) in the VM.
- return null;
- }
- if (isDisconnected()) {
- return null;
- }
- synchronized (fThreads) {
- fThreads.add(jdiThread);
- }
- jdiThread.fireCreationEvent();
- return jdiThread;
- }
-
- private Iterator getThreadIterator() {
- List threadList;
- synchronized (fThreads) {
- threadList= (List) fThreads.clone();
- }
- return threadList.iterator();
- }
-
- private boolean hasSuspendedThreads() {
- Iterator it = getThreadIterator();
- while(it.hasNext()){
- IThread thread = (IThread)it.next();
- if(thread.isSuspended())
- return true;
- }
- return false;
- }
-
- public boolean canResume() {
- return (isSuspended() || hasSuspendedThreads())
- && isAvailable() && !isPerformingHotCodeReplace();
- }
-
- protected void resume(boolean fireNotification) throws DebugException {
- if ((!isSuspended() && !hasSuspendedThreads())
- || !isAvailable()) {
- return;
- }
- try {
- setSuspended(false);
- resumeThreads();
- VirtualMachine vm = getVM();
- if (vm != null) {
- vm.resume();
- }
- if (fireNotification) {
- fireResumeEvent(DebugEvent.CLIENT_REQUEST);
- }
- } catch (VMDisconnectedException e) {
- disconnected();
- return;
- } catch (RuntimeException e) {
- setSuspended(true);
- fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_resume, new String[] {e.toString()}), e);
- }
- }
-
- private void setSuspended(boolean suspended) {
- fSuspended = suspended;
- }
-
- public boolean isSuspended() {
- return fSuspended;
- }
-
- private void setThreadList(ArrayList threads) {
- fThreads = threads;
- }
-
- public IThread[] getThreads() {
- synchronized (fThreads) {
- return (IThread[])fThreads.toArray(new IThread[0]);
- }
- }
-
- protected void removeAllThreads() {
- Iterator itr= getThreadIterator();
- while (itr.hasNext()) {
- DroolsThread child= (DroolsThread) itr.next();
- child.terminated();
- }
- synchronized (fThreads) {
- fThreads.clear();
- }
- }
-
- protected void initializeRequests() {
- setThreadStartHandler(new ThreadStartHandler());
- new ThreadDeathHandler();
- }
-
- class ThreadDeathHandler implements IJDIEventListener {
-
- protected ThreadDeathHandler() {
- createRequest();
- }
-
- /**
- * Creates and registers a request to listen to thread
- * death events.
- */
- protected void createRequest() {
- EventRequestManager manager = getEventRequestManager();
- if (manager != null) {
- try {
- EventRequest req= manager.createThreadDeathRequest();
- req.setSuspendPolicy(EventRequest.SUSPEND_NONE);
- req.enable();
- addJDIEventListener(this, req);
- } catch (RuntimeException e) {
- logError(e);
- }
- }
- }
-
- /**
- * Locates the model thread associated with the underlying JDI thread
- * that has terminated, and removes it from the collection of
- * threads belonging to this debug target. A terminate event is
- * fired for the model thread.
- *
- * @param event a thread death event
- * @param target the target in which the thread died
- * @return <code>true</code> - the thread should be resumed
- */
- public boolean handleEvent(Event event, JDIDebugTarget target) {
- ThreadReference ref= ((ThreadDeathEvent)event).thread();
- DroolsThread thread= (DroolsThread) findThread(ref);
- if (thread != null) {
- synchronized (fThreads) {
- fThreads.remove(thread);
- }
- thread.terminated();
- }
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
- */
- public void wonSuspendVote(Event event, JDIDebugTarget target) {
- // do nothing
- }
-
- }
-
- class ThreadStartHandler implements IJDIEventListener {
-
- protected EventRequest fRequest;
-
- protected ThreadStartHandler() {
- createRequest();
- }
-
- /**
- * Creates and registers a request to handle all thread start
- * events
- */
- protected void createRequest() {
- EventRequestManager manager = getEventRequestManager();
- if (manager != null) {
- try {
- EventRequest req= manager.createThreadStartRequest();
- req.setSuspendPolicy(EventRequest.SUSPEND_NONE);
- req.enable();
- addJDIEventListener(this, req);
- setRequest(req);
- } catch (RuntimeException e) {
- logError(e);
- }
- }
- }
-
- /**
- * Creates a model thread for the underlying JDI thread
- * and adds it to the collection of threads for this
- * debug target. As a side effect of creating the thread,
- * a create event is fired for the model thread.
- * The event is ignored if the underlying thread is already
- * marked as collected.
- *
- * @param event a thread start event
- * @param target the target in which the thread started
- * @return <code>true</code> - the thread should be resumed
- */
- public boolean handleEvent(Event event, JDIDebugTarget target) {
- ThreadReference thread= ((ThreadStartEvent)event).thread();
- try {
- if (thread.isCollected()) {
- return false;
- }
- } catch (VMDisconnectedException exception) {
- return false;
- } catch (ObjectCollectedException e) {
- return false;
- } catch (TimeoutException e) {
- // continue - attempt to create the thread
- }
- DroolsThread jdiThread= (DroolsThread) findThread(thread);
- if (jdiThread == null) {
- jdiThread = (DroolsThread) createThread(thread);
- if (jdiThread == null) {
- return false;
- }
- } else {
- jdiThread.disposeStackFrames();
- jdiThread.fireChangeEvent(DebugEvent.CONTENT);
- }
- return !jdiThread.isSuspended();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
- */
- public void wonSuspendVote(Event event, JDIDebugTarget target) {
- // do nothing
- }
-
- /**
- * Deregisters this event listener.
- */
- protected void deleteRequest() {
- if (getRequest() != null) {
- removeJDIEventListener(this, getRequest());
- setRequest(null);
- }
- }
-
- protected EventRequest getRequest() {
- return fRequest;
- }
-
- protected void setRequest(EventRequest request) {
- fRequest = request;
- }
- }
-
- private void disposeThreadHandler() {
- ThreadStartHandler handler = getThreadStartHandler2();
- if (handler != null) {
- handler.deleteRequest();
- }
- }
-
- public boolean hasThreads() {
- return fThreads.size() > 0;
- }
-
- protected ThreadStartHandler getThreadStartHandler2() {
- return fThreadStartHandler;
- }
-
- protected void setThreadStartHandler(ThreadStartHandler threadStartHandler) {
- fThreadStartHandler = threadStartHandler;
- }
-
- public boolean isOutOfSynch() throws DebugException {
- Iterator threads= getThreadIterator();
- while (threads.hasNext()) {
- JDIThread thread= (JDIThread)threads.next();
- if (thread.isOutOfSynch()) {
- return true;
- }
- }
- return false;
- }
-
- public boolean mayBeOutOfSynch() {
- Iterator threads= getThreadIterator();
- while (threads.hasNext()) {
- JDIThread thread= (JDIThread)threads.next();
- if (thread.mayBeOutOfSynch()) {
- return true;
- }
- }
- return false;
- }
-
- public JDIThread findThread(ThreadReference tr) {
- Iterator iter= getThreadIterator();
- while (iter.hasNext()) {
- JDIThread thread = (JDIThread) iter.next();
- if (thread.getUnderlyingThread().equals(tr))
- return thread;
- }
- return null;
- }
-
- public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
- if (!isAvailable()) {
- return;
- }
- if (supportsBreakpoint(breakpoint)) {
- try {
- ((JavaBreakpoint)breakpoint).removeFromTarget(this);
- getBreakpoints().remove(breakpoint);
- Iterator threads = getThreadIterator();
- while (threads.hasNext()) {
- ((DroolsThread)threads.next()).removeCurrentBreakpoint(breakpoint);
- }
- } catch (CoreException e) {
- logError(e);
- }
- }
- }
-
- protected void suspendThreads() {
- Iterator threads = getThreadIterator();
- while (threads.hasNext()) {
- ((DroolsThread)threads.next()).suspendedByVM();
- }
- }
-
- protected void resumeThreads() throws DebugException {
- Iterator threads = getThreadIterator();
- while (threads.hasNext()) {
- ((DroolsThread)threads.next()).resumedByVM();
- }
- }
-
- public void disconnect() throws DebugException {
-
- if (!isAvailable()) {
- // already done
- return;
- }
-
- if (!canDisconnect()) {
- notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_disconnect);
- }
-
- try {
- disposeThreadHandler();
- VirtualMachine vm = getVM();
- if (vm != null) {
- vm.dispose();
- }
- } catch (VMDisconnectedException e) {
- // if the VM disconnects while disconnecting, perform
- // normal disconnect handling
- disconnected();
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_disconnecting, new String[] {e.toString()}), e);
- }
-
- }
-
- public void terminate() throws DebugException {
- if (!isAvailable()) {
- return;
- }
- if (!supportsTerminate()) {
- notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_termination);
- }
- try {
- setTerminating(true);
- disposeThreadHandler();
- VirtualMachine vm = getVM();
- if (vm != null) {
- vm.exit(1);
- }
- IProcess process= getProcess();
- if (process != null) {
- process.terminate();
- }
- } catch (VMDisconnectedException e) {
- // if the VM disconnects while exiting, perform
- // normal termination processing
- terminated();
- } catch (TimeoutException exception) {
- // if there is a timeout see if the associated process is terminated
- IProcess process = getProcess();
- if (process != null && process.isTerminated()) {
- terminated();
- } else {
- // All we can do is disconnect
- disconnected();
- }
- } catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_terminating, new String[] {e.toString()}), e);
- }
- }
-
- public void handleVMStart(VMStartEvent event) {
- if (isResumeOnStartup()) {
- try {
- setSuspended(true);
- resume();
- } catch (DebugException e) {
- logError(e);
- }
- }
- // If any threads have resumed since thread collection was initialized,
- // update their status (avoid concurrent modification - use #getThreads())
- IThread[] threads = getThreads();
- for (int i = 0; i < threads.length; i++) {
- DroolsThread thread = (DroolsThread) threads[i];
- if (thread.isSuspended()) {
- try {
- boolean suspended = thread.getUnderlyingThread().isSuspended();
- if (!suspended) {
- thread.setRunning(true);
- thread.fireResumeEvent(DebugEvent.CLIENT_REQUEST);
- }
- } catch (VMDisconnectedException e) {
- } catch (ObjectCollectedException e){
- } catch (RuntimeException e) {
- logError(e);
- }
- }
- }
- }
-
- protected void initializeState() {
-
- List threads= null;
- VirtualMachine vm = getVM();
- if (vm != null) {
- try {
- threads= vm.allThreads();
- } catch (RuntimeException e) {
- internalError(e);
- }
- if (threads != null) {
- Iterator initialThreads= threads.iterator();
- while (initialThreads.hasNext()) {
- createThread((ThreadReference) initialThreads.next());
- }
- }
- }
-
- if (isResumeOnStartup()) {
- setSuspended(false);
- }
- }
-
- public void suspend() throws DebugException {
- if (isSuspended()) {
- return;
- }
- try {
- VirtualMachine vm = getVM();
- if (vm != null) {
- vm.suspend();
- }
- suspendThreads();
- setSuspended(true);
- fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
- } catch (RuntimeException e) {
- setSuspended(false);
- fireResumeEvent(DebugEvent.CLIENT_REQUEST);
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_suspend, new String[] {e.toString()}), e);
- }
- }
-
- public void prepareToSuspendByBreakpoint(JavaBreakpoint breakpoint) {
- setSuspended(true);
- suspendThreads();
- }
-
- protected void cancelSuspendByBreakpoint(JavaBreakpoint breakpoint) throws DebugException {
- setSuspended(false);
- resumeThreads();
- }
-}
+package org.drools.eclipse.debug.core;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.rule.builder.dialect.mvel.MVELDialect;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IThread;
+import org.eclipse.jdi.TimeoutException;
+import org.eclipse.jdt.debug.core.IJavaBreakpoint;
+import org.eclipse.jdt.internal.debug.core.IJDIEventListener;
+import org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint;
+import org.eclipse.jdt.internal.debug.core.model.JDIDebugModelMessages;
+import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
+import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
+import org.eclipse.jdt.internal.debug.core.model.JDIThread;
+
+import com.sun.jdi.ClassType;
+import com.sun.jdi.IntegerValue;
+import com.sun.jdi.Method;
+import com.sun.jdi.ObjectCollectedException;
+import com.sun.jdi.ObjectReference;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.StringReference;
+import com.sun.jdi.ThreadReference;
+import com.sun.jdi.VMDisconnectedException;
+import com.sun.jdi.VirtualMachine;
+import com.sun.jdi.event.ClassPrepareEvent;
+import com.sun.jdi.event.Event;
+import com.sun.jdi.event.MethodEntryEvent;
+import com.sun.jdi.event.ThreadDeathEvent;
+import com.sun.jdi.event.ThreadStartEvent;
+import com.sun.jdi.event.VMStartEvent;
+import com.sun.jdi.request.ClassPrepareRequest;
+import com.sun.jdi.request.EventRequest;
+import com.sun.jdi.request.EventRequestManager;
+import com.sun.jdi.request.MethodEntryRequest;
+
+public class DroolsDebugTarget extends JDIDebugTarget {
+
+ private ArrayList fThreads;
+ private ThreadStartHandler fThreadStartHandler = null;
+ private boolean fSuspended = true;
+
+ public DroolsDebugTarget(ILaunch launch,
+ VirtualMachine jvm,
+ String name,
+ boolean supportTerminate,
+ boolean supportDisconnect,
+ IProcess process,
+ boolean resume) {
+ super( launch,
+ jvm,
+ name,
+ supportTerminate,
+ supportDisconnect,
+ process,
+ resume );
+ }
+
+ public void breakpointAdded(IBreakpoint breakpoint) {
+
+ try {
+ if ( breakpoint instanceof DroolsLineBreakpoint ) {
+ ((DroolsLineBreakpoint) breakpoint).setJavaBreakpointProperties();
+
+ final DroolsLineBreakpoint d = (DroolsLineBreakpoint) breakpoint;
+
+ if ( d.getDialectName().equals( MVELDialect.ID ) ) {
+ //getBreakpoints().add( breakpoint );
+ //super.breakpointAdded(breakpoint);
+
+ Iterator handleriter = getVM().classesByName( "org.drools.base.mvel.MVELDebugHandler" ).iterator();
+ if ( !handleriter.hasNext() ) {
+ // Create class prepare request to add breakpoint after MVELDebugHanlder is loaded
+ ClassPrepareRequest req = getEventRequestManager().createClassPrepareRequest();
+ req.addClassFilter( "org.drools.base.mvel.MVELDebugHandler" );
+ req.setSuspendPolicy( EventRequest.SUSPEND_ALL );
+
+ addJDIEventListener( new IJDIEventListener() {
+
+ public boolean handleEvent(Event event,
+ JDIDebugTarget target) {
+ addRemoteBreakpoint( d );
+ return true;
+ }
+
+ public void wonSuspendVote(Event event,
+ JDIDebugTarget target) {
+ }
+
+ },
+ req );
+
+ req.enable();
+ return;
+ }
+
+ addRemoteBreakpoint( d );
+ } else {
+ // only add breakpoint if setting Java properties of DRL
+ // breakpoint does not generate an error
+ super.breakpointAdded( breakpoint );
+ }
+ } else {
+ super.breakpointAdded( breakpoint );
+ }
+ } catch ( Throwable t ) {
+ // Exception will be thrown when trying to use breakpoint
+ // on drl that is incorrect (cannot be parsed or compiled)
+ DroolsEclipsePlugin.log( t );
+ }
+ }
+
+ protected synchronized void initialize() {
+ setThreadList( new ArrayList( 5 ) );
+ super.initialize();
+ }
+
+ protected JDIThread createThread(ThreadReference thread) {
+ JDIThread jdiThread = null;
+ try {
+ jdiThread = new DroolsThread( this,
+ thread );
+ } catch ( ObjectCollectedException exception ) {
+ // ObjectCollectionException can be thrown if the thread has already
+ // completed (exited) in the VM.
+ return null;
+ }
+ if ( isDisconnected() ) {
+ return null;
+ }
+ synchronized ( fThreads ) {
+ fThreads.add( jdiThread );
+ }
+ jdiThread.fireCreationEvent();
+ return jdiThread;
+ }
+
+ private Iterator getThreadIterator() {
+ List threadList;
+ synchronized ( fThreads ) {
+ threadList = (List) fThreads.clone();
+ }
+ return threadList.iterator();
+ }
+
+ private boolean hasSuspendedThreads() {
+ Iterator it = getThreadIterator();
+ while ( it.hasNext() ) {
+ IThread thread = (IThread) it.next();
+ if ( thread.isSuspended() ) return true;
+ }
+ return false;
+ }
+
+ public boolean canResume() {
+ return (isSuspended() || hasSuspendedThreads()) && isAvailable() && !isPerformingHotCodeReplace();
+ }
+
+ protected void resume(boolean fireNotification) throws DebugException {
+ if ( (!isSuspended() && !hasSuspendedThreads()) || !isAvailable() ) {
+ return;
+ }
+ try {
+ setSuspended( false );
+ resumeThreads();
+ VirtualMachine vm = getVM();
+ if ( vm != null ) {
+ vm.resume();
+ }
+ if ( fireNotification ) {
+ fireResumeEvent( DebugEvent.CLIENT_REQUEST );
+ }
+ } catch ( VMDisconnectedException e ) {
+ disconnected();
+ return;
+ } catch ( RuntimeException e ) {
+ setSuspended( true );
+ fireSuspendEvent( DebugEvent.CLIENT_REQUEST );
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIDebugTarget_exception_resume,
+ new String[]{e.toString()} ),
+ e );
+ }
+ }
+
+ private void setSuspended(boolean suspended) {
+ fSuspended = suspended;
+ }
+
+ public boolean isSuspended() {
+ return fSuspended;
+ }
+
+ private void setThreadList(ArrayList threads) {
+ fThreads = threads;
+ }
+
+ public IThread[] getThreads() {
+ synchronized ( fThreads ) {
+ return (IThread[]) fThreads.toArray( new IThread[0] );
+ }
+ }
+
+ protected void removeAllThreads() {
+ Iterator itr = getThreadIterator();
+ while ( itr.hasNext() ) {
+ DroolsThread child = (DroolsThread) itr.next();
+ child.terminated();
+ }
+ synchronized ( fThreads ) {
+ fThreads.clear();
+ }
+ }
+
+ protected void initializeRequests() {
+ setThreadStartHandler( new ThreadStartHandler() );
+ new ThreadDeathHandler();
+ new MVELTraceHandler();
+ }
+
+ class ThreadDeathHandler
+ implements
+ IJDIEventListener {
+
+ protected ThreadDeathHandler() {
+ createRequest();
+ }
+
+ /**
+ * Creates and registers a request to listen to thread
+ * death events.
+ */
+ protected void createRequest() {
+ EventRequestManager manager = getEventRequestManager();
+ if ( manager != null ) {
+ try {
+ EventRequest req = manager.createThreadDeathRequest();
+ req.setSuspendPolicy( EventRequest.SUSPEND_NONE );
+ req.enable();
+ addJDIEventListener( this,
+ req );
+ } catch ( RuntimeException e ) {
+ logError( e );
+ }
+ }
+ }
+
+ /**
+ * Locates the model thread associated with the underlying JDI thread
+ * that has terminated, and removes it from the collection of
+ * threads belonging to this debug target. A terminate event is
+ * fired for the model thread.
+ *
+ * @param event a thread death event
+ * @param target the target in which the thread died
+ * @return <code>true</code> - the thread should be resumed
+ */
+ public boolean handleEvent(Event event,
+ JDIDebugTarget target) {
+ ThreadReference ref = ((ThreadDeathEvent) event).thread();
+ DroolsThread thread = (DroolsThread) findThread( ref );
+ if ( thread != null ) {
+ synchronized ( fThreads ) {
+ fThreads.remove( thread );
+ }
+ thread.terminated();
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
+ */
+ public void wonSuspendVote(Event event,
+ JDIDebugTarget target) {
+ // do nothing
+ }
+
+ }
+
+ class ThreadStartHandler
+ implements
+ IJDIEventListener {
+
+ protected EventRequest fRequest;
+
+ protected ThreadStartHandler() {
+ createRequest();
+ }
+
+ /**
+ * Creates and registers a request to handle all thread start
+ * events
+ */
+ protected void createRequest() {
+ EventRequestManager manager = getEventRequestManager();
+ if ( manager != null ) {
+ try {
+ EventRequest req = manager.createThreadStartRequest();
+ req.setSuspendPolicy( EventRequest.SUSPEND_NONE );
+ req.enable();
+ addJDIEventListener( this,
+ req );
+ setRequest( req );
+ } catch ( RuntimeException e ) {
+ logError( e );
+ }
+ }
+ }
+
+ /**
+ * Creates a model thread for the underlying JDI thread
+ * and adds it to the collection of threads for this
+ * debug target. As a side effect of creating the thread,
+ * a create event is fired for the model thread.
+ * The event is ignored if the underlying thread is already
+ * marked as collected.
+ *
+ * @param event a thread start event
+ * @param target the target in which the thread started
+ * @return <code>true</code> - the thread should be resumed
+ */
+ public boolean handleEvent(Event event,
+ JDIDebugTarget target) {
+ ThreadReference thread = ((ThreadStartEvent) event).thread();
+ try {
+ if ( thread.isCollected() ) {
+ return false;
+ }
+ } catch ( VMDisconnectedException exception ) {
+ return false;
+ } catch ( ObjectCollectedException e ) {
+ return false;
+ } catch ( TimeoutException e ) {
+ // continue - attempt to create the thread
+ }
+ DroolsThread jdiThread = (DroolsThread) findThread( thread );
+ if ( jdiThread == null ) {
+ jdiThread = (DroolsThread) createThread( thread );
+ if ( jdiThread == null ) {
+ return false;
+ }
+ } else {
+ jdiThread.disposeStackFrames();
+ jdiThread.fireChangeEvent( DebugEvent.CONTENT );
+ }
+ return !jdiThread.isSuspended();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
+ */
+ public void wonSuspendVote(Event event,
+ JDIDebugTarget target) {
+ // do nothing
+ }
+
+ /**
+ * Deregisters this event listener.
+ */
+ protected void deleteRequest() {
+ if ( getRequest() != null ) {
+ removeJDIEventListener( this,
+ getRequest() );
+ setRequest( null );
+ }
+ }
+
+ protected EventRequest getRequest() {
+ return fRequest;
+ }
+
+ protected void setRequest(EventRequest request) {
+ fRequest = request;
+ }
+ }
+
+ private void disposeThreadHandler() {
+ ThreadStartHandler handler = getThreadStartHandler2();
+ if ( handler != null ) {
+ handler.deleteRequest();
+ }
+ }
+
+ public boolean hasThreads() {
+ return fThreads.size() > 0;
+ }
+
+ protected ThreadStartHandler getThreadStartHandler2() {
+ return fThreadStartHandler;
+ }
+
+ protected void setThreadStartHandler(ThreadStartHandler threadStartHandler) {
+ fThreadStartHandler = threadStartHandler;
+ }
+
+ public boolean isOutOfSynch() throws DebugException {
+ Iterator threads = getThreadIterator();
+ while ( threads.hasNext() ) {
+ JDIThread thread = (JDIThread) threads.next();
+ if ( thread.isOutOfSynch() ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean mayBeOutOfSynch() {
+ Iterator threads = getThreadIterator();
+ while ( threads.hasNext() ) {
+ JDIThread thread = (JDIThread) threads.next();
+ if ( thread.mayBeOutOfSynch() ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public JDIThread findThread(ThreadReference tr) {
+ Iterator iter = getThreadIterator();
+ while ( iter.hasNext() ) {
+ JDIThread thread = (JDIThread) iter.next();
+ if ( thread.getUnderlyingThread().equals( tr ) ) return thread;
+ }
+ return null;
+ }
+
+ public void breakpointRemoved(IBreakpoint breakpoint,
+ IMarkerDelta delta) {
+ if ( !isAvailable() ) {
+ return;
+ }
+ if ( supportsBreakpoint( breakpoint ) ) {
+ try {
+
+ if ( breakpoint instanceof DroolsLineBreakpoint ) {
+ ((DroolsLineBreakpoint) breakpoint).setJavaBreakpointProperties();
+
+ final DroolsLineBreakpoint d = (DroolsLineBreakpoint) breakpoint;
+
+ if ( d.getDialectName().equals( MVELDialect.ID ) ) {
+ removeRemoteBreakpoint( (DroolsLineBreakpoint) breakpoint,
+ delta );
+ }
+ }
+
+ ((JavaBreakpoint) breakpoint).removeFromTarget( this );
+ getBreakpoints().remove( breakpoint );
+ Iterator threads = getThreadIterator();
+ while ( threads.hasNext() ) {
+ ((DroolsThread) threads.next()).removeCurrentBreakpoint( breakpoint );
+ }
+ } catch ( CoreException e ) {
+ logError( e );
+ }
+ }
+ }
+
+ protected void suspendThreads() {
+ Iterator threads = getThreadIterator();
+ while ( threads.hasNext() ) {
+ ((DroolsThread) threads.next()).suspendedByVM();
+ }
+ }
+
+ protected void resumeThreads() throws DebugException {
+ Iterator threads = getThreadIterator();
+ while ( threads.hasNext() ) {
+ ((DroolsThread) threads.next()).resumedByVM();
+ }
+ }
+
+ public void disconnect() throws DebugException {
+
+ if ( !isAvailable() ) {
+ // already done
+ return;
+ }
+
+ if ( !canDisconnect() ) {
+ notSupported( JDIDebugModelMessages.JDIDebugTarget_does_not_support_disconnect );
+ }
+
+ try {
+ disposeThreadHandler();
+ VirtualMachine vm = getVM();
+ if ( vm != null ) {
+ vm.dispose();
+ }
+ } catch ( VMDisconnectedException e ) {
+ // if the VM disconnects while disconnecting, perform
+ // normal disconnect handling
+ disconnected();
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIDebugTarget_exception_disconnecting,
+ new String[]{e.toString()} ),
+ e );
+ }
+
+ }
+
+ public void terminate() throws DebugException {
+ if ( !isAvailable() ) {
+ return;
+ }
+ if ( !supportsTerminate() ) {
+ notSupported( JDIDebugModelMessages.JDIDebugTarget_does_not_support_termination );
+ }
+ try {
+ setTerminating( true );
+ disposeThreadHandler();
+ VirtualMachine vm = getVM();
+ if ( vm != null ) {
+ vm.exit( 1 );
+ }
+ IProcess process = getProcess();
+ if ( process != null ) {
+ process.terminate();
+ }
+ } catch ( VMDisconnectedException e ) {
+ // if the VM disconnects while exiting, perform
+ // normal termination processing
+ terminated();
+ } catch ( TimeoutException exception ) {
+ // if there is a timeout see if the associated process is terminated
+ IProcess process = getProcess();
+ if ( process != null && process.isTerminated() ) {
+ terminated();
+ } else {
+ // All we can do is disconnect
+ disconnected();
+ }
+ } catch ( RuntimeException e ) {
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIDebugTarget_exception_terminating,
+ new String[]{e.toString()} ),
+ e );
+ }
+ }
+
+ public void handleVMStart(VMStartEvent event) {
+ if ( isResumeOnStartup() ) {
+ try {
+ setSuspended( true );
+ resume();
+ } catch ( DebugException e ) {
+ logError( e );
+ }
+ }
+ // If any threads have resumed since thread collection was initialized,
+ // update their status (avoid concurrent modification - use #getThreads())
+ IThread[] threads = getThreads();
+ for ( int i = 0; i < threads.length; i++ ) {
+ DroolsThread thread = (DroolsThread) threads[i];
+ if ( thread.isSuspended() ) {
+ try {
+ boolean suspended = thread.getUnderlyingThread().isSuspended();
+ if ( !suspended ) {
+ thread.setRunning( true );
+ thread.fireResumeEvent( DebugEvent.CLIENT_REQUEST );
+ }
+ } catch ( VMDisconnectedException e ) {
+ } catch ( ObjectCollectedException e ) {
+ } catch ( RuntimeException e ) {
+ logError( e );
+ }
+ }
+ }
+ }
+
+ protected void initializeState() {
+
+ List threads = null;
+ VirtualMachine vm = getVM();
+ if ( vm != null ) {
+ try {
+ threads = vm.allThreads();
+ } catch ( RuntimeException e ) {
+ internalError( e );
+ }
+ if ( threads != null ) {
+ Iterator initialThreads = threads.iterator();
+ while ( initialThreads.hasNext() ) {
+ createThread( (ThreadReference) initialThreads.next() );
+ }
+ }
+ }
+
+ if ( isResumeOnStartup() ) {
+ setSuspended( false );
+ }
+ }
+
+ public void suspend() throws DebugException {
+ if ( isSuspended() ) {
+ return;
+ }
+ try {
+ VirtualMachine vm = getVM();
+ if ( vm != null ) {
+ vm.suspend();
+ }
+ suspendThreads();
+ setSuspended( true );
+ fireSuspendEvent( DebugEvent.CLIENT_REQUEST );
+ } catch ( RuntimeException e ) {
+ setSuspended( false );
+ fireResumeEvent( DebugEvent.CLIENT_REQUEST );
+ targetRequestFailed( MessageFormat.format( JDIDebugModelMessages.JDIDebugTarget_exception_suspend,
+ new String[]{e.toString()} ),
+ e );
+ }
+ }
+
+ public void prepareToSuspendByBreakpoint(JavaBreakpoint breakpoint) {
+ setSuspended( true );
+ suspendThreads();
+ }
+
+ protected void cancelSuspendByBreakpoint(JavaBreakpoint breakpoint) throws DebugException {
+ setSuspended( false );
+ resumeThreads();
+ }
+
+ class MVELTraceHandler
+ implements
+ IJDIEventListener {
+
+ protected MVELTraceHandler() {
+ createRequest();
+ }
+
+ protected void createRequest() {
+ EventRequestManager manager = getEventRequestManager();
+ if ( manager != null ) {
+ try {
+ ClassPrepareRequest req = manager.createClassPrepareRequest();
+ req.addClassFilter( "org.drools.base.mvel.MVELDebugHandler" );
+ req.setSuspendPolicy( EventRequest.SUSPEND_ALL );
+ addJDIEventListener( MVELTraceHandler.this,
+ req );
+ req.enable();
+
+ } catch ( RuntimeException e ) {
+ logError( e );
+ }
+ }
+ }
+
+ /**
+ * Locates the model thread associated with the underlying JDI thread
+ * that has terminated, and removes it from the collection of
+ * threads belonging to this debug target. A terminate event is
+ * fired for the model thread.
+ *
+ * @param event a thread death event
+ * @param target the target in which the thread died
+ * @return <code>true</code> - the thread should be resumed
+ */
+ public boolean handleEvent(Event event,
+ JDIDebugTarget target) {
+ String name = ((ClassPrepareEvent) event).referenceType().name();
+
+ MethodEntryRequest req = getEventRequestManager().createMethodEntryRequest();
+ req.addClassFilter( ((ClassPrepareEvent) event).referenceType() );
+
+ //breakpointCatched
+
+ /*field= type.fieldByName(getFieldName());
+ Field field;
+ EventRequest req= manager.createModificationWatchpointRequest(field);
+ */
+ req.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD );
+ addJDIEventListener( new IJDIEventListener() {
+
+ public boolean handleEvent(Event event,
+ JDIDebugTarget target) {
+ MethodEntryEvent entryEvent = (MethodEntryEvent) event;
+
+ String name2 = entryEvent.method().name();
+
+ if ( !name2.equals( "onBreak" ) && !name2.equals( "receiveBreakpoints" ) ) {
+ //event.virtualMachine().resume();
+ return true;
+ }
+
+ try {
+ IThread[] tharr = getThreads();
+
+ ThreadReference t = null;
+ DroolsThread t2 = null;
+
+ for ( int i = 0; i < tharr.length; i++ ) {
+ DroolsThread th2 = (DroolsThread) tharr[i];
+ ThreadReference th2real = ((DroolsThread) tharr[i]).getUnderlyingThread();
+
+ //MVEL It doesn't have to be always main. find a better way for detection
+ if ( th2real.suspendCount() == 1 && th2.getName().equals( "main" ) ) {
+ t = th2real;
+ t2 = (DroolsThread) th2;
+
+ th2real.suspend();
+ th2.setRunning( false );
+ th2.fireSuspendEvent( DebugEvent.CLIENT_REQUEST );
+
+ return true;
+ }
+ }
+ } catch ( Exception t ) {
+ logError( t );
+ }
+ return true;
+
+ }
+
+ public void wonSuspendVote(Event event,
+ JDIDebugTarget target) {
+ // TODO Auto-generated method stub
+
+ }
+
+ },
+ req );
+
+ req.enable();
+
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
+ */
+ public void wonSuspendVote(Event event,
+ JDIDebugTarget target) {
+ // do nothing
+ }
+
+ }
+
+ public Object getDroolsBreakpoint(String source,
+ int line) {
+ Iterator iterator = getBreakpoints().iterator();
+ while ( iterator.hasNext() ) {
+ IJavaBreakpoint element = (IJavaBreakpoint) iterator.next();
+ if ( element instanceof DroolsLineBreakpoint ) {
+ DroolsLineBreakpoint l = (DroolsLineBreakpoint) element;
+ try {
+
+ if ( l == null || source == null ) {
+ return null;
+ }
+ if ( l.getLineNumber() == line && source.equals( l.getRuleName() ) ) {
+ return l;
+ }
+ } catch ( CoreException e ) {
+ logError( e );
+ }
+ }
+ }
+ return null;
+ }
+
+ private void addRemoteBreakpoint(DroolsLineBreakpoint d) {
+
+ try {
+ if (!d.isEnabled()) {
+ return; // No need to install disabled breakpoints
+ }
+ } catch ( CoreException e2 ) {
+ logError( e2 );
+ return; // No need to install breakpoints that are this much broken
+ }
+
+ Iterator handleriter = getVM().classesByName( "org.drools.base.mvel.MVELDebugHandler" ).iterator();
+ Object debugHandlerClass = handleriter.next();
+
+
+ int line;
+ String sourceName;
+
+ try {
+ line = d.getLineNumber();
+ sourceName = d.getTypeName();
+ } catch ( CoreException e1 ) {
+ logError( e1 );
+ return;
+ }
+
+ ReferenceType refType = (ReferenceType) debugHandlerClass;
+ Method m = (Method) refType.methodsByName( "registerBreakpoint" ).iterator().next();
+ List args = new ArrayList();
+ IntegerValue lineVal = getVM().mirrorOf( line );
+ StringReference nameVal = getVM().mirrorOf( sourceName );
+ JDIObjectValue val = (JDIObjectValue) newValue( sourceName );
+ ObjectReference realVal = val.getUnderlyingObject();
+ args.add( nameVal );
+ args.add( lineVal );
+
+ try {
+ ClassType tt = (ClassType) debugHandlerClass;
+ IThread[] tharr = getThreads();
+ ThreadReference t = null;
+ DroolsThread t2 = null;
+
+ for ( int i = 0; i < tharr.length; i++ ) {
+ IThread th2 = tharr[i];
+ ThreadReference th2real = ((DroolsThread) tharr[i]).getUnderlyingThread();
+ //MVEL It doesn't have to be always main. find a better way for detection. suspend count is most likely only at one thread so a bit more error-safe
+ if ( th2real.suspendCount() == 1 && th2.getName().equals( "main" ) ) {
+ t = th2real;
+ t2 = (DroolsThread) th2;
+ }
+ }
+
+ tt.invokeMethod( t,
+ m,
+ args,
+ ObjectReference.INVOKE_SINGLE_THREADED );
+ //t2.computeNewStackFrames();
+
+ super.breakpointAdded( d );
+
+ } catch ( Exception e ) {
+ logError( e );
+ }
+
+ }
+
+ private void removeRemoteBreakpoint(DroolsLineBreakpoint d,
+ IMarkerDelta delta) {
+ Iterator handleriter = getVM().classesByName( "org.drools.base.mvel.MVELDebugHandler" ).iterator();
+ Object debugHandlerClass = handleriter.next();
+
+ int line;
+ String sourceName;
+
+ try {
+ line = d.getLineNumber();
+ sourceName = d.getTypeName();
+ } catch ( CoreException e1 ) {
+ logError( e1 );
+ return;
+ }
+
+ ReferenceType refType = (ReferenceType) debugHandlerClass;
+ Method m = (Method) refType.methodsByName( "removeBreakpoint" ).iterator().next();
+ List args = new ArrayList();
+ IntegerValue lineVal = getVM().mirrorOf( line );
+ StringReference nameVal = getVM().mirrorOf( sourceName );
+ JDIObjectValue val = (JDIObjectValue) newValue( sourceName );
+ ObjectReference realVal = val.getUnderlyingObject();
+ args.add( nameVal );
+ args.add( lineVal );
+
+ try {
+ ClassType tt = (ClassType) debugHandlerClass;
+ IThread[] tharr = getThreads();
+ ThreadReference t = null;
+ DroolsThread t2 = null;
+
+ for ( int i = 0; i < tharr.length; i++ ) {
+ IThread th2 = tharr[i];
+ ThreadReference th2real = ((DroolsThread) tharr[i]).getUnderlyingThread();
+ //MVEL It doesn't have to be always main. find a better way for detection. suspend count is most likely only at one thread so a bit more error-safe
+ if ( th2real.suspendCount() == 1 && th2.getName().equals( "main" ) ) {
+ t = th2real;
+ t2 = (DroolsThread) th2;
+ }
+ }
+
+ tt.invokeMethod( t,
+ m,
+ args,
+ ObjectReference.INVOKE_SINGLE_THREADED );
+
+ } catch ( Exception e ) {
+ logError( e );
+ }
+
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -7,104 +7,137 @@
import org.drools.eclipse.DroolsEclipsePlugin;
import org.drools.eclipse.DRLInfo.FunctionInfo;
import org.drools.eclipse.DRLInfo.RuleInfo;
+import org.drools.rule.builder.dialect.mvel.MVELDialect;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint;
public class DroolsLineBreakpoint extends JavaLineBreakpoint {
-
- /**
- * Default constructor is required for the breakpoint manager
- * to re-create persisted breakpoints. After instantiating a breakpoint,
- * the <code>setMarker(...)</code> method is called to restore
- * this breakpoint's attributes.
- */
- public DroolsLineBreakpoint() {
- }
-
- /**
- * Constructs a line breakpoint on the given resource at the given
- * line number.
- *
- * @param resource file on which to set the breakpoint
- * @param lineNumber line number of the breakpoint
- * @throws CoreException if unable to create the breakpoint
- */
- public DroolsLineBreakpoint(IResource resource, int lineNumber)
+
+ private static final String DIALECT = "org.drools.eclipse.debug.core.breakpointDialect";
+
+ /**
+ * Default constructor is required for the breakpoint manager
+ * to re-create persisted breakpoints. After instantiating a breakpoint,
+ * the <code>setMarker(...)</code> method is called to restore
+ * this breakpoint's attributes.
+ */
+ public DroolsLineBreakpoint() {
+ super();
+ }
+
+ /**
+ * Constructs a line breakpoint on the given resource at the given
+ * line number.
+ *
+ * @param resource file on which to set the breakpoint
+ * @param lineNumber line number of the breakpoint
+ * @throws CoreException if unable to create the breakpoint
+ */
+ public DroolsLineBreakpoint(IResource resource, int lineNumber)
throws CoreException {
- super(resource, "", -1, -1, -1, 0, true,
- createAttributesMap(lineNumber), IDroolsDebugConstants.DROOLS_MARKER_TYPE);
- }
-
- private static Map createAttributesMap(int lineNumber) {
- Map map = new HashMap();
- map.put(IDroolsDebugConstants.DRL_LINE_NUMBER, new Integer(lineNumber));
- return map;
- }
-
- public int getDRLLineNumber() {
- return getMarker().getAttribute(IDroolsDebugConstants.DRL_LINE_NUMBER, -1);
- }
-
- public String getModelIdentifier() {
- return IDroolsDebugConstants.ID_DROOLS_DEBUG_MODEL;
- }
-
- public void setJavaBreakpointProperties() throws CoreException {
- IMarker marker = getMarker();
- int drlLineNumber = getDRLLineNumber();
- if (marker.exists()) {
- marker.setAttribute(TYPE_NAME, getRuleClassName(marker.getResource(), drlLineNumber));
- marker.setAttribute(IMarker.LINE_NUMBER, getRuleLineNumber(getMarker().getResource(), drlLineNumber));
- }
- }
-
- private String getRuleClassName(IResource resource, int lineNumber) throws CoreException {
- try {
- DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(resource, true);
- if (drlInfo != null) {
- RuleInfo ruleInfo = drlInfo.getRuleInfo(lineNumber);
- if (ruleInfo != null) {
- return ruleInfo.getClassName();
- }
- FunctionInfo functionInfo = drlInfo.getFunctionInfo(lineNumber);
- if (functionInfo != null) {
- return functionInfo.getClassName();
- }
- }
- throw new CoreException(new Status(IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
- "Cannot determine ruleClassName for " + resource + " " + lineNumber, null));
- } catch (Throwable t) {
- throw new CoreException(new Status(IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
- "Cannot determine ruleClassName for " + resource + " " + lineNumber, t));
- }
- }
-
- private int getRuleLineNumber(IResource resource, int lineNumber) throws CoreException {
- try {
- DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(resource, true);
- if (drlInfo != null) {
- RuleInfo ruleInfo = drlInfo.getRuleInfo(lineNumber);
- if (ruleInfo != null) {
- if (ruleInfo.getConsequenceDrlLineNumber() < lineNumber) {
- return ruleInfo.getConsequenceJavaLineNumber()
- + (lineNumber - ruleInfo.getConsequenceDrlLineNumber() + 1);
- }
- }
- FunctionInfo functionInfo = drlInfo.getFunctionInfo(lineNumber);
- if (functionInfo != null) {
- return functionInfo.getJavaLineNumber()
- + (lineNumber - functionInfo.getDrlLineNumber());
- }
- }
- throw new CoreException(new Status(IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
- "Cannot determine ruleLineNumber for " + resource + " " + lineNumber, null));
- } catch(Throwable t) {
- throw new CoreException(new Status(IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
- "Cannot determine ruleLineNumber for " + resource + " " + lineNumber, t));
- }
- }
+ super( resource, "", -1, -1, -1, 0, true,
+ createAttributesMap( lineNumber ), IDroolsDebugConstants.DROOLS_MARKER_TYPE );
+ setJavaBreakpointProperties();
+ }
+
+ private static Map createAttributesMap(int lineNumber) {
+ Map map = new HashMap();
+ map.put( IDroolsDebugConstants.DRL_LINE_NUMBER, new Integer( lineNumber ) );
+ return map;
+ }
+
+ public int getDRLLineNumber() {
+ return getMarker().getAttribute( IDroolsDebugConstants.DRL_LINE_NUMBER, -1 );
+ }
+
+ public String getModelIdentifier() {
+ return IDroolsDebugConstants.ID_DROOLS_DEBUG_MODEL;
+ }
+
+ public String getDialectName() {
+ return getMarker().getAttribute( DIALECT, "Unknown");
+ }
+
+ public void setJavaBreakpointProperties() throws CoreException {
+ IMarker marker = getMarker();
+ int drlLineNumber = getDRLLineNumber();
+ if ( marker.exists() ) {
+ try {
+ DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource( marker.getResource(), true );
+
+ marker.setAttribute( TYPE_NAME, getRuleClassName( drlInfo, marker.getResource().toString(), drlLineNumber ) );
+ int ruleLineNumber = getRuleLineNumber( drlInfo, marker.getResource().toString(), drlLineNumber );
+ marker.setAttribute( IMarker.LINE_NUMBER, ruleLineNumber );
+ marker.setAttribute( DIALECT, getDialect( drlInfo, drlLineNumber ) );
+
+ } catch ( Throwable t ) {
+ throw new CoreException( new Status( IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
+ "Cannot determine ruleInfo " + marker.getResource() + " " + drlLineNumber, t ) );
+ }
+ }
+ }
+
+ private String getDialect(DRLInfo info, int drlLineNumber) {
+ if ( info != null ) {
+ return info.getRuleInfo( drlLineNumber ).getDialect().getId();
+ }
+ return null;
+ }
+
+ private String getRuleClassName(DRLInfo drlInfo, String resource, int lineNumber) throws CoreException {
+ if ( drlInfo != null ) {
+ RuleInfo ruleInfo = drlInfo.getRuleInfo( lineNumber );
+ if ( ruleInfo != null ) {
+ return ruleInfo.getClassName();
+ }
+ FunctionInfo functionInfo = drlInfo.getFunctionInfo( lineNumber );
+ if ( functionInfo != null ) {
+ return functionInfo.getClassName();
+ }
+ }
+ throw new CoreException( new Status( IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
+ "Cannot determine ruleClassName for " + resource + " " + lineNumber, null ) );
+ }
+
+ private int getRuleLineNumber(DRLInfo drlInfo, String resource, int lineNumber) throws CoreException {
+ if ( drlInfo != null ) {
+ RuleInfo ruleInfo = drlInfo.getRuleInfo( lineNumber );
+ if ( ruleInfo != null ) {
+ if ( ruleInfo.getConsequenceDrlLineNumber() < lineNumber ) {
+
+ int line = ruleInfo.getConsequenceJavaLineNumber()
+ + (lineNumber - ruleInfo.getConsequenceDrlLineNumber());
+ if (ruleInfo.getDialect().getId().equals( MVELDialect.ID )) {
+ return line;
+ }
+ return line+1;
+ }
+ }
+ FunctionInfo functionInfo = drlInfo.getFunctionInfo( lineNumber );
+ if ( functionInfo != null ) {
+ return functionInfo.getJavaLineNumber()
+ + (lineNumber - functionInfo.getDrlLineNumber());
+ }
+ }
+ throw new CoreException( new Status( IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
+ "Cannot determine ruleLineNumber for " + resource + " " + lineNumber, null ) );
+ }
+
+ public String getRuleName() {
+ IMarker marker = getMarker();
+ if ( marker.exists() ) {
+ try {
+ return (String) marker.getAttribute( TYPE_NAME);
+ } catch ( CoreException e ) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -74,10 +74,11 @@
String methodName = getMethodName();
String signature = getSignature();
String type = getDeclaringTypeName();
- if ("consequence".equals(methodName) && signature.startsWith(CONSEQUENCE_SIGNATURE)) {
+ if ("consequence".equals(methodName) && signature.startsWith(CONSEQUENCE_SIGNATURE)) {
return DroolsEclipsePlugin.getDefault().getRuleInfoByClass(type);
}
- } catch (DebugException exc) {
+
+ } catch (DebugException exc) {
DroolsEclipsePlugin.log(exc);
}
return null;
@@ -97,13 +98,14 @@
synchronized (fThread) {
RuleInfo ruleInfo = getExecutingRuleInfo();
if (ruleInfo != null) {
- return ruleInfo.getConsequenceDrlLineNumber() + (getInternalLineNumber() - ruleInfo.getConsequenceJavaLineNumber() - 1);
+ return ruleInfo.getConsequenceDrlLineNumber() + (getInternalLineNumber() - ruleInfo.getConsequenceJavaLineNumber() - 1);
}
FunctionInfo functionInfo = getExecutingFunctionInfo();
if (functionInfo != null) {
return functionInfo.getDrlLineNumber() + (getInternalLineNumber() - functionInfo.getJavaLineNumber());
}
}
+
return getInternalLineNumber();
}
@@ -197,46 +199,50 @@
}
}
- protected JDIStackFrame bind(StackFrame frame, int depth) {
- if (initialized) {
- synchronized (fThread) {
- if (fDepth == -2) {
- // first initialization
- fStackFrame = frame;
- fDepth = depth;
- fLocation = frame.location();
- return this;
- } else if (depth == -1) {
- // mark as invalid
- fDepth = -1;
- fStackFrame = null;
- return null;
- } else if (fDepth == depth) {
- Location location = frame.location();
- Method method = location.method();
- if (method.equals(fLocation.method())) {
- try {
- if (method.declaringType().defaultStratum().equals("Java") || //$NON-NLS-1$
- equals(getSourceName(location), getSourceName(fLocation))) {
- // TODO: what about receiving type being the same?
- fStackFrame = frame;
- fLocation = location;
- clearCachedData();
- return this;
- }
- } catch (DebugException e) {
- }
- }
- }
+ protected JDIStackFrame bind(StackFrame frame, int depth) {
+ if (initialized) {
+ synchronized (fThread) {
+ if (fDepth == -2) {
+ // first initialization
+ fStackFrame = frame;
+ fDepth = depth;
+ fLocation = frame.location();
+ return this;
+ } else if (depth == -1) {
+ // mark as invalid
+ fDepth = -1;
+ fStackFrame = null;
+ return null;
+ } else if (fDepth == depth) {
+ Location location = frame.location();
+ Method method = location.method();
+ if (method.equals(fLocation.method())) {
+ try {
+ if (method.declaringType().defaultStratum().equals("Java") || //$NON-NLS-1$
+ equals(getSourceName(location), getSourceName(fLocation))) {
+ // TODO: what about receiving type being the same?
+ fStackFrame = frame;
+ fLocation = location;
+ clearCachedData();
+ return this;
+ }
+ } catch (DebugException e) {
+ }
+ }
+ }
// invalidate this franme
- bind(null, -1);
- // return a new frame
- return new DroolsStackFrame(fThread, frame, depth);
- }
- } else {
- return null;
- }
- }
+ bind(null, -1);
+ // return a new frame
+ return createNewDroolsFrame(frame, depth);
+ }
+ } else {
+ return null;
+ }
+ }
+
+ protected DroolsStackFrame createNewDroolsFrame(StackFrame frame, int depth) {
+ return DroolsThread.createCustomFrame( fThread, depth, frame );
+ }
public IThread getThread() {
return fThread;
@@ -569,4 +575,5 @@
return locals;
}
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -15,9 +15,13 @@
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
import org.eclipse.jdt.internal.debug.core.model.JDIThread;
+import com.sun.jdi.ClassType;
import com.sun.jdi.IncompatibleThreadStateException;
import com.sun.jdi.InvalidStackFrameException;
+import com.sun.jdi.Location;
+import com.sun.jdi.Method;
import com.sun.jdi.ObjectCollectedException;
+import com.sun.jdi.ObjectReference;
import com.sun.jdi.StackFrame;
import com.sun.jdi.ThreadReference;
@@ -25,7 +29,7 @@
private List fStackFrames;
private boolean fRefreshChildren = true;
-
+
public DroolsThread(JDIDebugTarget target, ThreadReference thread) throws ObjectCollectedException {
super(target, thread);
}
@@ -34,11 +38,11 @@
super.initialize();
fStackFrames = new ArrayList();
}
-
+
public synchronized List computeStackFrames() throws DebugException {
return computeStackFrames(fRefreshChildren);
}
-
+
protected synchronized List computeStackFrames(boolean refreshChildren) throws DebugException {
if (isSuspended()) {
if (isTerminated()) {
@@ -55,7 +59,16 @@
int newFrames = newSize - oldSize; // number of frames to create, if any
int depth = oldSize;
for (int i = newFrames - 1; i >= 0; i--) {
- fStackFrames.add(0, new DroolsStackFrame(this, (StackFrame) frames.get(i), depth));
+ StackFrame currentFrame = (StackFrame) frames.get(i);
+ //MVEL: create an mvel stack frame when the declaring type is our debugger?
+
+ DroolsStackFrame customFrame;
+
+ customFrame = createCustomFrame( this, depth,
+ currentFrame );
+
+ fStackFrames.add( 0, customFrame );
+
depth++;
}
int numToRebind = Math.min(newSize, oldSize); // number of frames to attempt to rebind
@@ -69,8 +82,8 @@
}
offset--;
}
-
+
}
fRefreshChildren = false;
} else {
@@ -78,22 +91,35 @@
}
return fStackFrames;
}
-
+
+ public final static DroolsStackFrame createCustomFrame(DroolsThread thread, int depth,
+ StackFrame currentFrame) {
+ DroolsStackFrame customFrame;
+ Location loc = currentFrame.location();
+ if ( loc.declaringType().name().equals( "org.drools.base.mvel.MVELDebugHandler" )
+ && loc.method().name().equals( "onBreak" ) ) {
+ customFrame = new MVELStackFrame( thread, currentFrame, depth );
+ } else {
+ customFrame = new DroolsStackFrame( thread, currentFrame, depth );
+ }
+ return customFrame;
+ }
+
private List getUnderlyingFrames() throws DebugException {
if (!isSuspended()) {
// Checking isSuspended here eliminates a race condition in resume
// between the time stack frames are preserved and the time the
// underlying thread is actually resumed.
- requestFailed(JDIDebugModelMessages.JDIThread_Unable_to_retrieve_stack_frame___thread_not_suspended__1, null, IJavaThread.ERR_THREAD_NOT_SUSPENDED);
+ requestFailed(JDIDebugModelMessages.JDIThread_Unable_to_retrieve_stack_frame___thread_not_suspended__1, null, IJavaThread.ERR_THREAD_NOT_SUSPENDED);
}
try {
return getUnderlyingThread().frames();
} catch (IncompatibleThreadStateException e) {
- requestFailed(JDIDebugModelMessages.JDIThread_Unable_to_retrieve_stack_frame___thread_not_suspended__1, e, IJavaThread.ERR_THREAD_NOT_SUSPENDED);
+ requestFailed(JDIDebugModelMessages.JDIThread_Unable_to_retrieve_stack_frame___thread_not_suspended__1, e, IJavaThread.ERR_THREAD_NOT_SUSPENDED);
} catch (RuntimeException e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThread_exception_retrieving_stack_frames_2, new String[] {e.toString()}), e);
+ targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThread_exception_retrieving_stack_frames_2, new String[] {e.toString()}), e);
} catch (InternalError e) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThread_exception_retrieving_stack_frames_2, new String[] {e.toString()}), e);
+ targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThread_exception_retrieving_stack_frames_2, new String[] {e.toString()}), e);
}
// execution will not reach this line, as
// #targetRequestFailed will thrown an exception
@@ -112,7 +138,7 @@
fStackFrames.clear();
fRefreshChildren = true;
}
-
+
protected void popFrame(IStackFrame frame) throws DebugException {
JDIDebugTarget target= (JDIDebugTarget)getDebugTarget();
if (target.canPopFrames()) {
@@ -134,27 +160,27 @@
size= computeStackFrames().size();
}
} catch (IncompatibleThreadStateException exception) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThread_exception_popping, new String[] {exception.toString()}),exception);
+ targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThread_exception_popping, new String[] {exception.toString()}),exception);
} catch (InvalidStackFrameException exception) {
// InvalidStackFrameException can be thrown when all but the
// deepest frame were popped. Fire a changed notification
// in case this has occured.
fireChangeEvent(DebugEvent.CONTENT);
- targetRequestFailed(exception.toString(),exception);
+ targetRequestFailed(exception.toString(),exception);
} catch (RuntimeException exception) {
- targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThread_exception_popping, new String[] {exception.toString()}),exception);
+ targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThread_exception_popping, new String[] {exception.toString()}),exception);
}
}
}
-
+
protected void terminated() {
super.terminated();
}
-
+
protected void removeCurrentBreakpoint(IBreakpoint bp) {
super.removeCurrentBreakpoint(bp);
}
-
+
protected synchronized void suspendedByVM() {
super.suspendedByVM();
}
@@ -162,17 +188,28 @@
protected synchronized void resumedByVM() throws DebugException {
super.resumedByVM();
}
-
+
protected void setRunning(boolean running) {
super.setRunning(running);
}
-
+
protected void dropToFrame(IStackFrame frame) throws DebugException {
super.dropToFrame(frame);
}
-
+
protected synchronized void stepToFrame(IStackFrame frame) throws DebugException {
super.stepToFrame(frame);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.debug.core.model.JDIThread#newInstance(com.sun.jdi.ClassType, com.sun.jdi.Method, java.util.List)
+ */
+ public ObjectReference newInstance(ClassType receiverClass,
+ Method constructor,
+ List args) throws DebugException {
+ return super.newInstance( receiverClass,
+ constructor,
+ args );
+ }
+
}
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,333 @@
+package org.drools.eclipse.debug.core;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.DRLInfo.RuleInfo;
+import org.drools.eclipse.debug.DebugUtil;
+import org.drools.eclipse.debug.VariableWrapper;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IValue;
+import org.eclipse.debug.core.model.IVariable;
+import org.eclipse.jdi.internal.StackFrameImpl;
+import org.eclipse.jdt.debug.core.IJavaValue;
+import org.eclipse.jdt.internal.debug.core.model.JDILocalVariable;
+import org.eclipse.jdt.internal.debug.core.model.JDINullValue;
+import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
+
+import com.sun.jdi.AbsentInformationException;
+import com.sun.jdi.ArrayReference;
+import com.sun.jdi.BooleanValue;
+import com.sun.jdi.ClassNotLoadedException;
+import com.sun.jdi.ClassType;
+import com.sun.jdi.Field;
+import com.sun.jdi.IncompatibleThreadStateException;
+import com.sun.jdi.IntegerValue;
+import com.sun.jdi.InvalidTypeException;
+import com.sun.jdi.InvocationException;
+import com.sun.jdi.LocalVariable;
+import com.sun.jdi.Method;
+import com.sun.jdi.ObjectReference;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.StackFrame;
+import com.sun.jdi.StringReference;
+import com.sun.jdi.ThreadReference;
+import com.sun.jdi.Value;
+
+public class MVELStackFrame extends DroolsStackFrame {
+
+ public MVELStackFrame(DroolsThread thread,
+ StackFrame frame,
+ int depth) {
+ super( thread,
+ frame,
+ depth );
+ //MVEL:Logging
+ try {
+ Iterator i = thread.getUnderlyingThread().frames().iterator();
+ while ( i.hasNext() ) {
+ StackFrameImpl o = (StackFrameImpl) i.next();
+ }
+ } catch ( IncompatibleThreadStateException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ public IVariable[] getVariables() throws DebugException {
+ /* IVariable[] variables = super.getVariables();
+ List result = new ArrayList((variables.length - 1)/2);
+ for (int i = 0; i < variables.length; i++) {
+ String name = variables[i].getName();
+ if (!(name.equals("drools")) && !(name.endsWith("__Handle__"))) {
+ result.add(variables[i]);
+ }
+ }
+ */
+
+ List result = new ArrayList( 0 );
+
+ Method method = getUnderlyingMethod(); // onBreak
+ ReferenceType declaringType = method.declaringType(); // org.drools.base.mvel.MVELDebugHandler
+
+ //ReferenceType declaringType = .location().declaringType();
+ try {
+
+ Object var = method.variables().get( 0 );
+ LocalVariable v2 = (LocalVariable) var;
+ DroolsLocalVariable frameLocal = new DroolsLocalVariable( this,
+ v2 );
+ result.add( frameLocal );
+
+ IValue knownVars = DebugUtil.getValueByExpression( "return getFactory().getKnownVariables().toArray(new String[0]);", frameLocal.getValue());
+
+ IValue factory = DebugUtil.getValueByExpression( "return getFactory();", frameLocal.getValue());
+
+ JDIObjectValue vvv = (JDIObjectValue) knownVars;
+
+ if (vvv!=null) {
+ ArrayReference arr = (ArrayReference) vvv.getUnderlyingObject();
+ Iterator varIter = arr.getValues().iterator();
+
+ while ( varIter.hasNext() ) {
+ final String varName = ((StringReference) varIter.next()).value();
+ IJavaValue val = (IJavaValue) DebugUtil.getValueByExpression( "return getVariableResolver(\"" + varName + "\").getValue();",
+ factory );
+ if ( val != null ) {
+ final ObjectReference valRef = ((JDIObjectValue) val).getUnderlyingObject();
+ //MVELThisVariable t2 = new MVELThisVariable((JDIDebugTarget) getDebugTarget(),valRef,varName);
+
+ VariableWrapper local = new VariableWrapper( varName,
+ val );
+
+ IValue isLocal = DebugUtil.getValueByExpression( "return getParserContext().getVariables();",
+ frameLocal.getValue() );
+ local.setPublic( true );
+ //local.setLocal( true );
+ result.add( local );
+ } else {
+ DroolsEclipsePlugin.log( new Exception("Unable to get value for variable named '"+varName+"'") );
+ }
+ }
+
+ IValue localVars = DebugUtil.getValueByExpression( "return getParserContext().getVariables();", frameLocal.getValue());
+ IValue globalVars = DebugUtil.getValueByExpression( "return getParserContext().getInputs();", frameLocal.getValue());
+
+ result.add(new VariableWrapper("LocalVariables", (IJavaValue) localVars));
+ result.add(new VariableWrapper("GlobalVariables", (IJavaValue) globalVars));
+
+
+
+ //now iterate over localVars and add all that have getValue() non-null
+
+ //MVELThisVariable t2 = new MVELThisVariable((JDIDebugTarget) getDebugTarget(),((JDIObjectValue)variables).getUnderlyingObject(),"parserContext variables");
+ //result.add(t2);
+ }
+
+ IVariable[] vararr = (IVariable[]) result.toArray( new IVariable[result.size()] );
+ return vararr;
+
+ } catch ( Throwable t ) {
+ t.printStackTrace();
+ }
+
+
+ IVariable[] vararr = (IVariable[]) result.toArray( new IVariable[result.size()] );
+
+ Arrays.sort( vararr,
+ new Comparator() {
+
+ public int compare(Object var1,
+ Object var2) {
+ try {
+ return ((IVariable) var1).getName().compareTo( ((IVariable) var2).getName() );
+ } catch ( DebugException e ) {
+ return 0;
+ }
+ }
+
+ } );
+ return vararr;
+ }
+
+ private boolean internalHasNext(Value iter) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException, DebugException {
+ BooleanValue hasNext = (BooleanValue) runMethod( iter,
+ "hasNext" );
+ return hasNext.booleanValue();
+ }
+
+ private Value fetchField(Value factoryVar,
+ String fieldName) throws ClassNotLoadedException, DebugException {
+ return fetchField((ObjectReference)factoryVar, fieldName );
+ }
+
+ private Value runMethod(Value val,
+ String methodName) throws InvalidTypeException,
+ ClassNotLoadedException,
+ IncompatibleThreadStateException,
+ InvocationException, DebugException {
+
+ ObjectReference refObj = (ObjectReference) val;
+ ReferenceType t = refObj.referenceType();
+ Method m2 = (Method) t.methodsByName( methodName ).iterator().next();
+ ThreadReference thread = ((DroolsThread) getThread()).getUnderlyingThread();
+
+ Value res = refObj.invokeMethod( thread,
+ m2,
+ new ArrayList(),
+ 0 );
+
+ return res;
+ }
+
+ private Value fetchField(DroolsLocalVariable frameLocal,
+ String fieldName) throws DebugException,
+ ClassNotLoadedException {
+ ObjectReference objRef = ((JDIObjectValue) frameLocal.getValue()).getUnderlyingObject();
+ return fetchField( objRef,
+ fieldName );
+ }
+
+ private Value fetchField(ObjectReference ref,
+ String fieldName) throws ClassNotLoadedException, DebugException {
+ ClassType varType = (ClassType) ref.type();
+ Field field = varType.fieldByName( fieldName );
+ Value res = ref.getValue( field );
+ return res;
+ }
+
+ protected DroolsStackFrame createNewDroolsFrame(StackFrame frame,
+ int depth) {
+ return new MVELStackFrame( (DroolsThread) getThread(),
+ frame,
+ depth );
+ }
+
+ public String getReceivingTypeName() throws DebugException {
+ return "getReceivingTypeName";
+ }
+
+ public String getMethodName() throws DebugException {
+ return "getMethodName";
+ }
+
+ /* public String getDeclaringTypeName() throws DebugException {
+ return "MVELRunner";
+ }
+ */
+ public int getLineNumber() throws DebugException {
+ /* DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource( marker.getResource(),
+ true );*/
+
+ //RuleInfo ruleINF = getExecutingRuleInfo();
+ DroolsDebugTarget t = (DroolsDebugTarget) getDebugTarget();
+
+ int lineNr = getBreakpointLineNumber();
+ String sourceName = getMVELName();
+
+ DroolsLineBreakpoint bpoint = (DroolsLineBreakpoint) t.getDroolsBreakpoint( sourceName,
+ lineNr );
+
+ if ( bpoint == null ) {
+ return -1;
+ }
+ int line;
+ line = bpoint.getDRLLineNumber();
+ return line;
+ //return getUnderlyingStackFrame().location().lineNumber();
+ }
+
+ public RuleInfo getExecutingRuleInfo() {
+ try {
+ String methodName = getMethodName();
+ String signature = getSignature();
+ String type = getDeclaringTypeName();
+
+ return DroolsEclipsePlugin.getDefault().getRuleInfoByClass( type );
+
+ } catch ( DebugException exc ) {
+ DroolsEclipsePlugin.log( exc );
+ }
+ return null;
+ }
+
+ public int getBreakpointLineNumber() {
+ try {
+ Object o = getRemoteVar( "lineNumber" );
+ if ( o == null ) {
+ return -1;
+ }
+ //getLineNumber
+ IntegerValue val = (IntegerValue) o;
+ return val.value();
+ } catch ( Throwable e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+ public String getMVELName() {
+ try {
+ Object rem = getRemoteVar( "sourceName" );
+ if ( rem == null ) {
+ return null;
+ }
+ //getSourceName
+ StringReference res = (StringReference) rem;
+ return res.value();
+ } catch ( Throwable e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ private Object getRemoteVar(String methodName) throws AbsentInformationException,
+ ClassNotLoadedException,
+ DebugException,
+ InvalidTypeException,
+ IncompatibleThreadStateException,
+ InvocationException {
+
+ //frame arg
+ Method method = getUnderlyingMethod(); // onBreak
+ ReferenceType declaringType = method.declaringType(); // org.drools.base.mvel.MVELDebugHandler
+
+ LocalVariable var = (LocalVariable) method.variables().get( 0 );//frame
+
+ JDILocalVariable jdivar = new JDILocalVariable(this, (LocalVariable) var);
+
+ ClassType frameType = (ClassType) var.type();
+
+ IValue value = jdivar.getValue();
+ if (value instanceof JDINullValue) {
+ return null;
+ }
+ ObjectReference o = (ObjectReference) ((JDIObjectValue)value).getUnderlyingObject();
+
+ if ( o == null ) {
+ return null;
+ }
+ Field field = frameType.fieldByName( methodName );
+ Value val = o.getValue( field );
+
+ return val;
+ }
+
+ public String getSourceName() throws DebugException {
+ return getMVELName();
+ }
+
+ public String getSourcePath() throws DebugException {
+ return "";
+ }
+
+
+}
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,25 @@
+package org.drools.eclipse.debug.core;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
+import org.eclipse.jdt.internal.debug.core.model.JDIThisVariable;
+
+import com.sun.jdi.ObjectReference;
+
+public class MVELThisVariable extends JDIThisVariable {
+
+ private String label;
+
+ public MVELThisVariable(JDIDebugTarget target, ObjectReference object, String label) {
+ super( target, object );
+ this.label = label;
+ }
+
+ public String getName() {
+ return label;
+ }
+
+ public boolean isPublic() throws DebugException {
+ return true;
+ }
+}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DroolsLineBreakpointAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DroolsLineBreakpointAdapter.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DroolsLineBreakpointAdapter.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -79,7 +79,7 @@
}
}
- public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
+ public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
// do nothing
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/Keywords.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/Keywords.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/Keywords.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -16,42 +16,48 @@
private String[] allDrools;
private String[] allJava;
+ private String[] allMvel;
private static Keywords instance;
-
+
public static Keywords getInstance() {
if (instance == null) {
instance = new Keywords();
}
return instance;
}
-
-
+
+
public String[] getAllDroolsKeywords() {
return allDrools;
}
-
+
public String[] getAllJavaKeywords() {
return allJava;
}
-
-
+
+ public String[] getAllMvelKeywords() {
+ return allMvel;
+ }
+
+
private Keywords() {
allDrools = readKeywords("keywords.properties");
- allJava = readKeywords("java_keywords.properties");
+ allJava = readKeywords("java_keywords.properties");
+ allMvel = readKeywords("mvel_keywords.properties");
}
-
+
private String[] readKeywords(String fileName) {
InputStream stream = this.getClass().getResourceAsStream(fileName);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
-
+
List list = new ArrayList();
-
+
String line = null;
while ((line = reader.readLine()) != null) {
- if (!line.startsWith( "#" )) list.add( line );
+ if (!line.startsWith( "#" )) list.add( line );
}
-
+
return (String[]) list.toArray( new String[list.size()] );
}
catch ( IOException e ) {
@@ -66,6 +72,6 @@
}
}
}
-
-
+
+
}
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,196 @@
+package org.drools.eclipse.editors.completion;
+
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.compiler.DrlParser;
+import org.drools.compiler.DroolsParserException;
+import org.drools.lang.Location;
+import org.drools.lang.descr.BaseDescr;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.lang.descr.RuleDescr;
+
+/**
+ * A utility class that invokes the DRLParser on some partial drl text, and provides
+ * information back about the context of that parserd drl,
+ * such as a location type, a dialect, and so on.
+ *
+ */
+public class CompletionContext {
+
+ static final Pattern PATTERN_PATTERN_OPERATOR = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\),]+)(\\s*([<>=!]+)\\s*[^\\s<>!=:]*\\s*(&&|\\|\\|))*\\s+",
+ Pattern.DOTALL );
+
+ static final Pattern PATTERN_PATTERN_COMPARATOR_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s*(([<>=!]+)\\s*[^\\s<>!=:]+\\s*(&&|\\|\\|)\\s*)*([<>=!]+)\\s*[^\\s<>!=:]*",
+ Pattern.DOTALL );
+
+ static final Pattern EVAL_PATTERN = Pattern.compile( ".*\\s+eval\\s*\\(\\s*([(^\\))(\\([^\\)]*\\)?)]*)",
+ Pattern.DOTALL );
+
+ static final Pattern ACCUMULATE_PATTERN_INIT = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern ACCUMULATE_PATTERN_ACTION = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern ACCUMULATE_PATTERN_REVERSE = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)\\)\\s*,?\\s*reverse\\s*\\(\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern ACCUMULATE_PATTERN_RESULT = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)\\)\\s*,?(\\s*reverse\\s*\\(\\s*(.*)\\)\\s*,?)?\\s*result\\s*\\(\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern THEN_PATTERN = Pattern.compile( ".*\n\\s*when\\s*(.*)\n\\s*then\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern ENDS_WITH_SPACES = Pattern.compile( ".*\\s+",
+ Pattern.DOTALL );
+
+ static final Pattern MVEL_DIALECT = Pattern.compile( ".*dialect\\s+\"mvel\".*",
+ Pattern.DOTALL );
+
+ private String backText;
+ private DrlParser parser;
+ private RuleDescr rule;
+ private PackageDescr packageDescr;
+ private boolean javaDialect = true;
+
+ public CompletionContext(String ruleText) {
+ this.backText = ruleText;
+ this.parser = new DrlParser();
+
+ try {
+ packageDescr = parser.parse( ruleText );
+ List rules = packageDescr.getRules();
+ if ( rules != null && rules.size() == 1 ) {
+ this.rule = (RuleDescr) rules.get( 0 );
+ }
+
+ } catch ( DroolsParserException exc ) {
+ // do nothing
+ }
+
+ determineDialect( ruleText );
+ }
+
+ public boolean isJavaDialect() {
+ return javaDialect;
+ }
+
+ public PackageDescr getPackageDescr() {
+ return packageDescr;
+ }
+
+ //note: this is a crude but reasonably fast way to determine the dialect,
+ //especially when parsing imcomplete rules
+ private void determineDialect(String backText) {
+ //which dialect are we using for this rule?
+ //we test only for mvel for now: java is the default dialect
+ if ( MVEL_DIALECT.matcher( backText ).matches() ) {
+ javaDialect = false;
+ } else {
+ javaDialect = true;
+ }
+ }
+
+ public Location getLocation() {
+ if ( backText == null || rule == null ) {
+ return new Location( Location.LOCATION_UNKNOWN );
+ }
+ return determineLocationForDescr( rule,
+ parser.getLocation(),
+ backText );
+ }
+
+ public RuleDescr getRule() {
+ return rule;
+ }
+
+ private static Location determineLocationForDescr(BaseDescr descr,
+ Location location,
+ String backText) {
+ if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR ) {
+ if ( !ENDS_WITH_SPACES.matcher( backText ).matches() ) {
+ location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_START );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_END ) {
+ if ( !backText.endsWith( " " ) ) {
+ location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_EVAL ) {
+ Matcher matcher = EVAL_PATTERN.matcher( backText );
+ if ( matcher.matches() ) {
+ String content = matcher.group( 1 );
+ location.setProperty( Location.LOCATION_EVAL_CONTENT,
+ content );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_START ) {
+ Matcher matcher = PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
+ location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
+ matcher.group( 7 ) );
+ return location;
+ }
+
+ matcher = PATTERN_PATTERN_OPERATOR.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR );
+ return location;
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM ) {
+ if ( location.getProperty( Location.LOCATION_FROM_CONTENT ) == null ) {
+ location.setProperty( Location.LOCATION_FROM_CONTENT,
+ "" );
+ } else if ( ((String) location.getProperty( Location.LOCATION_FROM_CONTENT )).length() > 0 && ENDS_WITH_SPACES.matcher( backText ).matches() ) {
+ location.setType( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_INIT ) {
+ Matcher matcher = ACCUMULATE_PATTERN_INIT.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT,
+ matcher.group( 1 ) );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION ) {
+ Matcher matcher = ACCUMULATE_PATTERN_ACTION.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT,
+ matcher.group( 2 ) );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE ) {
+ Matcher matcher = ACCUMULATE_PATTERN_REVERSE.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_REVERSE_CONTENT,
+ matcher.group( 3 ) );
+ }
+ matcher = ACCUMULATE_PATTERN_RESULT.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT,
+ matcher.group( 5 ) );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT ) {
+ Matcher matcher = ACCUMULATE_PATTERN_RESULT.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT,
+ matcher.group( 5 ) );
+ }
+ } else if ( location.getType() == Location.LOCATION_RHS ) {
+ Matcher matcher = THEN_PATTERN.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setProperty( Location.LOCATION_LHS_CONTENT,
+ matcher.group( 1 ) );
+ location.setProperty( Location.LOCATION_RHS_CONTENT,
+ matcher.group( 2 ) );
+ return location;
+ }
+ }
+
+ return location;
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,49 +1,216 @@
package org.drools.eclipse.editors.completion;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.eclipse.jdt.core.Signature;
+
public class CompletionUtil {
-
- private CompletionUtil() {
- }
+ protected static final Pattern INCOMPLETED_MVEL_EXPRESSION = Pattern.compile( "[\\.\\(\\{\\[]\\Z",
+ Pattern.DOTALL );
+
+ protected static final Pattern COMPLETED_MVEL_EXPRESSION = Pattern.compile( "]\\)\\}\\]\\Z",
+ Pattern.DOTALL );
+
+ private CompletionUtil() {
+ }
+
/** Looks behind, gets stuff after the white space. Basically ripping out the last word.*/
public static String stripLastWord(String prefix) {
- if ("".equals(prefix)) {
- return prefix;
- }
- if (prefix.charAt(prefix.length() - 1) == ' ') {
- return "";
- } else {
- char[] c = prefix.toCharArray();
- int start = 0;
- for (int i = c.length - 1; i >=0; i-- ) {
- if (Character.isWhitespace(c[i]) || c[i] == '(' || c[i] == ':' || c[i] == ';' || c[i] == '=' || c[i] == '<' || c[i] == '>' || c[i] == '.' || c[i] == '{' || c[i] == '}') {
- start = i + 1;
- break;
- }
- }
- prefix = prefix.substring(start, prefix.length());
- return prefix;
- }
+ if ( "".equals( prefix ) ) {
+ return prefix;
+ }
+ if ( prefix.charAt( prefix.length() - 1 ) == ' ' ) {
+ return "";
+ } else {
+ char[] c = prefix.toCharArray();
+ int start = 0;
+ for ( int i = c.length - 1; i >= 0; i-- ) {
+ if ( Character.isWhitespace( c[i] ) || c[i] == '(' || c[i] == ':' || c[i] == ';' || c[i] == '=' || c[i] == '<' || c[i] == '>' || c[i] == '.' || c[i] == '{' || c[i] == '}' ) {
+ start = i + 1;
+ break;
+ }
+ }
+ prefix = prefix.substring( start,
+ prefix.length() );
+ return prefix;
+ }
}
-
+
public static String stripWhiteSpace(String prefix) {
- if ("".equals(prefix)) {
- return prefix;
- }
- if (prefix.charAt(prefix.length() - 1) == ' ') {
- return "";
- } else {
- char[] c = prefix.toCharArray();
- int start = 0;
- for (int i = c.length - 1; i >=0; i-- ) {
- if (Character.isWhitespace(c[i])) {
- start = i + 1;
- break;
- }
- }
- prefix = prefix.substring(start, prefix.length());
- return prefix;
- }
+ if ( "".equals( prefix ) ) {
+ return prefix;
+ }
+ if ( prefix.charAt( prefix.length() - 1 ) == ' ' ) {
+ return "";
+ } else {
+ char[] c = prefix.toCharArray();
+ int start = 0;
+ for ( int i = c.length - 1; i >= 0; i-- ) {
+ if ( Character.isWhitespace( c[i] ) ) {
+ start = i + 1;
+ break;
+ }
+ }
+ prefix = prefix.substring( start,
+ prefix.length() );
+ return prefix;
+ }
}
-
+
+ /**
+ *
+ * @param backText
+ * @return a substring of the back text, that should be compilable
+ * without syntax errors by the mvel compiler
+ * TODO: add tests and more use cases
+ */
+ public static String getCompilableText(String backText) {
+ if ( backText.endsWith( ";" ) ) {
+ //RHS expression should compile if it ends with ;
+ return backText;
+ } else if ( CompletionUtil.COMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) {
+ //RHS expression should compile if closed. just need to close the statement
+ return backText + ";";
+ } else if ( INCOMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) {
+ //remove the last char and close the statement
+ return backText.substring( 0,
+ backText.length() - 1 ) + ";";
+ } else {
+ return backText;
+ }
+ }
+
+ /*
+ * propertyname extraction and bean convention methods names checks
+ */
+
+ public static boolean isGetter(String methodName,
+ int argCount,
+ String returnedType) {
+ return isAccessor( methodName,
+ argCount,
+ 0,
+ "get",
+ returnedType,
+ Signature.SIG_VOID,
+ false );
+ }
+
+ public static boolean isSetter(String methodName,
+ int argCount,
+ String returnedType) {
+ return isAccessor( methodName,
+ argCount,
+ 1,
+ "set",
+ returnedType,
+ Signature.SIG_VOID,
+ true );
+ }
+
+ public static boolean isIsGetter(String methodName,
+ int argCount,
+ String returnedType) {
+ return isAccessor( methodName,
+ argCount,
+ 0,
+ "is",
+ returnedType,
+ Signature.SIG_BOOLEAN,
+ true );
+ }
+
+ public static String getPropertyName(String methodName,
+ int parameterCount,
+ String returnType) {
+ if ( methodName == null ) {
+ return null;
+ }
+ String simpleName = methodName.replaceAll( "\\(\\)",
+ "" );
+ int prefixLength = 0;
+ if ( isIsGetter( simpleName,
+ parameterCount,
+ returnType ) ) {
+
+ prefixLength = 2;
+
+ } else if ( isGetter( simpleName,
+ parameterCount,
+ returnType ) //
+ || isSetter( methodName,
+ parameterCount,
+ returnType ) ) {
+
+ prefixLength = 3;
+ } else {
+ return methodName;
+ }
+
+ char firstChar = Character.toLowerCase( simpleName.charAt( prefixLength ) );
+ String propertyName = firstChar + simpleName.substring( prefixLength + 1 );
+ return propertyName;
+ }
+
+ public static String getPropertyName(String methodName,
+ char[] signature) {
+ if ( signature == null || methodName == null ) {
+ return methodName;
+ }
+
+ int parameterCount = Signature.getParameterCount( signature );
+ String returnType = new String( Signature.getReturnType( signature ) );
+
+ return getPropertyName( methodName,
+ parameterCount,
+ returnType );
+ }
+
+ private static boolean isAccessor(String methodName,
+ int actualParameterCount,
+ int requiredParameterCount,
+ String prefix,
+ String returnType,
+ String requiredReturnType,
+ boolean includeType) {
+
+ if ( methodName.length() < prefix.length() + 1 ) {
+ return false;
+ }
+
+ if ( !methodName.startsWith( prefix ) ) {
+ return false;
+ }
+
+ if ( actualParameterCount != requiredParameterCount ) {
+ return false;
+ }
+
+ if ( includeType ) {
+ if ( !requiredReturnType.equals( returnType ) ) {
+ return false;
+ }
+ } else {
+ if ( requiredReturnType.equals( returnType ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean isStartOfNewStatement(String text,
+ String prefix) {
+ String javaTextWithoutPrefix = text.substring( 0,
+ text.length() - prefix.length() );
+
+ if ( "".equals( javaTextWithoutPrefix.trim() ) || DefaultCompletionProcessor.START_OF_NEW_JAVA_STATEMENT.matcher( javaTextWithoutPrefix ).matches() ) {
+ return true;
+ }
+ return false;
+ }
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,8 +1,10 @@
package org.drools.eclipse.editors.completion;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -18,7 +20,6 @@
import org.drools.lang.descr.GlobalDescr;
import org.drools.util.StringUtils;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.CompletionProposal;
import org.eclipse.jdt.core.CompletionRequestor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -29,230 +30,306 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
-
/**
* This is the basic completion processor that is used when the editor is outside of a rule block
* partition.
* The provides the content assistance for basic rule assembly stuff.
- *
- * This processor will also read behind the current editing position, to provide some context to
+ *
+ * This processor will also read behind the current editing position, to provide some context to
* help provide the pop up list.
- *
+ *
* @author Michael Neale, Kris Verlaenen
*/
public class DefaultCompletionProcessor extends AbstractCompletionProcessor {
- private static final String NEW_RULE_TEMPLATE = "rule \"new rule\"" + System.getProperty("line.separator") + "\twhen" + System.getProperty("line.separator") + "\t\t" + System.getProperty("line.separator") + "\tthen" + System.getProperty("line.separator") + "\t\t" + System.getProperty("line.separator") + "end";
- private static final String NEW_QUERY_TEMPLATE = "query \"query name\"" + System.getProperty("line.separator") + "\t#conditions" + System.getProperty("line.separator") + "end";
- private static final String NEW_FUNCTION_TEMPLATE = "function void yourFunction(Type arg) {" + System.getProperty("line.separator") + "\t/* code goes here*/" + System.getProperty("line.separator") + "}";
- private static final String NEW_TEMPLATE_TEMPLATE = "template Name" + System.getProperty("line.separator") + "\t" + System.getProperty("line.separator") + "end";
- private static final Pattern IMPORT_PATTERN = Pattern.compile(".*\n\\W*import\\W[^;\\s]*", Pattern.DOTALL);
+ private static final String NEW_RULE_TEMPLATE = "rule \"new rule\"" + System.getProperty( "line.separator" ) + "\twhen" + System.getProperty( "line.separator" ) + "\t\t" + System.getProperty( "line.separator" ) + "\tthen"
+ + System.getProperty( "line.separator" ) + "\t\t" + System.getProperty( "line.separator" ) + "end";
+ private static final String NEW_QUERY_TEMPLATE = "query \"query name\"" + System.getProperty( "line.separator" ) + "\t#conditions" + System.getProperty( "line.separator" ) + "end";
+ private static final String NEW_FUNCTION_TEMPLATE = "function void yourFunction(Type arg) {" + System.getProperty( "line.separator" ) + "\t/* code goes here*/" + System.getProperty( "line.separator" ) + "}";
+ private static final String NEW_TEMPLATE_TEMPLATE = "template Name" + System.getProperty( "line.separator" ) + "\t" + System.getProperty( "line.separator" ) + "end";
+ private static final Pattern IMPORT_PATTERN = Pattern.compile( ".*\n\\W*import\\W[^;\\s]*",
+ Pattern.DOTALL );
// TODO: doesn't work for { inside functions
- private static final Pattern FUNCTION_PATTERN = Pattern.compile( ".*\n\\W*function\\s+(\\S+)\\s+(\\S+)\\s*\\(([^\\)]*)\\)\\s*\\{([^\\}]*)", Pattern.DOTALL);
- protected static final Image VARIABLE_ICON = DroolsPluginImages.getImage(DroolsPluginImages.VARIABLE);
- protected static final Image METHOD_ICON = DroolsPluginImages.getImage(DroolsPluginImages.METHOD);
- private static final Pattern START_OF_NEW_JAVA_STATEMENT = Pattern.compile(".*[;{}]\\s*", Pattern.DOTALL);
+ private static final Pattern FUNCTION_PATTERN = Pattern.compile( ".*\n\\W*function\\s+(\\S+)\\s+(\\S+)\\s*\\(([^\\)]*)\\)\\s*\\{([^\\}]*)",
+ Pattern.DOTALL );
+ protected static final Image VARIABLE_ICON = DroolsPluginImages.getImage( DroolsPluginImages.VARIABLE );
+ protected static final Image METHOD_ICON = DroolsPluginImages.getImage( DroolsPluginImages.METHOD );
+ protected static final Image CLASS_ICON = DroolsPluginImages.getImage( DroolsPluginImages.CLASS );
+ protected static final Pattern START_OF_NEW_JAVA_STATEMENT = Pattern.compile( ".*[;{}]\\s*",
+ Pattern.DOTALL );
+
public DefaultCompletionProcessor(AbstractRuleEditor editor) {
- super(editor);
+ super( editor );
}
-
- protected List getCompletionProposals(ITextViewer viewer, int documentOffset) {
+
+ protected List getCompletionProposals(ITextViewer viewer,
+ int documentOffset) {
try {
- IDocument doc = viewer.getDocument();
- String backText = readBackwards( documentOffset, doc );
-
- String prefix = CompletionUtil.stripLastWord(backText);
-
- List props = null;
- Matcher matcher = IMPORT_PATTERN.matcher(backText);
- if (matcher.matches()) {
- String classNameStart = backText.substring(backText.lastIndexOf("import") + 7);
- props = getAllClassProposals(classNameStart, documentOffset);
- } else {
- matcher = FUNCTION_PATTERN.matcher(backText);
- if (matcher.matches()) {
- // extract function parameters
- Map params = extractParams(matcher.group(3));
- // add global parameters
- List globals = getGlobals();
- if (globals != null) {
- for (Iterator iterator = globals.iterator(); iterator.hasNext(); ) {
- GlobalDescr global = (GlobalDescr) iterator.next();
- params.put(global.getIdentifier(), global.getType());
- }
- }
- String functionText = matcher.group(4);
- props = getJavaCompletionProposals(functionText, prefix, params);
- filterProposalsOnPrefix(prefix, props);
- } else {
- props = getPossibleProposals(viewer, documentOffset, backText, prefix);
- }
- }
- return props;
- } catch (Throwable t) {
- DroolsEclipsePlugin.log(t);
+ IDocument doc = viewer.getDocument();
+ String backText = readBackwards( documentOffset,
+ doc );
+
+ String prefix = CompletionUtil.stripLastWord( backText );
+
+ List props = null;
+ Matcher matcher = IMPORT_PATTERN.matcher( backText );
+ if ( matcher.matches() ) {
+ String classNameStart = backText.substring( backText.lastIndexOf( "import" ) + 7 );
+ props = getAllClassProposals( classNameStart,
+ documentOffset );
+ } else {
+ matcher = FUNCTION_PATTERN.matcher( backText );
+ if ( matcher.matches() ) {
+ // extract function parameters
+ Map params = extractParams( matcher.group( 3 ) );
+ // add global parameters
+ List globals = getGlobals();
+ if ( globals != null ) {
+ for ( Iterator iterator = globals.iterator(); iterator.hasNext(); ) {
+ GlobalDescr global = (GlobalDescr) iterator.next();
+ params.put( global.getIdentifier(),
+ global.getType() );
+ }
+ }
+ String functionText = matcher.group( 4 );
+ props = getJavaCompletionProposals( functionText,
+ prefix,
+ params );
+ filterProposalsOnPrefix( prefix,
+ props );
+ } else {
+ props = getPossibleProposals( viewer,
+ documentOffset,
+ backText,
+ prefix );
+ }
+ }
+ return props;
+ } catch ( Throwable t ) {
+ DroolsEclipsePlugin.log( t );
}
return null;
- }
-
- private Map extractParams(String params) {
- Map result = new HashMap();
- String[] parameters = StringUtils.split(params, ",");
- for (int i = 0; i < parameters.length; i++) {
- String[] typeAndName = StringUtils.split(parameters[i]);
- if (typeAndName.length == 2) {
- result.put(typeAndName[1], typeAndName[0]);
- }
- }
- return result;
- }
+ }
- private List getAllClassProposals(final String classNameStart, final int documentOffset) {
- final List list = new ArrayList();
- IEditorInput input = getEditor().getEditorInput();
- if (input instanceof IFileEditorInput) {
- IProject project = ((IFileEditorInput) input).getFile().getProject();
- IJavaProject javaProject = JavaCore.create(project);
-
- CompletionRequestor requestor = new CompletionRequestor() {
- public void accept(org.eclipse.jdt.core.CompletionProposal proposal) {
- String className = new String(proposal.getCompletion());
- if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.PACKAGE_REF) {
- RuleCompletionProposal prop = new RuleCompletionProposal(classNameStart.length(), className, className + ".");
- prop.setImage(DroolsPluginImages.getImage(DroolsPluginImages.PACKAGE));
- list.add(prop);
- } else if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF) {
- RuleCompletionProposal prop = new RuleCompletionProposal(classNameStart.length() - proposal.getReplaceStart(), className, className + ";");
- prop.setImage(DroolsPluginImages.getImage(DroolsPluginImages.CLASS));
- list.add(prop);
- }
- // ignore all other proposals
- }
- };
+ private Map extractParams(String params) {
+ Map result = new HashMap();
+ String[] parameters = StringUtils.split( params,
+ "," );
+ for ( int i = 0; i < parameters.length; i++ ) {
+ String[] typeAndName = StringUtils.split( parameters[i] );
+ if ( typeAndName.length == 2 ) {
+ result.put( typeAndName[1],
+ typeAndName[0] );
+ }
+ }
+ return result;
+ }
- try {
- javaProject.newEvaluationContext().codeComplete(classNameStart, classNameStart.length(), requestor);
- } catch (Throwable t) {
- DroolsEclipsePlugin.log(t);
- }
- }
- return list;
- }
-
- protected List getPossibleProposals(ITextViewer viewer, int documentOffset, String backText, final String prefix) {
+ private List getAllClassProposals(final String classNameStart,
+ final int documentOffset) {
+ final List list = new ArrayList();
+ IEditorInput input = getEditor().getEditorInput();
+ if ( input instanceof IFileEditorInput ) {
+ IProject project = ((IFileEditorInput) input).getFile().getProject();
+ IJavaProject javaProject = JavaCore.create( project );
+
+ CompletionRequestor requestor = new CompletionRequestor() {
+ public void accept(org.eclipse.jdt.core.CompletionProposal proposal) {
+ String className = new String( proposal.getCompletion() );
+ if ( proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.PACKAGE_REF ) {
+ RuleCompletionProposal prop = new RuleCompletionProposal( classNameStart.length(),
+ className,
+ className + "." );
+ prop.setImage( DroolsPluginImages.getImage( DroolsPluginImages.PACKAGE ) );
+ list.add( prop );
+ } else if ( proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF ) {
+ RuleCompletionProposal prop = new RuleCompletionProposal( classNameStart.length() - proposal.getReplaceStart(),
+ className,
+ className + ";" );
+ prop.setImage( DroolsPluginImages.getImage( DroolsPluginImages.CLASS ) );
+ list.add( prop );
+ }
+ // ignore all other proposals
+ }
+ };
+
+ try {
+ javaProject.newEvaluationContext().codeComplete( classNameStart,
+ classNameStart.length(),
+ requestor );
+ } catch ( Throwable t ) {
+ DroolsEclipsePlugin.log( t );
+ }
+ }
+ return list;
+ }
+
+ protected List getPossibleProposals(ITextViewer viewer,
+ int documentOffset,
+ String backText,
+ final String prefix) {
List list = new ArrayList();
- list.add(new RuleCompletionProposal(prefix.length(), "rule", NEW_RULE_TEMPLATE, 6));
- list.add(new RuleCompletionProposal(prefix.length(), "import", "import "));
- list.add(new RuleCompletionProposal(prefix.length(), "expander", "expander "));
- list.add(new RuleCompletionProposal(prefix.length(), "global", "global "));
- list.add(new RuleCompletionProposal(prefix.length(), "package", "package "));
- list.add(new RuleCompletionProposal(prefix.length(), "query", NEW_QUERY_TEMPLATE));
- list.add(new RuleCompletionProposal(prefix.length(), "function", NEW_FUNCTION_TEMPLATE, 14));
- list.add(new RuleCompletionProposal(prefix.length(), "template", NEW_TEMPLATE_TEMPLATE, 9));
- filterProposalsOnPrefix(prefix, list);
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "rule",
+ NEW_RULE_TEMPLATE,
+ 6 ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "import",
+ "import " ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "expander",
+ "expander " ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "global",
+ "global " ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "package",
+ "package " ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "query",
+ NEW_QUERY_TEMPLATE ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "function",
+ NEW_FUNCTION_TEMPLATE,
+ 14 ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "template",
+ NEW_TEMPLATE_TEMPLATE,
+ 9 ) );
+ filterProposalsOnPrefix( prefix,
+ list );
return list;
}
- protected List getJavaCompletionProposals(final String javaText, final String prefix, Map params) {
- final List list = new ArrayList();
- IEditorInput input = getEditor().getEditorInput();
- if (input instanceof IFileEditorInput) {
- IProject project = ((IFileEditorInput) input).getFile().getProject();
- IJavaProject javaProject = JavaCore.create(project);
-
- CompletionRequestor requestor = new CompletionRequestor() {
- public void accept(CompletionProposal proposal) {
- // TODO set other proposal properties too (display name, icon, ...)
- String completion = new String(proposal.getCompletion());
- RuleCompletionProposal prop = new RuleCompletionProposal(prefix.length(), completion);
- switch (proposal.getKind()) {
- case CompletionProposal.LOCAL_VARIABLE_REF:
- prop.setImage(VARIABLE_ICON);
- break;
- case CompletionProposal.METHOD_REF:
- // TODO: Object methods are proposed when in the start of a line
- String javaTextWithoutPrefix = javaText.substring(0, javaText.length() - prefix.length());
- if ("".equals(javaTextWithoutPrefix.trim()) || START_OF_NEW_JAVA_STATEMENT.matcher(javaTextWithoutPrefix).matches()) {
- return;
- }
- prop.setImage(METHOD_ICON);
- break;
- default:
- }
- list.add(prop);
- }
- };
+ /**
+ * @return a list of regular Java'ish RuleCompletionProposal
+ */
+ protected List getJavaCompletionProposals(final String javaText,
+ final String prefix,
+ Map params) {
+ final List list = new ArrayList();
+ CompletionRequestor requestor = new JavaCompletionRequestor( prefix,
+ javaText,
+ list );
- try {
- IEvaluationContext evalContext = javaProject.newEvaluationContext();
- List imports = getImports();
- if (imports != null && imports.size() > 0) {
- evalContext.setImports((String[]) imports.toArray(new String[imports.size()]));
- }
- StringBuffer javaTextWithParams = new StringBuffer();
- Iterator iterator = params.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry entry = (Map.Entry) iterator.next();
- // this does not seem to work, so adding variables manually
- // evalContext.newVariable((String) entry.getValue(), (String) entry.getKey(), null);
- javaTextWithParams.append(entry.getValue() + " " + entry.getKey() + ";\n");
- }
- javaTextWithParams.append("org.drools.spi.KnowledgeHelper drools;");
- javaTextWithParams.append(javaText);
- String text = javaTextWithParams.toString();
- evalContext.codeComplete(text, text.length(), requestor);
- } catch (Throwable t) {
- DroolsEclipsePlugin.log(t);
- }
- }
- return list;
- }
-
- protected List getImports() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getImports();
- }
- return Collections.EMPTY_LIST;
- }
-
- protected List getFunctions() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getFunctions();
- }
- return Collections.EMPTY_LIST;
- }
-
- protected Set getTemplates() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getTemplates();
- }
- return Collections.EMPTY_SET;
- }
-
- protected FactTemplateDescr getTemplate(String name) {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getTemplate(name);
- }
- return null;
- }
-
- protected List getGlobals() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getGlobals();
- }
- return Collections.EMPTY_LIST;
- }
-
- protected List getClassesInPackage() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getClassesInPackage();
- }
- return Collections.EMPTY_LIST;
- }
-
- protected boolean isStartOfJavaExpression(String text) {
- return "".equals(text.trim()) || START_OF_NEW_JAVA_STATEMENT.matcher(text).matches();
- }
+ requestJavaCompletionProposals( javaText,
+ prefix,
+ params,
+ requestor );
+ return list;
+ }
+ /**
+ * @return a list of "MVELified" RuleCompletionProposal. Thta list contains only unqiue proposal based on
+ * the overrriden equals in {@link RuleCompletionProposal} to avoid the situation when several
+ * accessors can exist for one property. for that case we want to keep only one proposal.
+ */
+ protected List getJavaMvelCompletionProposals(final String javaText,
+ final String prefix,
+ Map params) {
+ final Collection set = new HashSet();
+ CompletionRequestor requestor = new MvelCompletionRequestor( prefix,
+ javaText,
+ set );
+ requestJavaCompletionProposals( javaText,
+ prefix,
+ params,
+ requestor );
+ List list = new ArrayList();
+ list.addAll( set );
+ return list;
+ }
+
+ protected void requestJavaCompletionProposals(final String javaText,
+ final String prefix,
+ Map params,
+ CompletionRequestor requestor) {
+
+ IEditorInput input = getEditor().getEditorInput();
+ if ( !(input instanceof IFileEditorInput) ) {
+ return;
+ }
+ IProject project = ((IFileEditorInput) input).getFile().getProject();
+ IJavaProject javaProject = JavaCore.create( project );
+
+ try {
+ IEvaluationContext evalContext = javaProject.newEvaluationContext();
+ List imports = getImports();
+ if ( imports != null && imports.size() > 0 ) {
+ evalContext.setImports( (String[]) imports.toArray( new String[imports.size()] ) );
+ }
+ StringBuffer javaTextWithParams = new StringBuffer();
+ Iterator iterator = params.entrySet().iterator();
+ while ( iterator.hasNext() ) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ // this does not seem to work, so adding variables manually
+ // evalContext.newVariable((String) entry.getValue(), (String) entry.getKey(), null);
+ javaTextWithParams.append( entry.getValue() + " " + entry.getKey() + ";\n" );
+ }
+ javaTextWithParams.append( "org.drools.spi.KnowledgeHelper drools;" );
+ javaTextWithParams.append( javaText );
+ String text = javaTextWithParams.toString();
+ System.out.println( "" );
+ System.out.println( "MVEL: synthetic Java text:" + text );
+ evalContext.codeComplete( text,
+ text.length(),
+ requestor );
+ } catch ( Throwable t ) {
+ DroolsEclipsePlugin.log( t );
+ }
+ }
+
+ protected String getPackage() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getPackage();
+ }
+ return "";
+ }
+
+ protected List getImports() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getImports();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ protected List getFunctions() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getFunctions();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ protected Set getTemplates() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getTemplates();
+ }
+ return Collections.EMPTY_SET;
+ }
+
+ protected FactTemplateDescr getTemplate(String name) {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getTemplate( name );
+ }
+ return null;
+ }
+
+ protected List getGlobals() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getGlobals();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ protected List getClassesInPackage() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getClassesInPackage();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ protected boolean isStartOfDialectExpression(String text) {
+ return "".equals( text.trim() ) || START_OF_NEW_JAVA_STATEMENT.matcher( text ).matches();
+ }
}
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,43 @@
+package org.drools.eclipse.editors.completion;
+
+import java.util.Collection;
+
+import org.eclipse.jdt.core.CompletionProposal;
+import org.eclipse.jdt.core.CompletionRequestor;
+
+public class JavaCompletionRequestor extends CompletionRequestor {
+ private final String prefix;
+ private final String text;
+ private final Collection list;
+
+ public JavaCompletionRequestor(String prefix,
+ String text,
+ Collection list) {
+ this.prefix = prefix;
+ this.text = text;
+ this.list = list;
+ }
+
+ public void accept(CompletionProposal proposal) {
+ // TODO set other proposal properties too (display name, icon, ...)
+ String completion = new String( proposal.getCompletion() );
+ RuleCompletionProposal prop = new RuleCompletionProposal( prefix.length(),
+ completion );
+
+ switch ( proposal.getKind() ) {
+ case CompletionProposal.LOCAL_VARIABLE_REF :
+ prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ break;
+ case CompletionProposal.METHOD_REF :
+ // TODO: Object methods are proposed when in the start of a line
+ if ( CompletionUtil.isStartOfNewStatement( text,
+ prefix ) ) {
+ return;
+ }
+ prop.setImage( DefaultCompletionProcessor.METHOD_ICON );
+ break;
+ default :
+ }
+ list.add( prop );
+ }
+}
\ No newline at end of file
Deleted: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,639 +0,0 @@
-package org.drools.eclipse.editors.completion;
-
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.drools.compiler.DrlParser;
-import org.drools.compiler.DroolsParserException;
-import org.drools.lang.Location;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.PackageDescr;
-import org.drools.lang.descr.RuleDescr;
-
-public class LocationDeterminator {
-
-// private static final Pattern PATTERN_PATTERN_START = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*[^\\s<>!=:]*",
-// Pattern.DOTALL );
- static final Pattern PATTERN_PATTERN_OPERATOR = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\),]+)(\\s*([<>=!]+)\\s*[^\\s<>!=:]*\\s*(&&|\\|\\|))*\\s+",
- Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_CONTAINS_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+contains\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_MATCHES_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+matches\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_EXCLUDES_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+excludes\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_IN_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+(not\\s+)?in\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_MEMBER_OF_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+(not\\s+)?memberOf\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
- static final Pattern PATTERN_PATTERN_COMPARATOR_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s*(([<>=!]+)\\s*[^\\s<>!=:]+\\s*(&&|\\|\\|)\\s*)*([<>=!]+)\\s*[^\\s<>!=:]*",
- Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_CONTAINS_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+contains\\s+[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_MATCHES_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+matches\\s+[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_EXCLUDES_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+excludes\\s+[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_IN_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+(not\\s+)?in\\s+\\([^\\)]+\\)\\s*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_MEMBER_OF_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+(not\\s+)?memberOf\\s+[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_COMPARATOR_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s*([<>=!]+)\\s*[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-
-// private static final Pattern PATTERN_PATTERN = Pattern.compile( "((\\S+)\\s*:\\s*)?(\\S+)\\s*(\\(.*)",
-// Pattern.DOTALL );
-// private static final Pattern EXISTS_PATTERN = Pattern.compile( ".*\\s+exists\\s*\\(?\\s*((\\S*)\\s*:)?\\s*\\S*",
-// Pattern.DOTALL );
-// private static final Pattern NOT_PATTERN = Pattern.compile( ".*\\s+not\\s*\\(?\\s*((\\S*)\\s*:)?\\s*\\S*",
-// Pattern.DOTALL );
- static final Pattern EVAL_PATTERN = Pattern.compile( ".*\\s+eval\\s*\\(\\s*([(^\\))(\\([^\\)]*\\)?)]*)",
- Pattern.DOTALL );
-// private static final Pattern FROM_PATTERN = Pattern.compile( ".*\\)\\s+from\\s+",
-// Pattern.DOTALL );
-// private static final Pattern ACCUMULATE_PATTERN = Pattern.compile( ".*\\)\\s+from\\s+accumulate\\s*\\(\\s*",
-// Pattern.DOTALL );
- static final Pattern ACCUMULATE_PATTERN_INIT = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)",
- Pattern.DOTALL );
- static final Pattern ACCUMULATE_PATTERN_ACTION = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)",
- Pattern.DOTALL );
- static final Pattern ACCUMULATE_PATTERN_REVERSE = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)\\)\\s*,?\\s*reverse\\s*\\(\\s*(.*)",
- Pattern.DOTALL );
- static final Pattern ACCUMULATE_PATTERN_RESULT = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)\\)\\s*,?(\\s*reverse\\s*\\(\\s*(.*)\\)\\s*,?)?\\s*result\\s*\\(\\s*(.*)",
- Pattern.DOTALL );
-// private static final Pattern COLLECT_PATTERN = Pattern.compile( ".*\\)\\s+from\\s+collect\\s*\\(\\s*",
-// Pattern.DOTALL );
-
- static final Pattern THEN_PATTERN = Pattern.compile( ".*\n\\s*when\\s*(.*)\n\\s*then\\s*(.*)",
- Pattern.DOTALL );
-
- static final Pattern ENDS_WITH_SPACES = Pattern.compile( ".*\\s+",
- Pattern.DOTALL );
-
- private LocationDeterminator() {
- }
-
- public static Location getLocation(String backText) {
- DrlParser parser = new DrlParser();
- try {
- PackageDescr packageDescr = parser.parse( backText );
- List rules = packageDescr.getRules();
- if ( rules != null && rules.size() == 1 ) {
- return determineLocationForDescr( (RuleDescr) rules.get( 0 ),
- parser.getLocation(),
- backText );
- }
- } catch ( DroolsParserException exc ) {
- // do nothing
- }
- return new Location( Location.LOCATION_UNKNOWN );
- }
-
- public static Location determineLocationForDescr(BaseDescr descr,
- Location location,
- String backText) {
- if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR ) {
- if ( !ENDS_WITH_SPACES.matcher( backText ).matches() ) {
- location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_START );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_END ) {
- if ( !backText.endsWith( " " ) ) {
- location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_EVAL ) {
- Matcher matcher = EVAL_PATTERN.matcher( backText );
- if ( matcher.matches() ) {
- String content = matcher.group( 1 );
- location.setProperty( Location.LOCATION_EVAL_CONTENT,
- content );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_START ) {
- Matcher matcher = PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
- location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
- matcher.group( 7 ) );
- return location;
- }
-
- matcher = PATTERN_PATTERN_OPERATOR.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR );
- return location;
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM ) {
- if ( location.getProperty( Location.LOCATION_FROM_CONTENT ) == null ) {
- location.setProperty( Location.LOCATION_FROM_CONTENT,
- "" );
- } else if ( ((String) location.getProperty( Location.LOCATION_FROM_CONTENT )).length() > 0 && ENDS_WITH_SPACES.matcher( backText ).matches() ) {
- location.setType( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_INIT ) {
- Matcher matcher = ACCUMULATE_PATTERN_INIT.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT,
- matcher.group( 1 ) );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION ) {
- Matcher matcher = ACCUMULATE_PATTERN_ACTION.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT,
- matcher.group( 2 ) );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE) {
- Matcher matcher = ACCUMULATE_PATTERN_REVERSE.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_REVERSE_CONTENT,
- matcher.group( 3 ) );
- }
- matcher = ACCUMULATE_PATTERN_RESULT.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT,
- matcher.group( 5 ) );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT ) {
- Matcher matcher = ACCUMULATE_PATTERN_RESULT.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT,
- matcher.group( 5 ) );
- }
- } else if ( location.getType() == Location.LOCATION_RHS ) {
- Matcher matcher = THEN_PATTERN.matcher( backText );
- if ( matcher.matches() ) {
- location.setProperty( Location.LOCATION_LHS_CONTENT,
- matcher.group( 1 ) );
- location.setProperty( Location.LOCATION_RHS_CONTENT,
- matcher.group( 2 ) );
- return location;
- }
- }
-
- return location;
- // if (descr instanceof RuleDescr) {
- // RuleDescr ruleDescr = (RuleDescr) descr;
- // Object o = ruleDescr.getConsequence();
- // if (o == null) {
- // Matcher matcher = THEN_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_RHS);
- // location.setProperty(Location.LOCATION_LHS_CONTENT, matcher.group(1));
- // location.setProperty(Location.LOCATION_RHS_CONTENT, matcher.group(2));
- // return location;
- // }
- // }
- // AndDescr lhs = ruleDescr.getLhs();
- // if (lhs == null) {
- // return new Location(Location.LOCATION_RULE_HEADER);
- // }
- // List subDescrs = lhs.getDescrs();
- // if (subDescrs.size() == 0) {
- // Matcher matcher = EXISTS_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // matcher = NOT_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // matcher = FROM_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_LHS_FROM);
- // location.setProperty(Location.LOCATION_FROM_CONTENT, "");
- // return location;
- // }
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
- // }
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(subDescrs.size() - 1);
- // if (subDescr == null) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
- // }
- // if (endReached(subDescr)) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
- // }
- // return determineLocationForDescr(subDescr, backText);
- // } else if (descr instanceof PatternDescr) {
- // PatternDescr patternDescr = (PatternDescr) descr;
- //// int locationType;
- //// String propertyName = null;
- //// String evaluator = null;
- //// boolean endOfConstraint = false;
- //// List subDescrs = columnDescr.getDescrs();
- //// if (subDescrs.size() > 0) {
- //// BaseDescr lastDescr = (BaseDescr) subDescrs.get(subDescrs.size() - 1);
- //// if (lastDescr.getEndCharacter() != -1) {
- //// endOfConstraint = true;
- //// }
- //// if (lastDescr instanceof FieldConstraintDescr) {
- //// FieldConstraintDescr lastFieldDescr = (FieldConstraintDescr) lastDescr;
- //// propertyName = lastFieldDescr.getFieldName();
- //// List restrictions = lastFieldDescr.getRestrictions();
- //// if (restrictions.size() > 0) {
- //// RestrictionDescr restriction = (RestrictionDescr) restrictions.get(restrictions.size() - 1);
- //// if (restriction instanceof LiteralRestrictionDescr) {
- //// LiteralRestrictionDescr literal = (LiteralRestrictionDescr) restriction;
- //// evaluator = literal.getEvaluator();
- //// } else if (restriction instanceof VariableRestrictionDescr) {
- //// VariableRestrictionDescr variable = (VariableRestrictionDescr) restriction;
- //// evaluator = variable.getEvaluator();
- //// }
- //// }
- //// }
- //// }
- //// if (endOfConstraint) {
- //// locationType = Location.LOCATION_INSIDE_CONDITION_END;
- //// } else if (evaluator != null) {
- //// locationType = Location.LOCATION_INSIDE_CONDITION_ARGUMENT;
- //// } else if (propertyName != null) {
- //// locationType = Location.LOCATION_INSIDE_CONDITION_OPERATOR;
- //// } else {
- //// locationType = Location.LOCATION_INSIDE_CONDITION_START;
- //// }
- //// Location location = new Location(locationType);
- //// location.setProperty(Location.LOCATION_PROPERTY_CLASS_NAME, columnDescr.getObjectType());
- //// location.setProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME, propertyName);
- //// location.setProperty(Location.LOCATION_PROPERTY_OPERATOR, evaluator);
- //// return location;
- // // TODO: this is not completely safe, there are rare occasions where this could fail
- // Pattern pattern = Pattern.compile(".*(" + patternDescr.getObjectType() + ")\\s*\\((.*)", Pattern.DOTALL);
- // Matcher matcher = pattern.matcher(backText);
- // String patternContents = null;
- // while (matcher.find()) {
- // patternContents = "(" + matcher.group(2);
- // }
- // if (patternContents == null) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
- // }
- // List subDescrs = patternDescr.getDescrs();
- // if (subDescrs.size() > 0) {
- // Object lastDescr = subDescrs.get(subDescrs.size() - 1);
- // if (lastDescr instanceof FieldConstraintDescr) {
- // FieldConstraintDescr lastFieldDescr = (FieldConstraintDescr) lastDescr;
- // List restrictions = lastFieldDescr.getRestrictions();
- // // if there are multiple restrictions, filter out all the rest so that
- // // only the last one remains
- // if (restrictions.size() > 2) {
- // Object last = restrictions.get(restrictions.size() - 2);
- // if (last instanceof RestrictionConnectiveDescr) {
- // RestrictionConnectiveDescr lastRestr = (RestrictionConnectiveDescr) last;
- // String connective = "&&";
- // if (lastRestr.getConnective() == RestrictionConnectiveDescr.OR) {
- // connective = "||";
- // }
- // int connectiveLocation = patternContents.lastIndexOf(connective);
- // patternContents = "( " + lastFieldDescr.getFieldName() + " " + patternContents.substring(connectiveLocation + 1);
- // }
- // }
- // if (restrictions.size() > 1) {
- // Object last = restrictions.get(restrictions.size() - 1);
- // if (last instanceof RestrictionConnectiveDescr) {
- // RestrictionConnectiveDescr lastRestr = (RestrictionConnectiveDescr) last;
- // String connective = "&&";
- // if (lastRestr.getConnective() == RestrictionConnectiveDescr.OR) {
- // connective = "||";
- // }
- // int connectiveLocation = patternContents.lastIndexOf(connective);
- // patternContents = "( " + lastFieldDescr.getFieldName() + " " + patternContents.substring(connectiveLocation + 1);
- // }
- // }
- // }
- // }
- // return getLocationForPatttern(patternContents, patternDescr.getObjectType());
- // } else if (descr instanceof ExistsDescr) {
- // List subDescrs = ((ExistsDescr) descr).getDescrs();
- // if (subDescrs.size() == 0) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // if (subDescrs.size() == 1) {
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(0);
- // if (subDescr == null) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // Location result = determineLocationForDescr(subDescr, backText);
- // if (result.getType() == Location.LOCATION_LHS_BEGIN_OF_CONDITION) {
- // result.setType(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // return result;
- // }
- // return determineLocationForDescr(descr, backText);
- // } else if (descr instanceof NotDescr) {
- // List subDescrs = ((NotDescr) descr).getDescrs();
- // if (subDescrs.size() == 0) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // if (subDescrs.size() == 1) {
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(0);
- // if (subDescr == null) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // Location location = determineLocationForDescr(subDescr, backText);
- // if (location.getType() == Location.LOCATION_LHS_BEGIN_OF_CONDITION) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // return location;
- // }
- // return determineLocationForDescr(descr, backText);
- // } else if (descr instanceof AndDescr) {
- // List subDescrs = ((AndDescr) descr).getDescrs();
- // int size = subDescrs.size();
- // if (size == 2) {
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(1);
- // if (subDescr == null) {
- // Matcher matcher = EXISTS_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // matcher = NOT_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
- // } else {
- // Location location = determineLocationForDescr(subDescr, backText);
- // if (location.getType() == Location.LOCATION_LHS_BEGIN_OF_CONDITION) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
- // }
- // return location;
- // }
- // }
- // return new Location(Location.LOCATION_UNKNOWN);
- // } else if (descr instanceof OrDescr) {
- // List subDescrs = ((OrDescr) descr).getDescrs();
- // int size = subDescrs.size();
- // if (size == 2) {
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(1);
- // if (subDescr == null) {
- // Matcher matcher = EXISTS_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // matcher = NOT_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
- // } else {
- // Location location = determineLocationForDescr(subDescr, backText);
- // if (location.getType() == Location.LOCATION_LHS_BEGIN_OF_CONDITION) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
- // }
- // return location;
- // }
- // }
- // return new Location(Location.LOCATION_UNKNOWN);
- // } else if (descr instanceof FromDescr) {
- // Location location = new Location(Location.LOCATION_LHS_FROM);
- // String content = CompletionUtil.stripWhiteSpace(backText);
- // location.setProperty(Location.LOCATION_FROM_CONTENT, content);
- // return location;
- // } else if (descr instanceof AccumulateDescr) {
- // Matcher matcher = ACCUMULATE_PATTERN.matcher(backText);
- // int end = -1;
- // while (matcher.find()) {
- // end = matcher.end();
- // }
- // String accumulateText = backText.substring(end);
- // matcher = ACCUMULATE_PATTERN_RESULT.matcher(accumulateText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE);
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT, matcher.group(2));
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT, matcher.group(3));
- // return location;
- // }
- // matcher = ACCUMULATE_PATTERN_ACTION.matcher(accumulateText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE);
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT, matcher.group(2));
- // return location;
- // }
- // matcher = ACCUMULATE_PATTERN_INIT.matcher(accumulateText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE);
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
- // return location;
- // }
- // matcher = PATTERN_PATTERN.matcher(accumulateText);
- // if (matcher.matches()) {
- // String className = matcher.group(3);
- // String patternContents = matcher.group(4);
- // return getLocationForPatttern(patternContents, className);
- // }
- // return new Location(Location.LOCATION_LHS_FROM_ACCUMULATE);
- // } else if (descr instanceof CollectDescr) {
- // Matcher matcher = COLLECT_PATTERN.matcher(backText);
- // int end = -1;
- // while (matcher.find()) {
- // end = matcher.end();
- // }
- // String collectText = backText.substring(end);
- // matcher = PATTERN_PATTERN.matcher(collectText);
- // if (matcher.matches()) {
- // String className = matcher.group(3);
- // String columnContents = matcher.group(4);
- // return getLocationForPatttern(columnContents, className);
- // }
- // return new Location(Location.LOCATION_LHS_FROM_COLLECT);
- // } else if (descr instanceof EvalDescr) {
- // Matcher matcher = EVAL_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // String content = matcher.group(1);
- // Location location = new Location(Location.LOCATION_LHS_INSIDE_EVAL);
- // location.setProperty(Location.LOCATION_EVAL_CONTENT, content);
- // return location;
- // }
- // }
- //
- // return new Location(Location.LOCATION_UNKNOWN);
- }
-
-// private static boolean endReached(BaseDescr descr) {
-// if ( descr == null ) {
-// return false;
-// }
-// if ( descr instanceof PatternDescr ) {
-// return descr.getEndCharacter() != -1;
-// } else if ( descr instanceof ExistsDescr ) {
-// List descrs = ((ExistsDescr) descr).getDescrs();
-// if ( descrs.isEmpty() ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) );
-// } else if ( descr instanceof NotDescr ) {
-// List descrs = ((NotDescr) descr).getDescrs();
-// if ( descrs.isEmpty() ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) );
-// } else if ( descr instanceof NotDescr ) {
-// List descrs = ((NotDescr) descr).getDescrs();
-// if ( descrs.isEmpty() ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) );
-// } else if ( descr instanceof AndDescr ) {
-// List descrs = ((AndDescr) descr).getDescrs();
-// if ( descrs.size() != 2 ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) ) && endReached( (BaseDescr) descrs.get( 1 ) );
-// } else if ( descr instanceof OrDescr ) {
-// List descrs = ((OrDescr) descr).getDescrs();
-// if ( descrs.size() != 2 ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) ) && endReached( (BaseDescr) descrs.get( 1 ) );
-// } else if ( descr instanceof EvalDescr ) {
-// return ((EvalDescr) descr).getContent() != null;
-// }
-// return descr.getEndCharacter() != -1;
-// // else if (descr instanceof AccumulateDescr) {
-// // return ((AccumulateDescr) descr).getResultCode() != null;
-// // } else if (descr instanceof CollectDescr) {
-// // return ((CollectDescr) descr).getSourceColumn() != null;
-// // }
-// // return false;
-// }
-//
-// private static Location getLocationForPatttern(String patternContents,
-// String className) {
-// Matcher matcher = PATTERN_PATTERN_OPERATOR.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_START.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_START );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// if ( matcher.group( 8 ) != null ) {
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// matcher.group( 8 ) );
-// } else {
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// matcher.group( 4 ) );
-// }
-// return location;
-// }
-// matcher = PATTERN_PATTERN_CONTAINS_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "contains" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_EXCLUDES_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "excludes" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_IN_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "in" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_MEMBER_OF_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "memberOf" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_MATCHES_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "matches" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_CONTAINS_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_MATCHES_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_EXCLUDES_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_IN_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_MEMBER_OF_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_COMPARATOR_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-}
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,64 @@
+package org.drools.eclipse.editors.completion;
+
+import java.util.Collection;
+
+import org.eclipse.jdt.core.CompletionProposal;
+import org.eclipse.jdt.core.CompletionRequestor;
+
+public class MvelCompletionRequestor extends CompletionRequestor {
+ private final String prefix;
+ private final String text;
+ private final Collection list;
+
+ public MvelCompletionRequestor(String prefix,
+ String text,
+ Collection list) {
+ this.prefix = prefix;
+ this.text = text;
+ this.list = list;
+ }
+
+ public void accept(CompletionProposal proposal) {
+ // TODO set other proposal properties too (display name, icon, ...)
+ String completion = new String( proposal.getCompletion() );
+ RuleCompletionProposal prop = new RuleCompletionProposal( prefix.length(),
+ completion );;
+
+ switch ( proposal.getKind() ) {
+ case CompletionProposal.LOCAL_VARIABLE_REF :
+ prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ break;
+
+ case CompletionProposal.METHOD_REF :
+ // TODO: Object methods are proposed when in the start of a line
+
+ //get the eventual property name for that method name and signature
+ String propertyOrMethodName = CompletionUtil.getPropertyName( completion,
+ proposal.getSignature() );
+ //is the completion for a bean accessor?
+ boolean isAccessor = completion.equals( propertyOrMethodName );
+
+ prop = new RuleCompletionProposal( prefix.length(),
+ propertyOrMethodName );
+ boolean startOfNewStatement = CompletionUtil.isStartOfNewStatement( text,
+ prefix );
+ if ( startOfNewStatement ) {
+ //ignore non accessor methods when starting a new statement
+ if ( isAccessor ) {
+ prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ }
+ } else {
+ if ( isAccessor ) {
+ prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ } else {
+ prop.setImage( DefaultCompletionProcessor.METHOD_ICON );
+ }
+ }
+
+ break;
+
+ default :
+ }
+ list.add( prop );
+ }
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -8,12 +8,14 @@
import java.util.Map;
import org.drools.base.ClassTypeResolver;
-import org.drools.compiler.DrlParser;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilderConfiguration;
+import org.drools.eclipse.DRLInfo;
import org.drools.eclipse.DroolsEclipsePlugin;
import org.drools.eclipse.DroolsPluginImages;
+import org.drools.eclipse.DRLInfo.RuleInfo;
import org.drools.eclipse.editors.AbstractRuleEditor;
+import org.drools.eclipse.editors.DRLRuleEditor;
import org.drools.eclipse.util.ProjectClassLoader;
import org.drools.lang.Location;
import org.drools.lang.descr.AndDescr;
@@ -27,11 +29,14 @@
import org.drools.lang.descr.OrDescr;
import org.drools.lang.descr.PackageDescr;
import org.drools.lang.descr.PatternDescr;
-import org.drools.lang.descr.RuleDescr;
+import org.drools.rule.builder.dialect.mvel.MVELDialect;
import org.drools.util.asm.ClassFieldInspector;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.swt.graphics.Image;
+import org.mvel.ExpressionCompiler;
+import org.mvel.ParserContext;
+import org.mvel.PropertyVerifier;
/**
* For handling within rules.
@@ -40,743 +45,1053 @@
*/
public class RuleCompletionProcessor extends DefaultCompletionProcessor {
- private static final Image DROOLS_ICON =
- DroolsPluginImages.getImage(DroolsPluginImages.DROOLS);
+ private static final Image DROOLS_ICON = DroolsPluginImages.getImage( DroolsPluginImages.DROOLS );
- private static final Image CLASS_ICON =
- DroolsPluginImages.getImage(DroolsPluginImages.CLASS);
+ private static final Image CLASS_ICON = DroolsPluginImages.getImage( DroolsPluginImages.CLASS );
- public RuleCompletionProcessor(AbstractRuleEditor editor) {
- super(editor);
- }
+ /**
+ * A CompletionContext contains the DRL backtext parsing results, to avoid multilpe parser invocations
+ */
+ private CompletionContext context;
- protected List getCompletionProposals(ITextViewer viewer, int documentOffset) {
- try {
- final List list = new ArrayList();
+ public RuleCompletionProcessor(AbstractRuleEditor editor) {
+ super( editor );
+ }
- IDocument doc = viewer.getDocument();
- String backText = readBackwards(documentOffset, doc);
- final String prefix = CompletionUtil.stripLastWord(backText);
+ protected List getCompletionProposals(ITextViewer viewer,
+ int documentOffset) {
+ try {
+ final List list = new ArrayList();
- if (backText.length() < 5) {
- return list;
- }
+ IDocument doc = viewer.getDocument();
- Location location = LocationDeterminator.getLocation(backText);
- if (location.getType() == Location.LOCATION_RULE_HEADER) {
- addRuleHeaderProposals(list, prefix, backText);
- } else if (location.getType() == Location.LOCATION_RHS) {
- addRHSCompletionProposals(list, prefix, backText,
- (String) location.getProperty(Location.LOCATION_LHS_CONTENT),
- (String) location.getProperty(Location.LOCATION_RHS_CONTENT));
- } else {
- addLHSCompletionProposals(list, location, prefix, backText);
- }
+ String backText = readBackwards( documentOffset,
+ doc );
+ final String prefix = CompletionUtil.stripLastWord( backText );
- filterProposalsOnPrefix(prefix, list);
- return list;
- } catch (Throwable t) {
- DroolsEclipsePlugin.log(t);
- }
- return null;
- }
+ //FIXME:where does the magic number 5 come from? "rule "?
+ if ( backText.length() < 5 ) {
+ return list;
+ }
- protected void addRHSCompletionProposals(List list, String prefix, String backText,
- String conditions, String consequence) {
- // only add functions and keywords if at the beginning of a
- // new statement
- String consequenceWithoutPrefix = consequence.substring(0,
- consequence.length() - prefix.length());
- if (isStartOfJavaExpression(consequenceWithoutPrefix)) {
- addRHSKeywordCompletionProposals(list, prefix);
- addRHSFunctionCompletionProposals(list, prefix);
- }
- addRHSJavaCompletionProposals(list, prefix, backText, conditions, consequence);
- }
+ this.context = new CompletionContext( backText );
+ Location location = context.getLocation();
- protected void addLHSCompletionProposals(List list,
- Location location, String prefix, String backText) {
- switch (location.getType()) {
- case Location.LOCATION_LHS_BEGIN_OF_CONDITION:
- // if we are at the beginning of a new condition
- // add drools keywords
- list.add(new RuleCompletionProposal(prefix.length(), "and",
- "and ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "or",
- "or ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "from",
- "from ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "forall",
- "forall( )", 8, DROOLS_ICON));
- RuleCompletionProposal prop = new RuleCompletionProposal(prefix
- .length(), "eval", "eval( )", 6);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- prop = new RuleCompletionProposal(prefix.length(), "then",
- "then" + System.getProperty("line.separator") + "\t");
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- // we do not break but also add all elements that are needed for
- // and/or
- case Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR:
- list.add(new RuleCompletionProposal(prefix.length(), "not",
- "not ", DROOLS_ICON));
- // we do not break but also add all elements that are needed for
- // not
- case Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT:
- list.add(new RuleCompletionProposal(prefix.length(), "exists",
- "exists ", DROOLS_ICON));
- // we do not break but also add all elements that are needed for
- // exists
- case Location.LOCATION_LHS_FROM_ACCUMULATE:
- case Location.LOCATION_LHS_FROM_COLLECT:
- case Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS:
- // and add imported classes
- Iterator iterator = getImports().iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next();
- int index = name.lastIndexOf(".");
- if (index != -1) {
- String className = name.substring(index + 1);
- RuleCompletionProposal p = new RuleCompletionProposal(
- prefix.length(), className, className + "( )",
- className.length() + 2);
- p.setPriority(-1);
- p.setImage(CLASS_ICON);
- list.add(p);
- }
- }
- iterator = getClassesInPackage().iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next();
- int index = name.lastIndexOf(".");
- if (index != -1) {
- String className = name.substring(index + 1);
- RuleCompletionProposal p = new RuleCompletionProposal(
- prefix.length(), className, className + "( )",
- className.length() + 2);
- p.setPriority(-1);
- p.setImage(CLASS_ICON);
- list.add(p);
- }
- }
- iterator = getTemplates().iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next();
- RuleCompletionProposal p = new RuleCompletionProposal(
- prefix.length(), name, name + "( )",
- name.length() + 2);
- p.setPriority(-1);
- p.setImage(CLASS_ICON);
- list.add(p);
- }
- break;
- case Location.LOCATION_LHS_INSIDE_CONDITION_START:
- String className = (String) location
- .getProperty(Location.LOCATION_PROPERTY_CLASS_NAME);
- String propertyName = (String) location
- .getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME);
- if (className != null) {
- boolean isTemplate = addFactTemplatePropertyProposals(
- prefix, className, list);
- if (!isTemplate) {
- ClassTypeResolver resolver = new ClassTypeResolver(
- getImports(), ProjectClassLoader
- .getProjectClassLoader(getEditor()));
- try {
- String currentClass = className;
- if (propertyName != null) {
- String[] nestedProperties = propertyName.split("\\.");
- int nbSuperProperties = nestedProperties.length - 1;
- if (propertyName.endsWith(".")) {
- nbSuperProperties++;
- }
- for (int i = 0; i < nbSuperProperties; i++) {
- String simplePropertyName = nestedProperties[i];
- currentClass = getSimplePropertyClass(currentClass, simplePropertyName);
- currentClass = convertToNonPrimitiveClass(currentClass);
- }
- }
- RuleCompletionProposal p = new RuleCompletionProposal(prefix.length(), "this");
- p.setImage(METHOD_ICON);
- list.add(p);
- Class clazz = resolver.resolveType(currentClass);
- if (clazz != null) {
- if (Map.class.isAssignableFrom(clazz)) {
- p = new RuleCompletionProposal(
- prefix.length(), "this['']", "this['']", 6);
- p.setImage(METHOD_ICON);
- list.add(p);
- }
- ClassFieldInspector inspector = new ClassFieldInspector(clazz);
- Map types = inspector.getFieldTypes();
- Iterator iterator2 = inspector.getFieldNames().keySet().iterator();
- while (iterator2.hasNext()) {
- String name = (String) iterator2.next();
- p = new RuleCompletionProposal(
- prefix.length(), name, name + " ");
- p.setImage(METHOD_ICON);
- list.add(p);
- Class type = (Class) types.get(name);
- if (type != null && Map.class.isAssignableFrom(type)) {
- name += "['']";
- p = new RuleCompletionProposal(
- prefix.length(), name, name, name.length() - 2);
- p.setImage(METHOD_ICON);
- list.add(p);
- }
- }
- }
- } catch (IOException exc) {
- // Do nothing
- } catch (ClassNotFoundException exc) {
- // Do nothing
- }
- }
- }
- break;
- case Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR:
- className = (String) location
- .getProperty(Location.LOCATION_PROPERTY_CLASS_NAME);
- String property = (String) location
- .getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME);
- String type = getPropertyClass(className, property);
+ if ( location.getType() == Location.LOCATION_RULE_HEADER ) {
+ addRuleHeaderProposals( list,
+ prefix,
+ backText );
+ } else if ( location.getType() == Location.LOCATION_RHS ) {
+ addRHSCompletionProposals( list,
+ prefix,
+ backText,
+ (String) location.getProperty( Location.LOCATION_LHS_CONTENT ),
+ (String) location.getProperty( Location.LOCATION_RHS_CONTENT ) );
+ } else {
+ addLHSCompletionProposals( list,
+ location,
+ prefix,
+ backText );
+ }
- list.add(new RuleCompletionProposal(prefix.length(), "==",
- "== ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "!=",
- "!= ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), ":", ": ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "->",
- "-> ( )", 5, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "memberOf",
- "memberOf ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "not memberOf",
- "not memberOf ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "in",
- "in ( )", 5, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "not in",
- "not in ( )", 9, DROOLS_ICON));
+ filterProposalsOnPrefix( prefix,
+ list );
+ return list;
+ } catch ( Throwable t ) {
+ t.printStackTrace();
+ DroolsEclipsePlugin.log( t );
+ }
+ return null;
+ }
- if (isComparable(type)) {
- list.add(new RuleCompletionProposal(prefix.length(), "<",
- "< ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "<=",
- "<= ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), ">",
- "> ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), ">=",
- ">= ", DROOLS_ICON));
- }
- if (type.equals("java.lang.String")) {
- list.add(new RuleCompletionProposal(prefix.length(),
- "matches", "matches \"\"", 9, DROOLS_ICON));
- }
- if (isSubtypeOf(type, "java.util.Collection")) {
- list.add(new RuleCompletionProposal(prefix.length(),
- "contains", "contains ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(),
- "excludes", "excludes ", DROOLS_ICON));
- }
- break;
- case Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT:
- // determine type
- className = (String) location
- .getProperty(Location.LOCATION_PROPERTY_CLASS_NAME);
- property = (String) location
- .getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME);
- String operator = (String) location
- .getProperty(Location.LOCATION_PROPERTY_OPERATOR);
- type = getPropertyClass(className, property);
+ protected void addRHSCompletionProposals(List list,
+ String prefix,
+ String backText,
+ String conditions,
+ String consequence) {
+ // only add functions and keywords if at the beginning of a
+ // new statement
+ String consequenceWithoutPrefix = consequence.substring( 0,
+ consequence.length() - prefix.length() );
+ if ( context == null ) {
+ context = new CompletionContext( backText );
+ }
- if ("in".equals(operator)) {
- list.add(new RuleCompletionProposal(prefix.length(), "()",
- "( )", 2, DROOLS_ICON));
- break;
- }
+ boolean startOfDialectExpression = isStartOfDialectExpression( consequenceWithoutPrefix );
+ if ( startOfDialectExpression ) {
+ addRHSKeywordCompletionProposals( list,
+ prefix );
+ addRHSFunctionCompletionProposals( list,
+ prefix );
+ }
- if ("contains".equals(operator) || "excludes".equals(operator)) {
- type = "java.lang.Object";
- }
+ if ( context.isJavaDialect() ) {
+ System.out.println( "MVEL: Adding Java Dialect completions" );
+ addRHSJavaCompletionProposals( list,
+ prefix,
+ backText,
+ consequence );
+ } else {
+ System.out.println( "MVEL: Adding MVEL Dialect completions" );
+ addRHSMvelCompletionProposals( list,
+ prefix,
+ backText,
+ consequence,
+ startOfDialectExpression );
+ }
+ }
- if ("memberOf".equals(operator)) {
- type = "java.util.Collection";
- }
+ protected void addLHSCompletionProposals(List list,
+ Location location,
+ String prefix,
+ String backText) {
+ switch ( location.getType() ) {
+ case Location.LOCATION_LHS_BEGIN_OF_CONDITION :
+ // if we are at the beginning of a new condition
+ // add drools keywords
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "and",
+ "and ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "or",
+ "or ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "from",
+ "from ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "forall",
+ "forall( )",
+ 8,
+ DROOLS_ICON ) );
- boolean isObject = false;
- if ("java.lang.Object".equals(type)) {
- isObject = true;
- }
+ RuleCompletionProposal prop = new RuleCompletionProposal( prefix.length(),
+ "eval",
+ "eval( )",
+ 6 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ prop = new RuleCompletionProposal( prefix.length(),
+ "then",
+ "then" + System.getProperty( "line.separator" ) + "\t" );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ // we do not break but also add all elements that are needed for
+ // and/or
+ case Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR :
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "not",
+ "not ",
+ DROOLS_ICON ) );
+ // we do not break but also add all elements that are needed for
+ // not
+ case Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT :
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "exists",
+ "exists ",
+ DROOLS_ICON ) );
+ // we do not break but also add all elements that are needed for
+ // exists
+ case Location.LOCATION_LHS_FROM_ACCUMULATE :
+ case Location.LOCATION_LHS_FROM_COLLECT :
+ case Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS :
+ // and add imported classes
+ Iterator iterator = getImports().iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next();
+ int index = name.lastIndexOf( "." );
+ if ( index != -1 ) {
+ String className = name.substring( index + 1 );
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ className,
+ className + "( )",
+ className.length() + 2 );
+ p.setPriority( -1 );
+ p.setImage( CLASS_ICON );
+ list.add( p );
+ }
+ }
+ iterator = getClassesInPackage().iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next();
+ int index = name.lastIndexOf( "." );
+ if ( index != -1 ) {
+ String className = name.substring( index + 1 );
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ className,
+ className + "( )",
+ className.length() + 2 );
+ p.setPriority( -1 );
+ p.setImage( CLASS_ICON );
+ list.add( p );
+ }
+ }
+ iterator = getTemplates().iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next();
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ name,
+ name + "( )",
+ name.length() + 2 );
+ p.setPriority( -1 );
+ p.setImage( CLASS_ICON );
+ list.add( p );
+ }
+ break;
+ case Location.LOCATION_LHS_INSIDE_CONDITION_START :
+ String className = (String) location.getProperty( Location.LOCATION_PROPERTY_CLASS_NAME );
+ String propertyName = (String) location.getProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME );
+ if ( className != null ) {
+ boolean isTemplate = addFactTemplatePropertyProposals( prefix,
+ className,
+ list );
+ if ( !isTemplate ) {
+ ClassTypeResolver resolver = new ClassTypeResolver( getImports(),
+ ProjectClassLoader.getProjectClassLoader( getEditor() ) );
+ try {
+ String currentClass = className;
+ if ( propertyName != null ) {
+ String[] nestedProperties = propertyName.split( "\\." );
+ int nbSuperProperties = nestedProperties.length - 1;
+ if ( propertyName.endsWith( "." ) ) {
+ nbSuperProperties++;
+ }
+ for ( int i = 0; i < nbSuperProperties; i++ ) {
+ String simplePropertyName = nestedProperties[i];
+ currentClass = getSimplePropertyClass( currentClass,
+ simplePropertyName );
+ currentClass = convertToNonPrimitiveClass( currentClass );
+ }
+ }
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ "this" );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ Class clazz = resolver.resolveType( currentClass );
+ if ( clazz != null ) {
+ if ( Map.class.isAssignableFrom( clazz ) ) {
+ p = new RuleCompletionProposal( prefix.length(),
+ "this['']",
+ "this['']",
+ 6 );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ }
+ ClassFieldInspector inspector = new ClassFieldInspector( clazz );
+ Map types = inspector.getFieldTypes();
+ Iterator iterator2 = inspector.getFieldNames().keySet().iterator();
+ while ( iterator2.hasNext() ) {
+ String name = (String) iterator2.next();
+ p = new RuleCompletionProposal( prefix.length(),
+ name,
+ name + " " );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ Class type = (Class) types.get( name );
+ if ( type != null && Map.class.isAssignableFrom( type ) ) {
+ name += "['']";
+ p = new RuleCompletionProposal( prefix.length(),
+ name,
+ name,
+ name.length() - 2 );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ }
+ }
+ }
+ } catch ( IOException exc ) {
+ // Do nothing
+ } catch ( ClassNotFoundException exc ) {
+ // Do nothing
+ }
+ }
+ }
+ break;
+ case Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR :
+ className = (String) location.getProperty( Location.LOCATION_PROPERTY_CLASS_NAME );
+ String property = (String) location.getProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME );
+ String type = getPropertyClass( className,
+ property );
- list.add(new RuleCompletionProposal(prefix.length(), "null",
- "null ", DROOLS_ICON));
- if ("boolean".equals(type)) {
- list.add(new RuleCompletionProposal(prefix.length(),
- "true", "true ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(),
- "false", "false ", DROOLS_ICON));
- }
- if (isObject || "java.lang.String".equals(type)) {
- list.add(new RuleCompletionProposal(prefix.length(),
- "\"\"", "\"\"", 1, DROOLS_ICON));
- }
- if (isObject || "java.util.Date".equals(type)) {
- list
- .add(new RuleCompletionProposal(prefix.length(),
- "\"dd-mmm-yyyy\"", "\"dd-mmm-yyyy\"", 1,
- DROOLS_ICON));
- }
- list.add(new RuleCompletionProposal(prefix.length(), "()",
- "( )", 2, DROOLS_ICON));
- // add parameters with possibly matching type
- DrlParser parser = new DrlParser();
- try {
- PackageDescr descr = parser.parse(backText);
- List rules = descr.getRules();
- if (rules != null && rules.size() == 1) {
- Map result = new HashMap();
- getRuleParameters(result, ((RuleDescr) rules.get(0))
- .getLhs().getDescrs());
- Iterator iterator2 = result.entrySet().iterator();
- while (iterator2.hasNext()) {
- Map.Entry entry = (Map.Entry) iterator2.next();
- String paramName = (String) entry.getKey();
- String paramType = (String) entry.getValue();
- if (isSubtypeOf(paramType, type)) {
- RuleCompletionProposal proposal = new RuleCompletionProposal(
- prefix.length(), paramName);
- proposal.setPriority(-1);
- proposal.setImage(VARIABLE_ICON);
- list.add(proposal);
- }
- }
- }
- } catch (DroolsParserException exc) {
- // do nothing
- }
- // add globals with possibly matching type
- List globals = getGlobals();
- if (globals != null) {
- for (iterator = globals.iterator(); iterator.hasNext(); ) {
- GlobalDescr global = (GlobalDescr) iterator.next();
- if (isSubtypeOf(global.getType(), type)) {
- RuleCompletionProposal proposal = new RuleCompletionProposal(
- prefix.length(), global.getIdentifier());
- proposal.setPriority(-1);
- proposal.setImage(VARIABLE_ICON);
- list.add(proposal);
- }
- }
- }
- break;
- case Location.LOCATION_LHS_INSIDE_EVAL:
- String content = (String) location
- .getProperty(Location.LOCATION_EVAL_CONTENT);
- list.addAll(getJavaCompletionProposals(content, prefix,
- getRuleParameters(backText)));
- break;
- case Location.LOCATION_LHS_INSIDE_CONDITION_END:
- list.add(new RuleCompletionProposal(prefix.length(), "&&", "&& ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "||", "|| ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), ",", ", ",
- DROOLS_ICON));
- break;
- case Location.LOCATION_LHS_FROM:
- String fromText = (String) location
- .getProperty(Location.LOCATION_FROM_CONTENT);
- int index = fromText.indexOf('.');
- if (index == -1) {
- // add accumulate and collect keyword
- list
- .add(new RuleCompletionProposal(
- prefix.length(),
- "accumulate",
- "accumulate ( , init ( ), action ( ), result ( ) )",
- 13, DROOLS_ICON));
- PackageBuilderConfiguration config = new PackageBuilderConfiguration(
- ProjectClassLoader.getProjectClassLoader(getEditor()), null);
- Map accumulateFunctions = config.getAccumulateFunctionsMap();
- for (Iterator iterator2 = accumulateFunctions.keySet().iterator(); iterator2.hasNext(); ) {
- String accumulateFunction = (String) iterator2.next();
- list.add(new RuleCompletionProposal(
- prefix.length(),
- "accumulate " + accumulateFunction,
- "accumulate ( , " + accumulateFunction + "( ) )",
- 13, DROOLS_ICON));
- }
- list.add(new RuleCompletionProposal(prefix.length(),
- "collect", "collect ( )", 10, DROOLS_ICON));
- // add all functions
- if ("".equals(fromText)) {
- List functions = getFunctions();
- iterator = functions.iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next() + "()";
- prop = new RuleCompletionProposal(prefix.length(),
- name, name, name.length() - 1);
- prop.setPriority(-1);
- prop.setImage(METHOD_ICON);
- list.add(prop);
- }
- }
- list.addAll(getJavaCompletionProposals(fromText, prefix,
- getRuleParameters(backText)));
- }
- break;
- case Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE:
- content = (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
- list.addAll(getJavaCompletionProposals(content, prefix,
- getRuleParameters(backText)));
- break;
- case Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE:
- content = (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
- content += (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT);
- list.addAll(getJavaCompletionProposals(content, prefix,
- getRuleParameters(backText)));
- break;
- case Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE:
- content = (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
- content += (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT);
- content += (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT);
- list.addAll(getJavaCompletionProposals(content, prefix,
- getRuleParameters(backText)));
- break;
- }
- }
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "==",
+ "== ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "!=",
+ "!= ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ ":",
+ ": ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "->",
+ "-> ( )",
+ 5,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "memberOf",
+ "memberOf ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "not memberOf",
+ "not memberOf ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "in",
+ "in ( )",
+ 5,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "not in",
+ "not in ( )",
+ 9,
+ DROOLS_ICON ) );
- private String getPropertyClass(String className, String propertyName) {
- if (className != null && propertyName != null) {
- FactTemplateDescr template = getTemplate(className);
- if (template != null) {
- Iterator iterator = template.getFields().iterator();
- while (iterator.hasNext()) {
- FieldTemplateDescr field = (FieldTemplateDescr) iterator
- .next();
- if (propertyName.equals(field.getName())) {
- String type = field.getClassType();
- if (isPrimitiveType(type)) {
- return type;
- }
- ClassTypeResolver resolver = new ClassTypeResolver(
- getImports(), ProjectClassLoader
- .getProjectClassLoader(getEditor()));
- try {
- Class clazz = resolver.resolveType(type);
- if (clazz != null) {
- return clazz.getName();
- }
- } catch (ClassNotFoundException exc) {
- exc.printStackTrace();
- // Do nothing
- }
- }
- }
- // if not found, return null
- } else {
- String[] nestedProperties = propertyName.split("\\.");
- String currentClass = className;
- for (int i = 0; i < nestedProperties.length; i++) {
- String simplePropertyName = nestedProperties[i];
- currentClass = getSimplePropertyClass(currentClass, simplePropertyName);
- }
- return currentClass;
- }
- }
- return null;
- }
+ if ( isComparable( type ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "<",
+ "< ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "<=",
+ "<= ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ ">",
+ "> ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ ">=",
+ ">= ",
+ DROOLS_ICON ) );
+ }
+ if ( type.equals( "java.lang.String" ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "matches",
+ "matches \"\"",
+ 9,
+ DROOLS_ICON ) );
+ }
+ if ( isSubtypeOf( type,
+ "java.util.Collection" ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "contains",
+ "contains ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "excludes",
+ "excludes ",
+ DROOLS_ICON ) );
+ }
+ break;
+ case Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT :
+ // determine type
+ className = (String) location.getProperty( Location.LOCATION_PROPERTY_CLASS_NAME );
+ property = (String) location.getProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME );
+ String operator = (String) location.getProperty( Location.LOCATION_PROPERTY_OPERATOR );
+ type = getPropertyClass( className,
+ property );
- private String getSimplePropertyClass(String className, String propertyName) {
- if ("this".equals(propertyName)) {
- return className;
- }
- if (propertyName.endsWith("]")) {
- // TODO can we take advantage of generics here?
- return "java.lang.Object";
- }
- ClassTypeResolver resolver = new ClassTypeResolver(
- getImports(), ProjectClassLoader
- .getProjectClassLoader(getEditor()));
- try {
- Class clazz = resolver.resolveType(className);
- if (clazz != null) {
- Class clazzz = (Class) new ClassFieldInspector(clazz)
- .getFieldTypes().get(propertyName);
- if (clazzz != null) {
- return clazzz.getName();
- }
- }
- } catch (IOException exc) {
- // Do nothing
- } catch (ClassNotFoundException exc) {
- // Do nothing
- }
- return "java.lang.Object";
- }
+ if ( "in".equals( operator ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "()",
+ "( )",
+ 2,
+ DROOLS_ICON ) );
+ break;
+ }
- private Map getRuleParameters(String backText) {
- Map result = new HashMap();
- // add globals
- List globals = getGlobals();
- if (globals != null) {
- for (Iterator iterator = globals.iterator(); iterator.hasNext(); ) {
- GlobalDescr global = (GlobalDescr) iterator.next();
- result.put(global.getIdentifier(), global.getType());
- }
- }
- // add parameters defined in conditions
- try {
- DrlParser parser = new DrlParser();
- PackageDescr descr = parser.parse(backText);
- List rules = descr.getRules();
- if (rules != null && rules.size() == 1) {
- getRuleParameters(result, ((RuleDescr) rules.get(0)).getLhs()
- .getDescrs());
- }
- } catch (DroolsParserException exc) {
- // do nothing
- }
- return result;
- }
+ if ( "contains".equals( operator ) || "excludes".equals( operator ) ) {
+ type = "java.lang.Object";
+ }
- private boolean isComparable(String type) {
- if (type == null) {
- return false;
- }
- if (isPrimitiveNumericType(type)) {
- return true;
- }
- if (isObjectNumericType(type)) {
- return true;
- }
- if (isSubtypeOf(type, "java.lang.Comparable")) {
- return true;
- }
- return false;
- }
+ if ( "memberOf".equals( operator ) ) {
+ type = "java.util.Collection";
+ }
- private boolean isPrimitiveType(String type) {
- return isPrimitiveNumericType(type) || type.equals("boolean");
- }
+ boolean isObject = false;
+ if ( "java.lang.Object".equals( type ) ) {
+ isObject = true;
+ }
- private boolean isPrimitiveNumericType(String type) {
- return type.equals("byte") || type.equals("short")
- || type.equals("int") || type.equals("long")
- || type.equals("float") || type.equals("double")
- || type.equals("char");
- }
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "null",
+ "null ",
+ DROOLS_ICON ) );
+ if ( "boolean".equals( type ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "true",
+ "true ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "false",
+ "false ",
+ DROOLS_ICON ) );
+ }
+ if ( isObject || "java.lang.String".equals( type ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "\"\"",
+ "\"\"",
+ 1,
+ DROOLS_ICON ) );
+ }
+ if ( isObject || "java.util.Date".equals( type ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "\"dd-mmm-yyyy\"",
+ "\"dd-mmm-yyyy\"",
+ 1,
+ DROOLS_ICON ) );
+ }
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "()",
+ "( )",
+ 2,
+ DROOLS_ICON ) );
+ // add parameters with possibly matching type
+ if ( context == null ) {
+ context = new CompletionContext( backText );
+ }
- private boolean isObjectNumericType(String type) {
- return type.equals("java.lang.Byte") || type.equals("java.lang.Short")
- || type.equals("java.lang.Integer")
- || type.equals("java.lang.Long")
- || type.equals("java.lang.Float")
- || type.equals("java.lang.Double")
- || type.equals("java.lang.Char");
- }
+ if ( context.getRule() != null ) {
+ Map result = new HashMap();
+ addRuleParameters( result,
+ context.getRule().getLhs().getDescrs() );
+ Iterator iterator2 = result.entrySet().iterator();
+ while ( iterator2.hasNext() ) {
+ Map.Entry entry = (Map.Entry) iterator2.next();
+ String paramName = (String) entry.getKey();
+ String paramType = (String) entry.getValue();
+ if ( isSubtypeOf( paramType,
+ type ) ) {
+ RuleCompletionProposal proposal = new RuleCompletionProposal( prefix.length(),
+ paramName );
+ proposal.setPriority( -1 );
+ proposal.setImage( VARIABLE_ICON );
+ list.add( proposal );
+ }
+ }
+ } // add globals with possibly matching type
+ List globals = getGlobals();
+ if ( globals != null ) {
+ for ( iterator = globals.iterator(); iterator.hasNext(); ) {
+ GlobalDescr global = (GlobalDescr) iterator.next();
+ if ( isSubtypeOf( global.getType(),
+ type ) ) {
+ RuleCompletionProposal proposal = new RuleCompletionProposal( prefix.length(),
+ global.getIdentifier() );
+ proposal.setPriority( -1 );
+ proposal.setImage( VARIABLE_ICON );
+ list.add( proposal );
+ }
+ }
+ }
+ break;
+ case Location.LOCATION_LHS_INSIDE_EVAL :
+ String content = (String) location.getProperty( Location.LOCATION_EVAL_CONTENT );
+ list.addAll( getJavaCompletionProposals( content,
+ prefix,
+ getRuleParameters( backText ) ) );
+ break;
+ case Location.LOCATION_LHS_INSIDE_CONDITION_END :
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "&&",
+ "&& ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "||",
+ "|| ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ ",",
+ ", ",
+ DROOLS_ICON ) );
+ break;
+ case Location.LOCATION_LHS_FROM :
+ String fromText = (String) location.getProperty( Location.LOCATION_FROM_CONTENT );
+ int index = fromText.indexOf( '.' );
+ if ( index == -1 ) {
+ // add accumulate and collect keyword
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "accumulate",
+ "accumulate ( , init ( ), action ( ), result ( ) )",
+ 13,
+ DROOLS_ICON ) );
+ PackageBuilderConfiguration config = new PackageBuilderConfiguration( ProjectClassLoader.getProjectClassLoader( getEditor() ),
+ null );
+ Map accumulateFunctions = config.getAccumulateFunctionsMap();
+ for ( Iterator iterator2 = accumulateFunctions.keySet().iterator(); iterator2.hasNext(); ) {
+ String accumulateFunction = (String) iterator2.next();
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "accumulate " + accumulateFunction,
+ "accumulate ( , " + accumulateFunction + "( ) )",
+ 13,
+ DROOLS_ICON ) );
+ }
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "collect",
+ "collect ( )",
+ 10,
+ DROOLS_ICON ) );
+ // add all functions
+ if ( "".equals( fromText ) ) {
+ List functions = getFunctions();
+ iterator = functions.iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next() + "()";
+ prop = new RuleCompletionProposal( prefix.length(),
+ name,
+ name,
+ name.length() - 1 );
+ prop.setPriority( -1 );
+ prop.setImage( METHOD_ICON );
+ list.add( prop );
+ }
+ }
+ list.addAll( getJavaCompletionProposals( fromText,
+ prefix,
+ getRuleParameters( backText ) ) );
+ }
+ break;
+ case Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE :
+ content = (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT );
+ list.addAll( getJavaCompletionProposals( content,
+ prefix,
+ getRuleParameters( backText ) ) );
+ break;
+ case Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE :
+ content = (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT );
+ content += (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT );
+ list.addAll( getJavaCompletionProposals( content,
+ prefix,
+ getRuleParameters( backText ) ) );
+ break;
+ case Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE :
+ content = (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT );
+ content += (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT );
+ content += (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT );
+ list.addAll( getJavaCompletionProposals( content,
+ prefix,
+ getRuleParameters( backText ) ) );
+ break;
+ }
+ }
- /**
- * Returns true if the first class is the same or a subtype of the second
- * class.
- *
- * @param class1
- * @param class2
- * @return
- */
- private boolean isSubtypeOf(String class1, String class2) {
- if (class1 == null || class2 == null) {
- return false;
- }
- class1 = convertToNonPrimitiveClass(class1);
- class2 = convertToNonPrimitiveClass(class2);
- // TODO add code to take primitive types into account
- ClassTypeResolver resolver = new ClassTypeResolver(getImports(), ProjectClassLoader
- .getProjectClassLoader(getEditor()));
- try {
- Class clazz1 = resolver.resolveType(class1);
- Class clazz2 = resolver.resolveType(class2);
- if (clazz1 == null || clazz2 == null) {
- return false;
- }
- return clazz2.isAssignableFrom(clazz1);
- } catch (ClassNotFoundException exc) {
- return false;
- }
- }
+ private String getPropertyClass(String className,
+ String propertyName) {
+ if ( className != null && propertyName != null ) {
+ FactTemplateDescr template = getTemplate( className );
+ if ( template != null ) {
+ Iterator iterator = template.getFields().iterator();
+ while ( iterator.hasNext() ) {
+ FieldTemplateDescr field = (FieldTemplateDescr) iterator.next();
+ if ( propertyName.equals( field.getName() ) ) {
+ String type = field.getClassType();
+ if ( isPrimitiveType( type ) ) {
+ return type;
+ }
+ ClassTypeResolver resolver = new ClassTypeResolver( getImports(),
+ ProjectClassLoader.getProjectClassLoader( getEditor() ) );
+ try {
+ Class clazz = resolver.resolveType( type );
+ if ( clazz != null ) {
+ return clazz.getName();
+ }
+ } catch ( ClassNotFoundException exc ) {
+ exc.printStackTrace();
+ // Do nothing
+ }
+ }
+ }
+ // if not found, return null
+ } else {
+ String[] nestedProperties = propertyName.split( "\\." );
+ String currentClass = className;
+ for ( int i = 0; i < nestedProperties.length; i++ ) {
+ String simplePropertyName = nestedProperties[i];
+ currentClass = getSimplePropertyClass( currentClass,
+ simplePropertyName );
+ }
+ return currentClass;
+ }
+ }
+ return null;
+ }
- private String convertToNonPrimitiveClass(String clazz) {
- if (!isPrimitiveType(clazz)) {
- return clazz;
- }
- if ("byte".equals(clazz)) {
- return "java.lang.Byte";
- } else if ("short".equals(clazz)) {
- return "java.lang.Short";
- } else if ("int".equals(clazz)) {
- return "java.lang.Integer";
- } else if ("long".equals(clazz)) {
- return "java.lang.Long";
- } else if ("float".equals(clazz)) {
- return "java.lang.Float";
- } else if ("double".equals(clazz)) {
- return "java.lang.Double";
- } else if ("char".equals(clazz)) {
- return "java.lang.Char";
- } else if ("boolean".equals(clazz)) {
- return "java.lang.Boolean";
- }
- // should never occur
- return null;
- }
+ private String getSimplePropertyClass(String className,
+ String propertyName) {
+ if ( "this".equals( propertyName ) ) {
+ return className;
+ }
+ if ( propertyName.endsWith( "]" ) ) {
+ // TODO can we take advantage of generics here?
+ return "java.lang.Object";
+ }
+ ClassTypeResolver resolver = new ClassTypeResolver( getImports(),
+ ProjectClassLoader.getProjectClassLoader( getEditor() ) );
+ try {
+ Class clazz = resolver.resolveType( className );
+ if ( clazz != null ) {
+ Class clazzz = (Class) new ClassFieldInspector( clazz ).getFieldTypes().get( propertyName );
+ if ( clazzz != null ) {
+ return clazzz.getName();
+ }
+ }
+ } catch ( IOException exc ) {
+ // Do nothing
+ } catch ( ClassNotFoundException exc ) {
+ // Do nothing
+ }
+ return "java.lang.Object";
+ }
- private void addRHSFunctionCompletionProposals(List list, String prefix) {
- Iterator iterator;
- RuleCompletionProposal prop;
- List functions = getFunctions();
- iterator = functions.iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next() + "()";
- prop = new RuleCompletionProposal(prefix.length(), name,
- name + ";", name.length() - 1);
- prop.setPriority(-1);
- prop.setImage(METHOD_ICON);
- list.add(prop);
- }
- }
+ private Map getRuleParameters(String backText) {
+ Map result = new HashMap();
+ // add globals
+ List globals = getGlobals();
+ if ( globals != null ) {
+ for ( Iterator iterator = globals.iterator(); iterator.hasNext(); ) {
+ GlobalDescr global = (GlobalDescr) iterator.next();
+ result.put( global.getIdentifier(),
+ global.getType() );
+ }
+ }
- private void addRHSKeywordCompletionProposals(
- List list, String prefix) {
- RuleCompletionProposal prop = new RuleCompletionProposal(prefix
- .length(), "update", "update();", 7);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- prop = new RuleCompletionProposal(prefix.length(), "retract",
- "retract();", 8);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- prop = new RuleCompletionProposal(prefix.length(), "insert",
- "insert();", 7);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- prop = new RuleCompletionProposal(prefix.length(), "insertLogical",
- "insertLogical();", 14);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- }
+ if ( context == null ) {
+ context = new CompletionContext( backText );
+ }
+ if ( context.getRule() == null ) {
+ return result;
+ }
- private void addRHSJavaCompletionProposals(List list, String prefix, String backText,
- String conditions, String consequence) {
- list.addAll(getJavaCompletionProposals(consequence, prefix,
- getRuleParameters(backText)));
- }
+ // add parameters defined in conditions
+ addRuleParameters( result,
+ context.getRule().getLhs().getDescrs() );
+ return result;
+ }
- private void getRuleParameters(Map result, List descrs) {
- if (descrs == null) {
- return;
- }
- Iterator iterator = descrs.iterator();
- while (iterator.hasNext()) {
- BaseDescr descr = (BaseDescr) iterator.next();
- getRuleParameters(result, descr);
- }
- }
+ private boolean isComparable(String type) {
+ if ( type == null ) {
+ return false;
+ }
+ if ( isPrimitiveNumericType( type ) ) {
+ return true;
+ }
+ if ( isObjectNumericType( type ) ) {
+ return true;
+ }
+ if ( isSubtypeOf( type,
+ "java.lang.Comparable" ) ) {
+ return true;
+ }
+ return false;
+ }
- private void getRuleParameters(Map result, BaseDescr descr) {
- if (descr == null) {
- return;
- }
- if (descr instanceof PatternDescr) {
- String name = ((PatternDescr) descr).getIdentifier();
- if (name != null) {
- result.put(name, ((PatternDescr) descr).getObjectType());
- }
- getRuleSubParameters(result, ((PatternDescr) descr).getDescrs(),
- ((PatternDescr) descr).getObjectType());
- } else if (descr instanceof AndDescr) {
- getRuleParameters(result, ((AndDescr) descr).getDescrs());
- } else if (descr instanceof OrDescr) {
- getRuleParameters(result, ((OrDescr) descr).getDescrs());
- } else if (descr instanceof ExistsDescr) {
- getRuleParameters(result, ((ExistsDescr) descr).getDescrs());
- } else if (descr instanceof NotDescr) {
- getRuleParameters(result, ((NotDescr) descr).getDescrs());
- }
- }
+ private boolean isPrimitiveType(String type) {
+ return isPrimitiveNumericType( type ) || type.equals( "boolean" );
+ }
- private void getRuleSubParameters(Map result, List descrs, String clazz) {
- if (descrs == null) {
- return;
- }
- Iterator iterator = descrs.iterator();
- while (iterator.hasNext()) {
- BaseDescr descr = (BaseDescr) iterator.next();
- if (descr instanceof FieldBindingDescr) {
- FieldBindingDescr fieldDescr = (FieldBindingDescr) descr;
- String name = fieldDescr.getIdentifier();
- String field = fieldDescr.getFieldName();
- String type = getPropertyClass(clazz, field);
- if (name != null) {
- result.put(name, type);
- }
- }
- }
- }
+ private boolean isPrimitiveNumericType(String type) {
+ return type.equals( "byte" ) || type.equals( "short" ) || type.equals( "int" ) || type.equals( "long" ) || type.equals( "float" ) || type.equals( "double" ) || type.equals( "char" );
+ }
- private void addRuleHeaderProposals(List list, String prefix, String backText) {
- list.add(new RuleCompletionProposal(prefix.length(), "salience",
- "salience ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "no-loop",
- "no-loop ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "agenda-group",
- "agenda-group ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "duration",
- "duration ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "auto-focus",
- "auto-focus ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "when", "when"
- + System.getProperty("line.separator") + "\t ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(),
- "activation-group", "activation-group ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "date-effective",
- "date-effective \"dd-MMM-yyyy\"", 16, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "date-expires",
- "date-expires \"dd-MMM-yyyy\"", 14, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "enabled",
- "enabled false", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "ruleflow-group",
- "ruleflow-group \"\"", 16, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "lock-on-active",
- "lock-on-active ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "dialect \"java\"",
- "dialect \"java\"", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "dialect \"mvel\"",
- "dialect \"mvel\"", DROOLS_ICON));
- }
+ private boolean isObjectNumericType(String type) {
+ return type.equals( "java.lang.Byte" ) || type.equals( "java.lang.Short" ) || type.equals( "java.lang.Integer" ) || type.equals( "java.lang.Long" ) || type.equals( "java.lang.Float" ) || type.equals( "java.lang.Double" )
+ || type.equals( "java.lang.Char" );
+ }
- private boolean addFactTemplatePropertyProposals(String prefix,
- String templateName, List list) {
- FactTemplateDescr descr = getTemplate(templateName);
- if (descr == null) {
- return false;
- }
- Iterator iterator = descr.getFields().iterator();
- while (iterator.hasNext()) {
- FieldTemplateDescr field = (FieldTemplateDescr) iterator.next();
- String fieldName = field.getName();
- RuleCompletionProposal p = new RuleCompletionProposal(prefix
- .length(), fieldName, fieldName + " ");
- p.setImage(METHOD_ICON);
- list.add(p);
- }
- return true;
- }
+ /**
+ * Returns true if the first class is the same or a subtype of the second
+ * class.
+ *
+ * @param class1
+ * @param class2
+ * @return
+ */
+ private boolean isSubtypeOf(String class1,
+ String class2) {
+ if ( class1 == null || class2 == null ) {
+ return false;
+ }
+ class1 = convertToNonPrimitiveClass( class1 );
+ class2 = convertToNonPrimitiveClass( class2 );
+ // TODO add code to take primitive types into account
+ ClassTypeResolver resolver = new ClassTypeResolver( getImports(),
+ ProjectClassLoader.getProjectClassLoader( getEditor() ) );
+ try {
+ Class clazz1 = resolver.resolveType( class1 );
+ Class clazz2 = resolver.resolveType( class2 );
+ if ( clazz1 == null || clazz2 == null ) {
+ return false;
+ }
+ return clazz2.isAssignableFrom( clazz1 );
+ } catch ( ClassNotFoundException exc ) {
+ return false;
+ }
+ }
+ private String convertToNonPrimitiveClass(String clazz) {
+ if ( !isPrimitiveType( clazz ) ) {
+ return clazz;
+ }
+ if ( "byte".equals( clazz ) ) {
+ return "java.lang.Byte";
+ } else if ( "short".equals( clazz ) ) {
+ return "java.lang.Short";
+ } else if ( "int".equals( clazz ) ) {
+ return "java.lang.Integer";
+ } else if ( "long".equals( clazz ) ) {
+ return "java.lang.Long";
+ } else if ( "float".equals( clazz ) ) {
+ return "java.lang.Float";
+ } else if ( "double".equals( clazz ) ) {
+ return "java.lang.Double";
+ } else if ( "char".equals( clazz ) ) {
+ return "java.lang.Char";
+ } else if ( "boolean".equals( clazz ) ) {
+ return "java.lang.Boolean";
+ }
+ // should never occur
+ return null;
+ }
+
+ private void addRHSFunctionCompletionProposals(List list,
+ String prefix) {
+ Iterator iterator;
+ RuleCompletionProposal prop;
+ List functions = getFunctions();
+ iterator = functions.iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next() + "()";
+ prop = new RuleCompletionProposal( prefix.length(),
+ name,
+ name + ";",
+ name.length() - 1 );
+ prop.setPriority( -1 );
+ prop.setImage( METHOD_ICON );
+ list.add( prop );
+ }
+ }
+
+ private void addRHSKeywordCompletionProposals(List list,
+ String prefix) {
+ RuleCompletionProposal prop = new RuleCompletionProposal( prefix.length(),
+ "update",
+ "update();",
+ 7 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ prop = new RuleCompletionProposal( prefix.length(),
+ "retract",
+ "retract();",
+ 8 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ prop = new RuleCompletionProposal( prefix.length(),
+ "insert",
+ "insert();",
+ 7 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ prop = new RuleCompletionProposal( prefix.length(),
+ "insertLogical",
+ "insertLogical();",
+ 14 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ }
+
+ private void addRHSJavaCompletionProposals(List list,
+ String prefix,
+ String backText,
+ String consequence) {
+ list.addAll( getJavaCompletionProposals( consequence,
+ prefix,
+ getRuleParameters( backText ) ) );
+ }
+
+ private void addRHSMvelCompletionProposals(List list,
+ String prefix,
+ String backText,
+ String consequence,
+ boolean expressionStart) {
+
+ List mvelCompletionProposals = getMvelCompletionProposals( consequence,
+ prefix,
+ getRuleParameters( backText ),
+ backText,
+ expressionStart );
+ list.addAll( mvelCompletionProposals );
+ }
+
+ private List getMvelCompletionProposals(final String consequence,
+ final String prefix,
+ Map params,
+ String backText,
+ boolean startOfExpression) {
+
+ final List proposals = new ArrayList();
+
+ if ( !(getEditor() instanceof DRLRuleEditor) ) {
+ return proposals;
+ }
+
+ String compilableConsequence = CompletionUtil.getCompilableText( consequence );
+
+ //attempt to compile and analyze
+ try {
+ DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource( (DRLRuleEditor) getEditor(),
+ true,
+ true );
+
+ ParserContext compilationContext = createMvelAnalysisContext( params,
+ drlInfo,
+ compilableConsequence );
+
+ if ( startOfExpression ) {
+ List jdtProps = getJavaMvelCompletionProposals( "",
+ prefix,
+ params );
+ proposals.addAll( jdtProps );
+ addMvelVariables( proposals,
+ compilationContext );
+
+ addMvelInputs( proposals,
+ compilationContext );
+
+ } else {
+ //we are completing the methods for an existing type or variable
+ //find the last type in the expression to complete against
+ String[] lines = compilableConsequence.split( ";" );
+ String lastLine = lines[lines.length - 1];
+ Class lastType = new PropertyVerifier( lastLine,
+ compilationContext ).analyze();
+
+ String type = lastType.getPackage().getName() + "." + lastType.getName();
+ String javaText = "\n"+type + " o = new " + type + "(); o.";
+ List jdtProps = getJavaMvelCompletionProposals( javaText,
+ prefix,
+ params );
+ proposals.addAll( jdtProps );
+ }
+
+ } catch ( Throwable e ) {
+ // do nothing
+ e.printStackTrace();
+ }
+
+ return proposals;
+ }
+
+ private ParserContext createMvelAnalysisContext(Map params,
+ DRLInfo drlInfo,
+ String compilableConsequence) throws DroolsParserException {
+
+ String currentRulename = context.getRule().getName();
+ RuleInfo[] ruleInfos = drlInfo.getRuleInfos();
+ RuleInfo currentRule = null;
+ for ( int i = 0; i < ruleInfos.length; i++ ) {
+ if ( currentRulename.equals( ruleInfos[i].getRuleName() ) ) {
+ currentRule = ruleInfos[i];
+ break;
+ }
+ }
+ MVELDialect dialect = (MVELDialect) currentRule.getDialect();
+
+ ExpressionCompiler compiler = new ExpressionCompiler( compilableConsequence );
+
+ final ParserContext initialContext = new ParserContext();
+ initialContext.setStrictTypeEnforcement( false );
+ Map imports = dialect.getClassImportResolverFactory().getImportedClasses();
+ imports.putAll( dialect.getStaticMethodImportResolverFactory().getImportedMethods() );
+ initialContext.setImports( imports );
+ initialContext.setInterceptors( dialect.getInterceptors() );
+ initialContext.setInputs( params );
+
+ compiler.compile( initialContext );
+
+ ParserContext compilationContext = compiler.getParserContextState();
+ return compilationContext;
+ }
+
+ private void addMvelInputs(final List proposals,
+ ParserContext compilationContext) {
+ Map inputs = compilationContext.getInputs();
+ for ( Iterator iter = inputs.keySet().iterator(); iter.hasNext(); ) {
+ String prop = (String) iter.next();
+ RuleCompletionProposal rcp = new RuleCompletionProposal( prop.length(),
+ prop );
+ rcp.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ proposals.add( rcp );
+
+ System.out.println( " MVEL: added inputs from mvel eval: name:" + prop + " type:" + inputs.get( prop ).getClass() );
+ }
+ }
+
+ private void addMvelVariables(final List proposals,
+ ParserContext compilationContext) {
+ Map variables = compilationContext.getVariables();
+ for ( Iterator iter = variables.keySet().iterator(); iter.hasNext(); ) {
+ String prop = (String) iter.next();
+ RuleCompletionProposal rcp = new RuleCompletionProposal( prop.length(),
+ prop );
+ rcp.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ proposals.add( rcp );
+
+ System.out.println( " MVEL: added completion: got variable from mvel eval: name:" + prop + " type:" + variables.get( prop ).getClass() );
+ }
+ }
+
+ private void addRuleParameters(Map result,
+ List descrs) {
+ if ( descrs == null ) {
+ return;
+ }
+ Iterator iterator = descrs.iterator();
+ while ( iterator.hasNext() ) {
+ BaseDescr descr = (BaseDescr) iterator.next();
+ addRuleParameters( result,
+ descr );
+ }
+ }
+
+ private void addRuleParameters(Map result,
+ BaseDescr descr) {
+ if ( descr == null ) {
+ return;
+ }
+ if ( descr instanceof PatternDescr ) {
+ String name = ((PatternDescr) descr).getIdentifier();
+ if ( name != null ) {
+ result.put( name,
+ ((PatternDescr) descr).getObjectType() );
+ }
+ addRuleSubParameters( result,
+ ((PatternDescr) descr).getDescrs(),
+ ((PatternDescr) descr).getObjectType() );
+ } else if ( descr instanceof AndDescr ) {
+ addRuleParameters( result,
+ ((AndDescr) descr).getDescrs() );
+ } else if ( descr instanceof OrDescr ) {
+ addRuleParameters( result,
+ ((OrDescr) descr).getDescrs() );
+ } else if ( descr instanceof ExistsDescr ) {
+ addRuleParameters( result,
+ ((ExistsDescr) descr).getDescrs() );
+ } else if ( descr instanceof NotDescr ) {
+ addRuleParameters( result,
+ ((NotDescr) descr).getDescrs() );
+ }
+ }
+
+ private void addRuleSubParameters(Map result,
+ List descrs,
+ String clazz) {
+ if ( descrs == null ) {
+ return;
+ }
+ Iterator iterator = descrs.iterator();
+ while ( iterator.hasNext() ) {
+ BaseDescr descr = (BaseDescr) iterator.next();
+ if ( descr instanceof FieldBindingDescr ) {
+ FieldBindingDescr fieldDescr = (FieldBindingDescr) descr;
+ String name = fieldDescr.getIdentifier();
+ String field = fieldDescr.getFieldName();
+ String type = getPropertyClass( clazz,
+ field );
+ if ( name != null ) {
+ result.put( name,
+ type );
+ }
+ }
+ }
+ }
+
+ private void addRuleHeaderProposals(List list,
+ String prefix,
+ String backText) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "salience",
+ "salience ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "no-loop",
+ "no-loop ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "agenda-group",
+ "agenda-group ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "duration",
+ "duration ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "auto-focus",
+ "auto-focus ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "when",
+ "when" + System.getProperty( "line.separator" ) + "\t ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "activation-group",
+ "activation-group ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "date-effective",
+ "date-effective \"dd-MMM-yyyy\"",
+ 16,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "date-expires",
+ "date-expires \"dd-MMM-yyyy\"",
+ 14,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "enabled",
+ "enabled false",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "ruleflow-group",
+ "ruleflow-group \"\"",
+ 16,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "lock-on-active",
+ "lock-on-active ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "dialect \"java\"",
+ "dialect \"java\"",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "dialect \"mvel\"",
+ "dialect \"mvel\"",
+ DROOLS_ICON ) );
+ }
+
+ private boolean addFactTemplatePropertyProposals(String prefix,
+ String templateName,
+ List list) {
+ FactTemplateDescr descr = getTemplate( templateName );
+ if ( descr == null ) {
+ return false;
+ }
+ Iterator iterator = descr.getFields().iterator();
+ while ( iterator.hasNext() ) {
+ FieldTemplateDescr field = (FieldTemplateDescr) iterator.next();
+ String fieldName = field.getName();
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ fieldName,
+ fieldName + " " );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ }
+ return true;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -6,41 +6,67 @@
/**
* Holds a completion proposal to be popped up.
- *
+ *
* @author Michael Neale
*
*/
public class RuleCompletionProposal {
-
+
private String content;
private String display;
- private int replacementLength;
- private int cursorPosition;
- private Image image;
- private int priority;
-
+ private int replacementLength;
+ private int cursorPosition;
+ private Image image;
+ private int priority;
+
/** This is used when the stuff that is displayed, is the stuff that is used. */
- public RuleCompletionProposal(int replacementLength, String content) {
- this(replacementLength, content, content);
+ public RuleCompletionProposal(int replacementLength,
+ String content) {
+ this( replacementLength,
+ content,
+ content );
}
/** This is used when a different display value is shown to what is put in when selected. */
- public RuleCompletionProposal(int replacementLength, String display, String content) {
- this(replacementLength, display, content, content.length());
+ public RuleCompletionProposal(int replacementLength,
+ String display,
+ String content) {
+ this( replacementLength,
+ display,
+ content,
+ content.length() );
}
-
+
/** Also allows an icon to be used */
- public RuleCompletionProposal(int replacementLength, String display, String content, Image image) {
- this(replacementLength, display, content, content.length(), image);
+ public RuleCompletionProposal(int replacementLength,
+ String display,
+ String content,
+ Image image) {
+ this( replacementLength,
+ display,
+ content,
+ content.length(),
+ image );
}
- public RuleCompletionProposal(int replacementLength, String display, String content, int cursorPosition) {
- this(replacementLength, display, content, cursorPosition, null);
+ public RuleCompletionProposal(int replacementLength,
+ String display,
+ String content,
+ int cursorPosition) {
+ this( replacementLength,
+ display,
+ content,
+ cursorPosition,
+ null );
}
-
+
/** This is used when a different display value is shown to what is put in when selected. */
- public RuleCompletionProposal(int replacementLength, String display, String content, int cursorPosition, Image image) {
- this.replacementLength = replacementLength;
+ public RuleCompletionProposal(int replacementLength,
+ String display,
+ String content,
+ int cursorPosition,
+ Image image) {
+ this.replacementLength = replacementLength;
this.content = content;
this.display = display;
this.cursorPosition = cursorPosition;
@@ -54,46 +80,71 @@
public String getDisplay() {
return display;
}
-
+
public int getReplacementLength() {
- return replacementLength;
- }
+ return replacementLength;
+ }
- public int getCursorPosition() {
- return cursorPosition;
+ public int getCursorPosition() {
+ return cursorPosition;
}
-
- public Image getImage() {
- return image;
- }
- public void setImage(Image image) {
- this.image = image;
- }
-
- public int getPriority() {
- return priority;
- }
+ public Image getImage() {
+ return image;
+ }
- public void setPriority(int priority) {
- this.priority = priority;
- }
-
+ public void setImage(Image image) {
+ this.image = image;
+ }
+
+ public int getPriority() {
+ return priority;
+ }
+
+ public void setPriority(int priority) {
+ this.priority = priority;
+ }
+
public String toString() {
return content;
}
-
- public static class RuleCompletionProposalComparator implements Comparator {
- public int compare(Object arg0, Object arg1) {
- RuleCompletionProposal prop0 = (RuleCompletionProposal) arg0;
- RuleCompletionProposal prop1 = (RuleCompletionProposal) arg1;
- if (prop0.getPriority() == prop1.getPriority()) {
- return prop0.getDisplay().compareTo(prop1.getDisplay());
- } else if (prop0.getPriority() > prop1.getPriority()) {
- return -1;
- } else {
- return 1;
- }
- }
+
+ public static class RuleCompletionProposalComparator
+ implements
+ Comparator {
+ public int compare(Object arg0,
+ Object arg1) {
+ RuleCompletionProposal prop0 = (RuleCompletionProposal) arg0;
+ RuleCompletionProposal prop1 = (RuleCompletionProposal) arg1;
+ if ( prop0.getPriority() == prop1.getPriority() ) {
+ return prop0.getDisplay().compareTo( prop1.getDisplay() );
+ } else if ( prop0.getPriority() > prop1.getPriority() ) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
}
-}
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((content == null) ? 0 : content.hashCode());
+ result = PRIME * result + ((display == null) ? 0 : display.hashCode());
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final RuleCompletionProposal other = (RuleCompletionProposal) obj;
+ if ( content == null ) {
+ if ( other.content != null ) return false;
+ } else if ( !content.equals( other.content ) ) return false;
+ if ( display == null ) {
+ if ( other.display != null ) return false;
+ } else if ( !display.equals( other.display ) ) return false;
+ return true;
+ }
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -13,31 +13,31 @@
/**
* Break apart the rule source, very very simply.
- *
+ *
* The job of the partitioner is to identify if the cursor position
* is in a rule block, or not. Comments are also generated as a
* separate partition.
- *
+ * TODO: add support for dialect based partitioning for correct syntaxhighlighting
* @author Michael Neale
*/
public class DRLPartionScanner extends RuleBasedPartitionScanner {
public static final String RULE_PART_CONTENT = "__partition_rule_content";
public static final String RULE_COMMENT = "__partition_multiline_comment";
-
+
public static final String[] LEGAL_CONTENT_TYPES = {
IDocument.DEFAULT_CONTENT_TYPE,
RULE_PART_CONTENT,
RULE_COMMENT
};
-
+
public DRLPartionScanner() {
initialise();
}
-
+
private void initialise() {
List rules = new ArrayList();
-
+
// rules
IToken rulePartition = new Token(RULE_PART_CONTENT);
rules.add(new MultiLineRule("\nrule", "\nend", rulePartition));
@@ -47,7 +47,7 @@
// comments
IToken comment = new Token(RULE_COMMENT);
rules.add( new MultiLineRule("/*", "*/", comment, (char) 0, true));
-
+
setPredicateRules((IPredicateRule[]) rules.toArray(new IPredicateRule[rules.size()]));
}
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -21,43 +21,45 @@
/**
* Basic keyword scanner for syntax highlighting.
- *
+ *
* @author Michael Neale
*/
public class DRLScanner extends RuleBasedScanner {
-
+
private static final Color KEYWORD_COLOR = ColorManager.getInstance().getColor(ColorManager.KEYWORD);
private static final Color COMMENT_COLOR = ColorManager.getInstance().getColor(ColorManager.SINGLE_LINE_COMMENT);
private static final Color STRING_COLOR = ColorManager.getInstance().getColor(ColorManager.STRING);
private static final Color DEFAULT_COLOR = ColorManager.getInstance().getColor(ColorManager.DEFAULT);
-
+
private static final String[] DROOLS_KEYWORDS = Keywords.getInstance().getAllDroolsKeywords();
private static final String[] JAVA_KEYWORDS = Keywords.getInstance().getAllJavaKeywords();
+ private static final String[] MVEL_KEYWORDS = Keywords.getInstance().getAllMvelKeywords();
- private static final String[] TYPES = { "void", "boolean", "char", "byte", "short", "strictfp", "int", "long", "float", "double" };
+ private static final String[] JAVA_TYPES = { "void", "boolean", "char", "byte", "short", "strictfp", "int", "long", "float", "double" };
- private static final String[] CONSTANTS = { "false", "true", "null" };
-
+ private static final String[] JAVA_CONSTANTS = { "false", "true", "null" };
+ private static final String[] MVEL_CONSTANTS = { "false", "true", "null", "nil", "empty", "this" };
+
public DRLScanner() {
-
+
IToken keyword = new Token(new TextAttribute(KEYWORD_COLOR, null, SWT.BOLD));
IToken comment= new Token(new TextAttribute(COMMENT_COLOR));
IToken string = new Token(new TextAttribute(STRING_COLOR));
IToken other = new Token(new TextAttribute(DEFAULT_COLOR));
-
+
List rules = new ArrayList();
rules.add(new EndOfLineRule("//", comment));
rules.add(new EndOfLineRule("#", comment));
-
+
// Add rule for strings and character constants.
- rules.add(new SingleLineRule("\"", "\"", string, '\\'));
- rules.add(new SingleLineRule("'", "'", string, '\\'));
-
- //for unfilled "holes"
+ rules.add(new SingleLineRule("\"", "\"", string, '\\'));
+ rules.add(new SingleLineRule("'", "'", string, '\\'));
+
+ //for unfilled "holes"
//rules.add(new SingleLineRule("{", "}", comment));
-
+
// Add generic whitespace rule.
rules.add(new WhitespaceRule(new WhitespaceDetector()));
@@ -65,18 +67,27 @@
WordRule wordRule= new WordRule(new RuleWordDetector(), other);
for (int i= 0; i < DROOLS_KEYWORDS.length; i++)
wordRule.addWord(DROOLS_KEYWORDS[i], keyword);
+
for (int i= 0; i < JAVA_KEYWORDS.length; i++)
wordRule.addWord(JAVA_KEYWORDS[i], keyword);
- for (int i= 0; i < TYPES.length; i++)
- wordRule.addWord(TYPES[i], keyword);
- for (int i= 0; i < CONSTANTS.length; i++)
- wordRule.addWord(CONSTANTS[i], keyword);
- rules.add(wordRule);
-
+ for (int i= 0; i < JAVA_TYPES.length; i++)
+ wordRule.addWord(JAVA_TYPES[i], keyword);
+ for (int i= 0; i < JAVA_CONSTANTS.length; i++)
+ wordRule.addWord(JAVA_CONSTANTS[i], keyword);
+
+ //FIXME: this a bit brutal. we should identify different highlighting for Java and Mvel
+ for (int i= 0; i < MVEL_KEYWORDS.length; i++)
+ wordRule.addWord(MVEL_KEYWORDS[i], keyword);
+ for (int i= 0; i < MVEL_CONSTANTS.length; i++)
+ wordRule.addWord(MVEL_CONSTANTS[i], keyword);
+
+
+ rules.add(wordRule);
+
IRule[] result= new IRule[rules.size()];
- rules.toArray(result);
-
+ rules.toArray(result);
+
setRules(result);
}
-
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupDirector.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupDirector.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupDirector.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -6,7 +6,7 @@
public class DroolsSourceLookupDirector extends AbstractSourceLookupDirector {
public void initializeParticipants() {
- addParticipants(new ISourceLookupParticipant[]{new DroolsSourceLookupParticipant()});
+ addParticipants(new ISourceLookupParticipant[]{new MVELSourceLookupParticipant(), new DroolsSourceLookupParticipant()} );
}
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupParticipant.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupParticipant.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupParticipant.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -12,7 +12,8 @@
if (object instanceof DroolsStackFrame) {
RuleInfo ruleInfo = ((DroolsStackFrame) object).getExecutingRuleInfo();
if (ruleInfo != null) {
- return ruleInfo.getSourcePathName();
+ String p = ruleInfo.getSourcePathName();
+ return p;
}
FunctionInfo functionInfo = ((DroolsStackFrame) object).getExecutingFunctionInfo();
if (functionInfo != null) {
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/MVELSourceLookupParticipant.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,57 @@
+package org.drools.eclipse.launching;
+
+import org.drools.eclipse.DRLInfo.FunctionInfo;
+import org.drools.eclipse.DRLInfo.RuleInfo;
+import org.drools.eclipse.debug.core.DroolsDebugTarget;
+import org.drools.eclipse.debug.core.MVELStackFrame;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
+import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant;
+
+class MVELSourceLookupParticipant extends JavaSourceLookupParticipant{
+ public void dispose() {
+ //do nothing
+ }
+
+ public Object[] findSourceElements(Object object) throws CoreException {
+ if (object instanceof MVELStackFrame) {
+ MVELStackFrame frame = (MVELStackFrame) object;
+
+ int lineNumber = frame.getBreakpointLineNumber();
+ String mvelName = frame.getMVELName();
+
+ IDebugTarget target = frame.getDebugTarget();
+ if (target instanceof DroolsDebugTarget) {
+ DroolsDebugTarget droolsTarget = (DroolsDebugTarget)target;
+ Object bpoint = droolsTarget.getDroolsBreakpoint(mvelName, lineNumber);
+ return new Object[] {bpoint};
+ }
+ }
+ return null;
+ }
+
+ public String getSourceName(Object object) throws CoreException {
+ if (object instanceof MVELStackFrame) {
+ MVELStackFrame frame = (MVELStackFrame) object;
+ RuleInfo ruleInfo = frame.getExecutingRuleInfo();
+ if (ruleInfo != null) {
+ String sourcePath = ruleInfo.getSourcePathName();
+ return sourcePath;
+ }
+ FunctionInfo functionInfo = frame.getExecutingFunctionInfo();
+ if (functionInfo != null) {
+ return functionInfo.getSourcePathName();
+ }
+ }
+ return super.getSourceName(object);
+ }
+
+ public void init(ISourceLookupDirector director) {
+ //do nothing
+ }
+
+ public void sourceContainersChanged(ISourceLookupDirector director) {
+ //do nothing
+ }
+}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,20 @@
+# this contains the mvel keywords for syntax highlighting
+if
+else
+foreach
+switch
+var
+while
+do
+for
+return
+instanceof
+is
+contains
+soundslike
+strsim
+convertable_to
+new
+in
+with
+
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/.classpath 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/.classpath 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,11 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry kind="src" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry combineaccessrules="false" kind="src" path="/drools-compiler"/>
- <classpathentry combineaccessrules="false" kind="src" path="/drools-core"/>
- <classpathentry combineaccessrules="false" kind="src" path="/drools-decisiontables"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="src" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,55 @@
+package org.drools.eclipse.editors.completion;
+
+import org.drools.eclipse.editors.scanners.DRLPartionScanner;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.FastPartitioner;
+
+import junit.framework.TestCase;
+
+public class AbstractCompletionProcessorTest extends TestCase {
+
+ public void testReadBackwards() throws BadLocationException {
+ //setup
+ IDocument doc = getDoc();
+ int rhsStartOffset = 150;
+
+ AbstractCompletionProcessor proc = new MockCompletionProcessor();
+ String backText = proc.readBackwards( rhsStartOffset,
+ doc );
+ String rule2 = "\nrule YourRule \n" + //
+ " dialect \"mvel\"\n" + //
+ " when\n" + //
+ " Class ( )\n" + //
+ " then\n";
+
+ assertEquals( rule2,
+ backText );
+ }
+
+ private IDocument getDoc() {
+ String input = "rule MyRule \n" + //
+ " when\n" + //
+ " Class ( )\n" + //
+ " then\n" + //
+ " System.out.println(\"Hey\");\n" + //
+ "end\n" + //
+ "rule YourRule \n" + //
+ " dialect \"mvel\"\n" + //
+ " when\n" + //
+ " Class ( )\n" + //
+ " then\n" + //
+ " " +//
+ "end\n\n" ;
+
+ IDocument doc = new Document( input );
+ IDocumentPartitioner partitioner = new FastPartitioner( new DRLPartionScanner(),
+ DRLPartionScanner.LEGAL_CONTENT_TYPES );
+ partitioner.connect( doc );
+ doc.setDocumentPartitioner( partitioner );
+ return doc;
+ }
+
+}
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,1542 @@
+package org.drools.eclipse.editors.completion;
+
+import org.drools.lang.Location;
+
+import junit.framework.TestCase;
+
+/**
+ * Test to check the location determination when doing code completion inside
+ * rule condtions.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ *
+ */
+public class CompletionContextTest extends TestCase {
+
+ public void testColumnOperatorPattern() {
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("(name:property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name:property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name:property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", property2 ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name : property2 ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name:property2 ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name : property2 ").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("(prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name:prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("(name:prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property <= ").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : property == ").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("(property==").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property contains ").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", property2 >= ").matches());
+ }
+
+ public void testColumnArgumentPattern() {
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property >= ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(property== ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( name : property == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(name:property== ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( name : property == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\", property2 == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\",property2== ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\", property2 == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == otherProp").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(property==otherProp").matches());
+ }
+
+ public void testCheckLHSLocationDetermination() {
+ String input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class( condition == true ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " class: Class( condition == true, condition2 == null ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class( condition == true ) \n" +
+ " Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " class: Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " class:Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** Inside of condition: start */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( na";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("na", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name.subProperty['test'].subsu";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("name.subProperty['test'].subsu", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( condition == true, ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( condition == true, na";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( condition == true, \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( c: condition, \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name: ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name:";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ /** Inside of condition: Operator */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class(property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class (name:property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class (name:property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1, name : property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1 == \"value\", name : property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1 == \"value\",property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1, \n" +
+ " name : property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ /** Inside of condition: argument */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property== ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : property <= ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("<=", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name:property != ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("!=", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1, property2 == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class (name:property== ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property == otherPropertyN";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property == \"someth";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property contains ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("contains", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property excludes ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("excludes", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property matches \"prop";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("matches", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property in ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("in", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property in ('1', '2') ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property in ('1', '2'), ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not in ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("in", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not in ('1', '2') ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not in ('1', '2'), ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property memberOf ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("memberOf", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property memberOf collection ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property memberOf collection, ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not memberOf ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("memberOf", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not memberOf collection ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not memberOf collection, ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+
+ /** EXISTS */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ( Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ( name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** NOT */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ // TODO
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists name : Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not Class () \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** AND */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) && ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class () and ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " name : Class ( name: property ) and ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name: property ) \n" +
+ " and ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) && name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and not Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and exists Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( name ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("name", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( name == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) and not ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) and exists ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and not Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** OR */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) || ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class () or ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " name : Class ( name: property ) or ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name: property ) \n" +
+ " or ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) || name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( name ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("name", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( name == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) or not ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) or exists ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ /** EVAL */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( myCla";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("myCla", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMetho";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMetho", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMethod(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMethod(", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMethod().get";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMethod().get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMethod(\"someStringWith)))\").get";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMethod(\"someStringWith)))\").get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMethod(\"someStringWith(((\").get";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMethod(\"someStringWith(((\").get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( true )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getProperty(name).isTrue() )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getProperty(\"someStringWith(((\").isTrue() )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getProperty((((String) s) )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getProperty((((String) s) )", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getProperty((((String) s))))";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( true ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** MULTIPLE RESTRICTIONS */
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : property1, property2 > 0 && ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property1 < 20, property2 > 0 && ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && < ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("<", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && < 10 ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && < 10, ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 || ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 || \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : property1, property2 > 0 || ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property1 < 20, property2 > 0 || ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && < 10 ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 || < 10 ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property == \"test\" || == \"test2\" ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ /** FROM */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) fr";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_FROM_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from myGlob";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+ assertEquals("myGlob", location.getProperty(Location.LOCATION_FROM_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from myGlobal.get";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+ assertEquals("myGlobal.get", location.getProperty(Location.LOCATION_FROM_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from myGlobal.getList() \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from getDroolsFunction() \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** FROM ACCUMULATE */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( total += $cheese.getPrice(); ), \n" +
+ " result( new Integer( total ) ) \n" +
+ " ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
+ assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+ assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( total += $cheese.getPrice(); ), \n" +
+ " result( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
+ assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+ assertEquals(" total += $cheese.getPrice(); ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
+ assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total =";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
+ assertEquals("int total =", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( total += $ch";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
+ assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+ assertEquals("total += $ch", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( total += $cheese.getPrice(); ), \n" +
+ " result( new Integer( tot";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
+ assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+ assertEquals(" total += $cheese.getPrice(); ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
+ assertEquals("new Integer( tot", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ /** FROM COLLECT */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_COLLECT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_COLLECT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( \n" +
+ " Cheese( type == $likes )" +
+ " ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( \n" +
+ " Cheese( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( \n" +
+ " Cheese( type ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( \n" +
+ " Cheese( type == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ /** NESTED FROM */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) from ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+
+//moved to testCheckLHSLocationDetermination_Failing
+// input =
+// "rule MyRule \n" +
+// " when \n" +
+// " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
+// location = new CompletionContext(input).getLocation();
+// assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** FORALL */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( " +
+ " Class ( pr";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("pr", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( " +
+ " Class ( property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( " +
+ " Class ( property == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( " +
+ " Class ( property == \"test\")" +
+ " C";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+ }
+
+ public void testCheckLHSLocationDetermination_Failing() {
+ String input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ }
+
+ public void testCheckRHSLocationDetermination() {
+ String input =
+ "rule MyRule \n" +
+ " when\n" +
+ " Class ( )\n" +
+ " then\n" +
+ " ";
+
+ Location location = new CompletionContext(input).getLocation();
+
+ assertEquals(Location.LOCATION_RHS, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_RHS_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when\n" +
+ " Class ( )\n" +
+ " then\n" +
+ " assert(null);\n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RHS, location.getType());
+ assertEquals("assert(null);\n ", location.getProperty(Location.LOCATION_RHS_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when\n" +
+ " Class ( )\n" +
+ " then\n" +
+ " meth";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RHS, location.getType());
+ assertEquals("meth", location.getProperty(Location.LOCATION_RHS_CONTENT));
+ }
+
+ public void testCheckRuleHeaderLocationDetermination() {
+ String input =
+ "rule MyRule ";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " salience 12 activation-group \"my";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+
+ // KRISV: still can't make this work... apparently, ANTLR is trying to recover from
+ // the error (unkown token) by deleting the token. I don't know why it continues to
+ // execute actions though, if the EOF is found.
+// input =
+// "rule \"Hello World\" ruleflow-group \"hello\" s";
+// location = new CompletionContext(input).getLocation();
+// assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckRuleHeaderLocationDetermination_dialect1() {
+ String input =
+ "rule MyRule \n" +
+ " dialect \"java\"";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckRuleHeaderLocationDetermination_dialect2() {
+ String input =
+ "rule MyRule \n" +
+ " dialect \"mvel\"";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckRuleHeaderLocationDetermination_dialect3() {
+ String input =
+ "rule MyRule \n" +
+ " dialect ";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckRuleHeaderLocationDetermination_dialect4() {
+ String input =
+ "rule MyRule \n" +
+ " dialect \"";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckQueryLocationDetermination() {
+ String input =
+ "query MyQuery ";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+
+ input =
+ "query \"MyQuery\" ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+
+ input =
+ "query MyQuery() ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "query MyQuery \n" +
+ " Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ }
+
+}
Copied: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java)
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -0,0 +1,143 @@
+package org.drools.eclipse.editors.completion;
+
+import org.eclipse.jdt.core.Signature;
+
+import junit.framework.TestCase;
+
+public class CompletionUtilTest extends TestCase {
+
+ public void testIsGetter() {
+ assertTrue( CompletionUtil.isGetter( "getThis",
+ 0,
+ "String" ) );
+ }
+
+ public void testIsGetterCannotReturnVoid() {
+ assertFalse( CompletionUtil.isGetter( "getThis",
+ 0,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsGetterWrongPrefix() {
+ assertFalse( CompletionUtil.isGetter( "hasThis",
+ 0,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsGetterTooManyArgs() {
+ assertFalse( CompletionUtil.isGetter( "getThis",
+ 2,
+ "String" ) );
+ }
+
+ public void testIsGetterMethodNameTooShort() {
+ assertFalse( CompletionUtil.isGetter( "get",
+ 2,
+ "String" ) );
+ }
+
+ public void testIsIsGetter() {
+ assertTrue( CompletionUtil.isIsGetter( "isGood",
+ 0,
+ Signature.SIG_BOOLEAN ) );
+ }
+
+ public void testIsIsGetterWrongPrefix() {
+ assertFalse( CompletionUtil.isIsGetter( "getThis",
+ 0,
+ Signature.SIG_BOOLEAN ) );
+ }
+
+ public void testIsIsGetterAlwaysReturnsBoolean() {
+ assertFalse( CompletionUtil.isIsGetter( "isThis",
+ 0,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsIsGetterTooManyArgs() {
+ assertFalse( CompletionUtil.isIsGetter( "isThis",
+ 2,
+ "String" ) );
+ }
+
+ public void testIsIsGetterMethodNameTooShort() {
+ assertFalse( CompletionUtil.isIsGetter( "is",
+ 2,
+ "String" ) );
+ }
+
+ public void testIsSetter() {
+ assertTrue( CompletionUtil.isSetter( "setThat",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsSetterWrongPrefix() {
+ assertFalse( CompletionUtil.isSetter( "getThat",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsSetterTooShort() {
+ assertFalse( CompletionUtil.isSetter( "se",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsSetterNoArgs() {
+ assertFalse( CompletionUtil.isSetter( "setThat",
+ 0,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsSetterWrongType() {
+ assertFalse( CompletionUtil.isSetter( "setThat",
+ 1,
+ "String" ) );
+ }
+
+ public void testGetPropertyName() {
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "getMe",
+ 0,
+ "String" ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "isMe",
+ 0,
+ Signature.SIG_BOOLEAN ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "setMe",
+ 1,
+ Signature.SIG_VOID ) );
+
+ assertEquals( "setMe",
+ CompletionUtil.getPropertyName( "setMe",
+ 0,
+ Signature.SIG_VOID ) );
+
+ assertEquals( "MySuperMethod",
+ CompletionUtil.getPropertyName( "MySuperMethod",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testGetPropertyNameStripsParenthesis() {
+
+ assertEquals( "MySuperMethod()",
+ CompletionUtil.getPropertyName( "MySuperMethod()",
+ 1,
+ Signature.SIG_VOID ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "getMe()",
+ 0,
+ "String" ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "isMe()",
+ 0,
+ Signature.SIG_BOOLEAN ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "setMe()",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/IncompleteParsingTest.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/IncompleteParsingTest.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/IncompleteParsingTest.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -18,8 +18,8 @@
import org.drools.lang.descr.VariableRestrictionDescr;
/**
- * Test to check the results from parsing incomplete rule fragments.
- *
+ * Test to check the results from parsing incomplete rule fragments.
+ *
* @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
*/
public class IncompleteParsingTest extends TestCase {
@@ -34,7 +34,7 @@
}
return null;
}
-
+
private PackageDescr parseString(String s) {
DrlParser parser = new DrlParser();
try {
@@ -44,26 +44,26 @@
}
return null;
}
-
-
+
+
public void testParsingColumn() {
- String input =
+ String input =
"rule MyRule \n" +
" when \n" +
" ";
RuleDescr rule = parseRuleString(input);
assertEquals(0, rule.getLhs().getDescrs().size());
-
+
/**
* This is how the parsed tree should look like:
- *
+ *
* RuleDescr
* PatternDescr [objectType = "Class"]
* FieldConstraintDescr [fieldName = "condition"]
* LiteralRestrictionDescr [evaluator = "==", text = "true"]
*/
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class( condition == true ) \n" +
@@ -85,7 +85,7 @@
assertEquals("==", restriction.getEvaluator());
assertEquals("true", restriction.getText());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" class: Class( condition == true, condition2 == null ) \n" +
@@ -95,14 +95,14 @@
pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertTrue(pattern.getEndCharacter() != -1);
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Cl";
rule = parseRuleString(input);
assertEquals(0, rule.getLhs().getDescrs().size());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class( condition == true ) \n" +
@@ -112,7 +112,7 @@
pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertTrue(pattern.getEndCharacter() != -1);
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" class:";
@@ -123,7 +123,7 @@
assertNull(pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" class: Cl";
@@ -136,7 +136,7 @@
assertEquals(0, pattern.getDescrs().size());
assertEquals(-1, pattern.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" class:Cl";
@@ -150,7 +150,7 @@
assertEquals(-1, pattern.getEndCharacter());
/** Inside of condition: start */
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class (";
@@ -162,9 +162,9 @@
assertEquals(0, pattern.getDescrs().size());
assertEquals(-1, pattern.getEndCharacter());
- input =
- "rule MyRule \n" +
- " when \n" +
+ input =
+ "rule MyRule \n" +
+ " when \n" +
" Class ( na";
rule = parseRuleString(input);
assertEquals(1, rule.getLhs().getDescrs().size());
@@ -172,13 +172,13 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(1, pattern.getDescrs().size());
- field = (FieldConstraintDescr) pattern.getDescrs().get(0);
+ field = (FieldConstraintDescr) pattern.getDescrs().get(0);
assertEquals( "na", field.getFieldName() );
assertEquals(-1, field.getEndCharacter());
- input =
- "rule MyRule \n" +
- " when \n" +
+ input =
+ "rule MyRule \n" +
+ " when \n" +
" Class ( name['xyz'].subname.subsubn";
rule = parseRuleString(input);
assertEquals(1, rule.getLhs().getDescrs().size());
@@ -186,11 +186,11 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(1, pattern.getDescrs().size());
- field = (FieldConstraintDescr) pattern.getDescrs().get(0);
+ field = (FieldConstraintDescr) pattern.getDescrs().get(0);
assertEquals( "name['xyz'].subname.subsubn", field.getFieldName() );
assertEquals(-1, field.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( condition == true, ";
@@ -200,10 +200,10 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(1, pattern.getDescrs().size());
- field = (FieldConstraintDescr) pattern.getDescrs().get(0);
+ field = (FieldConstraintDescr) pattern.getDescrs().get(0);
assertEquals(-1, field.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( c : condition, ";
@@ -213,10 +213,10 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(1, pattern.getDescrs().size());
- FieldBindingDescr fieldBinding = (FieldBindingDescr) pattern.getDescrs().get(0);
+ FieldBindingDescr fieldBinding = (FieldBindingDescr) pattern.getDescrs().get(0);
assertEquals(-1, fieldBinding.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( condition == true, na";
@@ -226,14 +226,14 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(2, pattern.getDescrs().size());
- field = (FieldConstraintDescr) pattern.getDescrs().get(0);
+ field = (FieldConstraintDescr) pattern.getDescrs().get(0);
assertEquals(-1, field.getEndCharacter());
assertEquals( "condition", field.getFieldName() );
field = (FieldConstraintDescr) pattern.getDescrs().get(1);
assertEquals( "na", field.getFieldName() );
assertEquals(-1, field.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( name:";
@@ -246,8 +246,8 @@
FieldBindingDescr binding1 = (FieldBindingDescr) pattern.getDescrs().get(0);
assertEquals("name", binding1.getIdentifier());
assertNull(binding1.getFieldName());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( property ";
@@ -261,8 +261,8 @@
assertEquals("property", field.getFieldName());
assertEquals(0, field.getRestrictions().size());
assertEquals(-1, field.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( name: property ";
@@ -275,8 +275,8 @@
FieldBindingDescr binding = (FieldBindingDescr) pattern.getDescrs().get(0);
assertEquals("name", binding.getIdentifier());
assertEquals("property", binding.getFieldName());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( name1: property1 == \"value1\", name2: property2 ";
@@ -298,8 +298,8 @@
binding = (FieldBindingDescr) pattern.getDescrs().get(2);
assertEquals("name2", binding.getIdentifier());
assertEquals("property2", binding.getFieldName());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class(name:property==";
@@ -315,8 +315,8 @@
field = (FieldConstraintDescr) pattern.getDescrs().get(1);
assertEquals("property", field.getFieldName());
assertEquals(1, field.getRestrictions().size());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class( property == otherPropertyN";
@@ -333,8 +333,8 @@
assertEquals("==", variable.getEvaluator());
assertEquals("otherPropertyN", variable.getIdentifier());
assertEquals(-1, field.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class( property == \"someth";
@@ -358,7 +358,7 @@
// TODO this method does not yet exist
// assertEquals(-1, field.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class( property contains ";
@@ -381,8 +381,8 @@
// starting character of this FieldConstraintDescr?
// TODO this method does not yet exist
assertEquals(-1, field.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class( property matches \"someth";
@@ -403,8 +403,8 @@
// assertEquals("someth", literal.getText());
// TODO this method does not yet exist
// assertEquals(-1, field.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" eval ( ";
@@ -413,8 +413,8 @@
EvalDescr eval = (EvalDescr) rule.getLhs().getDescrs().get(0);
assertEquals(input.indexOf( "eval" ), eval.getStartCharacter());
assertEquals(-1, eval.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( property > 0 & ";
@@ -433,7 +433,7 @@
RestrictionConnectiveDescr connective = (RestrictionConnectiveDescr) field.getRestriction();
assertEquals(RestrictionConnectiveDescr.AND, connective.getConnective());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( ) from a";
@@ -441,11 +441,11 @@
assertEquals(1, rule.getLhs().getDescrs().size());
pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Class", pattern.getObjectType());
- FromDescr from = (FromDescr) pattern.getSource();
+ FromDescr from = (FromDescr) pattern.getSource();
assertEquals(-1, from.getEndCharacter());
assertTrue(pattern.getEndCharacter() != -1);
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( property > 0 ) from myGlobal.getList() \n" +
@@ -457,7 +457,7 @@
from = (FromDescr) pattern.getSource();
assertTrue(from.getEndCharacter() != -1);
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( property > 0 ) from getDroolsFunction() \n" +
@@ -469,9 +469,9 @@
from = (FromDescr) pattern.getSource();
assertTrue(from.getEndCharacter() != -1);
}
-
+
public void testParsingCharactersStartEnd() {
- String input =
+ String input =
"package test; \n" +
"rule MyRule \n" +
" when \n" +
@@ -488,825 +488,4 @@
assertEquals(input.indexOf( ")" ), pattern.getRightParentCharacter());
assertEquals(input.indexOf( ")" ), pattern.getEndCharacter());
}
-
-// public void doTestRemainder() {
-//
-// /** EXISTS */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists ( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists(";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists ( Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists ( name : Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists Class (";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists Class ( ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// /** NOT */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " not ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " not Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " not exists ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " not exists Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " not Class (";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//
-// // TODO
-//// input =
-//// "rule MyRule \n" +
-//// " when \n" +
-//// " not exists Class (";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//
-//// input =
-//// "rule MyRule \n" +
-//// " when \n" +
-//// " not exists name : Class (";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " not Class () \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// /** AND */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) && ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class () and ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " name : Class ( name: property ) and ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( name: property ) \n" +
-// " and ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and Cl";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and name : Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) && name : Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and Class ( ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and not Class ( ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and exists Class ( ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and Class ( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and Class ( name ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-// assertEquals("name", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and Class ( name == ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists Class ( ) and not ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists Class ( ) and exists ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) and not Class ( ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// /** OR */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) or ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) || ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class () or ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " name : Class ( name: property ) or ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( name: property ) \n" +
-// " or ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) or Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) or name : Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) || name : Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) or Class ( ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) or Class ( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) or Class ( name ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-// assertEquals("name", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( ) or Class ( name == ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists Class ( ) or not ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " exists Class ( ) or exists ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
-//
-// /** EVAL */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval ( ";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval(";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( myCla";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("myCla", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMetho";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMetho", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMethod(";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMethod(", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMethod().get";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMethod().get", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMethod(\"someStringWith)))\").get";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMethod(\"someStringWith)))\").get", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMethod(\"someStringWith(((\").get";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMethod(\"someStringWith(((\").get", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( true )";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getProperty(name).isTrue() )";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getProperty(\"someStringWith(((\").isTrue() )";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getProperty((((String) s) )";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getProperty((((String) s) )", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getProperty((((String) s))))";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( true ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// /** MULTIPLE RESTRICTIONS */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 & ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 & " +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( name : property1, property2 > 0 & ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property2", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property1 < 20, property2 > 0 & ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property2", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 & < ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//// assertEquals("<", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_OPERATOR));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 | ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 | \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( name : property1, property2 > 0 | ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property2", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property1 < 20, property2 > 0 | ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property2", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 & < 10 ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 | < 10 ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property == \"test\" | == \"test2\" ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// /** FROM */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) fr";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM, location.getType());
-// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_FROM_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from myGlob";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_FROM, location.getType());
-//// assertEquals("myGlob", location.getProperty(LocationDeterminator.LOCATION_FROM_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from myGlobal.get";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_FROM, location.getType());
-//// assertEquals("myGlobal.get", location.getProperty(LocationDeterminator.LOCATION_FROM_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from myGlobal.getList() \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from getDroolsFunction() \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// /** FROM ACCUMULATE */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate ( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate(";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( total += $cheese.getPrice(); ), \n" +
-// " result( new Integer( total ) ) \n" +
-// " ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
-// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
-// assertEquals("int total = 0; ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( total += $cheese.getPrice(); ), \n" +
-// " result( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
-// assertEquals("int total = 0; ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-// assertEquals("total += $cheese.getPrice(); ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total =";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
-// assertEquals("int total =", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( total += $ch";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
-// assertEquals("int total = 0; ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-// assertEquals("total += $ch", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( total += $cheese.getPrice(); ), \n" +
-// " result( new Integer( tot";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
-// assertEquals("int total = 0; ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-// assertEquals("total += $cheese.getPrice(); ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-// assertEquals("new Integer( tot", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-// assertEquals("type", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-// assertEquals("type", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// /** FROM COLLECT */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_COLLECT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect(";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_COLLECT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( \n" +
-// " Cheese( type == $likes )" +
-// " ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( \n" +
-// " Cheese( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( \n" +
-// " Cheese( type ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-// assertEquals("type", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( \n" +
-// " Cheese( type == ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-// assertEquals("type", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-// }
-
}
Deleted: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java 2007-07-20 23:24:55 UTC (rev 13689)
@@ -1,1497 +0,0 @@
-package org.drools.eclipse.editors.completion;
-
-import org.drools.lang.Location;
-
-import junit.framework.TestCase;
-
-/**
- * Test to check the location determination when doing code completion inside
- * rule condtions.
- *
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
- *
- */
-public class LocationDeterminatorTest extends TestCase {
-
- public void testColumnOperatorPattern() {
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("(name:property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name:property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name:property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", property2 ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name : property2 ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name:property2 ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name : property2 ").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("(prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name:prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("(name:prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property <= ").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : property == ").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("(property==").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property contains ").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", property2 >= ").matches());
- }
-
- public void testColumnArgumentPattern() {
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property >= ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(property== ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( name : property == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(name:property== ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( name : property == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\", property2 == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\",property2== ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\", property2 == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == otherProp").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(property==otherProp").matches());
- }
-
- public void testCheckLHSLocationDetermination() {
- String input =
- "rule MyRule \n" +
- " when \n" +
- " ";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class( condition == true ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " class: Class( condition == true, condition2 == null ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class( condition == true ) \n" +
- " Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " class: Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " class:Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** Inside of condition: start */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( na";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("na", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name.subProperty['test'].subsu";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("name.subProperty['test'].subsu", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( condition == true, ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( condition == true, na";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( condition == true, \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( c: condition, \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name: ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name:";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- /** Inside of condition: Operator */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class(property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class (name:property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class (name:property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1, name : property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1 == \"value\", name : property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1 == \"value\",property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1, \n" +
- " name : property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- /** Inside of condition: argument */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property== ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : property <= ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("<=", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name:property != ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("!=", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1, property2 == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class (name:property== ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property == otherPropertyN";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property == \"someth";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property contains ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("contains", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property excludes ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("excludes", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property matches \"prop";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("matches", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property in ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("in", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property in ('1', '2') ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property in ('1', '2'), ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not in ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("in", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not in ('1', '2') ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not in ('1', '2'), ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property memberOf ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("memberOf", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property memberOf collection ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property memberOf collection, ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not memberOf ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("memberOf", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not memberOf collection ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not memberOf collection, ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
-
- /** EXISTS */
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists ( Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists ( name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** NOT */
- input =
- "rule MyRule \n" +
- " when \n" +
- " not ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not exists ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not exists Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- // TODO
- input =
- "rule MyRule \n" +
- " when \n" +
- " not exists Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not exists name : Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not Class () \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** AND */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) && ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class () and ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " name : Class ( name: property ) and ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name: property ) \n" +
- " and ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) && name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and not Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and exists Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Class ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Class ( name ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("name", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Class ( name == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) and not ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) and exists ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and not Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** OR */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) || ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class () or ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " name : Class ( name: property ) or ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name: property ) \n" +
- " or ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) || name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Class ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Class ( name ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("name", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Class ( name == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) or not ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) or exists ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- /** EVAL */
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( myCla";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("myCla", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMetho";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMetho", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMethod(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMethod(", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMethod().get";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMethod().get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMethod(\"someStringWith)))\").get";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMethod(\"someStringWith)))\").get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMethod(\"someStringWith(((\").get";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMethod(\"someStringWith(((\").get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( true )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getProperty(name).isTrue() )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getProperty(\"someStringWith(((\").isTrue() )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getProperty((((String) s) )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getProperty((((String) s) )", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getProperty((((String) s))))";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( true ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** MULTIPLE RESTRICTIONS */
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : property1, property2 > 0 && ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property1 < 20, property2 > 0 && ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && < ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("<", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && < 10 ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && < 10, ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 || ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 || \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : property1, property2 > 0 || ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property1 < 20, property2 > 0 || ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && < 10 ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 || < 10 ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property == \"test\" || == \"test2\" ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- /** FROM */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) fr";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_FROM_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from myGlob";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
- assertEquals("myGlob", location.getProperty(Location.LOCATION_FROM_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from myGlobal.get";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
- assertEquals("myGlobal.get", location.getProperty(Location.LOCATION_FROM_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from myGlobal.getList() \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from getDroolsFunction() \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** FROM ACCUMULATE */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( total += $cheese.getPrice(); ), \n" +
- " result( new Integer( total ) ) \n" +
- " ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
- assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
- assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( total += $cheese.getPrice(); ), \n" +
- " result( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
- assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
- assertEquals(" total += $cheese.getPrice(); ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
- assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total =";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
- assertEquals("int total =", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( total += $ch";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
- assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
- assertEquals("total += $ch", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( total += $cheese.getPrice(); ), \n" +
- " result( new Integer( tot";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
- assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
- assertEquals(" total += $cheese.getPrice(); ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
- assertEquals("new Integer( tot", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- /** FROM COLLECT */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_COLLECT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_COLLECT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( \n" +
- " Cheese( type == $likes )" +
- " ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( \n" +
- " Cheese( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( \n" +
- " Cheese( type ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( \n" +
- " Cheese( type == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- /** NESTED FROM */
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) from ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", $i : income > 100000 ) from town.getPersons(), max( $i ) )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** FORALL */
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( " +
- " Class ( pr";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("pr", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( " +
- " Class ( property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( " +
- " Class ( property == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( " +
- " Class ( property == \"test\")" +
- " C";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
- }
-
- public void testCheckRHSLocationDetermination() {
- String input =
- "rule MyRule \n" +
- " when\n" +
- " Class ( )\n" +
- " then\n" +
- " ";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RHS, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_RHS_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when\n" +
- " Class ( )\n" +
- " then\n" +
- " assert(null);\n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RHS, location.getType());
- assertEquals("assert(null);\n ", location.getProperty(Location.LOCATION_RHS_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when\n" +
- " Class ( )\n" +
- " then\n" +
- " meth";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RHS, location.getType());
- assertEquals("meth", location.getProperty(Location.LOCATION_RHS_CONTENT));
- }
-
- public void testCheckRuleHeaderLocationDetermination() {
- String input =
- "rule MyRule ";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
-
- input =
- "rule MyRule \n" +
- " salience 12 activation-group \"my";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
-
- // KRISV: still can't make this work... apparently, ANTLR is trying to recover from
- // the error (unkown token) by deleting the token. I don't know why it continues to
- // execute actions though, if the EOF is found.
-// input =
-// "rule \"Hello World\" ruleflow-group \"hello\" s";
-// location = LocationDeterminator.getLocation(input);
-// assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
- }
-
- public void testCheckQueryLocationDetermination() {
- String input =
- "query MyQuery ";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
-
- input =
- "query \"MyQuery\" ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
-
- input =
- "query MyQuery() ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "query MyQuery \n" +
- " Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- }
-
-}
Modified: labs/jbossrules/trunk/drools-jbrms/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/.classpath 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-jbrms/.classpath 2007-07-20 23:24:55 UTC (rev 13689)
@@ -23,7 +23,7 @@
<classpathentry kind="src" path="/drools-compiler"/>
<classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1.jar" sourcepath="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1-sources.jar"/>
<classpathentry kind="src" path="/drools-repository"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5/mvel14-1.2pre5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/jms/jms/1.1/jms-1.1.jar"/>
<classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar" sourcepath="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-io/commons-io/1.1/commons-io-1.1.jar"/>
Modified: labs/jbossrules/trunk/drools-jbrms/src/test/resources/RepoBinPackage.pkg
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-jsr94
___________________________________________________________________
Name: svn:ignore
- target
+ target
Modified: labs/jbossrules/trunk/drools-jsr94/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/.classpath 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/drools-jsr94/.classpath 2007-07-20 23:24:55 UTC (rev 13689)
@@ -16,7 +16,7 @@
<classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
<classpathentry kind="var" path="M2_REPO/jsr94/jsr94/1.1/jsr94-1.1.jar"/>
<classpathentry kind="src" path="/drools-compiler"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5/mvel14-1.2pre5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar"/>
<classpathentry kind="src" path="/drools-core"/>
<classpathentry kind="var" path="M2_REPO/jexcelapi/jxl/2.4.2/jxl-2.4.2.jar"/>
<classpathentry kind="var" path="M2_REPO/jsr94/jsr94-sigtest/1.1/jsr94-sigtest-1.1.jar"/>
Property changes on: labs/jbossrules/trunk/drools-repository
___________________________________________________________________
Name: svn:ignore
- .settings
target
+ .settings
target
repository
Property changes on: labs/jbossrules/trunk/drools-server
___________________________________________________________________
Name: svn:ignore
+ target
Copied: labs/jbossrules/trunk/m2_repo/org/mvel/mvel14/1.2pre5.4.r727 (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/m2_repo/org/mvel/mvel14/1.2pre5.4.r727)
Deleted: labs/jbossrules/trunk/m2_repo/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar
===================================================================
(Binary files differ)
Copied: labs/jbossrules/trunk/m2_repo/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar (from rev 13682, labs/jbossrules/branches/mvel-tooling-2007-06-30/m2_repo/org/mvel/mvel14/1.2pre5.4.r727/mvel14-1.2pre5.4.r727.jar)
===================================================================
(Binary files differ)
Modified: labs/jbossrules/trunk/pom.xml
===================================================================
--- labs/jbossrules/trunk/pom.xml 2007-07-20 22:04:04 UTC (rev 13688)
+++ labs/jbossrules/trunk/pom.xml 2007-07-20 23:24:55 UTC (rev 13689)
@@ -173,19 +173,19 @@
<enabled>false</enabled>
</releases>
</repository>
-
+
<repository>
<id>apache.org</id>
<name>Maven Snapshots</name>
<url>http://people.apache.org/repo/m2-snapshot-repository</url>
<snapshots>
<enabled>true</enabled>
- </snapshots>
+ </snapshots>
<releases>
<enabled>false</enabled>
</releases>
- </repository>
+ </repository>
<!-- this is needed for Seam which is not in the jboss repo or the maven one in a useful form -->
<repository>
@@ -454,7 +454,7 @@
<!--</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-report-plugin</artifactId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
<version>2.3</version>
<reportSets>
<reportSet>
@@ -462,7 +462,7 @@
<report>report-only</report>
</reports>
</reportSet>
- </reportSets>
+ </reportSets>
</plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
@@ -598,7 +598,7 @@
<groupId>org.drools</groupId>
<artifactId>drools-documentation</artifactId>
<version>${project.version}</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-server</artifactId>
@@ -651,7 +651,7 @@
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel14</artifactId>
- <version>1.2pre5</version>
+ <version>1.2pre5.4.r727</version>
</dependency>
<!-- drools-compiler -->
@@ -738,22 +738,22 @@
<exclusion>
<groupId>nekohtml</groupId>
<artifactId>nekohtml</artifactId>
- </exclusion>
- </exclusions>
+ </exclusion>
+ </exclusions>
</dependency>
-
+
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
- </dependency>
-
+ </dependency>
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.3.0</version>
- </dependency>
-
+ </dependency>
+
<dependency>
<groupId>org.tmatesoft</groupId>
<artifactId>svnkit</artifactId>
@@ -777,7 +777,7 @@
<artifactId>commons-fileupload</artifactId>
<version>1.1.1</version>
</dependency>
-
+
<!-- drools-examples -->
<dependency>
<groupId>foxtrot</groupId>
@@ -788,7 +788,7 @@
<groupId>com.jgoodies</groupId>
<artifactId>forms</artifactId>
<version>1.0.7</version><!-- TODO test that the upgrade from 1.0.4 isn't a problem -->
- </dependency>
+ </dependency>
<!--
TODO looks like jsr170:jcr:1.0 isn't used any more, remove it from /repository/jsr170/jcr/1.0
More information about the jboss-svn-commits
mailing list