List of usage examples for org.eclipse.jdt.core.dom MethodInvocation getRoot
public final ASTNode getRoot()
From source file:com.google.gdt.eclipse.platform.debug.eval.JSOEvalingASTInstructionCompiler.java
License:Open Source License
@Override public boolean visit(MethodInvocation node) { if (!isActive()) { return false; }/*w w w .j av a2s . c o m*/ IMethodBinding methodBinding = (IMethodBinding) node.getName().resolveBinding(); if (methodBinding == null) { // could be the receiver is not visible - for example a private field // access from super class ASTNode root = node.getRoot(); if (root instanceof CompilationUnit) { CompilationUnit cu = (CompilationUnit) root; IProblem[] problems = cu.getProblems(); for (int i = 0; i < problems.length; i++) { IProblem problem = problems[i]; setHasError(true); addErrorMessage(problem.getMessage()); } } } if (hasErrors()) { return true; } if (containsALocalType(methodBinding)) { setHasError(true); addErrorMessage( EvaluationEngineMessages.ASTInstructionCompiler_Method_which_contains_a_local_type_as_parameter_cannot_be_used_in_an_evaluation_expression_32); } if (hasErrors()) { return true; } int paramCount = methodBinding.getParameterTypes().length; String selector = methodBinding.getName(); String signature = getMethodSignature(methodBinding, null).replace('.', '/'); boolean isStatic = Flags.isStatic(methodBinding.getModifiers()); Expression expression = node.getExpression(); String typeName = getTypeName(methodBinding.getDeclaringClass()); if (isStatic) { boolean isJso = false; ITypeBinding parent = methodBinding.getDeclaringClass(); while (parent != null) { if (parent.getQualifiedName().equals("com.google.gwt.core.client.JavaScriptObject")) { isJso = true; break; } parent = parent.getSuperclass(); } if (isJso) { push(new JsoSendStaticMessage(typeName, selector, signature, paramCount, getCounter())); } else { push(new SendStaticMessage(typeName, selector, signature, paramCount, getCounter())); } if (expression != null) { node.getExpression().accept(this); addPopInstruction(); } } else { /* * Since we're dealing with a non-static method, we can't tell whether or * not this method is declared on a class that extends JavaScriptObject; * the method could be declared on an interface that MAY be implemented by * a subclass of JavaScriptObject. */ push(new JsoSendMessage(selector, signature, paramCount, typeName, getCounter())); if (expression == null) { push(new PushThis(getEnclosingLevel(node, methodBinding.getDeclaringClass()))); storeInstruction(); } else { node.getExpression().accept(this); } } List<?> arguments = node.arguments(); pushMethodArguments(methodBinding, arguments); return false; }
From source file:fr.imag.exschema.couchdb.CouchDBUtil.java
License:Open Source License
@Override public List<Set> discoverSchemas(final IJavaProject project) throws CoreException { String field;/*from w ww . j a v a 2 s . c o m*/ Set currentFields; Struct currentField; Set currentDatabase; String documentName; List<Set> returnValue; Set currentCollection; Struct currentDocument; Map<ASTNode, Set> collections; java.util.Set<ASTNode> databases; DocumentPutVisitor documentPutVisitor; DocumentSaveVisitor documentSaveVisitor; // Identify when documents are saved returnValue = new ArrayList<Set>(); documentSaveVisitor = new DocumentSaveVisitor(); Util.analyzeJavaProject(project, documentSaveVisitor); // Consider that each file where save invocations are used define a // combination of database/collection databases = Util.getNodesFiles(documentSaveVisitor.getUpdateInvocations()); collections = new HashMap<ASTNode, Set>(databases.size()); for (ASTNode database : databases) { currentDatabase = new Set(); currentDatabase.addAttribute(new Attribute("implementation", RooModel.COUCHDB.toString())); returnValue.add(currentDatabase); currentCollection = new Set(); currentDatabase.addSet(currentCollection); collections.put(database, currentCollection); currentCollection.addAttribute(new Attribute("name", "collection")); CouchDBUtil.logger.log(Util.LOGGING_LEVEL, "--Collection: " + "collection"); } // Get the attributes from the identified documents CouchDBUtil.logger.log(Util.LOGGING_LEVEL, "\nCouchDB documents (based on puts): "); for (MethodInvocation saveInvocation : documentSaveVisitor.getUpdateInvocations()) { // TODO: Consider operations that don't rely on variables // Only work with variables documentName = saveInvocation.arguments().get(0).toString(); if (Util.isVariableName(documentName)) { // Save documents based on the file where their associated // database is used currentCollection = collections.get(Util.getRootNode(saveInvocation)); if (currentCollection != null) { currentDocument = new Struct(); currentCollection.addStruct(currentDocument); currentDocument.addAttribute(new Attribute("name", documentName)); CouchDBUtil.logger.log(Util.LOGGING_LEVEL, "----Document: " + documentName); // Attributes added through the Document.put() method documentPutVisitor = new DocumentPutVisitor(); documentPutVisitor.setVariableName(documentName); saveInvocation.getRoot().accept(documentPutVisitor); if (!documentPutVisitor.getUpdateInvocations().isEmpty()) { currentFields = new Set(); currentDocument.addSet(currentFields); for (MethodInvocation putInvocation : documentPutVisitor.getUpdateInvocations()) { field = putInvocation.arguments().get(0).toString().replace('"', ' ').trim(); currentField = new Struct(); currentFields.addStruct(currentField); currentField.addAttribute(new Attribute("name", field)); CouchDBUtil.logger.log(Util.LOGGING_LEVEL, "------Field: " + field); } } } } } return returnValue; }
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;/*ww w . j av a 2 s. 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 www . j av a 2 s. c om * @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; }
From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java
License:Open Source License
/** * @return the local {@link MethodDeclaration} (i.e. declared in same {@link TypeDeclaration}) * that is invoked by given {@link MethodInvocation} or <code>null</code> if this method * is not local.//from w ww . j av a 2 s . c o m */ public static MethodDeclaration getLocalMethodDeclaration(final MethodInvocation invocation) { // quick check if there is local name with such name (just name, not signature) { ASTNode unit = invocation.getRoot(); String key = "getLocalMethodDeclaration.allMethods"; Set<String> allNames = getValue(unit, key, new RunnableObjectEx<Set<String>>() { public Set<String> runObject() throws Exception { Set<String> names = Sets.newTreeSet(); TypeDeclaration typeDeclaration = getEnclosingType(invocation); MethodDeclaration[] methods = typeDeclaration.getMethods(); for (MethodDeclaration method : methods) { names.add(method.getName().getIdentifier()); } return names; } }); if (!allNames.contains(invocation.getName().getIdentifier())) { return null; } } // perform precise search String key = "getLocalMethodDeclaration"; return getValue(invocation, key, new RunnableObjectEx<MethodDeclaration>() { public MethodDeclaration runObject() throws Exception { return getLocalMethodDeclaration0(invocation); } }); }