当前位置: 首页>>代码示例>>Java>>正文


Java PsiElement.getContainingFile方法代码示例

本文整理汇总了Java中com.intellij.psi.PsiElement.getContainingFile方法的典型用法代码示例。如果您正苦于以下问题:Java PsiElement.getContainingFile方法的具体用法?Java PsiElement.getContainingFile怎么用?Java PsiElement.getContainingFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.PsiElement的用法示例。


在下文中一共展示了PsiElement.getContainingFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAvailable

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    if (!element.isWritable()) return false;
    boolean isTwigFile = GravFileTemplateUtil.isTwigTemplateFile(element.getContainingFile()) || element.getContainingFile() instanceof HtmlFileImpl;
    boolean isXmlAttribute = false;
    if (!isTwigFile) return false;
    if (element.getParent() instanceof XmlAttributeValueImpl) {
        XmlAttributeValueImpl parent0 = ((XmlAttributeValueImpl) element.getParent());
        boolean hasTwigElement = PsiTreeUtil.findChildOfType(parent0, OuterLanguageElement.class) != null;
        if (!hasTwigElement && parent0.getParent() instanceof XmlAttributeImpl) {
            XmlAttributeImpl parent1 = (XmlAttributeImpl) parent0.getParent();
            if (parent1.getName().equalsIgnoreCase("href") || parent1.getName().equalsIgnoreCase("src"))
                isXmlAttribute = true;
        }
    }
    return isXmlAttribute;
}
 
开发者ID:PioBeat,项目名称:GravSupport,代码行数:18,代码来源:ConvertTwigResource.java

示例2: findDirectory

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Nullable
private static PsiDirectory findDirectory(PsiElement element) {
    final PhpClass phpClass = PsiTreeUtil.getParentOfType(element, PhpClass.class);
    final PsiFile file = element.getContainingFile();
    if (phpClass != null) {
        return findClassDirectory(phpClass, file);
    }

    PsiDirectory context = file.getOriginalFile().getContainingDirectory();
    if (context != null) {
        PsiDirectory root = context.getParentDirectory();
        while (root != null && !root.getName().equals("views")) {
            root = root.getParentDirectory();
        }

        file.putUserData(VIEWS_CONTEXT_DIRECTORY, context);
        file.putUserData(VIEWS_DIRECTORY, root);
        file.putUserData(VIEWS_DIRECTORY_MODIFIED, file.getModificationStamp());

        return root;
    }

    return null;
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:25,代码来源:ViewsUtil.java

示例3: setupConfigurationFromContext

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
protected boolean setupConfigurationFromContext(AppleScriptRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
  PsiElement elem = context.getPsiLocation();
  PsiFile file = elem != null ? elem.getContainingFile() : null;
  if (file == null) return false;
  boolean shouldSetUp = file.getFileType() == AppleScriptFileType.INSTANCE;
  VirtualFile vFile = file.getVirtualFile();
  String scriptPath = vFile != null ? file.getVirtualFile().getPath() : null;
  if (scriptPath != null) {
    configuration.setScriptPath(scriptPath);
    String[] parts = scriptPath.split("/");
    if (parts.length > 0) {
      configuration.setName(parts[parts.length - 1]);
    }
  }
  return shouldSetUp;
}
 
开发者ID:ant-druha,项目名称:AppleScript-IDEA,代码行数:18,代码来源:AppleScriptConfigurationProducer.java

示例4: findTemplateDeclarations

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
/** Finds the matching SoyTemplateBlock by their exact name. */
public static List<SoyTemplateBlock> findTemplateDeclarations(
    PsiElement element, String identifier) {
  if (identifier.startsWith(".")) {
    identifier = ((SoyFile) element.getContainingFile()).getNamespace() + identifier;
  } else {
    AliasMapper mapper = new AliasMapper(element.getContainingFile());
    identifier = mapper.normalizeIdentifier(identifier);
  }

  Project project = element.getProject();
  return TemplateBlockIndex.INSTANCE
      .get(identifier, project, GlobalSearchScope.allScope(project))
      .stream()
      .filter((block) -> block.getDefinitionIdentifier() != null)
      .collect(Collectors.toList());
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:18,代码来源:TemplateNameUtils.java

示例5: findLocalTemplateNames

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
/** Finds all local template names in the given file. */
public static List<String> findLocalTemplateNames(PsiElement element) {
  PsiFile file = element.getContainingFile();
  return TemplateBlockIndex.INSTANCE
      .getAllKeys(file.getProject())
      .stream()
      .flatMap(
          (key) ->
              TemplateBlockIndex.INSTANCE
                  .get(
                      key, file.getProject(), GlobalSearchScope.fileScope(file.getOriginalFile()))
                  .stream()
                  .filter((block) -> !block.isDelegate())
                  .map(SoyTemplateBlock::getName))
      .collect(Collectors.toList());
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:17,代码来源:TemplateNameUtils.java

示例6: getLocalInspectionsAtCaret

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
private Pair<List<ProblemDescriptor>, Integer> getLocalInspectionsAtCaret(String filename, String content) {

        PsiElement psiFile = myFixture.configureByText(filename, content);

        int caretOffset = myFixture.getCaretOffset();
        if(caretOffset <= 0) {
            fail("Please provide <caret> tag");
        }

        ProblemsHolder problemsHolder = new ProblemsHolder(InspectionManager.getInstance(getProject()), psiFile.getContainingFile(), false);

        for (LocalInspectionEP localInspectionEP : LocalInspectionEP.LOCAL_INSPECTION.getExtensions()) {
            Object object = localInspectionEP.getInstance();
            if(!(object instanceof LocalInspectionTool)) {
                continue;
            }

            ((LocalInspectionTool) object).buildVisitor(problemsHolder, false);
        }

        return new Pair<List<ProblemDescriptor>, Integer>(problemsHolder.getResults(), caretOffset);
    }
 
开发者ID:adelf,项目名称:idea-php-dotenv-plugin,代码行数:23,代码来源:DotEnvLightCodeInsightFixtureTestCase.java

示例7: collectSlowLineMarkers

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> list, @NotNull Collection<LineMarkerInfo> collection) {
    for (PsiElement element : list) {
        PsiFile file = element.getContainingFile();
        if (file == null) {
            continue;
        }
        VirtualFile virtualFile  = file.getVirtualFile();
        if (virtualFile == null) {
            continue;
        }
        String controllerName = CakeUtil.controllerBaseNameFromControllerFileName(virtualFile.getNameWithoutExtension());
        if (controllerName == null) {
            continue;
        }
        LineMarkerInfo info = getRelatedFiles(file, controllerName, element);
        addLineMarkerUnique(collection, info);
        PsiElement[] children = element.getChildren();
        for (PsiElement child : children) {
            info = getRelatedFiles(file, controllerName, child);
            addLineMarkerUnique(collection, info);
        }
    }
}
 
开发者ID:dmeybohm,项目名称:chocolate-cakephp,代码行数:25,代码来源:ControllerMethodLineMarker.java

示例8: getGotoDeclarationTargets

import com.intellij.psi.PsiElement; //导入方法依赖的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

示例9: findExtensionClass

import com.intellij.psi.PsiElement; //导入方法依赖的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

示例10: getGotoDeclarationTarget

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Nullable
@Override
public PsiElement getGotoDeclarationTarget(final PsiElement sourceElement, final Editor editor) {
    if (!(sourceElement instanceof LeafPsiElement)
        || !(((LeafPsiElement) sourceElement)
                 .getElementType().equals(ImpexTypes.MACRO_USAGE))) {
        return null;
    }

    final PsiFile originalFile = sourceElement.getContainingFile();

    final Collection<ImpexMacroDeclaration> macroDeclarations =
        PsiTreeUtil.findChildrenOfType(
            originalFile,
            ImpexMacroDeclaration.class
        );

    if (!macroDeclarations.isEmpty()) {
        for (final ImpexMacroDeclaration declaration : macroDeclarations) {
            if (sourceElement.textMatches(declaration.getFirstChild())) {
                return declaration.getFirstChild();
            }
        }
    }
    return null;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:ImpexMacrosGoToDeclarationHandler.java

示例11: getAnswerPlaceholder

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Nullable
private static AnswerPlaceholder getAnswerPlaceholder(PsiElement e, int offset) {
  PsiFile file = e.getContainingFile();
  if (file == null) {
    return null;
  }
  VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) {
    return null;
  }
  TaskFile taskFile = StudyUtils.getTaskFile(e.getProject(), virtualFile);
  if (taskFile == null) {
    return null;
  }
  Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
  if (document == null) {
    return null;
  }
  Editor editor = FileEditorManager.getInstance(e.getProject()).getSelectedTextEditor();
  return editor == null ? null : taskFile.getAnswerPlaceholder(offset);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:22,代码来源:StudyAnswerPlaceholderExtendWordHandler.java

示例12: getContextDirectory

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
public static PsiDirectory getContextDirectory(PsiElement element) {
    final PsiFile file = element.getContainingFile();

    if (file.getUserData(VIEWS_CONTEXT_DIRECTORY) != null) {
        Long modified = file.getUserData(VIEWS_DIRECTORY_MODIFIED);
        if (modified != null && modified == file.getModificationStamp()) {
            return file.getUserData(VIEWS_CONTEXT_DIRECTORY);
        }
    }

    findDirectory(element);

    return file.getUserData(VIEWS_CONTEXT_DIRECTORY);
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:15,代码来源:ViewsUtil.java

示例13: isConfigurationFromContext

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
public boolean isConfigurationFromContext(AppleScriptRunConfiguration configuration, ConfigurationContext context) {
  PsiElement elem = context.getPsiLocation();
  PsiFile file = elem != null ? elem.getContainingFile() : null;
  if (file == null) return false;
  VirtualFile currentFile = file.getVirtualFile();

  boolean isSameFile = false;
  if (currentFile != null) {
    isSameFile = currentFile.getPath().equals(configuration.getScriptPath());
  }
  return isSameFile;
}
 
开发者ID:ant-druha,项目名称:AppleScript-IDEA,代码行数:14,代码来源:AppleScriptConfigurationProducer.java

示例14: createModel

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
  final PsiFile file = element.getContainingFile();

  if (element.getNode().getElementType() == SoyTypes.OTHER) {
    return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
  } else {
    return new DocumentBasedFormattingModel(
        getRootBlock(file, file.getViewProvider(), settings),
        element.getProject(),
        settings,
        file.getFileType(),
        file);
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:16,代码来源:SoyFormattingModelBuilder.java

示例15: getPossibleNextIdentifierFragments

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
/**
 * Finds all fully qualified template names starting with a given prefix with respect to aliases
 * and template visibility.
 */
public static Collection<Fragment> getPossibleNextIdentifierFragments(
    Project project, PsiElement identifierElement, String identifier, boolean isDelegate) {
  AliasMapper mapper = new AliasMapper(identifierElement.getContainingFile());
  GlobalSearchScope scope =
      isDelegate
          ? GlobalSearchScope.allScope(project)
          : GlobalSearchScope.allScope(project)
              .intersectWith(
                  GlobalSearchScope.notScope(
                      GlobalSearchScope.fileScope(
                          identifierElement.getContainingFile().getOriginalFile())));

  return TemplateBlockIndex.INSTANCE
      .getAllKeys(project)
      .stream()

      // Filter out private templates, assuming those end with "_".
      .filter((key) -> !key.endsWith("_"))

      // Filter out deltemplates or normal templates based on `isDelegate`.
      // Also checks template's lang.
      .filter(
          (key) ->
              TemplateBlockIndex.INSTANCE
                  .get(key, project, scope)
                  .stream()
                  .anyMatch((block) -> block.isDelegate() == isDelegate))

      // Project matches into denormalized key space.
      .flatMap(mapper::denormalizeIdentifier)

      // Find the denormalized keys that match the identifier.
      .filter((key) -> key.startsWith(identifier))

      // Collect next fragments.
      .map((key) -> getNextFragment(key, identifier))
      .collect(Collectors.toList());
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:43,代码来源:TemplateNameUtils.java


注:本文中的com.intellij.psi.PsiElement.getContainingFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。