Example usage for org.eclipse.jdt.core.dom VariableDeclarationFragment getRoot

List of usage examples for org.eclipse.jdt.core.dom VariableDeclarationFragment getRoot

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom VariableDeclarationFragment getRoot.

Prototype

public final ASTNode getRoot() 

Source Link

Document

Returns the root node at or above this node; returns this node if it is a root.

Usage

From source file:fr.imag.exschema.hbase.HBaseUtil.java

License:Open Source License

@Override
public List<Set> discoverSchemas(final IJavaProject project) throws CoreException {
    String tableName;/* w ww.  j a v a2s  . c  o  m*/
    Set currentTableSet;
    List<Set> returnValue;
    String tableDescriptor;
    Set currentConfiguration;
    TablePutVisitor putVisitor;
    List<String> tableDescriptors;
    TableCreateVisitor createVisitor;
    List<ASTNode> tableDescriptorsRoots;
    Map<ASTNode, Set> configurationsMap;
    java.util.Set<ASTNode> configurations;
    TableIncrementVisitor incrementVisitor;
    List<Integer> tableDescriptorNameIndex;
    TableDeclareVisitor tableDeclareVisitor;
    DescriptorDeclareVisitor descriptorDeclareVisitor;

    // Identify when tables are created
    createVisitor = new TableCreateVisitor();
    Util.analyzeJavaProject(project, createVisitor);

    // Identify when tables are declared
    tableDeclareVisitor = new TableDeclareVisitor();
    Util.analyzeJavaProject(project, tableDeclareVisitor);

    // Identify when data is inserted in a table
    putVisitor = new TablePutVisitor();
    Util.analyzeJavaProject(project, putVisitor);

    // Identify when columns are added to a column family
    incrementVisitor = new TableIncrementVisitor();
    Util.analyzeJavaProject(project, incrementVisitor);

    // Join tables' creations and declarations
    tableDescriptors = new ArrayList<String>(
            createVisitor.getUpdateInvocations().size() + tableDeclareVisitor.getVariableDeclarations().size());
    tableDescriptorsRoots = new ArrayList<ASTNode>(tableDescriptors.size());
    tableDescriptorNameIndex = new ArrayList<Integer>(tableDescriptors.size());
    for (MethodInvocation createInvocation : createVisitor.getUpdateInvocations()) {
        tableDescriptors.add(createInvocation.arguments().get(0).toString());
        tableDescriptorsRoots.add(createInvocation.getRoot());

        // The table name is the first argument
        tableDescriptorNameIndex.add(0);
    }

    for (VariableDeclarationFragment variableDeclaration : tableDeclareVisitor.getVariableDeclarations()) {
        tableDescriptors.add(variableDeclaration.getName().toString());
        tableDescriptorsRoots.add(variableDeclaration.getRoot());

        // The table name is the second argument
        tableDescriptorNameIndex.add(1);
    }

    // Consider that each file where the tables are declared/created define
    // a new configuration
    returnValue = new ArrayList<Set>();
    configurations = Util.getNodesFiles(tableDescriptorsRoots);
    configurationsMap = new HashMap<ASTNode, Set>(configurations.size());
    for (ASTNode configuration : configurations) {
        currentConfiguration = new Set();
        currentConfiguration.addAttribute(new Attribute("implementation", RooModel.HBASE.toString()));

        returnValue.add(currentConfiguration);
        configurationsMap.put(configuration, currentConfiguration);
    }

    // Get tables data
    HBaseUtil.logger.log(Util.LOGGING_LEVEL, "\n\nHBase tables:");
    for (int i = 0; i < tableDescriptors.size(); i++) {
        tableDescriptor = tableDescriptors.get(i);

        // Table name
        descriptorDeclareVisitor = new DescriptorDeclareVisitor();
        descriptorDeclareVisitor.setVariableName(tableDescriptor);
        tableName = HBaseUtil.getHBaseName(tableDescriptorsRoots.get(i), descriptorDeclareVisitor,
                tableDescriptorNameIndex.get(i));
        if (tableName != null) {
            // Save tables based on the file where their associated
            // configuration is used
            currentConfiguration = configurationsMap.get(Util.getRootNode(tableDescriptorsRoots.get(i)));
            if (currentConfiguration != null) {
                currentTableSet = new Set();
                currentConfiguration.addSet(currentTableSet);
                currentTableSet.addAttribute(new Attribute("name", tableName));
                HBaseUtil.logger.log(Util.LOGGING_LEVEL, "\n--Table: " + tableName);

                // Analyze increment operations (HTableDescriptor.familyAdd)
                HBaseUtil.analyzeIncrementOperations(incrementVisitor, putVisitor, tableDescriptorsRoots.get(i),
                        tableName, tableDescriptor, currentTableSet);

                // Analyze put operations (HTable.put)
                HBaseUtil.analyzePutOperations(putVisitor, tableName, tableDescriptorsRoots.get(i),
                        currentTableSet);
            }
        }
    }

    return returnValue;
}

From source file:fr.imag.exschema.neo4j.Neo4jUtil.java

License:Open Source License

/**
 * Associate fields to their corresponding Neo4j's containers.
 * /*from   w ww.  ja  v a  2 s .co  m*/
 * @param declarations
 * @param updateInvocations
 * @return
 */
private static Map<String, List<String>> associateContainersFields(
        final List<VariableDeclarationFragment> declarations, List<MethodInvocation> updateInvocations) {
    String fragmentKey;
    String fragmentRoot;
    String invocationRoot;
    String fragmentString;
    List<String> currentFields;
    Map<String, List<String>> returnValue;

    returnValue = new HashMap<String, List<String>>();
    // Declarations
    for (VariableDeclarationFragment fragment : declarations) {
        currentFields = new ArrayList<String>();
        fragmentRoot = ((CompilationUnit) fragment.getRoot()).getTypeRoot().getElementName();

        // Fields
        for (MethodInvocation invocation : updateInvocations) {
            invocationRoot = ((CompilationUnit) invocation.getRoot()).getTypeRoot().getElementName();
            // Match name of declare and update variables, in the same file
            if (fragmentRoot.equals(invocationRoot)) {
                if (fragment.getName().toString().equals(invocation.getExpression().toString())) {
                    currentFields.add(invocation.arguments().get(0).toString().replace('"', ' ').trim());
                }
            }
        }

        // Save only the class name
        if (fragmentRoot.contains(".java")) {
            fragmentRoot = fragmentRoot.substring(0, fragmentRoot.indexOf(".java")).trim();
        }

        // Save only variable name if the declaration contains an assignment
        // (var=expr)
        fragmentString = fragment.toString();
        if (fragmentString.contains("=")) {
            fragmentString = fragmentString.substring(0, fragmentString.indexOf('=')).trim();
        }

        // Save association between fields and container
        fragmentKey = fragmentRoot + "." + fragmentString;
        if ((currentFields.size() > 0) && (returnValue.get(fragmentKey) == null)) {
            returnValue.put(fragmentKey, currentFields);
        }
    }

    return returnValue;
}