本文整理汇总了Java中org.netbeans.modules.parsing.api.Source.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java Source.getDocument方法的具体用法?Java Source.getDocument怎么用?Java Source.getDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.modules.parsing.api.Source
的用法示例。
在下文中一共展示了Source.getDocument方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContent
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
@NonNull
protected final CharSequence createContent() throws IOException {
final FileObject file = getHandle().resolveFileObject(false);
if (file == null) {
throw new FileNotFoundException("Cannot open file: " + toString());
}
final Source source = Source.create(file);
if (source == null) {
throw new IOException("No source for: " + FileUtil.getFileDisplayName(file)); //NOI18N
}
CharSequence content = source.createSnapshot().getText();
if (hasFilter && source.getDocument(false) == null) {
content = filter(content);
}
return content;
}
示例2: update
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
public final void update (CharSequence content) throws IOException {
if (content == null) {
update();
} else {
if (filter != null) {
final FileObject file = handle.resolveFileObject(false);
if (file != null) {
final Source source = Source.create(file);
if (source != null && source.getDocument(false) == null) {
content = filter.filterCharSequence(content);
}
}
}
this.text = toString(content);
}
this.tokens = null;
}
示例3: openDocument
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
/**
* Opens a Document where the Difference is to be applied. Throws IOException,
* if the document open fails. If the document is already opened, returns the opened
* instance. If the difference is CREATE and the document does not exist yet,
* the method may return {@code null}
*
* @throws IOException when document open fails
* @return Document to apply the Difference.
* @since java.source.base 1.1
*/
@CheckForNull
public Document openDocument() throws IOException {
if (ctxLookup == null) {
return null;
} else if (theSource != null) {
return theSource.getDocument(true);
}
// obtain the source again:
Source s = Source.create(sourceFile, ctxLookup);
if (s == null) {
return null;
}
return s.getDocument(true);
}
示例4: activate
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
public void activate() {
final Source source = getSourceControl().getSource();
final FileObject fo = source.getFileObject();
Document doc;
if (fo != null) {
try {
listenOnFileChanges();
listenOnParser();
DataObject dObj = DataObject.find(fo);
assignDocumentListener (dObj);
dobjListener = new DataObjectListener(dObj);
} catch (DataObjectNotFoundException e) {
LOGGER.log(Level.WARNING, "Ignoring events non existent file: {0}", FileUtil.getFileDisplayName(fo)); //NOI18N
}
} else if ((doc=source.getDocument(false)) != null) {
listenOnParser();
docListener = new DocListener (doc);
}
}
示例5: create
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
/**
* Create a names translator.
* @param smt translator handling the source maps.
* @param fileObject the generated source file
* @param lineNumber line number of the position at which we translate the names
* @param columnNumber column number of the position at which we translate the names
* @return an instance of names translator, or <code>null</code> when the corresponding source can not be loaded.
*/
public static NamesTranslator create(SourceMapsTranslator smt, FileObject fileObject,
int lineNumber, int columnNumber) {
if (!USE_SOURCE_MAPS) {
return null;
}
Source source = Source.create(fileObject);
if (source == null) {
return null;
}
Document doc = source.getDocument(true);
if (doc == null) {
return null;
}
// Check lineNumber:
try {
int lastLine = LineDocumentUtils.getLineIndex((LineDocument) doc, doc.getLength()-1);
if (lineNumber > lastLine) {
lineNumber = lastLine;
}
} catch (BadLocationException blex) {}
int offset = LineDocumentUtils.getLineStartFromIndex((LineDocument) doc, lineNumber) + columnNumber;
return new NamesTranslator(smt, fileObject, source, offset);
}
示例6: implement
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
public void implement() throws Exception {
Source source = Source.create(sourceFile);
final Document doc = source.getDocument(false);
ParserManager.parse(Collections.singleton(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
//html must be top level
Result result = resultIterator.getParserResult();
if(!(result instanceof HtmlParserResult)) {
return ;
}
ModificationResult modification = new ModificationResult();
if(HtmlSourceUtils.importStyleSheet(modification, (HtmlParserResult)result, externalStylesheet)) {
modification.commit();
// if(doc != null) {
// //refresh the index for the modified file
// HtmlSourceUtils.forceReindex(sourceFile);
// }
}
}
});
}
示例7: isDirty
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
@Override
protected final Long isDirty() {
final FileObject file = getHandle().resolveFileObject(false);
if (file == null) {
return null;
}
final Source source = Source.create(file);
if (source != null) {
Document doc = source.getDocument(false);
if (doc != null) {
return DocumentUtilities.getDocumentTimestamp(doc);
}
}
return null;
}
示例8: 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;
}
示例9: getDocument
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
/**
* Returns {@link Document} of this {@link CompilationInfoImpl}
* @return Document or null when the {@link DataObject} doesn't
* exist or has no {@link EditorCookie}.
* @throws java.io.IOException
*/
public Document getDocument() {
if (this.file == null) {
return null;
}
if (!this.file.isValid()) {
return null;
}
Source source = this.snapshot != null ? this.snapshot.getSource() : null;
if (source != null) {
return source.getDocument(false);
}
return null;
}
示例10: checkOccurrences
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
/** Test the occurrences to make sure they equal the golden file.
* If the symmetric parameter is set, this test will also ensure that asking for
* occurrences on ANY of the matches produced by the original caret position will
* produce the exact same map. This is obviously not appropriate for things like
* occurrences on the exit points.
*/
protected void checkOccurrences(String relFilePath, String caretLine, final boolean symmetric) throws Exception {
Source testSource = getTestSource(getTestFile(relFilePath));
Document doc = testSource.getDocument(true);
final int caretOffset = getCaretOffset(doc.getText(0, doc.getLength()), caretLine);
final OccurrencesFinder finder = getOccurrencesFinder();
assertNotNull("getOccurrencesFinder must be implemented", finder);
finder.setCaretPosition(caretOffset);
UserTask task = new UserTask() {
public @Override void run(ResultIterator resultIterator) throws Exception {
Parser.Result r = resultIterator.getParserResult(caretOffset);
if (r instanceof ParserResult) {
finder.run((ParserResult) r, null);
Map<OffsetRange, ColoringAttributes> occurrences = finder.getOccurrences();
if (occurrences == null) {
occurrences = Collections.emptyMap();
}
String annotatedSource = annotateFinderResult(resultIterator.getSnapshot(), occurrences, caretOffset);
assertDescriptionMatches(resultIterator.getSnapshot().getSource().getFileObject(), annotatedSource, true, ".occurrences");
if (symmetric) {
// Extra check: Ensure that occurrences are symmetric: Placing the caret on ANY of the occurrences
// should produce the same set!!
for (OffsetRange range : occurrences.keySet()) {
int midPoint = range.getStart() + range.getLength() / 2;
finder.setCaretPosition(midPoint);
finder.run((ParserResult) r, null);
Map<OffsetRange, ColoringAttributes> alternates = finder.getOccurrences();
assertEquals("Marks differ between caret positions - failed at " + midPoint, occurrences, alternates);
}
}
}
}
};
if (classPathsForTest == null || classPathsForTest.isEmpty()) {
ParserManager.parse(Collections.singleton(testSource), task);
} else {
Future<Void> future = ParserManager.parseWhenScanFinished(Collections.singleton(testSource), task);
if (!future.isDone()) {
future.get();
}
}
}
示例11: Model
import org.netbeans.modules.parsing.api.Source; //导入方法依赖的package包/类
Model(CssParserResult parserResult) {
this(++globalModelSerialNumber);
Node styleSheetNode = NodeUtil.query(parserResult.getParseTree(), NodeType.styleSheet.name());
Collection<Object> lookupContent = new ArrayList<>();
if (styleSheetNode == null) {
//empty file
lookupContent.add(getElementFactory().createStyleSheet());
} else {
lookupContent.add(styleSheetNode);
lookupContent.add((StyleSheet) getElementFactoryImpl(this).createElement(this, styleSheetNode));
}
Snapshot snapshot = parserResult.getSnapshot();
Source source = snapshot.getSource();
FileObject file = source.getFileObject();
Document doc = source.getDocument(true);
lookupContent.add(parserResult);
lookupContent.add(snapshot);
lookupContent.add(snapshot.getText());
if (file != null) {
lookupContent.add(file);
//Listen on the EditorCookie.Observable so we may re-new the document instance
//if the original document was closed.
//See issue http://netbeans.org/bugzilla/show_bug.cgi?id=219493 for more details
try {
dataObject = DataObject.find(file);
editorCookie = dataObject.getLookup().lookup(EditorCookie.Observable.class);
editorCookie.addPropertyChangeListener(WeakListeners.propertyChange(this, editorCookie));
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
}
documentLookup = new DocumentLookup();
if (doc != null) {
documentLookup.updateLookup(Lookups.fixed(doc));
}
MODEL_LOOKUP = new ProxyLookup(Lookups.fixed(lookupContent.toArray()), documentLookup);
}