Java Code Examples for com.intellij.psi.PsiReference#EMPTY_ARRAY

The following examples show how to use com.intellij.psi.PsiReference#EMPTY_ARRAY . 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: CamelBeanReferenceContributor.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
private PsiReference[] createSpringBeanMethodReference(@NotNull PsiElement element) {

        if (element.getText().contains("IntellijIdeaRulezzz")) {
            return PsiReference.EMPTY_ARRAY;
        }

        PsiClass psiClass = getCamelIdeaUtils().getBean(element);
        if (psiClass == null) {
            return PsiReference.EMPTY_ARRAY;
        }

        final String beanName = getJavaClassUtils().getBeanName(psiClass);
        final String methodName = StringUtils.stripDoubleQuotes(element.getText());

        if (methodName.equals(beanName) || methodName.isEmpty()) {
            return PsiReference.EMPTY_ARRAY;
        }

        return new PsiReference[] {new CamelBeanMethodReference(element, psiClass, methodName, new TextRange(1, methodName.length() + 1))};

    }
 
Example 2
Source File: StringLiteral.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Labels are taken to reference: - the actual target they reference - the BUILD package specified
 * before the colon (only if explicitly present)
 */
@Override
public PsiReference[] getReferences() {
  // first look for attribute-specific references
  String attributeName = getParentAttributeName();
  if (attributeName != null) {
    PsiReference[] refs =
        AttributeSpecificStringLiteralReferenceProvider.findReferences(attributeName, this);
    if (refs.length != 0) {
      return refs;
    }
  }
  PsiReference primaryReference = getReference();
  if (primaryReference instanceof LabelReference) {
    LabelReference labelReference = (LabelReference) primaryReference;
    return new PsiReference[] {
      primaryReference,
      new PackageReferenceFragment(labelReference),
      new ExternalWorkspaceReferenceFragment(labelReference)
    };
  }
  return primaryReference != null
      ? new PsiReference[] {primaryReference}
      : PsiReference.EMPTY_ARRAY;
}
 
Example 3
Source File: SQFVariable.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferences() {
	SQFFile sqfFile = (SQFFile) getContainingFile();
	if (sqfFile == null) {
		return PsiReference.EMPTY_ARRAY;
	}
	List<SQFVariable> vars = new ArrayList<>();
	PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
		PsiElement nodeAsElement = astNode.getPsi();
		if (nodeAsElement instanceof SQFVariable) {
			SQFVariable var = (SQFVariable) nodeAsElement;
			if (var.isLocal()) {
				return false;
			}
			if (SQFVariableName.nameEquals(var.getVarName(), getVarName())) {
				vars.add(var);
			}
		}
		return false;
	});
	if (vars.isEmpty()) {
		return PsiReference.EMPTY_ARRAY;
	}
	return new PsiReference[]{new SQFVariableReference.IdentifierReference(this, vars)};
}
 
Example 4
Source File: SQFString.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferences() {
	List<SQFVariableInStringReference> currentFileRefs = SQFScope.getVariableReferencesFor(this);
	PsiReference[] refsFromProviders = ReferenceProvidersRegistry.getReferencesFromProviders(this);
	if (currentFileRefs.size() == 0 && refsFromProviders.length == 0) {
		return PsiReference.EMPTY_ARRAY;
	}
	PsiReference[] refsAsArray = new PsiReference[currentFileRefs.size() + refsFromProviders.length];
	int i = 0;
	for (; i < currentFileRefs.size(); i++) {
		refsAsArray[i] = currentFileRefs.get(i);
	}
	for (int j = 0; j < refsFromProviders.length; i++, j++) {
		refsAsArray[i] = refsFromProviders[j];
	}
	return refsAsArray;
}
 
Example 5
Source File: SQFCommand.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferences() {
	SQFFile sqfFile = (SQFFile) getContainingFile();
	if (sqfFile == null) {
		return PsiReference.EMPTY_ARRAY;
	}
	List<SQFCommand> cmds = new ArrayList<>();
	PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
		PsiElement nodeAsElement = astNode.getPsi();
		if (nodeAsElement instanceof SQFCommand) {
			SQFCommand command = (SQFCommand) nodeAsElement;
			if (command.commandNameEquals(getCommandName())) {
				cmds.add(command);
			}
		}
		return false;
	});
	if (cmds.isEmpty()) {
		return PsiReference.EMPTY_ARRAY;
	}
	return new PsiReference[]{new SQFCommandReference(this, cmds)};
}
 
Example 6
Source File: NodeTypeReferenceContributor.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    YAMLKeyValue yamlElement = (YAMLKeyValue) element;

    // we support the following cases:
    // - superTypes
    // - constraints.nodeTypes
    // - root level (to find other definitions on root)
    if (parentKeyIs(yamlElement, "superTypes")
            || (parentKeyIs(yamlElement, "nodeTypes") && grandparentKeyIs(yamlElement, "constraints"))
            || isOnRootLevel(yamlElement)) {
        return new PsiReference[]{
                new NodeTypeReference(yamlElement)
        };
    }

    return PsiReference.EMPTY_ARRAY;
}
 
Example 7
Source File: HaskellReferenceProvider.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
                                             @NotNull ProcessingContext context) {
    if (!element.getLanguage().is(HaskellLanguage.INSTANCE)) {
        return PsiReference.EMPTY_ARRAY;
    }

    if (element instanceof PsiNamedElement) {
        PsiNamedElement se = (PsiNamedElement) element;
        return new PsiReference[]{new HaskellReference(se, se.getTextRange())};
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 8
Source File: BlueprintJavaClassReferenceProvider.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected PsiReference[] getAttributeReferences(@NotNull XmlAttribute attribute, @NotNull XmlAttributeValue value,
                                                ProcessingContext context) {
    if (isBeanClassAttribute(attribute) || isTypeAttributeInRoute(attribute)) {
        return javaClassReferenceProvider.getReferencesByElement(value, context);
    } else {
        return PsiReference.EMPTY_ARRAY;
    }
}
 
Example 9
Source File: YiiPsiReferenceProvider.java    From yiistorm with MIT License 5 votes vote down vote up
/**
 * Return reference or empty array
 *
 * @param element PsiElement
 * @param context ProcessingContext
 * @return PsiReference[]
 */
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    project = element.getProject();
    String elname = element.getClass().getName();
    //properties = PropertiesComponent.getInstance(project);
    /*boolean ProviderType2 = YiiRefsHelper.isYiiApplication(element);
    if (ProviderType2) {
        ProviderType2 = ProviderType2;
    }    */
    if (elname.endsWith("StringLiteralExpressionImpl")) {

        try {
            PsiFile file = element.getContainingFile();
            VirtualFile vfile = file.getVirtualFile();
            if (vfile != null) {
                String path = vfile.getPath();
                String basePath = project.getBasePath();
                if (basePath != null) {
                    projectPath = basePath.replace("\\", "/");
                    int ProviderType = YiiRefsHelper.getYiiObjectType(path, element);
                    switch (ProviderType) {
                        case YiiRefsHelper.YII_TYPE_AR_RELATION:
                            return ARRelationReferenceProvider.getReference(path, element);
                        case YiiRefsHelper.YII_TYPE_CACTION_TO_VIEW_RENDER:
                            return CActionRenderViewReferenceProvider.getReference(path, element);
                        case YiiRefsHelper.YII_TYPE_WIDGET_VIEW_RENDER:
                            return WidgetRenderViewReferenceProvider.getReference(path, element);
                        case YiiRefsHelper.YII_TYPE_CONTROLLER_ACTIONS_CACTION:
                            return ControlleActionsClassReferenceProvider.getReference(path, element);
                    }
                }
            }
        } catch (Exception e) {
            //System.err.println("error" + e.getMessage());
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 10
Source File: BlueprintPropertyNameReferenceProvider.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected PsiReference[] getAttributeReferences(@NotNull XmlAttribute attribute, @NotNull XmlAttributeValue value,
                                                ProcessingContext context) {
    if (isPropertyName(attribute, value)) {
        PsiClass beanClass = BeanUtils.getService().getPropertyBeanClass(attribute.getParent());
        if (beanClass != null) {
            return new PsiReference[] {new PropertyNameReference(value, value.getValue(), beanClass)};
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 11
Source File: CppKeyword.java    From CppTools with Apache License 2.0 5 votes vote down vote up
@NotNull
public PsiReference[] getReferences() {
  IElementType elementType = getNode().getElementType();
  if (elementType == CppTokenTypes.OPERATOR_KEYWORD) {
    return new PsiReference[] {new MyPsiPolyVariantReference(this)};
  }
  return PsiReference.EMPTY_ARRAY;
}
 
Example 12
Source File: CamelEndpointPsiReferenceProvider.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected PsiReference[] getCamelReferencesByElement(PsiElement element, ProcessingContext context) {
    String endpointUri = getEndpointUri(element);
    if (endpointUri == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    if (!isEndpoint(endpointUri)) {
        return PsiReference.EMPTY_ARRAY;
    }
    if (!CamelIdeaUtils.getService().isPlaceForEndpointUri(element)) {
        return PsiReference.EMPTY_ARRAY;
    }
    return getEndpointReferencesByElement(endpointUri, element, context);
}
 
Example 13
Source File: ControlleActionsClassReferenceProvider.java    From yiistorm with MIT License 5 votes vote down vote up
public static PsiReference[] getReference(String path, @NotNull PsiElement element) {
    try {

        String protectedPath = CommonHelper.searchCurrentProtected(path).replace(YiiPsiReferenceProvider.projectPath, "");
        VirtualFile baseDir = YiiPsiReferenceProvider.project.getBaseDir();
        if (protectedPath != null && baseDir != null) {
            path = path.replace(YiiPsiReferenceProvider.projectPath, "");
            String str = element.getText();
            TextRange textRange = CommonHelper.getTextRange(element, str);
            String uri = str.substring(textRange.getStartOffset(), textRange.getEndOffset());

            VirtualFile protectedVirtual = baseDir.findFileByRelativePath(protectedPath);
            VirtualFile appDir = baseDir.findFileByRelativePath(path);
            if (uri.matches("^application.+")) {
                uri = uri.replace("application.", "").replace(".", "/");
            }
            if (protectedVirtual != null) {
                VirtualFile file = protectedVirtual.findFileByRelativePath(uri + ".php");

                if (file == null) {
                    file = protectedVirtual.findFileByRelativePath("components/" + uri + ".php");
                }

                if (file != null) {

                    if (appDir != null) {
                        PsiReference ref = new FileReference(file, uri, element,
                                textRange, YiiPsiReferenceProvider.project, protectedVirtual, appDir);
                        return new PsiReference[]{ref};
                    }
                }
            }
        }
        return PsiReference.EMPTY_ARRAY;
    } catch (Exception e) {
        System.err.println("error" + e.getMessage());
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 14
Source File: I18nReferenceProvider.java    From yiistorm with MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    project = element.getProject();
    properties = PropertiesComponent.getInstance(project);
    String searchStringFull = CommonHelper.rmQuotes(element.getText());
    String searchString = searchStringFull;
    PsiFile currentFile = element.getContainingFile();

    String protectedPath = CommonHelper.searchCurrentProtected(CommonHelper.getFilePath(currentFile));
    if (protectedPath != null) {
        protectedPath = CommonHelper.getRelativePath(project, protectedPath);
        String[] result = I18NHelper.findMessageSource(searchStringFull, protectedPath, project);
        if (result != null) {
            protectedPath = result[0];
            searchString = result[2];
        } else {
            protectedPath += "/messages/" + I18NHelper.getLang(project);
        }
        try {
            String relativePath = protectedPath + "/" + searchString + ".php";
            VirtualFile viewfile = project.getBaseDir().findFileByRelativePath(relativePath);

            if (viewfile != null) {
                PsiReference ref = new I18nFileReference(
                        viewfile,
                        element,
                        element.getTextRange(),
                        project);
                return new PsiReference[]{ref};
            }
        } catch (Exception e) {
            System.err.println("error" + e.getMessage());
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 15
Source File: ARRelationReferenceProvider.java    From yiistorm with MIT License 5 votes vote down vote up
public static PsiReference[] getReference(String path, @NotNull PsiElement element) {
    try {

        String viewPath = path.replace(YiiPsiReferenceProvider.projectPath, "");
        String protectedPath = YiiRefsHelper.getCurrentProtected(path);
        protectedPath = protectedPath.replace(YiiPsiReferenceProvider.projectPath, "");
        if (ARRelationReferenceProvider.isARRelationClassName(element)) {

            String str = element.getText();
            TextRange textRange = CommonHelper.getTextRange(element, str);
            if (textRange != null) {
                VirtualFile baseDir = YiiPsiReferenceProvider.project.getBaseDir();
                if (baseDir != null) {
                    String className = element.getText();
                    VirtualFile v = ARRelationReferenceProvider.getClassFile(className);
                    VirtualFile appDir = baseDir.findFileByRelativePath(viewPath);
                    VirtualFile protectedPathDir = (!protectedPath.equals("")) ? baseDir.findFileByRelativePath(protectedPath) : null;
                    if (appDir != null) {
                        PsiReference ref = new FileReference(v, str.substring(textRange.getStartOffset(), textRange.getEndOffset())
                                , element,
                                textRange, YiiPsiReferenceProvider.project, protectedPathDir, appDir);
                        return new PsiReference[]{ref};
                    }
                }
            }
        }
        return PsiReference.EMPTY_ARRAY;
    } catch (Exception e) {
        //System.err.println("error" + e.getMessage());
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 16
Source File: XPath.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferences() {
	return PsiReference.EMPTY_ARRAY;
}
 
Example 17
Source File: MockReferenceProvidersRegistry.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected PsiReference[] doGetReferencesFromProviders(PsiElement context, PsiReferenceService.Hints hints) {
  return PsiReference.EMPTY_ARRAY;
}
 
Example 18
Source File: ControllerRenderViewReferenceProvider.java    From yiistorm with MIT License 4 votes vote down vote up
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    project = element.getProject();
    String elname = element.getClass().getName();
    properties = PropertiesComponent.getInstance(project);
    VirtualFile baseDir = project.getBaseDir();
    projectPath = baseDir.getCanonicalPath();
    if (elname.endsWith("StringLiteralExpressionImpl")) {

        try {
            PsiFile file = element.getContainingFile();
            VirtualFile vfile = file.getVirtualFile();
            if (vfile != null) {
                String path = vfile.getPath();
                String basePath = project.getBasePath();
                if (basePath != null) {

                    String themeName = properties.getValue("themeName");
                    Class elementClass = element.getClass();
                    String protectedPath = YiiRefsHelper.getCurrentProtected(path);
                    path = path.replace(projectPath, "");

                    String viewPathTheme = YiiRefsHelper.getRenderViewPath(path, themeName);
                    String viewPath = YiiRefsHelper.getRenderViewPath(path, null);

                    protectedPath = protectedPath.replace(projectPath, "")
                            .replaceAll("/controllers/[a-zA-Z0-9_]+?.(php|tpl)+", "");

                    Method method = elementClass.getMethod("getValueRange");
                    Object obj = method.invoke(element);
                    TextRange textRange = (TextRange) obj;
                    Class _PhpPsiElement = elementClass.getSuperclass().getSuperclass().getSuperclass();
                    Method phpPsiElementGetText = _PhpPsiElement.getMethod("getText");
                    Object obj2 = phpPsiElementGetText.invoke(element);
                    String str = obj2.toString();
                    String uri = str.substring(textRange.getStartOffset(), textRange.getEndOffset());
                    int start = textRange.getStartOffset();
                    int len = textRange.getLength();
                    String controllerName = YiiRefsHelper.getControllerClassName(path);


                    if (controllerName != null) {
                        if (baseDir != null) {
                            String inThemeFullPath = viewPathTheme + controllerName + "/" + uri
                                    + (uri.endsWith(".tpl") ? "" : ".php");
                            if (baseDir.findFileByRelativePath(inThemeFullPath) != null) {
                                viewPath = viewPathTheme;
                            }
                            VirtualFile appDir = baseDir.findFileByRelativePath(viewPath);
                            VirtualFile protectedPathDir = (!protectedPath.equals("")) ?
                                    baseDir.findFileByRelativePath(protectedPath) : null;
                            if (appDir != null) {
                                PsiReference ref = new ViewsReference(controllerName, uri, element,
                                        new TextRange(start, start + len), project, protectedPathDir, appDir);
                                return new PsiReference[]{ref};
                            }
                        }
                        return PsiReference.EMPTY_ARRAY;
                    }
                }
            }
        } catch (Exception e) {
            System.err.println("error" + e.getMessage());
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 19
Source File: ViewRenderViewReferenceProvider.java    From yiistorm with MIT License 4 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    project = element.getProject();
    String elname = element.getClass().getName();
    properties = PropertiesComponent.getInstance(project);
    if (elname.endsWith("StringLiteralExpressionImpl")) {
        try {
            PsiFile file = element.getContainingFile();
            VirtualFile vfile = file.getVirtualFile();
            if (vfile != null) {
                String path = vfile.getPath();
                VirtualFile baseDir = project.getBaseDir();
                if (baseDir == null) {
                    return PsiReference.EMPTY_ARRAY;
                }
                String basePath = baseDir.getCanonicalPath();
                if (basePath != null) {
                    String viewPath = path.replace(basePath, "")
                            .replaceAll("/[a-zA-Z0-9_]+?.(php|tpl)+", "");
                    String viewAbsolutePath = YiiRefsHelper.getViewParentPath(path
                            .replace(basePath, ""));
                    String protectedPath = YiiRefsHelper.getCurrentProtected(path);
                    protectedPath = protectedPath.replace(basePath, "");

                    String str = element.getText();
                    TextRange textRange = CommonHelper.getTextRange(element, str);
                    String uri = str.substring(textRange.getStartOffset(), textRange.getEndOffset());
                    int start = textRange.getStartOffset();
                    int len = textRange.getLength();

                    if (!uri.endsWith(".tpl") && !uri.startsWith("smarty:")) {
                        uri += ".php";
                    }

                    VirtualFile appDir = baseDir.findFileByRelativePath(viewPath);
                    VirtualFile protectedPathDir = (!protectedPath.equals(""))
                            ? baseDir.findFileByRelativePath(protectedPath) : null;

                    String filepath = viewPath + "/" + uri;
                    if (uri.matches("^//.+")) {
                        filepath = viewAbsolutePath + "/" + uri.replace("//", "");
                    }
                    VirtualFile viewfile = baseDir.findFileByRelativePath(filepath);

                    if (viewfile != null && appDir != null) {
                        PsiReference ref = new FileReference(
                                viewfile,
                                uri,
                                element,
                                new TextRange(start, start + len),
                                project,
                                protectedPathDir,
                                appDir);
                        return new PsiReference[]{ref};
                    }

                }
            }
        } catch (Exception e) {
            System.err.println("error" + e.getMessage());
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 20
Source File: GeneratedParserUtilBase.java    From Intellij-Dust with MIT License 4 votes vote down vote up
@Override
public PsiReference[] getReferences() {
    return PsiReference.EMPTY_ARRAY;
}