Package com.intellij.psi

Examples of com.intellij.psi.PsiElement


    return count;
  }

  private static int getUsageOffset(@NotNull Usage usage) {
    if (!(usage instanceof UsageInfo2UsageAdapter)) return -1;
    PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement();
    if (element == null) return -1;
    return element.getTextRange().getStartOffset();
  }
View Full Code Here


    @Override @Nullable
    protected PsiElement getPsiElementForHint(Object selectedValue) {
      if (selectedValue instanceof UsageNode) {
        final Usage usage = ((UsageNode) selectedValue).getUsage();
        if (usage instanceof UsageInfo2UsageAdapter) {
          final PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement();
          if (element != null) {
            final PsiElement view = UsageToPsiElementProvider.findAppropriateParentFrom(element);
            return view == null ? element : view;
          }
        }
      }
      return null;
View Full Code Here

  }

  @Nullable
  public static Color getColorForObject(Object object, Project project, @NotNull NullableFunction<Object, PsiElement> converter) {
    Color color = null;
    final PsiElement psi = converter.fun(object);
    if (psi != null) {
      if (!psi.isValid()) return null;

      final VirtualFile file = PsiUtilCore.getVirtualFile(psi);

      if (file != null) {
        color = FileColorManager.getInstance(project).getFileColor(file);
View Full Code Here

    // Check whether there is a completion item which is currently active and give a Symbol element
    // containing the lookup name back.
    final LookupEx activeLookup = LookupManager.getActiveLookup(editor);
    if ((activeLookup != null) && activeLookup.isFocused()) {
      final PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset() - 1);
      if (elementAt != null) {
        Symbol lookup = new SymbolImpl(elementAt.getNode());
        final LookupElement currentItem = activeLookup.getCurrentItem();
        final String lookupString = currentItem != null ? currentItem.getLookupString() : "";
        lookup.setName(lookupString);
        return lookup;
      }
    }

    if (contextElement != null) {
      PsiElement parent = contextElement.getParent();

      if ((contextElement instanceof PsiWhiteSpace) || !((parent instanceof Symbol) || (parent instanceof OperatorNameProvider))) {
        PsiElement elm = file.findElementAt(editor.getCaretModel().getOffset() - 1);
        if (elm != null) {
          contextElement = elm;
          parent = elm.getParent();
        }
      }

      if (parent instanceof Symbol) {
        return new SymbolImpl(parent.getNode());
View Full Code Here

    public PsiElement getSourceElement() {
        return runFile;
    }

    protected boolean setupConfigurationFromContext(HaskellRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
        PsiElement psiElement = sourceElement.get();
        PsiFile file = psiElement.getContainingFile();
        if (!(file instanceof HaskellFile))
            return false;
        HaskellFile hsFile = (HaskellFile) file;
        try {
            VirtualFile virtualFile = file.getVirtualFile();
View Full Code Here

        }
        return text;
    }

    private static IElementType findLiteralTokenType(PsiFile file, int selectionStart, int selectionEnd) {
        PsiElement elementAtSelection = file.findElementAt(selectionStart);
        if (elementAtSelection == null)
            return null;
        IElementType tokenType = elementAtSelection.getNode().getElementType();
        if (tokenType != HaskellTokenTypes.STRING)
            return null;
        TextRange textRange = elementAtSelection.getTextRange();
        if (selectionStart <= textRange.getStartOffset() || selectionEnd >= textRange.getEndOffset()) {
            return null;
        }
        return tokenType;
    }
View Full Code Here

    private static final String DUMMY = "DUMMY.";

    @Nullable
    public ASTNode createIdentNodeFromText(@NotNull String newName) {
        HaskellFile dummyFile = createHaskellFileFromText(newName);
        PsiElement firstChild = dummyFile.getFirstChild();
        if (firstChild != null)
            return firstChild.getNode();
        return null;
    }
View Full Code Here

        super(true);
    }

    @Override
    public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
        PsiElement element = queryParameters.getElementToSearch();
        if (!(element instanceof HPAbstractIdent))
            return;
        PsiFile file = element.getContainingFile();
        try {
            DeclarationPosition declaration = DeclarationPosition.get(file, LineCol.fromOffset(file, element.getTextOffset()));
            if (declaration == null)
                return;
            LineCol coord = declaration.coord;
            VirtualFile virtualFile = file.getVirtualFile();
            Project project = file.getProject();
            ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
            if (virtualFile == null)
                return;
            Module module = fileIndex.getModuleForFile(virtualFile);
            CompilerLocation compiler = CompilerLocation.get(module);
            if (compiler == null)
                return;
            List<String> args = compiler.getCompileOptionsList(
                "-m", "FindUsages",
                "-s", GHCUtil.rootsAsString(module, false),
                "--line-number", String.valueOf(coord.line), "--column-number", String.valueOf(coord.column),
                "-f", virtualFile.getPath()
            );
            final List<String> srcFiles = new ArrayList<String>();
            fileIndex.iterateContent(new ContentIterator() {
                public boolean processFile(VirtualFile virtualFile) {
                    if (HaskellCompiler.isCompilableFile(virtualFile)) {
                        srcFiles.add(virtualFile.getPath());
                    }
                    return true;
                }
            });
            args.addAll(srcFiles);
            ProcessLauncher launcher = new ProcessLauncher(true, null, args);
            BufferedReader bf = new BufferedReader(new StringReader(launcher.getStdOut()));
            while (true) {
                String srcLineCol = bf.readLine();
                if (srcLineCol == null)
                    break;
                LineCol refLineCol = LineCol.parse(srcLineCol);
                String srcModule = bf.readLine();
                if (srcModule != null) {
                    PsiElement elementAt = HPIdentImpl.getElementAt(project, new DeclarationPosition(refLineCol, srcModule));
                    PsiReference reference = elementAt.getReference();
                    consumer.process(reference);
                }
            }
        } catch (Exception e) {
            LOG.error(e);
View Full Code Here

            return null;
        PsiFile declarationModulePsiFile = PsiManager.getInstance(project).findFile(declarationModuleVirtualFile);
        if (declarationModulePsiFile == null)
            return null;
        int declarationStart = declaration.coord.getOffset(declarationModulePsiFile);
        PsiElement elementAt = declarationModulePsiFile.findElementAt(declarationStart);
        if (elementAt == null)
            return null;
        ASTNode parentNode = elementAt.getParent().getNode();
        if (parentNode.getElementType() == HaskellElementTypes.INFIX_PREFIX_IDENT) {
            return new HPInfixPrefixIdentImpl(parentNode);
        }
        return new HPIdentImpl(elementAt.getNode());
    }
View Full Code Here

                EMPTY_ARRAY :
                elements.toArray(new StructureViewTreeElement[elements.size()]);
    }

    private List<PSQLStructureViewElement> getChildren(PsiElement parent, List<PSQLStructureViewElement> elements) {
        PsiElement child = parent.getFirstChild();
        while (child != null) {
            if (child instanceof BasePsiElement) {
                BasePsiElement basePsiElement = (BasePsiElement) child;
                if (basePsiElement.getElementType().is(ElementTypeAttribute.STRUCTURE)) {
                    if (elements == null) {
                        elements = new ArrayList<PSQLStructureViewElement>();
                    }
                    elements.add(new PSQLStructureViewElement(child));
                } else {
                    elements = getChildren(basePsiElement, elements);
                }
            }
            child = child.getNextSibling();
        }
        return elements;
    }
View Full Code Here

TOP

Related Classes of com.intellij.psi.PsiElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.