當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。