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


Java PsiElement.getProject方法代码示例

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


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

示例1: 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

示例2: 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

示例3: resolve

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
public Stream<LookupElementBuilder> resolve(String path, PsiElement position) {
    Project project = position.getProject();
    Stream<String> keys;
    if (path.isEmpty()) {
        keys = CoffigResolver.from(project)
                .onlyAtTopLevel()
                .classes()
                .map(CoffigResolver.Match::getName);
    } else {
        keys = CoffigResolver.from(project)
                .find(path)
                .filter(CoffigResolver.Match::isFullyResolved)
                .map(CoffigResolver.Match::allProperties)
                .orElse(Stream.empty());
    }
    return keys.map(key -> key.split("\\.")[0]).map(LookupElementBuilder::create);
}
 
开发者ID:seedstack,项目名称:intellij-plugin,代码行数:19,代码来源:KeyCompletionProvider.java

示例4: 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

示例5: 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();
    VirtualFile virtualFile = containingFile.getVirtualFile();
    String filename = virtualFile.getNameWithoutExtension();
    String controllerName = CakeUtil.controllerBaseNameFromControllerFileName(filename);
    if (controllerName == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    PsiDirectory appDir = PsiUtil.getAppDirectoryFromFile(containingFile);
    String templatePath = String.format("View/%s/%s.ctp", controllerName, psiElement.getText());
    VirtualFile relativeFile = VfsUtil.findRelativeFile(appDir, templatePath);
    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,代码行数:33,代码来源:TemplateGotoDeclarationHandler.java

示例6: resolveConfigInfo

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
private Optional<ConfigInfo> resolveConfigInfo(PsiElement psiElement) {
    if (isConfigFile(psiElement)) {
        String path = resolvePath(psiElement);
        if (!path.isEmpty()) {
            Project project = psiElement.getProject();
            return CoffigResolver.from(project)
                    .onlyAtTopLevel()
                    .find(path, 0)
                    .flatMap(match -> findResourceBundle(project, match.getConfigClass()).flatMap(propertiesFile -> extractConfigInfo(propertiesFile, match)));
        }
    }
    return Optional.empty();
}
 
开发者ID:seedstack,项目名称:intellij-plugin,代码行数:14,代码来源:CoffigDocumentationProvider.java

示例7: resolve

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
public Stream<LookupElementBuilder> resolve(String joined, PsiElement position) {
    Project project = position.getProject();
    return CoffigResolver.from(project)
            .find(joined)
            .flatMap(match -> match.resolveField(match.getUnmatchedPath())
                    .map(PsiVariable::getType)
                    .map(psiType -> buildStream(match.getUnmatchedPath(), position, psiType)))
            .orElse(Stream.empty());
}
 
开发者ID:seedstack,项目名称:intellij-plugin,代码行数:11,代码来源:ValueCompletionProvider.java

示例8: addCompletions

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
protected void addCompletions(@NotNull final CompletionParameters completionParameters,
    final ProcessingContext processingContext, @NotNull final CompletionResultSet resultSet) {

  PsiElement element = completionParameters.getPosition();
  if (element instanceof PsiComment) {
    return;
  }

  Project project = element.getProject();
  Module module = ModuleUtil.findModuleForPsiElement(element);

  SuggestionIndexService service =
      ServiceManager.getService(project, SuggestionIndexService.class);

  if ((module == null || !service.canProvideSuggestions(project, module)) && !service
      .canProvideSuggestions(project)) {
    return;
  }

  YAMLKeyValue keyValue = getParentOfType(element, YAMLKeyValue.class);

  List<LookupElementBuilder> suggestions;
  // For top level element, since there is no parent keyValue would be null
  String queryString = truncateIdeaDummyIdentifier(element);

  if (keyValue == null) {
    if (module == null) {
      suggestions = service
          .computeSuggestions(project, element.getClass().getClassLoader(), null, queryString);
    } else {
      suggestions = service
          .computeSuggestions(project, module, element.getClass().getClassLoader(), null,
              queryString);
    }
  } else {
    List<String> containerElements = new ArrayList<>();
    do {
      containerElements.add(0, truncateIdeaDummyIdentifier(keyValue.getKeyText()));
      keyValue = getParentOfType(keyValue, YAMLKeyValue.class);
    } while (keyValue != null);

    if (module == null) {
      suggestions = service
          .computeSuggestions(project, element.getClass().getClassLoader(), containerElements,
              queryString);
    } else {
      suggestions = service
          .computeSuggestions(project, module, element.getClass().getClassLoader(),
              containerElements, queryString);
    }
  }

  if (suggestions != null) {
    suggestions.forEach(resultSet::addElement);
  }
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:58,代码来源:YamlCompletionProvider.java

示例9: annotate

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
public void annotate(
    @NotNull final PsiElement psiElement, @NotNull final AnnotationHolder annotationHolder
) {
    if (psiElement instanceof XmlTag && isTypeSystemXmlFile(psiElement.getContainingFile())) {
        final Project project = psiElement.getProject();
        final DomElement dom = DomManager.getDomManager(project).getDomElement((XmlTag) psiElement);

        if (dom instanceof ItemType) {
            final ItemType itemType = (ItemType) dom;
            if (itemType.getCode().getXmlAttributeValue() == null) {
                return;
            }

            final Collection<? extends PsiElement> alternativeDoms = findAlternativeDoms(itemType);
            if (!alternativeDoms.isEmpty()) {
                NavigationGutterIconBuilder
                    .create(AllIcons.Actions.Nextfile, TypeSystemGutterAnnotator::findAlternativeDoms)
                    .setTarget(itemType)
                    .setTooltipText(alternativeDoms.size() > 1
                                        ? "Alternative Definitions"
                                        : "Alternative Definition")
                    .setAlignment(GutterIconRenderer.Alignment.RIGHT)
                    .install(annotationHolder, itemType.getCode().getXmlAttributeValue());
            }

            final Optional<TSMetaClass> firstExtender = findFirstExtendingMetaClass(itemType);
            if (firstExtender.isPresent()) {
                NavigationGutterIconBuilder
                    .create(
                        AllIcons.Gutter.OverridenMethod,
                        TypeSystemGutterAnnotator::findAllExtendingXmlAttributes
                    )
                    .setTarget(itemType)
                    .setAlignment(GutterIconRenderer.Alignment.LEFT)
                    .setTooltipText("Has subtypes")
                    .install(annotationHolder, itemType.getCode().getXmlAttributeValue());
            }
        }
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:42,代码来源:TypeSystemGutterAnnotator.java


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