Java Code Examples for com.intellij.psi.util.PsiTreeUtil#getChildOfAnyType()

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#getChildOfAnyType() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: NutzCodeInsight   File: SqlsXmlUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static PsiElement getXmlIdBindPsiElement(PsiMethodCallExpression psiMethodCallExpression, List<String> keys, String id) {
    for (String key : keys) {
        String text = psiMethodCallExpression.getText();
        if (text.startsWith(key)
                || text.startsWith("super." + key)
                || text.startsWith("this." + key)) {
            PsiExpressionList psiExpressionList = PsiTreeUtil.getChildOfAnyType(psiMethodCallExpression, PsiExpressionList.class);
            if (Objects.nonNull(psiExpressionList)) {
                List<PsiLiteralExpression> psiLiteralExpressions = PsiTreeUtil.getChildrenOfAnyType(psiExpressionList, PsiLiteralExpression.class);
                for (PsiLiteralExpression psiLiteralExpression : psiLiteralExpressions) {
                    if (!psiLiteralExpression.getText().contains(" ") && id.equals(((PsiLiteralExpressionImpl) psiLiteralExpression).getInnerText())) {
                        return psiLiteralExpression;
                    }
                }
            }
        }
    }
    return null;
}
 
Example 2
private Signature getChildElementSignature(PsiElement element) {

        element = PsiTreeUtil.getChildOfAnyType(element, Variable.class, FieldReference.class, ArrayAccessExpression.class);
        if (element == null) {
            return null;
        }

        Signature signature = new Signature();

        if (element instanceof PhpReference) {
            signature.set(((PhpReference) element).getSignature());
        }
        else if (element instanceof ArrayAccessExpression) {
            signature.set(getTypeForArrayAccess(element));
        }

        return signature.hasValidClassSignature() ? signature : null;
    }
 
Example 3
Source Project: intellij-haxe   File: HaxeResolveUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static List<HaxeFieldDeclaration> getClassVarDeclarations(HaxeClass haxeClass) {
  PsiElement body = null;
  final HaxeComponentType type = HaxeComponentType.typeOf(haxeClass);
  if (type == HaxeComponentType.CLASS) {
    body = PsiTreeUtil.getChildOfAnyType(haxeClass, HaxeClassBody.class, HaxeExternClassDeclarationBody.class);
  }

  final List<HaxeFieldDeclaration> result = new ArrayList<>();

  if (body == null) {
    return result;
  }

  final HaxeFieldDeclaration[] variables = PsiTreeUtil.getChildrenOfType(body, HaxeFieldDeclaration.class);

  if (variables == null) {
    return result;
  }
  Collections.addAll(result, variables);
  return result;
}
 
Example 4
Source Project: silex-idea-plugin   File: Utils.java    License: MIT License 5 votes vote down vote up
public static Container findContainerForMethodReference(MethodReference methodReference) {
    Signature signature = new Signature();

    PsiElement signatureElement = PsiTreeUtil.getChildOfAnyType(methodReference, Variable.class, FieldReference.class, ArrayAccessExpression.class);
    if (signatureElement == null) {
        return null;
    }

    PhpIndex phpIndex = PhpIndex.getInstance(methodReference.getProject());

    Container container;

    if (signatureElement instanceof Variable || signatureElement instanceof FieldReference) {
        signature.set(((PhpReference) signatureElement).getSignature());

        ArrayList<String> parameters = new ArrayList<String>();
        if (!Utils.findPimpleContainer(phpIndex, signature.base, parameters)) {
            return null;
        }

        container = ContainerResolver.get(methodReference.getProject());

        // find proper base container from signature
        for (String parameter : parameters) {
            container = container.getContainers().get(getResolvedParameter(phpIndex, parameter));
            if (container == null)
                return null;
        }

        return container;
    }

    if (signatureElement instanceof ArrayAccessExpression) {
        return findContainerForPimpleArrayAccess((ArrayAccessExpression) signatureElement, false);
    }

    return null;
}
 
Example 5
Source Project: intellij-haxe   File: HaxeClassModel.java    License: Apache License 2.0 5 votes vote down vote up
public List<HaxeFieldModel> getFields() {
  HaxePsiCompositeElement body = PsiTreeUtil.getChildOfAnyType(haxeClass, isEnum() ? HaxeEnumBody.class : HaxeClassBody.class);

  if (body != null) {
    return PsiTreeUtil.getChildrenOfAnyType(body, HaxeFieldDeclaration.class, HaxeAnonymousTypeField.class, HaxeEnumValueDeclaration.class)
      .stream()
      .map(HaxeFieldModel::new)
      .collect(Collectors.toList());
  } else {
    return Collections.emptyList();
  }
}
 
Example 6
Source Project: intellij-haxe   File: HaxeSymbolIndex.java    License: Apache License 2.0 5 votes vote down vote up
@NotNull
private static List<HaxeNamedComponent> getNamedComponents(@Nullable final HaxeClass cls) {
  final PsiElement body = PsiTreeUtil.getChildOfAnyType(cls, BODY_TYPES);
  final List<HaxeNamedComponent> components = new ArrayList<HaxeNamedComponent>();
  if (body != null) {
    final Collection<HaxeNamedComponent> members = PsiTreeUtil.findChildrenOfAnyType(body, MEMBER_TYPES);
    for (HaxeNamedComponent member : members) {
      if (member instanceof HaxeMethod && ((HaxeMethod)member).isConstructor()) {
        continue;
      }
      components.add(member);
    }
  }
  return components;
}
 
Example 7
Source Project: silex-idea-plugin   File: Utils.java    License: MIT License 4 votes vote down vote up
private static Container findContainerForPimpleArrayAccess(ArrayAccessExpression arrayAccessElement, Boolean onlyParentContainers) {

        PsiElement children;
        PsiElement element = arrayAccessElement;
        while ((children = PsiTreeUtil.getChildOfType(element, ArrayAccessExpression.class)) != null) {
            element = children;
        }

        // check if var is pimple container
        Signature signature = new Signature();

        PsiElement signatureElement = PsiTreeUtil.getChildOfAnyType(element, Variable.class, FieldReference.class);
        if (signatureElement == null) {
            return null;
        }

        if (signatureElement instanceof Variable) {
            signature.set(((Variable) signatureElement).getSignature());
        }

        if (signatureElement instanceof FieldReference) {
            signature.set(((FieldReference) signatureElement).getSignature());
        }

        PhpIndex phpIndex = PhpIndex.getInstance(arrayAccessElement.getProject());

        ArrayList<String> parameters = new ArrayList<String>();
        if (!findPimpleContainer(phpIndex, signature.base, parameters)) {
            return null;
        }

        Container container = ContainerResolver.get(arrayAccessElement.getProject());

        // find proper base container from signature
        for (String parameter : parameters) {
            container = container.getContainers().get(getResolvedParameter(phpIndex, parameter));
            if (container == null)
                return null;
        }

        PsiElement lastElement = onlyParentContainers ? arrayAccessElement : arrayAccessElement.getParent();

        // find proper container
        while (!element.isEquivalentTo(lastElement) ) {

            ArrayIndex arrayIndex = ((ArrayAccessExpression)element).getIndex();
            if (arrayIndex == null) {
                return null;
            }

            PsiElement arrayIndexElement = arrayIndex.getValue();
            if (arrayIndexElement == null) {
                return null;
            }

            String containerName;

            if (arrayIndexElement instanceof StringLiteralExpression) {
                containerName = ((StringLiteralExpression) arrayIndexElement).getContents();
            }
            else if (arrayIndexElement instanceof MemberReference) {
                containerName = getResolvedParameter(phpIndex, ((MemberReference) arrayIndexElement).getSignature());
            }
            else return null;

            container = container.getContainers().get(containerName);
            if (container == null) {
                return null;
            }

            element = element.getParent();
        }

        return container;

    }
 
Example 8
@Nullable
public PsiElement getInnerElement()
{
	return PsiTreeUtil.getChildOfAnyType(this, DotNetExpression.class, DotNetStatement.class);
}