IDocumentPartitioner createRecipePartitioner() { IPredicateRule[] rules = { new SingleLineRule("--", null, new Token(SQL_SINGLE_COMMENT), (char) 0, true, false), //$NON-NLS-1$ new MultiLineRule("/*", "*/", new Token(SQL_MULTI_COMMENT), (char) 0, true), //$NON-NLS-1$ //$NON-NLS-2$ new MultiLineRule( "'", "'", new Token(SQL_CHARACTER_STRING_LITERAL), (char) 0 , true) //$NON-NLS-1$ //$NON-NLS-2$ }; RuleBasedPartitionScanner scanner = new RuleBasedPartitionScanner(); scanner.setPredicateRules(rules); return new FastPartitioner(scanner, CONTENT_TYPES); }
private IPartitionTokenScanner createKspPartitionScanner() { RuleBasedPartitionScanner scanner = new RuleBasedPartitionScanner(); scanner.setPredicateRules(new IPredicateRule[] { /* String entre double quote. */ new PatternRule("\"", "\"", new Token(KspRegionType.STRING.getContentType()), '\\', false), /* Commentaire multi-lignes */ new PatternRule("/*", "*/", new Token(KspRegionType.COMMENT.getContentType()), '\\', false), /* Commentaire fin de ligne */ new EndOfLineRule("//", new Token(KspRegionType.COMMENT.getContentType())) }); return scanner; }
private IDocumentPartitioner createConnectPartitioner(IDocument document, IPredicateRule[] rules, String[] types) { RuleBasedPartitionScanner scanner = new RuleBasedPartitionScanner(); scanner.setPredicateRules(rules); IDocumentPartitioner partitioner = new FastPartitioner(scanner, types); partitioner.connect(document); return partitioner; }
public String setupDocument(Document document) { IPartitionTokenScanner scanner = new RuleBasedPartitionScanner(); FastPartitioner partitioner = new FastPartitioner(scanner, new String[] { IDocument.DEFAULT_CONTENT_TYPE }); String[] managingPositionCategories = partitioner.getManagingPositionCategories(); String category = managingPositionCategories[0]; document.setDocumentPartitioner(partitioner); document.addPositionCategory(category); return category; }
public IRegion getKeyRegion(IDocument document, final String searchKey) { IPredicateRule[] rules = new IPredicateRule[4]; rules[0] = new EndOfLineRule("#", Token.UNDEFINED); rules[1] = new EndOfLineRule("!", Token.UNDEFINED); rules[2] = new WordPatternRule(new PropertyKeyDetector(), "\n", "=", KEY_TOKEN); rules[3] = new WordPatternRule(new PropertyKeyDetector(), "\n", ":", KEY_TOKEN); RuleBasedPartitionScanner scanner = new RuleBasedPartitionScanner(); scanner.setPredicateRules(rules); IDocumentPartitioner partitioner = new FastPartitioner(scanner, new String[] { KEY }); IRegion region = null; try { partitioner.connect(document); ITypedRegion[] tagRegions = partitioner.computePartitioning(0, document.getLength()); boolean firstRegion = true; for (ITypedRegion tagRegion : tagRegions) { if (KEY.equals(tagRegion.getType()) || firstRegion) { String key = null; try { // -1 remove = key = document.get(tagRegion.getOffset(), tagRegion.getLength() - 1); key = key.trim(); } catch (BadLocationException e) { e.printStackTrace(); } // first line isn't caught by the key_token rule if (firstRegion && key != null) { int indx = key.indexOf('='); if (indx != -1) { key = key.substring(0, indx).trim(); } } if (key != null) { key = key.replace("\\ ", " "); if (key.equals(searchKey)) { region = tagRegion; break; } } } firstRegion = false; } } finally { if (partitioner != null) { partitioner.disconnect(); } } return region; }