Package com.intellij.psi

Examples of com.intellij.psi.PsiFile


  @Override
  public Object getCurrentEditorElement() {
    if (myEditor == null) return null;
    final int offset = myEditor.getCaretModel().getOffset();
    final PsiFile file = getPsiFile();
    final PsiElement element = file.getViewProvider().findElementAt(offset, file.getLanguage());
    final PsiElement parent = element != null ? element.getParent() : null;
    if (parent instanceof Symbol) {
      return parent;
    }
    return null;
View Full Code Here


  protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    final Symbol callingSymbol = (Symbol) parameters.getPosition().getParent();
    final String callingSymbolName = callingSymbol.getSymbolName();

    if (!parameters.isExtendedCompletion()) {
      final PsiFile containingFile = parameters.getOriginalFile();
      List<Symbol> variants = Lists.newArrayList();

      GlobalDefinitionCompletionProvider visitor = new GlobalDefinitionCompletionProvider();
      containingFile.accept(visitor);
      for (String name : visitor.getFunctionsNames()) {
        if (!NAMES.contains(name)) {
          result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(name), GLOBAL_VARIABLE_PRIORITY));
        }
      }
View Full Code Here

    final PsiFileFactory factory = PsiFileFactory.getInstance(project);
    final StringBuilder stringBuilder = new StringBuilder("f[");
    stringBuilder.append(e.getText());
    stringBuilder.append("]");

    final PsiFile file = factory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, stringBuilder);
    final FunctionCall[] func = PsiTreeUtil.getChildrenOfType(file, FunctionCall.class);
    assert func != null && func[0] != null;
    PsiElement newElement = e.replace(func[0]);
    final PsiElement head = newElement.getFirstChild();
    return head == null ? null : head.getTextRange();
View Full Code Here

    final PsiFileFactory factory = PsiFileFactory.getInstance(project);
    final StringBuilder stringBuilder = new StringBuilder(myHead + "[{},\n");
    stringBuilder.append(e.getText());
    stringBuilder.append("\n]");

    final PsiFile file = factory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, stringBuilder);
    final FunctionCall[] func = PsiTreeUtil.getChildrenOfType(file, FunctionCall.class);
    assert func != null && func[0] != null;
    func[0] = (FunctionCall) codeStyleManager.reformat(func[0]);
    PsiElement newElement = e.replace(func[0]);
View Full Code Here

    final PsiFileFactory factory = PsiFileFactory.getInstance(project);
    final StringBuilder stringBuilder = new StringBuilder("(");
    stringBuilder.append(e.getText());
    stringBuilder.append(")&");

    final PsiFile file = factory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, stringBuilder);
    final Function[] func = PsiTreeUtil.getChildrenOfType(file, Function.class);
    assert func != null && func[0] != null;
    e.replace(func[0]);
    return null;
  }
View Full Code Here

  private void doFormatterActionTest(final FormatRunnableFactory formatAction,
                                     final String beforeText,
                                     String textAfter,
                                     LanguageFileType templateDataLanguageType) {
    PsiFile baseFile = createFile("A.hbs", beforeText);

    VirtualFile virtualFile = baseFile.getVirtualFile();
    assert virtualFile != null;
    TemplateDataLanguageMappings.getInstance(getProject()).setMapping(virtualFile, templateDataLanguageType.getLanguage());

    // fetch a fresh instance of the file -- the template data mapping creates a new instance,
    // which was causing problems in PsiFileImpl.isValid()
    final PsiFile file = PsiManager.getInstance(getProject()).findFile(virtualFile);
    assert file != null;

    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(formatAction.createFormatRunnable(file));
      }
    }, "", "");

    TemplateDataLanguageMappings.getInstance(getProject()).cleanupForNextTest();

    assertEquals("Reformat Code failed", prepareText(textAfter), prepareText(file.getText()));
    assertEquals("Reformat Code failed", prepareText(textAfter), prepareText(file.getText()));
  }
View Full Code Here

    } else {
      VirtualFile virtualFile =
          usage instanceof UsageInFile ? ((UsageInFile) usage).getFile() : null;
      if (virtualFile != null) {
        Project project = myUsageView.getProject();
        PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
        if (psiFile != null && psiFile.isValid()) {
          final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile);
          if (color != null) fileBgColor = color;
        }
      }
    }
View Full Code Here

        try {
            root = doCreateModel(element);
        } catch (Exception ex) {
            LOG.error(ex);
        }
        PsiFile file = element.getContainingFile();
        if (root == null) {
            root = new FakeBlock(file.getTextRange());
        }
        return new DocumentBasedFormattingModel(root, file.getProject(), settings, file.getFileType(), file);
    }
View Full Code Here

        }
        return new DocumentBasedFormattingModel(root, file.getProject(), settings, file.getFileType(), file);
    }

    private static Block doCreateModel(PsiElement element) throws IOException, InterruptedException, NoMatchException {
        final PsiFile file = element.getContainingFile();
        VirtualFile virtualFile = file.getVirtualFile();
        if (virtualFile == null)
            return null;
        Module module = DeclarationPosition.getDeclModule(file);
        CompilerLocation compiler = CompilerLocation.get(module);
        if (compiler == null)
            return null;
        List<String> args = compiler.getCompileOptionsList(
            "-m", "ParseTree",
            virtualFile.getPath()
        );
        ProcessLauncher launcher = new ProcessLauncher(false, virtualFile.getInputStream(), args);
        String stdOut = launcher.getStdOut();
        if (stdOut.trim().isEmpty())
            return null;
        RangeFactory factory = new RangeFactory() {

            public IRange parse(String str) {
                LineColRange range = new LineColRange(str);
                return new MyRange(range.getRange(file));
            }

            public IRange create(ILocation start, ILocation end) {
                MyLocation from = (MyLocation) start;
                MyLocation to = (MyLocation) end;
                return MyLocation.create(from, to);
            }
        };
        TreeParser parser = new TreeParser(new BufferedReader(new StringReader(stdOut)), factory);
        ModuleTree moduleTree = parser.readTree(new MyRange(file.getTextRange()));

        SortedMap<ILocation, Filler> ranges = new TreeMap<ILocation, Filler>();
        String text = file.getText();
        HaskellLexer lexer = new HaskellLexer();
        lexer.start(text);
        while (true) {
            IElementType type = lexer.getTokenType();
            if (type == null)
View Full Code Here

        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();
            if (virtualFile == null)
                return false;
            if (!hasMain(virtualFile, context.getModule()))
                return false;
            runFile = hsFile;
            Project project = file.getProject();
            configuration.setMainFile(runFile);
            VirtualFile baseDir = project.getBaseDir();
            if (baseDir != null) {
                configuration.setWorkingDirectory(baseDir.getPath());
            }
View Full Code Here

TOP

Related Classes of com.intellij.psi.PsiFile

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.