All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reextractor.util.VariableUtils Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package org.reextractor.util;

import org.eclipse.jdt.core.dom.*;

public class VariableUtils {

    public static String variable2String(VariableDeclaration variableDeclaration) {
        StringBuilder sb = new StringBuilder();
        sb.append(variableDeclaration.getName().getIdentifier());
        sb.append(" : ");
        if (variableDeclaration instanceof SingleVariableDeclaration) {
            sb.append(((SingleVariableDeclaration) variableDeclaration).getType().toString());
            if (((SingleVariableDeclaration) variableDeclaration).isVarargs())
                sb.append("...");
        } else {
            ASTNode parent = variableDeclaration.getParent();
            if (parent instanceof VariableDeclarationStatement) {
                sb.append(((VariableDeclarationStatement) parent).getType().toString());
            } else if (parent instanceof VariableDeclarationExpression) {
                sb.append(((VariableDeclarationExpression) parent).getType().toString());
            } else if (parent instanceof LambdaExpression) {
                sb.append("null");
            } else {
                sb.append("null");
            }
        }
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy