public DRLParserEngine(String rule) { this.ruleRefactorInfo = new DRLRuleRefactorInfo(); this.rule = rule; }
private void detectGlobals(CharSequence rule) { pattern = Pattern.compile(GLOBAL_PATTERN); matcher = pattern.matcher(rule); while (matcher.find()) ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.GLOBAL, matcher.start(), matcher.group()); }
@Override public List<AssistantOption> execute(int offset) { this.offset = offset; RuleBasicContentInfo contentInfo = ((DRLRuleRefactorInfo)ruleRefactorInfo).getContentAt(offset); if (contentInfo==null) return this.options; if ((option = this.bindVariable(contentInfo))!=null) this.options.add(option); if ((option = this.fixImports(contentInfo))!=null) this.options.add(option); if ((option = this.renameVariable(contentInfo))!=null) this.options.add(option); return this.options; }
@Override protected AssistantOption fixImports(RuleBasicContentInfo contentInfo) { if (contentInfo==null) return null; if (!contentInfo.getType().equals(DRLContentTypeEnum.RULE_LHS_LINE) && !contentInfo.getType().equals(DRLContentTypeEnum.RULE_RHS_LINE)) return null; List<RuleBasicContentInfo> imports = ((DRLRuleRefactorInfo)ruleRefactorInfo).getImports(); FixImport.execute(contentInfo, imports); return null; }
public RuleBasicContentInfo getContentAt(int offset) { if (contents.containsKey(offset)) return contents.get(offset); int previousKey = 0; for (Integer key : contents.keySet()) { if (key > offset) { RuleBasicContentInfo info = contents.get(previousKey); if ((previousKey + info.getContentLength()) >= offset) { if (info.getType().equals(DRLContentTypeEnum.RULE)) return searchInsideTheRule(offset, (RuleDRLContentInfo) info); return info; } return null; } previousKey = key; } RuleBasicContentInfo info = contents.get(previousKey); if (info.getType().equals(DRLContentTypeEnum.RULE)) return searchInsideTheRule(offset, (RuleDRLContentInfo) info); return (info.getContentLength() + previousKey > offset)?info:null; }
@Override public List<AssistantOption> execute(int offset) { this.offset = offset; RuleBasicContentInfo contentInfo = ((DRLRuleRefactorInfo)ruleRefactorInfo).getContentAt(offset); if (contentInfo==null) return this.options; if ((option = this.bindVariable(contentInfo))!=null) this.options.add(option); if ((option = this.fixImports(contentInfo))!=null) this.options.add(option); if ((option = this.renameVariable(contentInfo))!=null) this.options.add(option); return this.options; }
@Override protected AssistantOption fixImports(RuleBasicContentInfo contentInfo) { if (contentInfo==null) return null; if (!contentInfo.getType().equals(DRLContentTypeEnum.RULE_LHS_LINE) && !contentInfo.getType().equals(DRLContentTypeEnum.RULE_RHS_LINE)) return null; List<RuleBasicContentInfo> imports = ((DRLRuleRefactorInfo)ruleRefactorInfo).getImports(); FixImport.execute(contentInfo, imports); return null; }
public RuleBasicContentInfo getContentAt(int offset) { if (contents.containsKey(offset)) return contents.get(offset); int previousKey = 0; for (Integer key : contents.keySet()) { if (key > offset) { RuleBasicContentInfo info = contents.get(previousKey); if ((previousKey + info.getContentLength()) >= offset) { if (info.getType().equals(DRLContentTypeEnum.RULE)) return searchInsideTheRule(offset, (RuleDRLContentInfo) info); return info; } return null; } previousKey = key; } RuleBasicContentInfo info = contents.get(previousKey); if (info.getType().equals(DRLContentTypeEnum.RULE)) return searchInsideTheRule(offset, (RuleDRLContentInfo) info); return (info.getContentLength() + previousKey > offset)?info:null; }
@Test public void testExecuteEngine() { info = (DRLRuleRefactorInfo) engine.parse(); RuleBasicContentInfo content = info.getContentAt(123); assertEquals(true, content!=null); }
private void detectImports(CharSequence rule) { pattern = Pattern.compile(IMPORT_PATTERN); matcher = pattern.matcher(rule); while (matcher.find()) ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.IMPORT, matcher.start(), matcher.group()); }
public DRLParserEngine(String rule) { this.ruleRefactorInfo = new DRLRuleRefactorInfo(); this.rule = rule; }
@Test public void testInsideRHSRule() { info = (DRLRuleRefactorInfo) engine.parse(); RuleBasicContentInfo content = info.getContentAt(830); assertEquals(true, content!=null); }
private void detectGlobals(CharSequence rule) { pattern = Pattern.compile(GLOBAL_PATTERN); matcher = pattern.matcher(rule); while (matcher.find()) ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.GLOBAL, matcher.start(), matcher.group()); }
@Test public void testInsideTheRuleName() { info = (DRLRuleRefactorInfo) engine.parse(); RuleBasicContentInfo content = info.getContentAt(670); assertEquals(true, content==null); }
private void detectPackage(CharSequence rule) { pattern = Pattern.compile(PACKAGE_PATTERN); matcher = pattern.matcher(rule); if (matcher.find()) ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.PACKAGE, matcher.start(), matcher.group()); }
@Test public void testInsideLHSRule() { info = (DRLRuleRefactorInfo) engine.parse(); RuleBasicContentInfo content = info.getContentAt(790); assertEquals(true, content!=null); }
private void detectPackage(CharSequence rule) { pattern = Pattern.compile(PACKAGE_PATTERN); matcher = pattern.matcher(rule); if (matcher.find()) ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.PACKAGE, matcher.start(), matcher.group()); }
@Test public void testImport() { info = (DRLRuleRefactorInfo) engine.parse(); RuleBasicContentInfo content = info.getContentAt(9); assertEquals(true, content!=null); }
private void detectImports(CharSequence rule) { pattern = Pattern.compile(IMPORT_PATTERN); matcher = pattern.matcher(rule); while (matcher.find()) ((DRLRuleRefactorInfo) ruleRefactorInfo).addContent(DRLContentTypeEnum.IMPORT, matcher.start(), matcher.group()); }
@Test public void testNothingInteresting() { info = (DRLRuleRefactorInfo) engine.parse(); RuleBasicContentInfo content = info.getContentAt(199); assertEquals(true, content==null); }