com.intellij.psi.PsiDeclarationStatement Java Examples

The following examples show how to use com.intellij.psi.PsiDeclarationStatement. 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 File: RequiredPropAnnotator.java    From litho with Apache License 2.0 6 votes vote down vote up
/**
 * If element is a {@link PsiStatement} with {@code Component.create()} call, finds missing
 * required props for it.
 *
 * @param element element to verify
 * @param errorHandler handles a list of missing required props and reference to the {@code
 *     Component.create()} call in the statement
 * @param generatedClassResolver returns generated Litho class, or null if the provided method
 *     doesn't belong to any
 */
static void annotate(
    PsiElement element,
    BiConsumer<Collection<String>, PsiReferenceExpression> errorHandler,
    Function<PsiMethodCallExpression, PsiClass> generatedClassResolver) {
  if (element instanceof PsiDeclarationStatement) {
    Arrays.stream(((PsiDeclarationStatement) element).getDeclaredElements())
        .filter(PsiVariable.class::isInstance)
        .map(declaredVariable -> ((PsiVariable) declaredVariable).getInitializer())
        .forEach(
            expression -> handleIfMethodCall(expression, errorHandler, generatedClassResolver));
  } else if (element instanceof PsiExpressionStatement) {
    handleIfMethodCall(
        ((PsiExpressionStatement) element).getExpression(), errorHandler, generatedClassResolver);
  } else if (element instanceof PsiReturnStatement) {
    handleIfMethodCall(
        ((PsiReturnStatement) element).getReturnValue(), errorHandler, generatedClassResolver);
  }
}
 
Example #2
Source File: PsiJavaElementVisitor.java    From KodeBeagle with Apache License 2.0 6 votes vote down vote up
@Override
public final void visitElement(final PsiElement element) {
    super.visitElement(element);
    if (startOffset <= element.getTextOffset() && element.getTextOffset() <= endOffset) {
        if (element.getNode().getElementType().equals(JavaElementType.FIELD)) {
            visitPsiFields((PsiField) element);
        } else if (element.getNode().getElementType().
                equals(JavaElementType.DECLARATION_STATEMENT)) {
            visitPsiDeclarationStatement((PsiDeclarationStatement) element);
        } else if (element.getNode().getElementType().equals(JavaElementType.CATCH_SECTION)) {
            visitPsiCatchSection((PsiCatchSection) element);
        } else if (element.getNode().getElementType().
                equals(JavaElementType.RETURN_STATEMENT)) {
            visitPsiReturnStatement((PsiReturnStatement) element);
        } else {
            visitExpression(element);
        }
    }
}
 
Example #3
Source File: DeclarationStatementTranslator.java    From java2typescript with Apache License 2.0 6 votes vote down vote up
public static void translate(PsiDeclarationStatement stmt, TranslationContext ctx) {
    for (int i = 0; i < stmt.getDeclaredElements().length; i++) {

        if(i > 0) {
            ctx.append(", ");
        }

        PsiElement element1 = stmt.getDeclaredElements()[i];
        if (element1 instanceof PsiStatement) {
            StatementTranslator.translate((PsiStatement) element1, ctx);
        } else if (element1 instanceof PsiLocalVariable) {
            LocalVariableTranslator.translate((PsiLocalVariable) element1, ctx);
        } else {
            System.err.println("Not managed " + element1);
        }
    }
}
 
Example #4
Source File: InstanceOfVariableDeclarationStatement.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
public boolean instanceOf(PsiStatement statement) {
    if (statement instanceof PsiDeclarationStatement) {
        PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) statement;
        PsiElement[] declaredElements = declarationStatement.getDeclaredElements();
        for (PsiElement element : declaredElements) {
            if (element instanceof PsiVariable) {
                return true;
            }
        }
    }
    return false;
}
 
Example #5
Source File: PsiJavaElementVisitor.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
private void visitPsiDeclarationStatement(final PsiDeclarationStatement
                                                  declarationStatement) {
    Collection<PsiTypeElement> typeElements =
            PsiTreeUtil.findChildrenOfType(declarationStatement, PsiTypeElement.class);
    for (PsiTypeElement element : typeElements) {
        String type = removeSpecialSymbols(element.getType().getCanonicalText());
        addInMap(type, emptySet);
    }
}