/** * Create the default empty constructor. * * @param target * the class to insert the constructor into * @return the created constructor */ public <T> CtConstructor<T> createDefault(CtClass<T> target) { CtConstructor<T> constructor = factory.Core().createConstructor(); constructor.addModifier(ModifierKind.PUBLIC); target.addConstructor(constructor); return constructor; }
@Override public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) { CtConstructor<Object> c = factory.Core().createConstructor(); // if the source start of the class is equals to the source start of the constructor // it means that the constructor is implicit. c.setImplicit(scope.referenceContext.sourceStart() == constructorDeclaration.sourceStart()); if (constructorDeclaration.binding != null) { c.setExtendedModifiers(getModifiers(constructorDeclaration.binding.modifiers, true, true)); } // avoid to add explicit modifier to implicit constructor if (!c.isImplicit()) { for (CtExtendedModifier extendedModifier : getModifiers(constructorDeclaration.modifiers, false, true)) { c.addModifier(extendedModifier.getKind()); // avoid to keep implicit AND explicit modifier of the same kind. } } context.enter(c, constructorDeclaration); // Create block context.enter(factory.Core().createBlock(), constructorDeclaration); context.exit(constructorDeclaration); return true; }
/** * Create the default empty constructor. * * @param target * the class to insert the constructor into * @return the created constructor */ public <T> CtConstructor<T> createDefault(CtClass<T> target) { CtConstructor<T> constructor = factory.Core().createConstructor(); constructor.addModifier(ModifierKind.PUBLIC); target.addConstructor(constructor); return constructor; }