本文整理汇总了Java中org.netbeans.modules.parsing.api.Source.create方法的典型用法代码示例。如果您正苦于以下问题:Java Source.create方法的具体用法?Java Source.create怎么用?Java Source.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.modules.parsing.api.Source
的用法示例。
在下文中一共展示了Source.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
clearWorkDir();
MockMimeLookup.setInstances(MimePath.get(MIME), new TestParser.Factory());
final FileObject wd = FileUtil.toFileObject(getWorkDir());
final FileObject testFile = FileUtil.createData(
wd,
String.format("file.%s", //NOI18N
EXTENSION));
FileUtil.setMIMEType(EXTENSION,MIME);
src = Source.create(testFile);
cache = SourceAccessor.getINSTANCE().getCache(src);
task = new TestTask();
cancelTask = new CancelTask();
tpLogger = Logger.getLogger(TaskProcessor.class.getName());
tpLevel = tpLogger.getLevel();
tpLogger.setLevel(Level.FINE);
tpHandler = new TestHandler();
tpLogger.addHandler(tpHandler);
}
示例2: testXhtmlFile1
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
public void testXhtmlFile1() throws SAXException {
FileObject fo = getTestFile("testfiles/test1.xhtml");
Source source = Source.create(fo);
String code = source.createSnapshot().getText().toString();
SyntaxAnalyzerResult result = SyntaxAnalyzer.create(new HtmlSource(fo)).analyze();
assertNotNull(result);
HtmlVersion version = result.getHtmlVersion();
assertSame(HtmlVersion.XHTML10_STICT, version);
NbValidationTransaction vt = NbValidationTransaction.create(result.getHtmlVersion());
validate(code, true, result.getHtmlVersion(), vt);
assertSame(ParserMode.XML_NO_EXTERNAL_ENTITIES, vt.parser);
assertNotNull(vt.xmlParser);
assertNull(vt.htmlParser);
}
示例3: setUp
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
clearWorkDir();
MockMimeLookup.setInstances(
MimePath.get(MIME_FOO),
new FooParser.Factory(),
new Task1.Factory(),
new Task2.Factory());
FileUtil.setMIMEType(EXT_FOO, MIME_FOO);
final File wd = getWorkDir();
sourceFile = FileUtil.createData(new File(wd, "source.foo")); //NOI18N
assertNotNull(sourceFile);
assertEquals(MIME_FOO, sourceFile.getMIMEType());
source = Source.create(sourceFile);
assertNotNull(source);
Modification.getDefault().setSource(source);
}
示例4: propertyChange
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
public void propertyChange(final PropertyChangeEvent evt) {
String propName = evt.getPropertyName();
if ("completion-active".equals(propName)) { //NOI18N
Source source = null;
final JTextComponent lastEditor = lastEditorRef == null ? null : lastEditorRef.get();
final Document doc = lastEditor == null ? null : lastEditor.getDocument();
if (doc != null) {
String mimeType = DocumentUtilities.getMimeType (doc);
if (mimeType != null) {
source = Source.create(doc);
}
}
if (source != null) {
handleCompletionActive(source, evt.getNewValue());
}
}
}
示例5: testParserInvocation
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
public void testParserInvocation() throws Exception {
Source fxmlSource = Source.create(document);
ParserManager.parse(Collections.singleton(fxmlSource), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
Parser.Result result = resultIterator.getParserResult();
if (result instanceof FxmlParserResult) {
FxmlParserResult fxResult = (FxmlParserResult)result;
appendParsedTree(fxResult, report);
appendErrors(fxResult, report);
assertContents(report);
}
}
});
}
示例6: createSourceElementHandle
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
/**
* Resolves the {@link FileObject} and source element path to a parser
* result and {@link OpenTag}.
*
* The returned value is not cached and will run a parsing api task each
* time is called.
*
* @return An instance of {@link SourceElementHandle}
* exception is thrown.
* @throws ParseException
*/
public SourceElementHandle createSourceElementHandle() throws ParseException {
final AtomicReference<SourceElementHandle> seh_ref = new AtomicReference<>();
Source source = Source.create(file);
ParserManager.parse(Collections.singleton(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
ResultIterator ri = WebUtils.getResultIterator(resultIterator, "text/html");
if (ri == null) {
return;
}
HtmlParserResult result = (HtmlParserResult) ri.getParserResult();
Snapshot snapshot = result.getSnapshot();
Node root = result.root();
OpenTag openTag = ElementUtils.query(root, elementPath);
seh_ref.set(new SourceElementHandle(openTag, snapshot, file));
}
});
return seh_ref.get();
}
示例7: testCRLF197538
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
public void testCRLF197538() throws Exception {
prepareTest("test\r\ntest\r\ntest\r\n");
PositionRef start1 = ces.createPositionRef(5, Bias.Forward);
PositionRef end1 = ces.createPositionRef(9, Bias.Forward);
ModificationResult.Difference diff1 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start1, end1, "test", "abcde", Source.create(testFile));
PositionRef start2 = ces.createPositionRef(10, Bias.Forward);
PositionRef end2 = ces.createPositionRef(13, Bias.Forward);
ModificationResult.Difference diff2 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start2, end2, "tes", "a", Source.create(testFile));
ModificationResult result = new ModificationResult();
result.diffs = new HashMap<FileObject, List<ModificationResult.Difference>>();
result.diffs.put(testFile, Arrays.asList(diff1, diff2));
result.commit();
assertEquals("test\r\nabcde\r\nat\r\n", testFile.asText());
}
示例8: query
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
{
try {
this.caretOffset = caretOffset;
//if (queryType == TOOLTIP_QUERY_TYPE || Utilities.isJavaContext(component, caretOffset))
{
results = null;
anchorOffset = -1;
Source source = Source.create(doc);
if (source != null) {
ParserManager.parse(Collections.singletonList(source), getTask());
if ((queryType & COMPLETION_QUERY_TYPE) != 0) {
if (results != null) {
resultSet.addAllItems(results);
}
resultSet.setHasAdditionalItems(hasAdditionalItems > 0);
if (hasAdditionalItems == 1) {
resultSet.setHasAdditionalItemsText(NbBundle.getMessage(JPACodeCompletionProvider.class, "JCP-imported-items")); //NOI18N
}
if (hasAdditionalItems == 2) {
resultSet.setHasAdditionalItemsText(NbBundle.getMessage(JPACodeCompletionProvider.class, "JCP-instance-members")); //NOI18N
}
}
if (anchorOffset > -1) {
resultSet.setAnchorOffset(anchorOffset);
}
}
}
} catch (Exception e) {
Exceptions.printStackTrace(e);
} finally {
resultSet.finish();
}
}
}
示例9: getDocument
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
public StyledDocument getDocument() {
final FileObject file = getHandle().resolveFileObject(false);
if (file == null) {
return null;
}
final Source src = Source.create(file);
if (src == null) {
return null;
}
final Document doc = src.getDocument(false);
return (doc instanceof StyledDocument) ? ((StyledDocument)doc) : null;
}
示例10: assertParserResultType
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
private void assertParserResultType(String content, final int offset, Class resultType) throws ParseException {
Document doc = getDocument(content);
Source source = Source.create(doc);
final Result[] _result = new Result[1];
ParserManager.parse(Collections.singleton(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
_result[0] = resultIterator.getParserResult(offset);
}
});
Result result = _result[0];
assertNotNull(result);
assertEquals(resultType, result.getClass());
}
示例11: actionPerformed
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
public void actionPerformed(final ActionEvent evt, final JTextComponent component) {
if (component == null || !component.isEditable() || !component.isEnabled()) {
Toolkit.getDefaultToolkit().beep();
return;
}
final BaseDocument doc = (BaseDocument) component.getDocument();
final Source source = Source.create(doc);
if (source != null) {
final AtomicBoolean cancel = new AtomicBoolean();
ProgressUtils.runOffEventDispatchThread(new Runnable() {
@Override
public void run() {
try {
ModificationResult.runModificationTask(Collections.singleton(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult());
copy.toPhase(Phase.RESOLVED);
doOrganizeImports(copy, false);
}
}).commit();
} catch (Exception ex) {
Toolkit.getDefaultToolkit().beep();
}
}
}, NbBundle.getMessage(OrganizeImports.class, "MSG_OragnizeImports"), cancel, false); //NOI18N
}
}
示例12: prepareModificationResult2
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
private ModificationResult prepareModificationResult2() throws Exception {
PositionRef start1 = ces.createPositionRef(5, Bias.Forward);
PositionRef end1 = ces.createPositionRef(9, Bias.Forward);
ModificationResult.Difference diff1 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start1, end1, "test", "abcde", Source.create(testFile));
PositionRef start2 = ces.createPositionRef(11, Bias.Forward);
PositionRef end2 = ces.createPositionRef(13, Bias.Forward);
ModificationResult.Difference diff2 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start2, end2, "es", "a", Source.create(testFile));
ModificationResult result = new ModificationResult();
result.diffs = new HashMap<FileObject, List<ModificationResult.Difference>>();
result.diffs.put(testFile, Arrays.asList(diff1, diff2));
return result;
}
示例13: testBasic
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
public void testBasic() throws ParseException {
String code = ".myclass { color: red } #myid { color: blue }";
// 01234567890123456789012345678901234567890123456789
// 0 1 2 3 4
Document doc = getDocument(code);
assertNotNull(doc);
Source source = Source.create(doc);
assertNotNull(source);
assertEquals("text/css", source.getMimeType());
CssFileModel model = CssFileModel.create(source);
assertNotNull(model);
Collection<Entry> classes = model.getClasses();
assertNotNull(classes);
assertEquals(1, classes.size());
Entry e = classes.iterator().next();
assertNotNull(e);
assertEquals("myclass", e.getName());
assertTrue(e.isValidInSourceDocument());
assertEquals(new OffsetRange(9, 23), e.getBodyRange());
assertEquals(new OffsetRange(9, 23), e.getDocumentBodyRange());
assertEquals(0, e.getLineOffset());
assertFalse(e.isVirtual());
assertEquals(code, e.getLineText());
assertEquals(new OffsetRange(1, 8), e.getRange());
assertEquals(new OffsetRange(1, 8), e.getDocumentRange());
Collection<Entry> ids = model.getIds();
assertNotNull(ids);
assertEquals(1, ids.size());
e = ids.iterator().next();
assertNotNull(e);
assertEquals("myid", e.getName());
}
示例14: testBasicInEmbeddedCss
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
public void testBasicInEmbeddedCss() throws ParseException {
String code = "<html><head><title>x</title><style>.myclass { color: red } #myid { color: blue }</style></head></html>";
// 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
// 0 1 2 3 4 5 6 7 8 9
Document doc = getDocument(code, "text/html");
assertNotNull(doc);
Source source = Source.create(doc);
assertNotNull(source);
assertEquals("text/html", source.getMimeType());
CssFileModel model = CssFileModel.create(source);
assertNotNull(model);
Collection<Entry> classes = model.getClasses();
assertNotNull(classes);
assertEquals(1, classes.size());
Entry e = classes.iterator().next();
assertNotNull(e);
assertEquals("myclass", e.getName());
assertTrue(e.isValidInSourceDocument());
assertEquals(new OffsetRange(9, 23), e.getBodyRange());
assertEquals(new OffsetRange(44, 58), e.getDocumentBodyRange());
assertEquals(0, e.getLineOffset());
assertFalse(e.isVirtual());
assertEquals(".myclass { color: red } #myid { color: blue }", e.getLineText());
assertEquals(new OffsetRange(1, 8), e.getRange());
assertEquals(new OffsetRange(36, 43), e.getDocumentRange());
Collection<Entry> ids = model.getIds();
assertNotNull(ids);
assertEquals(1, ids.size());
e = ids.iterator().next();
assertNotNull(e);
assertEquals("myid", e.getName());
}
示例15: selectTheRuleInEditorIfOpened
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
/**
* Sets caret to the given css rule and focused the corresponding editor document if opened.
*/
private void selectTheRuleInEditorIfOpened(final Model omodel, final Rule orule) throws DataObjectNotFoundException, ParseException {
final FileObject file = omodel.getLookup().lookup(FileObject.class);
DataObject dobj = DataObject.find(file);
final EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
//first get instance of the new model so we can resolve the element's positions
final AtomicInteger ruleOffset = new AtomicInteger(-1);
Source source = Source.create(file);
ParserManager.parse(Collections.singleton(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
resultIterator = WebUtils.getResultIterator(resultIterator, "text/css");
if (resultIterator != null) {
CssParserResult result = (CssParserResult) resultIterator.getParserResult();
final Model model = Model.getModel(result);
model.runReadTask(new Model.ModelTask() {
@Override
public void run(StyleSheet styleSheet) {
ModelUtils utils = new ModelUtils(model);
Rule match = utils.findMatchingRule(omodel, orule);
if (match != null) {
ruleOffset.set(match.getStartOffset());
}
}
});
}
}
});
if (ruleOffset.get() == -1) {
return;
}
Mutex.EVENT.readAccess(new Runnable() {
@Override
public void run() {
JEditorPane[] openedPanes = ec.getOpenedPanes();
if (openedPanes != null && openedPanes.length > 0) {
JEditorPane pane = openedPanes[0];
pane.setCaretPosition(ruleOffset.get());
ec.open(); //give it a focus
LOGGER.log(Level.FINE, "Focused file {0} and set caret to offset {1}", new Object[]{file.getNameExt(), ruleOffset.get()});
}
}
});
}