com.jetbrains.php.completion.PhpLookupElement Java Examples

The following examples show how to use com.jetbrains.php.completion.PhpLookupElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {
    PsiElement parent = getElement().getParent();
    if(!(parent instanceof XmlAttributeValue)) {
        return Collections.emptyList();
    }

    Collection<PhpClass> phpClasses = new ArrayList<>();

    ContainerUtil.addIfNotNull(phpClasses, XmlHelper.getPhpClassForClassFactory((XmlAttributeValue) parent));
    ContainerUtil.addIfNotNull(phpClasses, XmlHelper.getPhpClassForServiceFactory((XmlAttributeValue) parent));

    Collection<LookupElement> lookupElements = new ArrayList<>();

    for (PhpClass phpClass : phpClasses) {
        lookupElements.addAll(PhpElementsUtil.getClassPublicMethod(phpClass).stream()
            .map(PhpLookupElement::new)
            .collect(Collectors.toList())
        );
    }

    return lookupElements;
}
 
Example #2
Source File: YamlCompletionContributor.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {

    PsiElement position = parameters.getPosition();
    if(!Symfony2ProjectComponent.isEnabled(position)) {
        return;
    }

    String service = YamlHelper.getPreviousSequenceItemAsText(position);
    if (service == null) {
        return;
    }

    PhpClass phpClass = ServiceUtil.getServiceClass(position.getProject(), service);
    if(phpClass == null) {
        return;
    }

    for (Method method : phpClass.getMethods()) {
        if(method.getAccess().isPublic() && !(method.getName().startsWith("__"))) {
            completionResultSet.addElement(new PhpLookupElement(method));
        }
    }

}
 
Example #3
Source File: ClassPublicMethodReference.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
@Deprecated
public Object[] getVariants() {

    PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(getElement().getProject(), this.className);
    if(phpClass == null) {
        return new Object[0];
    }

    List<LookupElement> lookupElements = new ArrayList<>();
    for(Method publicMethod: PhpElementsUtil.getClassPublicMethod(phpClass)) {
        lookupElements.add(new PhpLookupElement(publicMethod));
    }

    return lookupElements.toArray();
}
 
Example #4
Source File: LattePhpClassCompletionProvider.java    From intellij-latte with MIT License 5 votes vote down vote up
@Override
protected void addCompletions(
		@NotNull CompletionParameters params,
		ProcessingContext ctx,
		@NotNull CompletionResultSet results
) {
	PsiElement curr = params.getPosition().getOriginalElement();
	if (PsiTreeUtil.getParentOfType(curr, LattePhpContent.class) == null) {
		return;
	}

	PrefixMatcher prefixMatcher = results.getPrefixMatcher();
	String prefix = prefixMatcher.getPrefix();
	if (prefix.contains("\\")) {
		int index = prefix.lastIndexOf("\\");
		prefixMatcher = prefixMatcher.cloneWithPrefix(prefix.substring(index + 1));
	}

	Project project = params.getPosition().getProject();
	Collection<String> classNames = LattePhpUtil.getAllExistingClassNames(project, prefixMatcher);
	Collection<PhpNamedElement> variants = LattePhpUtil.getAllClassNamesAndInterfaces(project, classNames);

	// Add variants
	for (PhpNamedElement item : variants) {
		PhpLookupElement lookupItem = getPhpLookupElement(item, null);
		lookupItem.handler = PhpClassInsertHandler.getInstance();
		results.addElement(lookupItem);
	}
}
 
Example #5
Source File: BaseLatteCompletionProvider.java    From intellij-latte with MIT License 5 votes vote down vote up
PhpLookupElement getPhpLookupElement(@NotNull PhpNamedElement phpNamedElement, @Nullable String searchedWord) {
	PhpLookupElement lookupItem = new PhpLookupElement(phpNamedElement) {
		@Override
		public Set<String> getAllLookupStrings() {
			Set<String> original = super.getAllLookupStrings();
			Set<String> strings = new HashSet<String>(original.size() + 1);
			strings.addAll(original);
			strings.add(searchedWord == null ? this.getNamedElement().getFQN() : searchedWord);
			return strings;
		}
	};
	return lookupItem;
}
 
Example #6
Source File: PhpElementsUtil.java    From yiistorm with MIT License 5 votes vote down vote up
static public void addClassPublicMethodCompletion(CompletionResultSet completionResultSet, PhpClass phpClass) {
    for (Method method : phpClass.getMethods()) {
        if (method.getAccess().isPublic() && !method.getName().startsWith("__")) {
            completionResultSet.addElement(new PhpLookupElement(method));
        }
    }
}
 
Example #7
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
static public void addClassPublicMethodCompletion(CompletionResultSet completionResultSet, PhpClass phpClass) {
    for(Method method: getClassPublicMethod(phpClass)) {
        completionResultSet.addElement(new PhpLookupElement(method));
    }
}