本文整理汇总了Java中org.netbeans.spi.editor.completion.CompletionResultSet.addItem方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionResultSet.addItem方法的具体用法?Java CompletionResultSet.addItem怎么用?Java CompletionResultSet.addItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.spi.editor.completion.CompletionResultSet
的用法示例。
在下文中一共展示了CompletionResultSet.addItem方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: completePropName
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
private void completePropName(SpringBootService sbs, CompletionResultSet completionResultSet, String filter, int startOffset,
int caretOffset) {
final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
final boolean bDeprLast = prefs.getBoolean(PREF_DEPR_SORT_LAST, true);
final boolean bErrorShow = prefs.getBoolean(PREF_DEPR_ERROR_SHOW, true);
long mark = System.currentTimeMillis();
logger.log(FINER, "Completing property name: {0}", filter);
for (ConfigurationMetadataProperty propMeta : sbs.queryPropertyMetadata(filter)) {
if (Utils.isErrorDeprecated(propMeta)) {
// show error level deprecated props based on pref
if (bErrorShow) {
completionResultSet.addItem(new CfgPropCompletionItem(propMeta, sbs, startOffset, caretOffset, bDeprLast));
}
} else {
completionResultSet.addItem(new CfgPropCompletionItem(propMeta, sbs, startOffset, caretOffset, bDeprLast));
}
}
final long elapsed = System.currentTimeMillis() - mark;
logger.log(FINER, "Property completion of ''{0}'' took: {1} msecs", new Object[]{filter, elapsed});
}
示例2: createTask
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
@Override
public CompletionTask createTask(int queryType, JTextComponent component) {
if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE) {
return null;
}
return new AsyncCompletionTask(new AsyncCompletionQuery() {
@Override
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
//Iterate through the available locales
//and assign each country display name
//to a CompletionResultSet:
String text = DocumentHelper.getWordBeforeCaret(doc, caretOffset);
CompletionProposals[] words = CompletionProposals.values();
Arrays.sort(words);
for (CompletionProposals word : words) {
final String name = word.name().toLowerCase();
if (name.startsWith(text)) {
resultSet.addItem(new RTCompletionItem(name, caretOffset));
}
}
resultSet.finish();
}
}, component);
}
示例3: query
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
@Override
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
XMLSyntaxSupport support = XMLSyntaxSupport.getSyntaxSupport(doc);
if (support == null) {
resultSet.finish();
return;
}
CompletionResultItem endTagResultItem = CompletionUtil.getEndTagCompletionItem(
component, (BaseDocument) doc);
List<CompletionResultItem> completionItems = null;
if (!CompletionUtil.noCompletion(component) &&
(CompletionUtil.canProvideCompletion((BaseDocument) doc))) {
resultSet.setWaitText(NbBundle.getMessage(CompletionQuery.class, "MSG_PreparingXmlSchemas")); // NOI18N
PreparedResults res = createResultsAndTimedWait(doc, caretOffset);
if (res.isRunning()) {
resultSet.addItem(new FinishDownloadItem());
} else {
completionItems = res.items;
}
} else {
clearPreparedItems(doc);
}
if (isTaskCancelled()) {
resultSet.finish();
return;
}
if (endTagResultItem != null) resultSet.addItem(endTagResultItem);
if ((completionItems != null) && (completionItems.size() > 0)) {
resultSet.addAllItems(completionItems);
} else if ((endTagResultItem != null) &&
(! (endTagResultItem instanceof TagLastCharResultItem))) {
endTagResultItem.setExtraPaintGap(-CompletionPaintComponent.DEFAULT_ICON_TEXT_GAP);
}
resultSet.finish();
}
示例4: completeCommand
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
private void completeCommand(CompletionResultSet resultSet, String prefix, int startAt) {
if (prefix.startsWith("/")) {// NOI18N
prefix = prefix.substring(1).trim();
}
List<String> candidates = JShellLexer.getCommandsFromPrefix(prefix);
for (String s : candidates) {
resultSet.addItem(new CommandCompletionItem(session, startAt, s, prefix.length() < 2));
}
}
示例5: completePropValue
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
public void completePropValue(SpringBootService sbs, CompletionResultSet completionResultSet, String propName, String filter,
int startOffset, int caretOffset) {
long mark = System.currentTimeMillis();
logger.log(FINER, "Completing property value: {0}", filter);
for (ValueHint valueHint : sbs.queryHintMetadata(propName, filter)) {
completionResultSet.addItem(new CfgPropValueCompletionItem(valueHint, startOffset, caretOffset));
}
final long elapsed = System.currentTimeMillis() - mark;
logger.log(FINER, "Value completion of ''{0}'' on ''{1}'' took: {2} msecs", new Object[]{filter, propName, elapsed});
}
示例6: filter
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
@Override
protected void filter(CompletionResultSet resultSet) {
//System.out.println("Filter "+filter);
for ( Method m : currentType.getMethods()){
if ( m.getName().toLowerCase().indexOf(filter.toLowerCase()) == 0 && isStatic == Modifier.isStatic(m.getModifiers()) ){
resultSet.addItem(new MirahMethodCompletionItem(file, m, initialOffset, filter.length(), currentType));
}
}
resultSet.finish();
}
示例7: createTask
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
@Override
public CompletionTask createTask(int queryType, JTextComponent component) {
if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE) {
return null;
}
return new AsyncCompletionTask(new AsyncCompletionQuery() {
@Override
protected void query(CompletionResultSet completionResultSet, Document document, int caretOffset) {
String filter;
int startOffset;
try {
final StyledDocument bDoc = (StyledDocument) document;
final int lineStartOffset = getRowFirstNonWhite(bDoc, caretOffset);
final char[] line = bDoc.getText(lineStartOffset, caretOffset - lineStartOffset).toCharArray();
final int whiteOffset = indexOfWhite(line);
filter = new String(line, whiteOffset + 1, line.length - whiteOffset - 1);
filter = filter.toLowerCase();
if (whiteOffset > 0) {
startOffset = lineStartOffset + whiteOffset + 1;
} else {
startOffset = lineStartOffset;
}
String[] keywords = new String[]{"ClassMethod", "Method", "Property", "Parameter", "Index"};
for (String keyword : keywords) {
if (!keyword.equals("") && keyword.toLowerCase().startsWith(filter)) {
completionResultSet.addItem(new clsCompletionItem(keyword, startOffset, caretOffset));
}
}
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
completionResultSet.finish();
}
}, component);
}
示例8: query
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
protected void query(CompletionResultSet resultSet, Document document, final int caretOffset) {
Dictionary dictionary = ComponentPeer.getDictionary(document);
final TokenList l = ComponentPeer.ACCESSOR.lookupTokenList(document);
if (dictionary != null && l != null && document instanceof BaseDocument) {
final BaseDocument bdoc = (BaseDocument) document;
final String[] text = new String[2];
document.render(new Runnable() {
public void run() {
try {
int lineStart = Utilities.getRowStart(bdoc, caretOffset);
l.setStartOffset(lineStart);
while (l.nextWord()) {
int start = l.getCurrentWordStartOffset();
int end = l.getCurrentWordStartOffset() + l.getCurrentWordText().length();
if (start < caretOffset && end >= caretOffset) {
text[0] = l.getCurrentWordText().subSequence(0, caretOffset - start).toString();
text[1] = l.getCurrentWordText().toString();
return ;
}
}
} catch (BadLocationException e) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
}
}
});
if (text[0] != null) {
int i = 0;
for (String proposal : dictionary.findValidWordsForPrefix(text[0])) {
resultSet.addItem (new WordCompletionItem (
caretOffset - text[0].length (),
proposal
));
if (i == 8) break;
i++;
}
if (dictionary.validateWord (text [1]) != ValidityType.VALID) {
resultSet.addItem (new AddToDictionaryCompletionItem (
text [1],
true
));
resultSet.addItem (new AddToDictionaryCompletionItem (
text [1],
false
));
}
}
}
resultSet.finish();
}
示例9: query
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
@Override
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
try {
final Source source = Source.create(doc);
if (source != null) {
resultSet.setWaitText(Bundle.LBL_ScanningInProgress());
resultSet.addItem(new Item());
if (task.get() == null) {
final RequestProcessor.Task newTask = RP.create(new Runnable() {
@Override
public void run() {
try {
Future<Void> f = ParserManager.parseWhenScanFinished(Collections.singletonList(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
}
});
if (!f.isDone()) {
while (true) {
if (isTaskCancelled()) {
task.set(null);
f.cancel(false);
break;
}
try {
f.get(250, TimeUnit.MILLISECONDS);
task.set(null);
Completion.get().hideCompletion();
Completion.get().showCompletion();
break;
} catch (TimeoutException te) {
// retry
}
}
}
} catch (InterruptedException ie) {
} catch (ExecutionException ee) {
} catch (ParseException pe) {
}
}
});
if (task.compareAndSet(null, newTask)) {
newTask.schedule(0);
}
}
}
} finally {
resultSet.finish();
}
}
示例10: createTask
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
@Override
public CompletionTask createTask(int queryType, JTextComponent jtc) {
if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE) {
return null;
}
return new AsyncCompletionTask(new AsyncCompletionQuery() {
@Override
protected void query(CompletionResultSet crs, Document dcmnt, int caretOffset) {
String filter;
int startOffset;
try {
String fileContent = dcmnt.getText(dcmnt.getStartPosition().getOffset(),
dcmnt.getEndPosition().getOffset());
final StyledDocument bDoc = (StyledDocument) dcmnt;
final int lineStartOffset = getRowFirstNonArroba(bDoc, caretOffset);
final int length = caretOffset - lineStartOffset;
final char[] line = bDoc.getText(lineStartOffset, length <= 0 ? 0 : length).toCharArray();
final int charToStartOffSet = indexOfChartToStartCompletion(line);
filter = new String(line, charToStartOffSet + 1, line.length - charToStartOffSet - 1);
if (charToStartOffSet > 0) {
startOffset = lineStartOffset + charToStartOffSet + 1;
} else {
startOffset = lineStartOffset;
}
List<String> items = SBTLanguageHelper.getKeyWords();
items.addAll(SBTLanguageHelper.getVariables(fileContent));
for (String itemName : items) {
if (itemName.startsWith(filter)) {
crs.addItem(new SBTCompletionItem(itemName, startOffset, caretOffset));
}
}
} catch (BadLocationException ex) {
ExceptionManager.logException(ex);
}
crs.finish();
}
}, jtc);
}
示例11: createTask
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
/**
* Creates a completion task for query.
*
* @param queryType Query type
* @param component Text component
* @return Completion task or {@code null} if the type is not
* supported (unsupported is everything except
* {@link CompletionProvider#COMPLETION_QUERY_TYPE
* COMPLETION_QUERY_TYPE})
* @see CompletionProvider#createTask(int, JTextComponent)
*/
@Override
public CompletionTask createTask(int queryType, JTextComponent component)
{
if( queryType != CompletionProvider.COMPLETION_QUERY_TYPE )
{
return null;
}
return new AsyncCompletionTask(new AsyncCompletionQuery()
{
@Override
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset)
{
String filter = null;
int startOffset = caretOffset - 1;
try
{
final StyledDocument styledDoc = (StyledDocument) doc;
final int lineStartOffset = getRowFirstNonWhitespace(styledDoc, caretOffset);
final char line[] = styledDoc.getText(lineStartOffset, caretOffset - lineStartOffset).toCharArray();
final int whiteSpaceOffset = indexOfWhitespace(line);
filter = String.valueOf(line, whiteSpaceOffset + 1, line.length - whiteSpaceOffset - 1);
if( whiteSpaceOffset > 0 )
{
startOffset = lineStartOffset + whiteSpaceOffset + 1;
}
else
{
startOffset = lineStartOffset;
}
}
catch( BadLocationException ex )
{
Exceptions.printStackTrace(ex);
}
final Iterator<String> itr = keyWords.iterator();
int num = 0;
while( itr.hasNext() == true )
{
final String keyWord = itr.next();
if( keyWord.startsWith(filter) == true )
{
resultSet.addItem(new CMakeCompletionItem(keyWord, ItemType.FUNCTION, startOffset, caretOffset));
num++;
}
}
if( filter != null && (num == keyWords.size() || num == 0) )
{
int n = getVariableExpansionOffset(filter);
resultSet.addItem(new CMakeCompletionItem("$", ItemType.VARIABLE_EXPANSION, caretOffset - n, caretOffset));
}
resultSet.finish();
}
}, component);
}
示例12: query
import org.netbeans.spi.editor.completion.CompletionResultSet; //导入方法依赖的package包/类
@Override
protected void query(final CompletionResultSet crs, final Document doc, final int caretOffset) {
try {
BaseDocument bdoc = (BaseDocument)doc;
bdoc.readLock();
TokenHierarchy<?> hi = TokenHierarchy.get(doc);
bdoc.readUnlock();
if ( crs.isFinished() || this.isTaskCancelled()){
if ( !crs.isFinished() ){
crs.finish();
}
return;
}
String thisClassName = getThisClass(doc, caretOffset);
if ( thisClassName == null ){
crs.finish();
return;
}
FileObject fileObject = NbEditorUtilities.getFileObject(doc);
Class thisClass = MirahCodeCompleter.findClass(fileObject, thisClassName);
if ( thisClass == null){
crs.finish();
return;
}
TokenSequence<MirahTokenId> toks = MirahCodeCompleter.mirahTokenSequence(doc, caretOffset, true);
int bol = MirahCodeCompleter.getBeginningOfLine(doc, caretOffset);
int eol = MirahCodeCompleter.getEndOfLine(doc, caretOffset);
int defOffset = -1;
while ( toks.movePrevious() ){
if ( toks.token().id().ordinal() == Tokens.tDef.ordinal() ){
defOffset = toks.token().offset(hi);
break;
}
}
if ( defOffset < 0 ){
crs.finish();
return;
}
filter = "";
Class cls = thisClass;
if ( cls.getSuperclass() != null ){
cls = cls.getSuperclass();
}
ClassQuery cq = new ClassQuery(cls);
for ( Method m : cq.getAccessibleMethods(thisClass)){
//int modifiers = m.getModifiers();
//if ( Modifier.isPrivate(modifiers) ){
// continue;
//}
if ( m.getName().startsWith(filter) && !Modifier.isStatic(m.getModifiers()) ){
crs.addItem(new MirahDefCompletionItem(m, defOffset, eol-defOffset));
}
}
if ( !crs.isFinished() ){
crs.finish();
}
} finally {
if ( !crs.isFinished() ){
crs.finish();
}
}
}