当前位置: 首页>>代码示例>>Java>>正文


Java CompletionProvider类代码示例

本文整理汇总了Java中org.netbeans.spi.editor.completion.CompletionProvider的典型用法代码示例。如果您正苦于以下问题:Java CompletionProvider类的具体用法?Java CompletionProvider怎么用?Java CompletionProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompletionProvider类属于org.netbeans.spi.editor.completion包,在下文中一共展示了CompletionProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPackageCompletion

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
private void doPackageCompletion(JavaSource js, final String typedPrefix, final int substitutionOffset) throws IOException {
    js.runUserActionTask(new Task<CompilationController>() {

        @Override
        public void run(CompilationController cc) throws Exception {
            if (isCancelled()) {
                return;
            }

            cc.toPhase(Phase.ELEMENTS_RESOLVED);
            ClassIndex ci = cc.getClasspathInfo().getClassIndex();
            int index = substitutionOffset;
            int dotIndex = typedPrefix.lastIndexOf('.'); // NOI18N
            if (dotIndex != -1) {
                index += (dotIndex + 1);  // NOI18N
            }

            addPackages(ci,  typedPrefix, index, CompletionProvider.COMPLETION_ALL_QUERY_TYPE);
        }
    }, true);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JavaPackageCompletor.java

示例2: createCompleter

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
@Override
public Completer createCompleter(CompletionContext ctx) {
    FxNode parent = ctx.getElementParent();
    FxProperty pi = ctx.getEnclosingProperty();
    if (pi == null && parent.getKind() != FxNode.Kind.Source) {
        // can complete only in root and in properties
        return null;
    }
    if (ctx.getType() == CompletionContext.Type.BEAN ||
        ctx.getType() == CompletionContext.Type.ROOT ||
        ctx.getType() == CompletionContext.Type.CHILD_ELEMENT || 
        ctx.getType() == CompletionContext.Type.PROPERTY_ELEMENT) {
        
        if (pi == null || pi.getKind() == FxDefinitionKind.LIST) {
            return new ClassCompleter(ctx);
        } 
        if (ctx.getPrefix().startsWith("<") ||
            ctx.getCompletionType() == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
            return new ClassCompleter(ctx);
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ClassCompleter.java

示例3: collectDirectClasses

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
/**
 * Collects directly referenced classes, from the parent chain or imports.
 * 
 * @return 
 */
private void collectDirectClasses() {
    for (FxNode p : ctx.getParents()) {
        if (p.getKind() != FxNode.Kind.Instance) {
            continue;
        }
        FxInstance parentInstance = (FxInstance)p;
        String parentClass = parentInstance.getResolvedName();
        if (parentClass != null) {
            if (classPrefix != null && 
                !CompletionUtils.startsWith(CompletionUtils.getSimpleName(parentClass), classPrefix)) {
                continue;
            }
            directClasses.add(parentClass);
        }
    }
    if (ctx.getCompletionType() == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
        for (ImportDecl decl : ctx.getModel().getImports()) {
            String n = decl.getImportedName();
            
            if (!decl.isWildcard()) {
                directClasses.add(n);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:StaticPropertyCompleter.java

示例4: runNamedTest

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
private void runNamedTest(String name, String file) throws Exception {
    prepareData(name, file);
    writeSourceFile();
    Source s = Source.create(sourceFO);
    ParserManager.parse(Collections.singleton(s), new UserTask() {

        @Override
        public void run(ResultIterator resultIterator) throws Exception {
            FxmlParserResult res = (FxmlParserResult)resultIterator.getParserResult();
            CompletionContext ctx = new CompletionContext(res, offset, CompletionProvider.COMPLETION_QUERY_TYPE);
            CompletionContext.Type type = CompletionContext.Type.valueOf(state);
            assertEquals(type, ctx.getType());
        }
        
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:CompletionContextTest.java

示例5: queryImpl

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
private void queryImpl(CompletionResultSet resultSet, Document doc, int caretOffset) throws InterruptedException, ExecutionException {
    JavadocContext jdctx = new JavadocContext();
    items = new  ArrayList<CompletionItem>();
    this.caretOffset = caretOffset;
    runInJavac(JavaSource.forDocument(doc), jdctx);
    
    if (!ignoreCancel && isTaskCancelled()) {
        return;
    }
    
    if ((queryType & CompletionProvider.COMPLETION_QUERY_TYPE) != 0) {
        if (!items.isEmpty()) {
            resultSet.addAllItems(items);
        }
        resultSet.setHasAdditionalItems(hasAdditionalItems);
    }
    
    if (jdctx.anchorOffset >= 0) {
        resultSet.setAnchorOffset(jdctx.anchorOffset);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JavadocCompletionQuery.java

示例6: addTypes

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
private void addTypes(EnumSet<ElementKind> kinds, DeclaredType baseType,
        Set<? extends Element> toExclude, String prefix,
        int substitutionOffset, JavadocContext jdctx) {
    
    if (queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
        if (baseType == null) {
            addAllTypes(jdctx, kinds, toExclude, prefix, substitutionOffset);
        } else {
            Elements elements = jdctx.javac.getElements();
            for(DeclaredType subtype : getSubtypesOf(baseType, prefix, jdctx)) {
                TypeElement elem = (TypeElement)subtype.asElement();
                if ((toExclude == null || !toExclude.contains(elem)) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(elem)))
                    items.add(JavaCompletionItem.createTypeItem(jdctx.javac, elem, subtype, substitutionOffset, jdctx.getReferencesCount(), elements.isDeprecated(elem), false, false, false, false, false, null));
            }
        }
    } else {
        addLocalAndImportedTypes(jdctx, kinds, baseType, toExclude, prefix, substitutionOffset);
        hasAdditionalItems = true;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavadocCompletionQuery.java

示例7: performCompletionTest

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
private void performCompletionTest(String code, String... golden) throws Exception {
    int caret = code.indexOf('|');
    prepareTest(code.replace("|", ""));
    
    List<CompletionItem> resultObj = JavadocCompletionQuery.runCompletionQuery(CompletionProvider.COMPLETION_QUERY_TYPE, doc, caret);
    List<String> resultStrings = new ArrayList<String>(resultObj.size());
    
    for (CompletionItem ci : resultObj) {
        if (ci instanceof JavadocCompletionItem) {
            JavadocCompletionItem jci = (JavadocCompletionItem) ci;
            resultStrings.add(stripHTML(jci.getLeftHtmlText() + ":" + (jci.getRightHtmlText() != null ? jci.getRightHtmlText() : "")));
        } else {
            resultStrings.add(stripHTML(ci.toString()));
        }
    }
    List<String> goldenList = new ArrayList<String>(Arrays.asList(golden));
    
    if (goldenList.contains(null)) {
        goldenList.remove(null);
        assertTrue(resultStrings.toString(), resultStrings.containsAll(goldenList));
    } else {
        Collections.sort(goldenList);
        Collections.sort(resultStrings);
        assertEquals(goldenList, resultStrings);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:JavadocCompletionQueryTest.java

示例8: testPlainContent

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
public void testPlainContent() throws Exception {
    MockGrammarResult r = new MockGrammarResult();
    
    r.setDescription(PLAIN_DESCRIPTION_TEXT);
    ElementResultItem item = new ElementResultItem(0, r);
    CompletionTask task = item.doCreateDocumentationTask(r);

    CompletionResultSet rs = resultSetFor(task, CompletionProvider.DOCUMENTATION_QUERY_TYPE);
    task.query(rs);
    
    assertTrue(rs.isFinished());
    
    assertEquals(PLAIN_DESCRIPTION_TEXT, rsImpl.getDocumentation().getText());
 
    // should return null from the url.
    assertNull(rsImpl.getDocumentation().getURL());
    
    // should not be able to resolve links
    assertNull(rsImpl.getDocumentation().resolveLink("link"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ElementResultItemDocumentationTest.java

示例9: createDocResourceResultSet

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
private CompletionDocumentation createDocResourceResultSet(MockUrlGrammarResult r) throws Exception {
    if (r == null) {
        r = new MockUrlGrammarResult();
        r.setContentURL(createResourceName("res/docResource.html"));
        r.setExternal(true);
    }
    
    ElementResultItem item = new ElementResultItem(0, r);
    CompletionTask task = item.doCreateDocumentationTask(r);
    CompletionResultSet rs = resultSetFor(task, CompletionProvider.DOCUMENTATION_QUERY_TYPE);
    task.query(rs);

    assertTrue(rs.isFinished());
    
    return rsImpl.getDocumentation();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ElementResultItemDocumentationTest.java

示例10: createTask

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的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);
}
 
开发者ID:iti-luebeck,项目名称:RTeasy2,代码行数:26,代码来源:RTCompletionProvider.java

示例11: createTask

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
@Override
public CompletionTask createTask( int queryType, JTextComponent component )
{
    if (VaadinConfiguration.getInstance().isAddonCodeCompletionEnabled()) {
        VaadinSupport support = getSupport(component.getDocument());
        if (support == null || !support.isEnabled()) {
            return null;
        }

        if (queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
            return new AsyncCompletionTask(new AddonCompletionQuery(
                    component.getSelectionStart()), component);
        }
    }
    return null;
}
 
开发者ID:vaadin,项目名称:netbeans-plugin,代码行数:17,代码来源:AddOnCompletionProvider.java

示例12: createTask

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
@Override
public CompletionTask createTask(int queryType, JTextComponent component) {
    if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE && queryType !=CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
        return null;
    }
    return new AsyncCompletionTask(new PUCompletionQuery(queryType, component, component.getSelectionStart(), true), component);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:PUCompletionProvider.java

示例13: addPackages

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
private void addPackages(ClassIndex ci, String typedPrefix, int substitutionOffset, int queryType) {
    Set<SearchScope> scope = (queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) ? ALL : LOCAL;
    Set<String> packages = ci.getPackageNames(typedPrefix, true, scope);
    for (String pkg : packages) {
        if (pkg.length() > 0) {
            SpringXMLConfigCompletionItem item = SpringXMLConfigCompletionItem.createPackageItem(substitutionOffset, pkg, false);
            addCacheItem(item);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:JavaPackageCompletor.java

示例14: doSmartJavaCompletion

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
private void doSmartJavaCompletion(final JavaSource js, final String typedPrefix, final int substitutionOffset, final int queryType) throws IOException {
    js.runUserActionTask(new Task<CompilationController>() {

        public void run(CompilationController cc) throws Exception {
            if(isCancelled()) {
                return;
            }
            
            cc.toPhase(Phase.ELEMENTS_RESOLVED);
            
            ClassIndex ci = cc.getClasspathInfo().getClassIndex();
            // add packages
            addPackages(ci, typedPrefix, substitutionOffset, CompletionProvider.COMPLETION_ALL_QUERY_TYPE);
            if(isCancelled()) {
                return;
            }
            
            // add classes
            Set<ElementHandle<TypeElement>> matchingTypes;
            if(queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
                matchingTypes = ci.getDeclaredTypes(typedPrefix, NameKind.CASE_INSENSITIVE_PREFIX, ALL);
            } else {
                matchingTypes = ci.getDeclaredTypes(typedPrefix, NameKind.CASE_INSENSITIVE_PREFIX, LOCAL);
                setAdditionalItems(true);
            }
            
            for (ElementHandle<TypeElement> eh : matchingTypes) {
                if(isCancelled()) {
                    return;
                }
                if (eh.getKind() == ElementKind.CLASS) {
                    LazyTypeCompletionItem item = LazyTypeCompletionItem.create(substitutionOffset, eh, js);
                    addCacheItem(item);
                }
            }
        }
    }, true);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:JavaClassCompletor.java

示例15: complete

import org.netbeans.spi.editor.completion.CompletionProvider; //导入依赖的package包/类
@Override
public List<? extends CompletionItem> complete() {
    List<CompletionItem> result = new ArrayList<CompletionItem>();
    if (ctx.getCompletionType() == CompletionProvider.COMPLETION_QUERY_TYPE) {
        completeShallow(result);
    } else {
        completeAllEvents(result);
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:EventCompleter.java


注:本文中的org.netbeans.spi.editor.completion.CompletionProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。