// Metodo para tratamento de declarações de métodos private void methodDeclarationHandler(MethodDeclaration methodDeclaration, ApiClass apiClass) { IMethodBinding mb = methodDeclaration.resolveBinding(); if (mb == null) { return; } LinkedList<String> paramsType = new LinkedList<String>(); for (ITypeBinding pt : mb.getParameterTypes()) { paramsType.add(pt.getQualifiedName().toString()); } ApiMethod apiMethod = new ApiMethod(apiClass, mb.getName(), paramsType); this.setModifiers(apiMethod, methodDeclaration); if (mb.isConstructor()) { apiMethod.setConstructor(true); apiMethod.setVoid(false); apiMethod.setFunction(false); apiMethod.setReturnType(null); } else if (mb.getReturnType().getQualifiedName().equalsIgnoreCase("void")) { apiMethod.setVoid(true); apiMethod.setFunction(false); apiMethod.setReturnType(null); } else { apiMethod.setVoid(false); apiMethod.setFunction(true); apiMethod.setReturnType(mb.getReturnType().getQualifiedName()); } apiClass.getApiMethods().add(apiMethod); this.methodMap.put(mb, apiMethod); }
@Override public boolean visit(TypeDeclaration node) { if (node.isPackageMemberTypeDeclaration() || node.isMemberTypeDeclaration()) { ITypeBinding typeBinding = node.resolveBinding(); if (typeBinding != null) { // Criando classe ApiClass apiClass = new ApiClass(typeBinding.getQualifiedName()); apiClass.setInterface(typeBinding.isInterface()); this.setModifiers(apiClass, node); this.classMap.put(typeBinding, apiClass); if (!this.attachmentMap.containsKey(node.getRoot())) { Attachment attachment = new Attachment( typeBinding.getQualifiedName().concat(".java"), node.getRoot().toString().getBytes()); this.attachmentMap.put(node.getRoot(), attachment); } List<MethodDeclaration> declarations = new LinkedList<MethodDeclaration>(); for (Object o : node.bodyDeclarations()) { if (o instanceof MethodDeclaration) { declarations.add((MethodDeclaration) o); } } for (final MethodDeclaration declaration : declarations) { final List<Expression> invocations = new LinkedList<Expression>(); this.methodDeclarationHandler(declaration, apiClass); InvocationVisitor visitor = new InvocationVisitor(); declaration.accept(visitor); invocations.addAll(visitor.invocations); // Parte de extracao de exemplos, se não houver invocações eu pulo esta parte if (invocations.isEmpty()) { continue; } else { // Faço a extração de exemplos para cada invocação em separado Set<ApiMethod> methodsInvocations = new HashSet<ApiMethod>(); for (Expression mi : invocations) { methodsInvocations.add(this.mapInvocations.get(mi)); Example newExample = makeExample( declaration, Collections.singleton(mi), Collections.singletonList(this.mapInvocations.get(mi))); if (newExample != null) { this.examples.add(newExample); } } // Se houver mais de uma invocacao faço o slicing com sementes multiplas if (invocations.size() > 1) { // Itero sobre os conjuntos das regras Iterator<Set<ApiMethod>> it = this.methodSets.iterator(); while (it.hasNext()) { // Podando conjuntos Set<ApiMethod> s = it.next(); if (s.size() > methodsInvocations.size()) { break; } else { // Se as invocacoes identificadas envolvem metodos desejados eu processo if (methodsInvocations.containsAll(s)) { List<ApiMethod> methods = new ArrayList<ApiMethod>(); Set<Expression> invocationsTemp = new HashSet<Expression>(); for (Expression mi : invocations) { ApiMethod relatedMethod = this.mapInvocations.get(mi); if (s.contains(relatedMethod)) { methods.add(relatedMethod); invocationsTemp.add(mi); } } Example newExample = makeExample(declaration, invocationsTemp, methods); if (newExample != null) { this.examples.add(newExample); } } } } } } } } } return super.visit(node); }