com.intellij.psi.PsiElementResolveResult Java Examples

The following examples show how to use com.intellij.psi.PsiElementResolveResult. 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: PhpElementsUtil.java    From yiistorm with MIT License 6 votes vote down vote up
static public List<ResolveResult> getClassInterfaceResolveResult(Project project, String FQNClassOrInterfaceName) {

        PhpIndex phpIndex = PhpIndex.getInstance(project);
        Collection<PhpClass> phpClasses = phpIndex.getClassesByFQN(FQNClassOrInterfaceName);
        Collection<PhpClass> phpInterfaces = phpIndex.getInterfacesByFQN(FQNClassOrInterfaceName);

        List<ResolveResult> results = new ArrayList<ResolveResult>();
        for (PhpClass phpClass : phpClasses) {
            results.add(new PsiElementResolveResult(phpClass));
        }
        for (PhpClass phpInterface : phpInterfaces) {
            results.add(new PsiElementResolveResult(phpInterface));
        }

        return results;
    }
 
Example #2
Source File: SignalSlotMethodReference.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    if (classFqn.isEmpty()) {
        return ResolveResult.EMPTY_ARRAY;
    }

    List<ResolveResult> results = new ArrayList<>();
    PsiElement[] psiElements = SignalSlotDispatcherUtil.getSignalPsiElements(myElement.getProject(), classFqn, methodName);

    for (PsiElement psiElement : psiElements) {
        results.add(new PsiElementResolveResult(psiElement));
    }

    return results.toArray(new ResolveResult[0]);
}
 
Example #3
Source File: GLSLParameterInfoHandler.java    From glsl4idea with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void updateUI(Object p, @NotNull ParameterInfoUIContext context) {
    if (p instanceof PsiElementResolveResult) p = ((PsiElementResolveResult) p).getElement();
    if (!(p instanceof GLSLFunctionDeclaration)) return;
    GLSLFunctionDeclaration declaration = (GLSLFunctionDeclaration) p;
    GLSLParameterDeclaration[] parameters = declaration.getParameters();

    StringBuilder buffer = new StringBuilder();
    buffer.append(declaration.getType().getReturnType().getTypename())
            .append(' ').append(declaration.getName()).append('(');

    final int currentParameter = context.getCurrentParameterIndex();
    int highlightStartOffset = -1, highlightEndOffset = -1;

    for (int i = 0; i < parameters.length; i++) {
        if (i == currentParameter) highlightStartOffset = buffer.length();
        buffer.append(parameters[i].getText());
        if (i == currentParameter) highlightEndOffset = buffer.length();
        if (i < parameters.length - 1) buffer.append(", ");
    }
    buffer.append(')');

    context.setupUIComponentPresentation(buffer.toString(), highlightStartOffset, highlightEndOffset, false, false, false, context.getDefaultParameterColor());
}
 
Example #4
Source File: UserFuncReference.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    if (this.methodName == null) {

        return ResolveResult.EMPTY_ARRAY;
    }

    if (this.className == null) {
        Collection<Function> functionsByName = PhpIndex.getInstance(myElement.getProject()).getFunctionsByName(methodName);

        return PsiElementResolveResult.createResults(functionsByName);
    }

    String s = "#M#C\\" + this.className.replace("\\\\", "\\") + "." + this.methodName;
    Collection<? extends PhpNamedElement> bySignature = PhpIndex.getInstance(myElement.getProject()).getBySignature(s);

    return PsiElementResolveResult.createResults(bySignature);
}
 
Example #5
Source File: XQueryPrefixReference.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    XQueryFile file = (XQueryFile) myElement.getContainingFile();
    List<ResolveResult> results = new ArrayList<ResolveResult>();
    Collection<ResolveResult> primaryReferences = getPrimaryReferences();
    results.addAll(primaryReferences);
    if (shouldAddOtherReferences(primaryReferences)) {
        results.addAll(getReferencesFromNamespaceDeclarations(file.getNamespaceDeclarations()));
        results.addAll(getReferencesFromModuleImports(file.getModuleImports()));
        results.addAll(getReferencesFromModuleName(file.getModuleNamespaceName()));
    }
    if (results.isEmpty() && file.isPredeclaredNamespacePrefix(myElement.getText())) {
        results.add(new PsiElementResolveResult(getElement()));
    }
    return results.toArray(new ResolveResult[results.size()]);
}
 
Example #6
Source File: ViewHelperReference.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    if (myElement instanceof FluidViewHelperReference) {
        FluidViewHelperExpr viewHelperExpr = (FluidViewHelperExpr) PsiTreeUtil.findFirstParent(myElement, e -> e instanceof FluidViewHelperExpr);
        String presentableName = viewHelperExpr.getPresentableName();
        ViewHelper viewHelperByName = ViewHelperUtil.getViewHelperByName(myElement, presentableName);
        if (viewHelperByName == null) {

            return ResolveResult.EMPTY_ARRAY;
        }

        return PsiElementResolveResult.createResults(PhpIndex.getInstance(myElement.getProject()).getClassesByFQN(viewHelperByName.fqn));
    }

    return ResolveResult.EMPTY_ARRAY;
}
 
Example #7
Source File: NodeTypeReference.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    String nodeTypeNameToFindReferenceFor = yamlElement.getKeyText();

    // files which contain the NodeType definition
    Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NodeTypesYamlFileIndex.KEY, nodeTypeNameToFindReferenceFor, GlobalSearchScope.allScope(yamlElement.getProject()));

    return files
            .stream()
            // get the PSI for each file
            .map(file -> PsiManager.getInstance(yamlElement.getProject()).findFile(file))
            // ensure we only have YAML files
            .filter(psiFile -> psiFile instanceof YAMLFile)
            .map(psiFile -> (YAMLFile) psiFile)
            // get all YAML keys in these files
            .flatMap(yamlFile -> YAMLUtil.getTopLevelKeys(yamlFile).stream())
            // get the correct YAML key
            .filter(yamlKeyValue -> yamlKeyValue.getKeyText().equals(nodeTypeNameToFindReferenceFor))
            // remove "current" element if it exists
            .filter(yamlKeyValue -> yamlElement != yamlKeyValue)
            // build up the result object
            .map(yamlKeyValue -> new PsiElementResolveResult(yamlKeyValue, true))
            .toArray(PsiElementResolveResult[]::new);
}
 
Example #8
Source File: ConstraintPropertyReference.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {

    List<PsiElement> psiElements = new ArrayList<>();

    String content = ((StringLiteralExpression) getElement()).getContents();
    for(Field field: constraintPhpClass.getFields()) {
        String name = field.getName();
        if(!field.isConstant() && field.getModifier().isPublic() && content.equals(name)) {
            psiElements.add(field);
        }
    }

    return PsiElementResolveResult.createResults(psiElements);
}
 
Example #9
Source File: XQueryFunctionReference.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private ResolveResult[] convertToResolveResults(List<XQueryFunctionName> resolveResults) {
    ResolveResult[] convertedResults = new ResolveResult[resolveResults.size()];
    for (int i = 0; i < resolveResults.size(); i++) {
        convertedResults[i] = new PsiElementResolveResult(resolveResults.get(i));
    }
    return convertedResults;
}
 
Example #10
Source File: XQueryVariableReferenceResolver.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private ResolveResult[] convertToResolveResults(List<XQueryVarName> resolveResults) {
    ResolveResult[] convertedResults = new ResolveResult[resolveResults.size()];
    for (int i = 0; i < resolveResults.size(); i++) {
        convertedResults[i] = new PsiElementResolveResult(resolveResults.get(i));
    }
    return convertedResults;
}
 
Example #11
Source File: XQueryPrefixReference.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private Collection<ResolveResult> getReferencesFromModuleName(XQueryNamespacePrefix moduleNamespaceName) {
    if (moduleNamespaceName != null && myElement.getText().equals(moduleNamespaceName.getText())) {
        return Arrays.asList(new ResolveResult[]{new PsiElementResolveResult(moduleNamespaceName)});
    } else {
        return emptyList();
    }
}
 
Example #12
Source File: XQueryPrefixReference.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private Collection<ResolveResult> getReferencesFromModuleImports(Collection<XQueryModuleImport> moduleImports) {
    if (moduleImports.size() > 0) {
        List<ResolveResult> results = new ArrayList<ResolveResult>();
        for (XQueryModuleImport moduleImport : moduleImports) {
            XQueryNamespacePrefix namespaceName = moduleImport.getNamespacePrefix();
            if (namespaceName != null && myElement.getText().equals(namespaceName.getText())) {
                results.add(new PsiElementResolveResult(moduleImport.getNamespacePrefix()));
            }
        }
        return results;
    } else {
        return emptyList();
    }
}
 
Example #13
Source File: XQueryPrefixReference.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private Collection<ResolveResult> getReferencesFromNamespaceDeclarations(Collection<XQueryNamespaceDecl>
                                                                                 namespaceDeclarations) {
    if (namespaceDeclarations.size() > 0) {
        List<ResolveResult> results = new ArrayList<ResolveResult>();
        for (XQueryNamespaceDecl namespaceDeclaration : namespaceDeclarations) {
            if (myElement.getText().equals(namespaceDeclaration.getNamespacePrefix().getText())) {
                results.add(new PsiElementResolveResult(namespaceDeclaration.getNamespacePrefix()));
            }
        }
        return results;
    } else {
        return emptyList();
    }
}
 
Example #14
Source File: FormUnderscoreMethodReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    String contents = getElement().getContents();
    if(org.apache.commons.lang.StringUtils.isBlank(contents)) {
        return new ResolveResult[0];
    }

    Collection<PsiElement> psiElements = new ArrayList<>();

    Set<String> methods = getCamelizeAndUnderscoreString(contents);

    // provide setter fallback for non model class or or unknown methods
    for (String value : methods) {
        Method method = phpClass.findMethodByName("set" + value);
        if (method != null) {
            psiElements.add(method);
        }
    }

    // property path
    psiElements.addAll(this.phpClass.getFields().stream()
        .filter(field -> !field.isConstant() && field.getModifier().isPublic() && methods.contains(field.getName()))
        .collect(Collectors.toList())
    );

    return PsiElementResolveResult.createResults(psiElements);
}
 
Example #15
Source File: AbstractServiceReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    ContainerCollectionResolver.ServiceCollector collector = ContainerCollectionResolver
        .ServiceCollector.create(getElement().getProject());

    // Return the PsiElement for the class corresponding to the serviceId
    String serviceClass = collector.resolve(serviceId);
    if (serviceClass == null) {
        return new ResolveResult[0];
    }

    return PsiElementResolveResult.createResults(PhpIndex.getInstance(getElement().getProject()).getAnyByFQN(serviceClass));
}
 
Example #16
Source File: RouteParameterReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {

    List<ResolveResult> results = new ArrayList<>();

    for (PsiElement psiParameter : RouteHelper.getRouteParameterPsiElements(getElement().getProject(), this.routeName, parameterName)) {
        results.add(new PsiElementResolveResult(psiParameter));
    }

    return results.toArray(new ResolveResult[results.size()]);
}
 
Example #17
Source File: EventDispatcherEventReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {

    List<ResolveResult> resolveResults = new ArrayList<>();

    for(PsiElement psiElement: EventDispatcherSubscriberUtil.getEventPsiElements(getElement().getProject(), this.eventName)) {
        resolveResults.add(new PsiElementResolveResult(psiElement));
    }

    return resolveResults.toArray(new ResolveResult[resolveResults.size()]);
}
 
Example #18
Source File: ClassPublicMethodReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(getElement().getProject(), this.className);
    if(phpClass == null) {
        return new ResolveResult[0];
    }

    Method targetMethod = phpClass.findMethodByName(this.method);
    if(targetMethod == null) {
        return new ResolveResult[0];
    }

    return PsiElementResolveResult.createResults(targetMethod);
}
 
Example #19
Source File: ParameterXmlReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    Collection<PsiElement> targets = new ArrayList<>();

    targets.addAll(
        DotEnvUtil.getEnvironmentVariableTargetsForParameter(getElement().getProject(), this.parameterName)
    );

    targets.addAll(ServiceUtil.getServiceClassTargets(getElement().getProject(), this.parameterName));

    return PsiElementResolveResult.createResults(targets);
}
 
Example #20
Source File: ConstantXmlReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    String contents = getElement().getValue();
    if(StringUtils.isBlank(contents)) {
        return new ResolveResult[0];
    }

    return PsiElementResolveResult.createResults(
        ServiceContainerUtil.getTargetsForConstant(getElement().getProject(), contents)
    );
}
 
Example #21
Source File: TranslationReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    List<ResolveResult> results = new ArrayList<>();
    PsiElement[] psiElements = TranslationUtil.getTranslationPsiElements(this.element.getProject(), this.element.getContents(), this.domainName);

    for (PsiElement psiElement : psiElements) {
        results.add(new PsiElementResolveResult(psiElement));
    }

    return results.toArray(new ResolveResult[results.size()]);
}
 
Example #22
Source File: DoctrineRepositoryReference.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {

    PhpClass phpClass = PhpElementsUtil.getClassInsideAnnotation((StringLiteralExpression) getElement(), content);
    if(phpClass == null) {
        return new ResolveResult[0];
    }

    return new ResolveResult[] {
        new PsiElementResolveResult(phpClass)
    };
}
 
Example #23
Source File: DoctrinePhpClassFieldReference.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {
    List<PsiElement> psiElementList = this.phpClass.getFields().stream()
        .filter(field -> !field.isConstant() && content.equals(field.getName()))
        .collect(Collectors.toList());

    return PsiElementResolveResult.createResults(psiElementList);
}
 
Example #24
Source File: PhpClassReference.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {

    PhpClass phpClass = PhpElementsUtil.getClassInsideAnnotation((StringLiteralExpression) getElement(), content);
    if(phpClass == null) {
        return new ResolveResult[0];
    }

    return new ResolveResult[] {
        new PsiElementResolveResult(phpClass)
    };
}
 
Example #25
Source File: BuckIdentifierReference.java    From buck with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
  Project project = myElement.getProject();
  ResolveResult[] results =
      BuckIdentifierUtil.findIdentifiers(project, key).stream()
          .map(PsiElementResolveResult::new)
          .toArray(ResolveResult[]::new);
  return results;
}
 
Example #26
Source File: GLSLFunctionReference.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode) {
    final List<GLSLFunctionType> functions = sourceExpression.getPossibleCalledFunctions();
    ResolveResult[] result = new ResolveResult[functions.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = new PsiElementResolveResult(functions.get(i).getDefinition());
    }
    return result;
}
 
Example #27
Source File: ContextReference.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    if (myElement instanceof StringLiteralExpression) {
        String aspectFQN = TYPO3Utility.getFQNByAspectName(((StringLiteralExpression) myElement).getContents());
        if (aspectFQN == null) {
            return ResolveResult.EMPTY_ARRAY;
        }

        return PsiElementResolveResult.createResults(PhpIndex.getInstance(myElement.getProject()).getClassesByFQN(aspectFQN));
    }

    return ResolveResult.EMPTY_ARRAY;
}
 
Example #28
Source File: TemplateDefinitionReference.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
  return PsiElementResolveResult.createResults(
      TemplateNameUtils.findTemplateDeclarations(this.getElement(), templateName)
          .stream()
          .map(SoyTemplateBlock::getDefinitionIdentifier)
          .collect(Collectors.toList()));
}
 
Example #29
Source File: CamelBeanMethodReference.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {
    List<ResolveResult> results = new ArrayList<>();

    final PsiMethod[] methodsByName = getPsiClass().findMethodsByName(methodNameOnly, true);
    for (PsiMethod psiMethod : getJavaMethodUtils().getBeanMethods(Arrays.asList(methodsByName))) {
        if (getCamelIdeaUtils().isAnnotatedWithHandler(psiMethod)) {
            return new ResolveResult[] {new PsiElementResolveResult(psiMethod)};
        }
        results.add(new PsiElementResolveResult(psiMethod));
    }
    return results.toArray(new ResolveResult[results.size()]);
}
 
Example #30
Source File: DirectEndpointReference.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    return Optional.ofNullable(ModuleUtilCore.findModuleForPsiElement(myElement))
        .map(module -> CamelIdeaUtils.getService().findEndpointDeclarations(module, endpoint))
        .map(this::wrapAsDirectEndpointPsiElements)
        .map(PsiElementResolveResult::createResults)
        .orElse(ResolveResult.EMPTY_ARRAY);
}