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


Java PsiTreeUtil.getParentOfType方法代码示例

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


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

示例1: expectDomAttributeValue

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public static <T extends DomElement, V> GenericAttributeValue<V> expectDomAttributeValue(
    @NotNull final PsiElement element,
    @NotNull final Class<? extends T> domTagClass,
    @NotNull final Function<T, GenericAttributeValue<V>> domGetter
) {
    final DomManager domManager = DomManager.getDomManager(element.getProject());

    if (!(element instanceof XmlElement)) {
        return null;
    }

    final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    if (xmlAttribute == null) {
        return null;
    }

    final XmlTag xmlParentTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
    DomElement domParentTag = domManager.getDomElement(xmlParentTag);

    return Optional.ofNullable(domParentTag)
                   .map(o -> ObjectUtils.tryCast(o, domTagClass))
                   .map(domGetter)
                   .filter(val -> val == domManager.getDomElement(xmlAttribute))
                   .orElse(null);
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:26,代码来源:BeansUtils.java

示例2: invokeAutoPopup

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
    MethodReference reference = PsiTreeUtil.getParentOfType(position, MethodReference.class);
    if (reference != null && reference.getName() != null && reference.getName().equals("t") && reference.getClassReference() instanceof ClassReference) {
        ClassReference classReference = (ClassReference) reference.getClassReference();
        if (classReference == null || classReference.getName() == null || !classReference.getName().equals("Yii")) {
            return false;
        }
        if (typeChar == '\'' || typeChar == '"') {
            if (position instanceof LeafPsiElement && (position.getText().equals("$category") || position.getText().equals("$message"))) {
                return true;
            }
            if (position.getNextSibling() instanceof ParameterList) {
                return true;
            }
        }
    }

    return false;
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:21,代码来源:CompletionContributor.java

示例3: resolve

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Nullable
@Override
public PsiElement resolve() {
    PsiElement parent = PsiTreeUtil.getParentOfType(myElement, PsiLet.class);

    // If name is used in a let definition, it's already the reference
    if (parent instanceof PsiLet && ((PsiLet) parent).getNameIdentifier() == myElement) {
        return myElement;
    }

    // Find the name in the index
    Collection<PsiLet> elements = StubIndex.getElements(IndexKeys.LETS, m_referenceName, myElement.getProject(), GlobalSearchScope.allScope(myElement.getProject()), PsiLet.class);
    if (!elements.isEmpty()) {
        // TODO: only let with correct QN
        PsiLet let = elements.iterator().next();
        return let.getNameIdentifier();
    }

    return null;
}
 
开发者ID:reasonml-editor,项目名称:reasonml-idea-plugin,代码行数:21,代码来源:PsiVarNameReference.java

示例4: annotate

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {

    if (!(psiElement instanceof StringLiteralExpression)) {
        return;
    }

    StringLiteralExpression literalExpression = (StringLiteralExpression) psiElement;
    String value = literalExpression.getContents();

    if (value.isEmpty()) {
        return;
    }

    PsiElement methodReference = PsiTreeUtil.getParentOfType(psiElement, MethodReference.class);
    if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getIcon")) {
        annotateIconUsage(psiElement, annotationHolder, value);
    }
}
 
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:20,代码来源:IconAnnotator.java

示例5: firstStageMainSketchIdentification

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public static Collection<PsiFile> firstStageMainSketchIdentification(@NotNull Collection<PsiFile> parsedPdeFiles) {
    Set<PsiFile> shortlist = new HashSet<>();

    for (PsiFile parsedPdeFile : parsedPdeFiles) {
        PsiErrorElement firstErrorInFile = PsiTreeUtil.findChildOfType(parsedPdeFile, PsiErrorElement.class);

        if (firstErrorInFile == null) {
            continue;
        }

        PsiClass errorContainingClass = PsiTreeUtil.getParentOfType(firstErrorInFile, PsiClass.class);

        if (errorContainingClass == null) {
            shortlist.add(parsedPdeFile);
        }
    }

    return shortlist;
}
 
开发者ID:mistodev,项目名称:processing-idea,代码行数:20,代码来源:MigrationActions.java

示例6: findByLineAndColumn

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Nullable
private static PsiElement findByLineAndColumn(
    @NotNull final PsiElement file,
    @Nullable final Point columnAndLine
) {
    if (columnAndLine == null) {
        return file;
    }
    final int line = columnAndLine.y - 1;
    final int column = columnAndLine.x - 1;

    PsiElement leaf = findByLineAndColumn(file, line, column);

    if (leaf instanceof PsiWhiteSpace) {
        leaf = PsiTreeUtil.prevVisibleLeaf(leaf);
    }

    final PsiElement tag = leaf instanceof XmlTag ? leaf : PsiTreeUtil.getParentOfType(leaf, XmlTag.class);
    return tag == null ? leaf : tag;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:ValidateContextImpl.java

示例7: getClassName

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public static String getClassName(@NotNull PsiElement element) {
    ParameterList parameterList = PsiTreeUtil.getParentOfType(element, ParameterList.class);
    if (parameterList == null) {
        return null;
    }

    MethodReference methodReference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
    if (methodReference == null) {
        return null;
    }

    Variable variableBeingCalledOn = PsiTreeUtil.findChildOfType(methodReference, Variable.class);
    if (variableBeingCalledOn != null && variableBeingCalledOn.getInferredType() != null) {
        PhpType inferredType = variableBeingCalledOn.getInferredType();
        return inferredType.toString();
    }

    ClassReference classReference = PsiTreeUtil.getChildOfType(methodReference, ClassReference.class);

    return extractFqnFromClassReference(methodReference, classReference);
}
 
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:22,代码来源:PhpLangUtil.java

示例8: getElementInfo

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@NotNull
@Override
public String getElementInfo(@NotNull PsiElement psi) {
    ImpexFullHeaderParameter headerParameter = getLinkedHeaderParameter(psi);
    if (headerParameter != null) {
        return headerParameter.getText();
    }

    //ImpexHeaderLine headerLine = PsiTreeUtil.getParentOfType(element, ImpexHeaderLine.class, false);
    //assert headerLine != null;

    psi = adjustWhiteSpaceAndSeparator(psi);

    headerParameter = PsiTreeUtil.getParentOfType(psi, ImpexFullHeaderParameter.class, false);
    if (headerParameter != null) {
        return headerParameter.getText();
    }

    ImpexAnyHeaderMode mode = PsiTreeUtil.getParentOfType(psi, ImpexAnyHeaderMode.class, false);
    if (mode != null) {
        return mode.getText();
    }

    ImpexFullHeaderType type = PsiTreeUtil.getParentOfType(psi, ImpexFullHeaderType.class, false);
    if (type != null) {
        return type.getHeaderTypeName().getText();
    }

    return "<error> : " + psi.getNode().getElementType() + ": " + psi.getText();
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:31,代码来源:ImpexColumnBreadcrumbsProvider.java

示例9: addCompletions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public void addCompletions(
    @NotNull final CompletionParameters parameters,
    final ProcessingContext context,
    @NotNull final CompletionResultSet result
) {
    Validate.notNull(parameters);
    Validate.notNull(result);

    final PsiElement psiElementUnderCaret = parameters.getPosition();

    final ImpexAttribute impexAttribute = PsiTreeUtil.getParentOfType(
        psiElementUnderCaret, ImpexAttribute.class
    );

    if (impexAttribute == null) {
        return;
    }

    final String modifierName = impexAttribute.getAnyAttributeName().getText();
    final ImpexModifier impexModifier = AttributeModifier.getByModifierName(modifierName);

    if (null != impexModifier) {

        for (String possibleValue : impexModifier.getModifierValues()) {
            result.addElement(LookupElementBuilder.create(possibleValue));
        }

    } else {
        // show error message when not defined within hybris API
        Notifications.Bus.notify(new Notification(
            ImpexLanguage.getInstance().getDisplayName(),
            "possible error in your impex",
            "You typed an unknown hybris-ATTRIBUTE-modifier with name '" + modifierName + "'.",
            NotificationType.WARNING
        ));
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:39,代码来源:ImpexHeaderAttributeModifierValueCompletionProvider.java

示例10: shouldSkipAutopopup

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset)
{
    // Wrong file.
    if (!CompletionPreloader.isRocConfigFile(psiFile))
    {
        return ThreeState.UNSURE;
    }

    JSProperty property = PsiTreeUtil.getParentOfType(contextElement, JSProperty.class);
    // Wrong place in file.
    if (property == null)
    {
        return ThreeState.UNSURE;
    }

    Setting setting = CompletionPreloader
        .getCompletions()
        .getSetting(property.getQualifiedName());

    // Not a roc-setting.
    if (setting == null)
    {
        return ThreeState.UNSURE;
    }

    return setting.getSubCompletionVariants().size() > 1 ? ThreeState.NO : ThreeState.UNSURE;
}
 
开发者ID:whitefire,项目名称:roc-completion,代码行数:30,代码来源:SubCompletionConfidence.java

示例11: getPsiClassFromContext

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
private PsiClass getPsiClassFromContext(AnActionEvent e) {
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);

    if (psiFile == null || editor == null) {
        return null;
    }

    int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);
    
    return PsiTreeUtil.getParentOfType(element, PsiClass.class);
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:14,代码来源:DataMediatorAction.java

示例12: addCompletions

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public void addCompletions(
    @NotNull final CompletionParameters parameters,
    final ProcessingContext context,
    @NotNull final CompletionResultSet result
) {
    Validate.notNull(parameters);
    Validate.notNull(result);

    final PsiElement psiElementUnderCaret = parameters.getPosition();

    final ImpexAttribute impexAttribute = PsiTreeUtil.getParentOfType(
        psiElementUnderCaret, ImpexAttribute.class
    );

    if (impexAttribute == null) {
        return;
    }

    final String modifierName = impexAttribute.getAnyAttributeName().getText();

    final ImpexModifier impexModifier = TypeModifier.getByModifierName(modifierName);

    if (null != impexModifier) {

        for (String possibleValue : impexModifier.getModifierValues()) {
            result.addElement(LookupElementBuilder.create(possibleValue));
        }

    } else {
        // show error message when not defined within hybris API
        Notifications.Bus.notify(new Notification(
            ImpexLanguage.getInstance().getDisplayName(),
            "possible error in your impex",
            "You typed an unknown hybris-TYPE-modifier with name '" + modifierName + "'.",
            NotificationType.WARNING
        ));
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:40,代码来源:ImpexHeaderTypeModifierValueCompletionProvider.java

示例13: resolve

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Nullable
@Override
public PsiElement resolve() {
    // From the definition of a module
    PsiType parent = PsiTreeUtil.getParentOfType(myElement, PsiType.class);
    if (parent != null && parent.getNameIdentifier() == myElement) {
        return myElement;
    }

    return null;
}
 
开发者ID:reasonml-editor,项目名称:reasonml-idea-plugin,代码行数:12,代码来源:PsiTypeReference.java

示例14: collectNavigationMarkers

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {

    if (!(element instanceof StringLiteralExpression)) {
        return;
    }

    StringLiteralExpression literalExpression = (StringLiteralExpression) element;
    String value = literalExpression.getContents();

    if (value.isEmpty()) {
        return;
    }

    PsiElement methodReference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
    if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getAjaxUrl") || PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "buildUriFromRoute")) {

        if (RouteIndex.hasRoute(element.getProject(), value)) {
            Collection<RouteStub> routes = RouteIndex.getRoute(element.getProject(), value);
            routes.forEach(def -> {
                PsiElement[] routeDefinitionElements = RouteHelper.getRouteDefinitionElements(element.getProject(), value);
                NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder
                        .create(TYPO3CMSIcons.ROUTE_ICON)
                        .setTargets(routeDefinitionElements);

                if (def.getPath() != null) {
                    builder.setTooltipTitle("Path: " + def.getPath());
                }

                result.add(builder.createLineMarkerInfo(element));
            });

        }
    }
}
 
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:36,代码来源:RouteLineMarkerProvider.java

示例15: getParamAtPosition

import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Nullable
private static Parameter getParamAtPosition(@NotNull StringLiteralExpression element, @NotNull Integer position) {
    ParameterList parameterList = PsiTreeUtil.getParentOfType(element, ParameterList.class);
    if (parameterList == null) {
        return null;
    }

    MethodReference methodReference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
    if (methodReference == null) {
        return null;
    }

    String methodName = methodReference.getName();
    ClassReference classReference = PsiTreeUtil.getChildOfType(methodReference, ClassReference.class);

    // may be null if the call is chained
    String name = extractFqnFromClassReference(methodReference, classReference);

    if (name == null || methodName == null) {
        return null;
    }

    // there can be multiple classes in one project scope that share the same FQN
    Collection<PhpClass> phpClasses = PhpIndex.getInstance(element.getProject()).getClassesByFQN(name);
    for (PhpClass c : phpClasses) {
        Method method = c.findMethodByName(methodName);

        ParameterList originalMethodParameterList = PsiTreeUtil.getChildOfType(method, ParameterList.class);
        if (originalMethodParameterList != null) {
            List<Parameter> parameters = PsiTreeUtil.getChildrenOfTypeAsList(originalMethodParameterList, Parameter.class);
            if (parameters.size() > 0 && parameters.get(position) != null) {

                return parameters.get(position);
            }
        }
    }

    return null;
}
 
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:40,代码来源:PhpLangUtil.java


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