public static boolean functionDefinitelyRecurses( @NotNull JSFunction method) { final JSSourceElement[] body = method.getBody(); if (body != null) { for (final JSSourceElement element : body) { if (element instanceof JSStatement && RecursionUtil.statementDefinitelyRecurses((JSStatement) element, method)) { return true; } else if (element instanceof JSExpression && RecursionUtil.expressionDefinitelyRecurses((JSExpression) element, method)) { return true; } } } return false; }
public static boolean containsTestsInFiles(JSFile file) { JSSourceElement[] statements = file.getStatements(); for(JSSourceElement statement : statements) { if(statement instanceof JSExpressionStatement) { JSExpression expression = ((JSExpressionStatement) statement).getExpression(); if(expression instanceof JSCallExpression) { JSExpression methodExpression = ((JSCallExpression) expression).getMethodExpression(); if(methodExpression instanceof JSReferenceExpression) { JSExpression qualifier = ((JSReferenceExpression) methodExpression).getQualifier(); if(qualifier != null) { continue; } String referencedName = ((JSReferenceExpression) methodExpression).getReferencedName(); if("describe".equals(referencedName)) { JSArgumentList argumentList = ((JSCallExpression) expression).getArgumentList(); if(argumentList != null && argumentList.getArguments().length == 2) { return true; } } } } } } return false; }
@Override public JSSourceElement[] getStatements() { final StubElement stub = getStub(); if(stub != null) { return (JSSourceElement[]) stub.getChildrenByType(JSElementTypes.SOURCE_ELEMENTS, JSSourceElement.EMPTY_ARRAY); } return findChildrenByClass(JSSourceElement.class); }
@Override public JSSourceElement[] getBody() { final ASTNode[] children = getNode().getChildren(JSElementTypes.SOURCE_ELEMENTS); if(children.length == 0) { return JSSourceElement.EMPTY_ARRAY; } JSSourceElement[] result = new JSSourceElement[children.length]; for(int i = 0; i < children.length; i++) { result[i] = (JSSourceElement) children[i].getPsi(); } return result; }
@RequiredReadAction @Nullable @Override public PsiElement transform(@NotNull PsiElement psiElement) { if(psiElement instanceof UnityScriptDotNetTypeDeclaration) { CSharpLightTypeDeclarationBuilder builder = new CSharpLightTypeDeclarationBuilder(psiElement) { @NotNull @Override public Language getLanguage() { return JavaScriptLanguage.INSTANCE; } }; PsiElement navigationElement = psiElement.getNavigationElement(); builder.withName(((UnityScriptDotNetTypeDeclaration) psiElement).getName()); builder.setNavigationElement(navigationElement); builder.addModifier(DotNetModifier.PUBLIC); builder.putUserData(JS_MARKER, Boolean.TRUE); builder.addExtendType(new CSharpTypeRefByQName(psiElement, Unity3dTypes.UnityEngine.MonoBehaviour)); if(navigationElement instanceof JSFile) { for(JSSourceElement jsSourceElement : ((JSFile) navigationElement).getStatements()) { if(jsSourceElement instanceof JSFunction) { String funcName = jsSourceElement.getName(); if(funcName == null) { continue; } CSharpLightMethodDeclarationBuilder methodDeclarationBuilder = new CSharpLightMethodDeclarationBuilder(psiElement.getProject()); methodDeclarationBuilder.addModifier(DotNetModifier.PUBLIC); methodDeclarationBuilder.withReturnType(new CSharpTypeRefByQName(psiElement, DotNetTypes.System.Void)); methodDeclarationBuilder.withName(funcName); methodDeclarationBuilder.setNavigationElement(jsSourceElement); builder.addMember(methodDeclarationBuilder); } } } return builder; } return null; }
@Override public JSSourceElement[] getStatements() { return getStubOrPsiChildren(JSElementTypes.SOURCE_ELEMENTS, JSSourceElement.EMPTY_ARRAY); }