當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiFile類代碼示例

本文整理匯總了Java中com.intellij.psi.PsiFile的典型用法代碼示例。如果您正苦於以下問題:Java PsiFile類的具體用法?Java PsiFile怎麽用?Java PsiFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PsiFile類屬於com.intellij.psi包,在下文中一共展示了PsiFile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

import com.intellij.psi.PsiFile; //導入依賴的package包/類
@Override
public void actionPerformed(AnActionEvent event) {
    // TODO: insert action logic here
    Project project = event.getData(PlatformDataKeys.PROJECT);
    Object nav = event.getData(CommonDataKeys.NAVIGATABLE);
    String path;
    try {
        if (nav instanceof PsiDirectory) {
            PsiDirectory directory = (PsiDirectory) nav;
            path = directory.getVirtualFile().getPath();
        } else {
            PsiFile file = (PsiFile) nav;
            path = file.getVirtualFile().getPath();
        }
        Toast.make(project, MessageType.INFO, "Open: " + path);
        Runtime.getRuntime().exec("cmd /c start " + path);
    } catch (Exception e) {
        e.printStackTrace();
        if (nav instanceof PsiClass) {
            Toast.make(project, MessageType.ERROR, "Could not open the java file, double-click to open.");
            return;
        }

        Toast.make(project, MessageType.ERROR, e.getMessage());
    }
}
 
開發者ID:shenhuanet,項目名稱:OpenInExplorer-idea,代碼行數:27,代碼來源:RightAction.java

示例2: prepareRenaming

import com.intellij.psi.PsiFile; //導入依賴的package包/類
@Override
public void prepareRenaming(PsiElement psiElement, String s, Map<PsiElement, String> map) {
    renders.clear();
    for (PsiReference reference : findReferences(psiElement)) {
        final PsiElement element = reference.getElement();
        if (element instanceof StringLiteralExpression) {
            String fileName = ((StringLiteralExpression) element).getContents();
            if (fileName.contains("/")) {
                element.getParent().putUserData(RELATIVE_PATH, fileName.substring(0, fileName.lastIndexOf('/') + 1));
                fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
            }
            element.getParent().putUserData(WITH_EXT, fileName.contains("."));

            String realFile = ((PsiFile) psiElement).getName();
            if (realFile.contains(".")) {
                element.getParent().putUserData(OLD_EXT, realFile.substring(realFile.lastIndexOf('.')));
            }

            renders.add(element.getParent());
        }
    }
}
 
開發者ID:nvlad,項目名稱:yii2support,代碼行數:23,代碼來源:RenameViewProcessor.java

示例3: getRemovedGlobalFuntions

import com.intellij.psi.PsiFile; //導入依賴的package包/類
private Set<String> getRemovedGlobalFuntions(PhpPsiElement element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] constantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "FunctionCallMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : constantMatcherFiles) {

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(file, el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );
    }

    return elements.stream()
            .map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents())
            .collect(Collectors.toSet());
}
 
開發者ID:cedricziel,項目名稱:idea-php-typo3-plugin,代碼行數:26,代碼來源:FunctionCallMatcherInspection.java

示例4: getDeprecatedClassConstants

import com.intellij.psi.PsiFile; //導入依賴的package包/類
private Set<String> getDeprecatedClassConstants(PhpPsiElement element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] classConstantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : classConstantMatcherFiles) {

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(file, el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );
    }

    return elements.stream().map(stringLiteral -> ((StringLiteralExpression)stringLiteral).getContents()).collect(Collectors.toSet());
}
 
開發者ID:cedricziel,項目名稱:idea-php-typo3-plugin,代碼行數:24,代碼來源:ClassConstantMatcherInspection.java

示例5: FieldsDialog

import com.intellij.psi.PsiFile; //導入依賴的package包/類
public FieldsDialog(ConvertBridge.Operator operator, ClassEntity classEntity,
                    PsiElementFactory factory, PsiClass psiClass, PsiClass aClass, PsiFile file, Project project
        , String generateClassStr) {
    this.operator = operator;
    this.factory = factory;
    this.aClass = aClass;
    this.file = file;
    this.project = project;
    this.psiClass = psiClass;
    this.generateClassStr = generateClassStr;
    setContentPane(contentPane);
    setTitle("Virgo Model");
    getRootPane().setDefaultButton(buttonOK);
    this.setAlwaysOnTop(true);
    initListener(classEntity, generateClassStr);
}
 
開發者ID:zeng198821,項目名稱:CodeGenerate,代碼行數:17,代碼來源:FieldsDialog.java

示例6: getRelatedFiles

import com.intellij.psi.PsiFile; //導入依賴的package包/類
@Nullable
private LineMarkerInfo getRelatedFiles(@NotNull PsiFile file, @NotNull String controllerName, @NotNull PsiElement element) {
    if (!(element instanceof Method)) {
        return null;
    }
    Method method = (Method)element;
    if (!method.getAccess().isPublic()) {
        return null;
    }
    String methodName = method.getName();
    PsiDirectory appDir = PsiUtil.getAppDirectoryFromFile(file);
    String templatePath = String.format("View/%s/%s.ctp", controllerName, methodName);
    VirtualFile relativeFile = VfsUtil.findRelativeFile(appDir, templatePath);
    if (relativeFile == null) {
        return null;
    }

    PsiFile targetFile = PsiUtil.convertVirtualFileToPsiFile(method.getProject(), relativeFile);
    if (targetFile == null) {
        return null;
    }
    PsiElement targetElement = targetFile.getFirstChild();
    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(CakeIcons.LOGO).setTarget(targetElement);
    return builder.createLineMarkerInfo(method);
}
 
開發者ID:dmeybohm,項目名稱:chocolate-cakephp,代碼行數:26,代碼來源:ControllerMethodLineMarker.java

示例7: findExtensionClass

import com.intellij.psi.PsiFile; //導入依賴的package包/類
private PsiClass findExtensionClass( PsiElement element )
{
  PsiFile containingFile = element.getContainingFile();
  if( !(containingFile instanceof PsiJavaFileImpl) )
  {
    return null;
  }

  PsiJavaFileImpl file = (PsiJavaFileImpl)containingFile;
  for( PsiClass psiClass : file.getClasses() )
  {
    if( psiClass.getModifierList().findAnnotation( Extension.class.getName() ) != null )
    {
      return psiClass;
    }
  }

  return null;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:20,代碼來源:ExtensionClassAnnotator.java

示例8: ignoreUnresolvedReference

import com.intellij.psi.PsiFile; //導入依賴的package包/類
@Override
public boolean ignoreUnresolvedReference(@NotNull PyElement element, @NotNull PsiReference reference) {
  final PsiFile file = element.getContainingFile();
  final Project project = file.getProject();

  if (StudyTaskManager.getInstance(project).getCourse() == null) {
    return false;
  }
  TaskFile taskFile = StudyUtils.getTaskFile(project, file.getVirtualFile());
  if (taskFile == null || taskFile.isUserCreated() || taskFile.isHighlightErrors()) {
    return false;
  }
  if (PsiTreeUtil.getParentOfType(element, PyImportStatementBase.class) != null) {
    return false;
  }
  return true;
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:18,代碼來源:PyStudyInspectionExtension.java

示例9: execute

import com.intellij.psi.PsiFile; //導入依賴的package包/類
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
  myOriginalHandler.execute(editor, charTyped, dataContext);
  if (isMatchForClosingTag(editor, charTyped)) {
    int offset = editor.getCaretModel().getOffset();
    PsiFile file = dataContext.getData(LangDataKeys.PSI_FILE);
    if (file == null) {
      return;
    }
    PsiElement el = file.findElementAt(offset - 1);
    TagBlockElement block = (TagBlockElement) PsiTreeUtil
        .findFirstParent(el,
            parent -> parent instanceof TagBlockElement && !(parent instanceof SoyChoiceClause));
    if (block == null) {
      return;
    }
    String closingTag = block.getOpeningTag().generateClosingTag();
    insertClosingTag(editor, offset, closingTag);
    if (editor.getProject() != null) {
      PsiDocumentManager.getInstance(editor.getProject()).commitDocument(editor.getDocument());
      CodeStyleManager.getInstance(editor.getProject()).reformat(block);
    }
  }
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:24,代碼來源:ClosingTagHandler.java

示例10: getDeprecatedClasses

import com.intellij.psi.PsiFile; //導入依賴的package包/類
private Set<String> getDeprecatedClasses(PhpPsiElement element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] classNameMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassNameMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : classNameMatcherFiles) {

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(file, el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );
    }

    return elements.stream()
            .map(stringLiteral -> "\\" + ((StringLiteralExpression)stringLiteral).getContents())
            .collect(Collectors.toSet());
}
 
開發者ID:cedricziel,項目名稱:idea-php-typo3-plugin,代碼行數:26,代碼來源:ClassNameMatcherInspection.java

示例11: showHint

import com.intellij.psi.PsiFile; //導入依賴的package包/類
public void showHint(Project project) {
  Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course == null) {
    return;
  }
  StudyState studyState = new StudyState(StudyUtils.getSelectedStudyEditor(project));
  if (!studyState.isValid()) {
    return;
  }
  PsiFile file = PsiManager.getInstance(project).findFile(studyState.getVirtualFile());
  final Editor editor = studyState.getEditor();
  int offset = editor.getCaretModel().getOffset();
  AnswerPlaceholder answerPlaceholder = studyState.getTaskFile().getAnswerPlaceholder(offset);
  if (file == null) {
    return;
  }
  EduUsagesCollector.hintShown();

  final StudyToolWindow hintComponent = getHint(project, answerPlaceholder).getStudyToolWindow();
  hintComponent.setPreferredSize(new Dimension(400, 150));
  showHintPopUp(project, studyState, editor, hintComponent);
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:23,代碼來源:StudyShowHintAction.java

示例12: computeChildren

import com.intellij.psi.PsiFile; //導入依賴的package包/類
@Override
protected MultiMap<PsiFile, T> computeChildren(@Nullable PsiFile psiFile) {
    MultiMap<PsiFile, T> children = new MultiMap<>();
    Project project = getProject();
    if (project != null) {
        JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
        PsiClass serviceAnnotation = javaPsiFacade.findClass(getAnnotationQName(), GlobalSearchScope.allScope(project));
        if (serviceAnnotation != null) {
            AnnotatedElementsSearch.searchPsiClasses(serviceAnnotation, GlobalSearchScope.allScope(project)).forEach(psiClass -> {
                if (psiClass.isInterface() && isSatisfying(psiClass)) {
                    children.putValue(psiClass.getContainingFile(), createChild(psiClass));
                }
                return true;
            });
        }
    }
    return children;
}
 
開發者ID:seedstack,項目名稱:intellij-plugin,代碼行數:19,代碼來源:AnnotatedInterfaceNode.java

示例13: doParseAllInPackageTest

import com.intellij.psi.PsiFile; //導入依賴的package包/類
protected void doParseAllInPackageTest() {
  LOG.info("Parsing files in the package: " + getMyTargetDirectoryPath());
  System.out.println("Parsing files in the package: " + getMyTargetDirectoryPath());
  for (PsiFile psiFile : myPsiFiles) {
    LOG.info("File: " + psiFile.getName());
    System.out.print("File: " + psiFile.getName());
    try {
      ParsingTestCase.doCheckResult(myTargetTestDataDir, psiFile, checkAllPsiRoots(),
              psiFile.getVirtualFile().getNameWithoutExtension(), skipSpaces(), printRanges());
      System.out.println(": Ok");
    } catch (IOException e) {
      System.out.println(": Parsing failed" + psiFile.getName());
      e.printStackTrace();
    }
  }
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:17,代碼來源:AbstractParsingFixtureTestCase.java

示例14: handleEnterInComment

import com.intellij.psi.PsiFile; //導入依賴的package包/類
private static void handleEnterInComment(
    PsiElement element, @NotNull PsiFile file, @NotNull Editor editor) {
  if (element.getText().startsWith("/*")) {
    Document document = editor.getDocument();

    int caretOffset = editor.getCaretModel().getOffset();
    int lineNumber = document.getLineNumber(caretOffset);

    String lineTextBeforeCaret =
        document.getText(new TextRange(document.getLineStartOffset(lineNumber), caretOffset));
    String lineTextAfterCaret =
        document.getText(new TextRange(caretOffset, document.getLineEndOffset(lineNumber)));

    if (lineTextAfterCaret.equals("*/")) {
      return;
    }

    String toInsert = lineTextBeforeCaret.equals("") ? " * " : "* ";
    insertText(file, editor, toInsert, toInsert.length());
  }
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:22,代碼來源:EnterHandler.java

示例15: getGotoDeclarationTargets

import com.intellij.psi.PsiFile; //導入依賴的package包/類
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
    if (psiElement == null) {
        return PsiElement.EMPTY_ARRAY;
    }
    Project project = psiElement.getProject();
    if (!PlatformPatterns
            .psiElement(StringLiteralExpression.class)
            .withLanguage(PhpLanguage.INSTANCE)
            .accepts(psiElement.getContext())
    ) {
        return PsiElement.EMPTY_ARRAY;
    }
    PsiFile containingFile = psiElement.getContainingFile();
    PsiDirectory appDir = PsiUtil.getAppDirectoryFromFile(containingFile);
    String elementFilename = String.format("View/Elements/%s.ctp", psiElement.getText());
    VirtualFile relativeFile = VfsUtil.findRelativeFile(appDir, elementFilename);
    if (relativeFile != null) {
        Collection<VirtualFile> files = new HashSet<>();
        files.add(relativeFile);
        return PsiUtil.convertVirtualFilesToPsiFiles(project, files).toArray(new PsiElement[files.size()]);
    }
    return PsiElement.EMPTY_ARRAY;
}
 
開發者ID:dmeybohm,項目名稱:chocolate-cakephp,代碼行數:26,代碼來源:ElementGotoDeclarationHandler.java


注:本文中的com.intellij.psi.PsiFile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。