private void analyzeCompilationUnit(CompilationUnit unit, ICompilationUnit compilationUnit) { Set<String> filters = loadFilters(); ASTVisitor importsVisitor = new ImportsVisitor(filters); unit.accept(importsVisitor); List types = unit.types(); for (Iterator iter = types.iterator(); iter.hasNext();) { Object next = iter.next(); if (next instanceof TypeDeclaration) { // declaration: Contains one file content at a time. TypeDeclaration declaration = (TypeDeclaration) next; // traverseType(declaration,true); } } }
private static boolean hasFieldInitializers(TypeDeclaration typeDecl) { boolean returnFlag = false; for (FieldDeclaration fd : typeDecl.getFields()) { // Skip over primitive types if (fd.getType().isPrimitiveType() ) { continue; } if (fd.fragments().size() > 0) if (fd.fragments().get(0) instanceof VariableDeclarationFragment) { VariableDeclarationFragment vdf = (VariableDeclarationFragment) fd.fragments().get(0); if (vdf.getInitializer() != null) returnFlag = true; } } return returnFlag; }
private BlockInfo.Type getBlockType(ASTNode node) { if(node instanceof TypeDeclaration) return BlockInfo.Type.TYPE; else if(node instanceof MethodDeclaration) return BlockInfo.Type.METHOD; else if(node instanceof WhileStatement) return BlockInfo.Type.WHILE; else if(node instanceof ForStatement) return BlockInfo.Type.FOR; else if(node instanceof IfStatement) return BlockInfo.Type.IF; else return BlockInfo.Type.OTHER; }
@Override public boolean visit(FieldDeclaration node) { List fragments = node.fragments(); for(Object o : fragments) { VariableDeclarationFragment frag = (VariableDeclarationFragment) o; String varName = frag.getName().getIdentifier(); int line = cunit.getLineNumber(frag.getStartPosition()); ASTNode parent = node.getParent(); Scope scope = new Scope(cunit.getLineNumber(parent.getStartPosition()), getEndLine(parent, cunit)); TypeDeclaration dec = (TypeDeclaration) node.getParent(); String qName = dec.getName().getFullyQualifiedName(); PackageDeclaration packageDec = cunit.getPackage(); if(packageDec != null) qName = packageDec.getName().getFullyQualifiedName() + "." + qName; String type = !Modifier.isStatic(node.getModifiers()) ? qName : null; VariableTags tags = new VariableTags(varName, type, line, scope, true); variables.add(tags); } return false; }
@Override public boolean visit(TypeDeclaration node) { System.out.println(node.getParent().getClass()); if(info == null) info = new ClassInfo(node.resolveBinding().getQualifiedName(), VisibilityInfo.from(node)); for(FieldDeclaration f : node.getFields()) { if(!Modifier.isStatic(f.getModifiers())) { for(Object o : f.fragments()) { VariableDeclarationFragment frag = (VariableDeclarationFragment) o; info.addField(new FieldInfo(frag.getName().toString())); } } } return true; }
@Override public boolean visit(MethodDeclaration node) { boolean instanceMember = !node.isConstructor() && !Modifier.isStatic(node.getModifiers()); if(((TypeDeclaration) node.getParent()).isPackageMemberTypeDeclaration()) { AssignmentVisitor v = new AssignmentVisitor(); node.accept(v); if(instanceMember) { MethodInfo m = new MethodInfo( node.getName().getIdentifier(), VisibilityInfo.from(node), node.getReturnType2().resolveBinding().isParameterizedType() ? Object.class.toString() : node.getReturnType2().resolveBinding().getQualifiedName(), v.params, v.containsFieldAssignments); info.addMethod(m); } } return false; }
protected void init() throws JavaModelException { initMocks(this); DiContainer.clearDiContainer(); // Override mock dependencies diContainerOverrides(); // end of overrides DiContainer.initializeDiContainer(); given(handlerUtilWrapper.getActivePartId(dummyExecutionEvent)) .willReturn("org.eclipse.jdt.ui.CompilationUnitEditor"); given(workingCopyManagerWrapper.getCurrentCompilationUnit(dummyExecutionEvent)).willReturn(iCompilationUnit); given(preferenceStoreProvider.providePreferenceStore()).willReturn(preferenceStore); given(iCompilationUnit.getBuffer()).willReturn(iBuffer); given(iTypeExtractor.extract(any(TypeDeclaration.class))).willReturn(empty()); given(fullyQualifiedNameExtractor.getFullyQualifiedBaseTypeName(any(BuilderField.class))).willReturn(empty()); setDefaultPreferenceStoreSettings(); doNothing().when(iBuffer).setContents(outputCaptor.capture()); DiContainer.initializeDiContainer(); }
public static boolean hasConstructor(TypeDeclaration typeDecl, Map<ast.Type, TypeDeclaration> types, QualifiedClassName cThis) { boolean hasConstr = false; if (!hasFieldInitializers(typeDecl)) hasConstr = true; else { for (MethodDeclaration md : typeDecl.getMethods()) { if (md.isConstructor()) hasConstr = true; } } Type superclassType = typeDecl.getSuperclassType(); if (superclassType == null) return hasConstr; if (superclassType.resolveBinding().getQualifiedName().equals(Utils.JAVA_LANG_OBJECT)) return hasConstr; TypeDeclaration superTypeDecl = types.get(new QualifiedClassName(superclassType.resolveBinding(), cThis) .getType()); if (superTypeDecl != null) { hasConstr = hasConstr && hasConstructor(superTypeDecl, types, cThis); } return hasConstr; }
/** * returns all method declarations in a type, and its supertype recursively. * call MethodDeclaration.getBody() to get the body of the method. TODO: * actual/formal substitution * */ public static Set<MethodDeclaration> mBody(TypeDeclaration typeDecl, TypeHierarchy hierarchy, Map<ast.Type, TypeDeclaration> types, QualifiedClassName cThis) { Set<MethodDeclaration> returnSet = new HashSet<MethodDeclaration>(); for (MethodDeclaration md : typeDecl.getMethods()) { returnSet.add(md); } Type superclassType = typeDecl.getSuperclassType(); if (superclassType == null) return returnSet; if (superclassType.resolveBinding().getQualifiedName().equals(Utils.JAVA_LANG_OBJECT)) return returnSet; TypeDeclaration superTypeDecl = types.get(new QualifiedClassName(superclassType.resolveBinding(), cThis) .getType()); if (superTypeDecl != null) { Set<MethodDeclaration> auxSet = mBody(superTypeDecl, hierarchy, types, cThis); returnSet.addAll(auxSet); // TODO: here you don't want to add OverrideMethod // TODO: find a way to uniquely identify methods: define mtype. } return returnSet; }
/*** * Lookup an ast.MethodDeclaration based on className and methodName * * @param qualifiedTypeName * @param methodName * @return ast.MethodDeclaration * * HACK: XXX, also include in the search type of parameters. * Currently the search does not distinguish between C.m and C.m(A) * class C{ * void m(){} * void m(A a){} * } */ public static ast.MethodDeclaration getMethodDeclaration(String qualifiedTypeName, String methodName) { ast.MethodDeclaration methodDeclaration = Adapter.getInstance().getMethodDeclaration(qualifiedTypeName + methodName); if (methodDeclaration != null) return methodDeclaration; // If not found, it may not have been added yet? // XXX. But why not do this once? Collection<ast.MethodDeclaration> allNodes = Adapter.getInstance().getMethodDeclarations(); for (ast.MethodDeclaration md : allNodes) { ast.TypeDeclaration td = md.enclosingType; if (td != null && td.type != null) if (td.type.getFullyQualifiedName().equals(qualifiedTypeName)) if (md.methodName.equals(methodName)) { Adapter.getInstance().mapMethodDeclaration(md); return md; } } return null; }
/** * Method to get class attributes and add them in a list. * @author Mariana Azevedo * @since 13/07/2014 * @param node */ @SuppressWarnings("unchecked") private void getClassAttributes(CompilationUnit node){ for (Object type : node.types()){ if (type instanceof TypeDeclaration){ FieldDeclaration [] attributes = ((TypeDeclaration) type).getFields(); for (FieldDeclaration attribute: attributes){ List<FieldDeclaration> fragments = attribute.fragments(); Object obj = fragments.get(0); if (obj instanceof VariableDeclarationFragment){ String str = ((VariableDeclarationFragment) obj).getName().toString(); this.listOfAttributes.add(str); } } } } }
@Test public void testBuilderWithTwoSuperclassesShouldConcatenatesFieldsFromAll() throws Exception { // GIVEN given(iTypeExtractor.extract(any(TypeDeclaration.class))) .willReturn(of(firstSuperClassType)) .willReturn(of(secondSuperClassType)) .willReturn(empty()); String superClassInput = readClasspathFile("superclass_test_superclass_input.tjava"); super.setCompilationUnitInput(firstSuperClassICompilationUnit, superClassInput); String secondSuperClassInput = readClasspathFile("super_superclass_test_input.tjava"); super.setCompilationUnitInput(secondSuperClassICompilationUnit, secondSuperClassInput); String input = readClasspathFile("superclass_test_extends_input.tjava"); String expectedResult = readClasspathFile("superclass_with_two_superclasses_output.tjava"); super.setInput(input); // WHEN underTest.execute(dummyExecutionEvent); // THEN super.assertEqualsJavaContents(outputCaptor.getValue(), expectedResult); }
@BeforeMethod public void beforeMethod() throws JavaModelException { super.init(); underTest = new GenerateRegularBuilderHandler(); given(firstSuperClassType.getCompilationUnit()).willReturn(firstSuperClassICompilationUnit); given(firstSuperClassType.getElementName()).willReturn("TestSuperClass"); // When getting the superClass return the correct type typeExtractorAnswerProvider = new TypeExtractorAnswerProvider(Collections.singletonMap("TestClass", firstSuperClassType)); given(iTypeExtractor.extract(any(TypeDeclaration.class))) .willAnswer(a -> typeExtractorAnswerProvider.provideAnswer(a)); given(preferenceStore.getBoolean("org.helospark.builder.includeVisibleFieldsFromSuperclass")).willReturn(true); given(preferenceStore.getBoolean("org.helospark.builder.includeParametersFromSuperclassConstructor")).willReturn(true); }
public void generateBuilder(CompilationUnitModificationDomain modificationDomain, List<StagedBuilderProperties> stagedBuilderStages) { AST ast = modificationDomain.getAst(); TypeDeclaration originalType = modificationDomain.getOriginalType(); ListRewrite listRewrite = modificationDomain.getListRewrite(); builderRemover.removeExistingBuilderWhenNeeded(modificationDomain); // TODO: eventually have a better design to avoid nulls here List<TypeDeclaration> stageInterfaces = createStageInterfaces(modificationDomain, stagedBuilderStages); TypeDeclaration builderType = stagedBuilderClassCreator.createBuilderClass(modificationDomain, stagedBuilderStages, stageInterfaces); privateConstructorPopulator.addPrivateConstructorToCompilationUnit(ast, originalType, builderType, listRewrite, collectAllFieldsFromAllStages(stagedBuilderStages)); stagedBuilderStaticBuilderCreatorMethodCreator.addBuilderMethodToCompilationUnit(modificationDomain, builderType, stagedBuilderStages); stageInterfaces.stream().forEach(stageInterface -> listRewrite.insertLast(stageInterface, null)); listRewrite.insertLast(builderType, null); importPopulator.populateImports(modificationDomain); }
private SingleMemberAnnotation getTypeAnnotationParams(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation) { ArrayInitializer initializer = rewrite.getAST().newArrayInitializer(); if (!typeDeclaration.resolveBinding().getQualifiedName().equals(Config.MAINCLASS)) { StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral(); newStringLiteral.setLiteralValue("p"); ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY); listRewrite.insertFirst(newStringLiteral, null); } SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation(); newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation)); newParamAnnotation.setValue(initializer); return newParamAnnotation; }
public static MethodDeclaration getMethodDeclaration(String methodName) { IJavaElement javaElem = EditorUtility.getActiveEditorJavaInput(); if (javaElem.getElementType() == IJavaElement.COMPILATION_UNIT) { ICompilationUnit iCompUnit = (ICompilationUnit) javaElem; ASTNode astNode = Crystal.getInstance() .getASTNodeFromCompilationUnit(iCompUnit); if (astNode != null && astNode.getNodeType() == ASTNode.COMPILATION_UNIT) { CompilationUnit compUnit = (CompilationUnit) astNode; for (Object declaration : compUnit.types()) { if (declaration instanceof TypeDeclaration) { for (MethodDeclaration method : ((TypeDeclaration) declaration) .getMethods()) { if (methodName.contentEquals(method.getName() .getFullyQualifiedName())) { return method; } } } } } } return null; }
private void populateMethodDeclarations(TypeDeclaration declaration){ TypeDeclaration[] nestedTypes = declaration.getTypes(); for (int i = 0; i < nestedTypes.length; i++) { TypeDeclaration nestedType = nestedTypes[i]; populateMethodDeclarations(nestedType); } FieldDeclaration[] fields = declaration.getFields(); for (FieldDeclaration fieldDeclaration : fields) { fieldDeclaration.accept(new HeuristicOwnedVisitor()); } MethodDeclaration[] methods = declaration.getMethods(); for (MethodDeclaration methodDeclaration : methods) { methodDeclaration.accept(new HeuristicOwnedVisitor()); methodDeclaration.accept(new HeuristicOwnedLocalsVisitor()); this.methodDecls.add(methodDeclaration); } }
private void declareOtherDomains(ASTRewrite rewrite, ListRewrite listRewrite, TypeDeclaration typeDeclaration) { String qualifiedName = typeDeclaration.resolveBinding().getQualifiedName(); OGraphFacade facade = RefinementAnalysis.getFacade(); RefinementModel refinementModel = facade.getRefinementModel(); List<IOtherRefinement> otherRefinements = refinementModel.getOtherRefinements(); for(IOtherRefinement otherRefinement : otherRefinements ) { if (otherRefinement instanceof CreateDomain ) { CreateDomain createDomain = (CreateDomain)otherRefinement; String fullyQualifiedName = createDomain.getSrcIObject().getC().getFullyQualifiedName(); if (fullyQualifiedName.equals(qualifiedName)) { StringLiteral newStringLiteralPARAM = rewrite.getAST().newStringLiteral(); newStringLiteralPARAM.setLiteralValue(createDomain.getDstDomain()); listRewrite.insertLast(newStringLiteralPARAM, null); } } } }
private void setTypeAnnotationDomains(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName, ASTNode after) { SingleMemberAnnotation newParamAnnotation = getTypeAnnotationDomain(rewrite, typeDeclaration, annotation, domainName); ListRewrite paramRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY); if (after == null) { paramRewrite.insertFirst(newParamAnnotation, null); } else { paramRewrite.insertAfter(newParamAnnotation, after, null); } }
public List getAllSuperTypes(TypeDeclaration typeDeclaration) { List list = new ArrayList(); Type superclassType = typeDeclaration.getSuperclassType(); if (superclassType != null) { list.add(superclassType); } List superInterfaceTypes = typeDeclaration.superInterfaceTypes(); for (Iterator itSuperInterfacesIterator = superInterfaceTypes.iterator(); itSuperInterfacesIterator.hasNext();) { Object next = itSuperInterfacesIterator.next(); if (next instanceof SimpleType) { list.add(next); } } return list; }
@SuppressWarnings("unchecked") public MethodDeclaration createPrivateConstructorDefinition(AST ast, TypeDeclaration originalType, TypeDeclaration builderType, List<BuilderField> builderFields) { MethodDeclaration method = ast.newMethodDeclaration(); method.setConstructor(true); method.setName(ast.newSimpleName(originalType.getName().toString())); if (preferencesManager.getPreferenceValue(ADD_GENERATED_ANNOTATION)) { generatedAnnotationPopulator.addGeneratedAnnotation(ast, method); } method.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD)); SingleVariableDeclaration methodParameterDeclaration = ast.newSingleVariableDeclaration(); methodParameterDeclaration.setType(ast.newSimpleType(ast.newName(builderType.getName().toString()))); methodParameterDeclaration.setName(ast.newSimpleName(camelCaseConverter.toLowerCamelCase(builderType.getName().toString()))); method.parameters().add(methodParameterDeclaration); return method; }
@Test public void testSimpleExtendsWithStagedBuilder() throws Exception { // GIVEN underTest = new GenerateStagedBuilderHandler(); given(iTypeExtractor.extract(any(TypeDeclaration.class))) .willReturn(of(firstSuperClassType)) .willReturn(empty()); String superClassInput = readClasspathFile("superclass_test_superclass_input.tjava"); super.setCompilationUnitInput(firstSuperClassICompilationUnit, superClassInput); String input = readClasspathFile("superclass_test_extends_input.tjava"); String expectedResult = readClasspathFile("superclass_test_output_with_staged_builder.tjava"); super.setInput(input); // no change in order, all mandatory fields given(stagedBuilderStagePropertyInputDialogOpener.open(any(List.class))).willAnswer(invocation -> dialogAnswerProvider.provideAnswer(invocation)); // WHEN underTest.execute(dummyExecutionEvent); // THEN super.assertEqualsJavaContents(outputCaptor.getValue(), expectedResult); }
private static String getUniqueMethodName(ASTNode astNode, String suggestedName) throws JavaModelException { while (astNode != null && !(astNode instanceof TypeDeclaration)) { astNode = astNode.getParent(); } if (astNode instanceof TypeDeclaration) { ITypeBinding typeBinding = ((TypeDeclaration) astNode).resolveBinding(); if (typeBinding == null) { return suggestedName; } IType type = (IType) typeBinding.getJavaElement(); if (type == null) { return suggestedName; } IMethod[] methods = type.getMethods(); int suggestedPostfix = 2; String resultName = suggestedName; while (suggestedPostfix < 1000) { if (!hasMethod(methods, resultName)) { return resultName; } resultName = suggestedName + suggestedPostfix++; } } return suggestedName; }
/*** * Lookup an ast.FieldDeclaration based on qualifiedClassName and fieldName * @param qualifiedClassName - fully qualified typeName name as in package.Foo.f * @param fieldName - simple field name as in f * @return an ast.FieldDeclaration already stored in the map * @return null if no such declaration exists in the map */ public static ast.FieldDeclaration getFieldDeclaration(String qualifiedClassName, String fieldName) { ast.FieldDeclaration fieldDeclaration = Adapter.getInstance().getFieldDeclaration(qualifiedClassName + fieldName); if(fieldDeclaration != null) return fieldDeclaration; // If not found, it may not have been added yet? // XXX. But why not do this once? Collection<ast.TypeDeclaration> allNodes = Adapter.getInstance().getTypeDeclarations(); for (AstNode astNode : allNodes) { ast.TypeDeclaration td = (ast.TypeDeclaration) astNode; if (td.type.getFullyQualifiedName().equals(qualifiedClassName)) { List<ast.FieldDeclaration> fields = td.fields; if (fields != null) for (ast.FieldDeclaration fd : fields) { if (fd.fieldName.endsWith(fieldName)) { Adapter.getInstance().mapFieldDeclaration(fd); return fd; } } } } return null; }
/** * @param rewrite * @param declaration */ private void annotateMethods(ASTRewrite rewrite, TypeDeclaration declaration) { MethodDeclaration[] methods = declaration.getMethods(); for (int i = 0; i < methods.length; i++) { MethodDeclaration methodDeclaration = methods[i]; annotateMethodReturnType(rewrite, methodDeclaration); annotateMethodParameters(rewrite, methodDeclaration); DefaultingVisitor visitor = new DefaultingVisitor(); visitor.rewrite = rewrite; Block body = methodDeclaration.getBody(); if (body != null) { body.accept(visitor); } } }
@Override public boolean visit(MethodInvocation node) { visitExpressionIfName(node.getExpression()); if (node.getExpression() != null) { return true; } // node is of the form `methodName(...)`, and not eg., `Foo.methodName()`. org.eclipse.jdt.core.dom.SimpleName simpleName = node.getName(); if (compilationUnit.findDeclaringNode(simpleName.resolveBinding()) != null) { // simpleName is defined somewhere in this compilation unit - so no need to import it. return true; } // Do not report methods that appear in inner/anonymous classes that have a superclass: // Jade doesn't currently fetch inherited symbols for inner/anonymous classes, which // leads to inherited methods being imported. (b/35660499, b/35727475) // This isn't perfect because another class might call a same-named method; if this // becomes a problem, I'll use a blacklist. AbstractTypeDeclaration containingClass = getContainingClass(node); if (!(containingClass.getParent() instanceof CompilationUnit) && containingClass instanceof TypeDeclaration && ((TypeDeclaration) containingClass).getSuperclassType() != null) { return true; } if (isDescendantOfAnonymousClassDeclaration(node)) { return true; } // Work around Eclipse JDT Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=462192, // where `simpleName.resolveBinding() == null` happens even though 'simpleName' is // defined in the current compilation unit. Set<String> methods = methodsOfClass.get(containingClass); if (methods.isEmpty()) { methods.addAll(getMethodDeclarations(containingClass)); } if (!methods.contains(simpleName.getIdentifier())) { int startPosition = simpleName.getStartPosition(); symbols.put( simpleName.getIdentifier(), Metadata.create( compilationUnit.getLineNumber(startPosition), compilationUnit.getColumnNumber(startPosition), true)); } return true; }
@Override public boolean visit(TypeDeclaration node) { if (currentTypeModelBuilder().typeName() != null) { typeModelBuilders.push(new TypeModelBuilder(astNodeFactory)); } currentTypeModelBuilder().withTypeName(node.getName()) .withModifiers(node.modifiers()) .withSuperType(node.getSuperclassType()) .withIsInterface(node.isInterface()); return true; }
@Override public void endVisit(TypeDeclaration node) { if (typeModelBuilders.size() > 1) { TypeModel typeModel = typeModelBuilders.pop().build(); currentTypeModelBuilder().withInnerType(typeModel); } }
public boolean visit(TypeDeclaration typeDeclaration) { List<Type> supertypes = new ArrayList<Type>(); Type superclass = typeDeclaration.getSuperclassType(); if (superclass != null) { supertypes.add(superclass); } supertypes.addAll(typeDeclaration.superInterfaceTypes()); RastNode sdType = visitTypeDeclaration(typeDeclaration, supertypes, typeDeclaration.isInterface() ? NodeTypes.INTERFACE_DECLARATION : NodeTypes.CLASS_DECLARATION); containerStack.push(sdType); if (typeDeclaration.isInterface()) { sdType.addStereotypes(Stereotype.ABSTRACT); } return true; }
public boolean visit(TypeDeclaration typeDeclaration) { List<Type> supertypes = new ArrayList<Type>(); Type superclass = typeDeclaration.getSuperclassType(); if (superclass != null) { supertypes.add(superclass); } supertypes.addAll(typeDeclaration.superInterfaceTypes()); SDType sdType = visitTypeDeclaration(typeDeclaration, supertypes); containerStack.push(sdType); sdType.setIsInterface(typeDeclaration.isInterface()); return true; }
public boolean visit(CompilationUnit node) { IJavaElement thisFile = node.getJavaElement(); for (Object abstractTypeDeclaration : node.types()) { if (abstractTypeDeclaration instanceof TypeDeclaration) { TypeDeclaration td = (TypeDeclaration) abstractTypeDeclaration; typeToFileMap_.put(getQualifiedName(td.resolveBinding()), thisFile); } } return true; }
@Override public boolean visit(TypeDeclaration node) { BlockInfo block = createBlock(node); current = block; current.setId(node.getName().toString()); if(node.getParent() instanceof CompilationUnit) roots.add(block); return true; }
private void updateTypeAnnotationDomains(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName, ASTNode after, ASTNode current) { SingleMemberAnnotation newParamAnnotation = getTypeAnnotationDomain(rewrite, typeDeclaration, annotation, domainName); ListRewrite paramRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY); paramRewrite.replace(current, newParamAnnotation, null); }
private List<MethodDeclaration> extractPrivateConstructors(TypeDeclaration mainType) { return Arrays.stream(mainType.getMethods()) .filter(method -> method.isConstructor()) .filter(method -> method.parameters().size() == 1) .filter(isPrivatePredicate) .collect(Collectors.toList()); }
private void addValueFlow(OOGContext value, OObject O_C, QualifiedClassName cthis, NewObjectInstruction instr, AnnotationInfo pInfo) { Variable l = instr.getTarget(); DomainP owner = Utils.getOwner(cthis, pInfo); OObject o = value.getO(); TypeDeclaration typeDecl = pointsToAnalysis.getTypeDecl(ast.Type.createFrom(instr.resolveInstantiatedType())); IMethodBinding mb = instr.resolveBinding().getMethodDeclaration(); ThisVariable that = getThatVariable(mb, typeDecl); FlowAnnot flowAnnot = new FlowAnnot(getInvocation(o,instr), FlowAnnotType.CALL); if (that != null) { FlowGraphNode src = new FlowGraphNode(o, l, owner); FlowGraphNode dst = new FlowGraphNode(O_C, that, new DomainP(O_C.getQCN(), Constants.OWNER)); FlowGraphEdge edge = new FlowGraphEdge(src, dst, flowAnnot); value.getFG().addInfoFlow(edge); } List<Variable> argOperands = instr.getArgOperands(); List<Variable> fparams = getFormalParams(mb, typeDecl); for (Variable a : argOperands) { List<DomainP> list = value.getGamma().get(a); boolean condition = list != null && list.size() > 0 && fparams!=null && fparams.size()>0 && argOperands.size()==fparams.size() && !(a.resolveType().isPrimitive()); if (condition) { Variable fParam = fparams.get(argOperands.indexOf(a)); List<DomainP> declaredParamDomains = getDomainsOfFormalParams(mb, typeDecl, cthis, argOperands.indexOf(a)); if (declaredParamDomains != null && declaredParamDomains.size() > 0) { FlowGraphNode src2 = new FlowGraphNode(o, a, list.get(0)); FlowGraphNode dst2 = new FlowGraphNode(O_C, fParam, declaredParamDomains.get(0)); FlowGraphEdge edge2 = new FlowGraphEdge(src2, dst2, flowAnnot); value.getFG().addInfoFlow(edge2); } } else { // try again later - argument is a field and was not properly // handled yet } } }
private void traverseType(TypeDeclaration declaration) { if(baseTraceabilityObject !=null ){ DeclarationVisitor visitor = new DeclarationVisitor(declaration, baseTraceabilityObject); if(visitor.getEnclosingDeclaration()!=null || visitor.getExpressions() !=null){ this.visitor = visitor; } } }
@Override public boolean visit(TypeDeclaration pClassNode) { if (firstTime) { firstTime = false; return true; } return firstTime; }
@Override public boolean visit(TypeDeclaration typeDeclaration) { ITypeBinding binding = typeDeclaration.resolveBinding(); if (binding != null) { IType type = (IType) binding.getJavaElement(); TypeDetails typeDetails = new TypeDetails(); typeDetails.setModifiers(typeDeclaration.getModifiers()); allDetails.put(type.getHandleIdentifier(), typeDetails); } return true; }
private void traverseType(TypeDeclaration declaration) { if(baseTraceabilityObject !=null ){ DeclarationVisitor myVisitor = new DeclarationVisitor(declaration, baseTraceabilityObject); if(myVisitor.getEnclosingDeclaration() !=null ) foundEnclosingDeclaration = myVisitor.getEnclosingDeclaration(); if(myVisitor.getExpressions() != null){ expressionsFound = myVisitor.getExpressions(); } } }