下面列出了com.intellij.psi.util.PsiTreeUtil#getChildOfType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Object invoke(Method method, Object[] args) throws IllegalAccessException {
Class<?> returnType = method.getReturnType();
if (returnType.isEnum()) {
PsiAnnotation currentAnnotation =
AnnotationUtil.findAnnotationInHierarchy(
mListOwner, Collections.singleton(mAnnotationClass.getCanonicalName()));
PsiReferenceExpression declaredValue =
(PsiReferenceExpression) currentAnnotation.findAttributeValue(method.getName());
if (declaredValue == null) {
return method.getDefaultValue();
}
PsiIdentifier identifier = PsiTreeUtil.getChildOfType(declaredValue, PsiIdentifier.class);
return Enum.valueOf((Class<Enum>) returnType, identifier.getText());
}
try {
if (args == null) {
return method.invoke(mStubbed);
}
return method.invoke(mStubbed, args);
} catch (InvocationTargetException e) {
return method.getDefaultValue();
}
}
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
DotNetType element = myPointer.getElement();
if(element == null)
{
return;
}
CSharpFragmentFileImpl typeFragment = CSharpFragmentFactory.createTypeFragment(project, myTypeText, element);
DotNetType newType = PsiTreeUtil.getChildOfType(typeFragment, DotNetType.class);
if(newType == null)
{
return;
}
element.replace(newType);
}
@NotNull
@Override
public PsiType getType() {
PsiType psiType = null;
final HaxeTypeTag tag = PsiTreeUtil.getChildOfType(this, HaxeTypeTag.class);
if (tag != null) {
final HaxeTypeOrAnonymous toa = tag.getTypeOrAnonymous();
final HaxeType type = (toa != null) ? toa.getType() : null;
psiType = (type != null) ? type.getPsiType() : null;
}
return psiType != null ? psiType : HaxePsiTypeAdapter.DYNAMIC;
}
default PsiElement argumentsToken() {
if (this instanceof CypherFunctionInvocation) {
return PsiTreeUtil.getChildOfType(this, CypherArgumentList.class);
}
if (this instanceof CypherProcedureInvocation) {
return PsiTreeUtil.getChildOfType(this, CypherArgumentList.class);
} else {
return this;
}
}
@Override
public List<ThriftDeclaration> findSubDeclarations() {
ThriftDeclarationBody body = PsiTreeUtil.getChildOfType(this, ThriftDeclarationBody.class);
if (body == null) {
return Collections.emptyList();
}
return PsiTreeUtil.getChildrenOfTypeAsList(body, ThriftDeclaration.class);
}
@Nullable
private static PsiElement findTestSuiteReference(PsiElement element) {
if (element instanceof JSVarStatement) {
// variable assignment might be
// testSuite = goog.require('goog.testing.testSuite')
JSVariable variable = PsiTreeUtil.getChildOfType(element, JSVariable.class);
if (variable != null && isImportingTestSuite(variable)) {
return variable;
}
} else if (element instanceof JSExpressionStatement) {
// expression statement might be
// goog.require('goog.testing.testSuite')
if (isImportingTestSuite(element)) {
JSLiteralExpression literal =
PsiTreeUtil.findChildOfType(element, JSLiteralExpression.class);
// this should be 'goog.testing.testSuite'
if (literal == null) {
return null;
}
for (PsiReference reference : literal.getReferences()) {
if (reference instanceof JSGclModuleReference) {
// this should be testSuite, and should resolve to the function
return reference.resolve();
}
}
}
}
return null;
}
@NotNull
public SQFCodeBlock getBlock() {
SQFCodeBlock block = PsiTreeUtil.getChildOfType(this, SQFCodeBlock.class);
if (block == null) {
throw new IllegalStateException("the block returned shouldn't be null");
}
return block;
}
/**
* fo<caret>o:
* class: foo
* arguments: []
*/
@Nullable
public static ServiceYamlContainer create(@NotNull YAMLKeyValue yamlServiceKeyValue) {
YAMLMapping childOfType = PsiTreeUtil.getChildOfType(yamlServiceKeyValue, YAMLMapping.class);
if(childOfType == null) {
return null;
}
String serviceClass = null;
YAMLKeyValue aClass = childOfType.getKeyValueByKey("class");
if(aClass != null) {
// service:
// class: Foobar
YAMLValue value = aClass.getValue();
if(value instanceof YAMLScalar) {
serviceClass = ((YAMLScalar) value).getTextValue();
}
} else {
// Foobar:
// argument: ~
String keyText = yamlServiceKeyValue.getKeyText();
if(StringUtils.isNotBlank(keyText) && YamlHelper.isClassServiceId(keyText)) {
serviceClass = keyText;
}
}
if (StringUtils.isBlank(serviceClass)) {
return null;
}
return new ServiceYamlContainer(yamlServiceKeyValue, childOfType.getKeyValueByKey("arguments"), serviceClass);
}
@Override
@Nullable
public HaskellConsym getConsym() {
return PsiTreeUtil.getChildOfType(this, HaskellConsym.class);
}
@Nullable
public static HaxePackageStatement createPackageStatementFromPath(Project myProject, String path) {
final PsiFile dummyFile = createDummyFile(myProject, "package " + path + ";");
return PsiTreeUtil.getChildOfType(dummyFile, HaxePackageStatement.class);
}
@Override
@Nullable
public HaskellBkind getBkind() {
return PsiTreeUtil.getChildOfType(this, HaskellBkind.class);
}
@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
if (DumbService.getInstance(psiElement.getProject()).isDumb() || !TYPO3CMSProjectSettings.isEnabled(psiElement)) {
return null;
}
// $GLOBALS['TYPO3_DB']
if (!(psiElement instanceof ArrayAccessExpression)) {
return null;
}
VariableImpl variable = PsiTreeUtil.getChildOfType(psiElement, VariableImpl.class);
if (variable == null || !variable.getName().equals("GLOBALS")) {
return null;
}
ArrayIndex arrayIndex = PsiTreeUtil.getChildOfType(psiElement, ArrayIndex.class);
if (arrayIndex == null) {
return null;
}
StringLiteralExpression arrayIndexName = PsiTreeUtil.getChildOfType(arrayIndex, StringLiteralExpressionImpl.class);
if (arrayIndexName == null) {
return null;
}
switch (arrayIndexName.getContents()) {
case "TYPO3_DB":
return new PhpType().add("#C\\TYPO3\\CMS\\Core\\Database\\DatabaseConnection");
case "TSFE":
return new PhpType().add("#C\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController");
case "BE_USER":
return new PhpType().add("#C\\TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication");
case "LANG":
return new PhpType().add("#C\\TYPO3\\CMS\\Lang\\LanguageService");
case "TYPO3_REQUEST":
return new PhpType().add("#C\\Psr\\Http\\Message\\ServerRequestInterface");
default:
return null;
}
}
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;
}
@Override
@Nullable
public HaskellVarop getVarop() {
return PsiTreeUtil.getChildOfType(this, HaskellVarop.class);
}
@Override
@Nullable
public HaskellGconsym getGconsym() {
return PsiTreeUtil.getChildOfType(this, HaskellGconsym.class);
}
/**
* Retrieve the (first) catch statement that belongs to the given element.
*/
public static HaxeCatchStatement getCatchStatement(PsiElement elem) {
return PsiTreeUtil.getChildOfType(elem, HaxeCatchStatement.class);
}
@Override
@Nullable
public HaskellQtyconsym getQtyconsym() {
return PsiTreeUtil.getChildOfType(this, HaskellQtyconsym.class);
}
@Override
@Nullable
public HaskellQtyconop getQtyconop() {
return PsiTreeUtil.getChildOfType(this, HaskellQtyconop.class);
}
@Override
@Nullable
public HaskellConop getConop() {
return PsiTreeUtil.getChildOfType(this, HaskellConop.class);
}
@Override
@Nullable
public HaskellVars getVars() {
return PsiTreeUtil.getChildOfType(this, HaskellVars.class);
}