/** * Creates a new parameter. */ public <T> CtParameter<T> createParameter(CtExecutable<?> parent, CtTypeReference<T> type, String name) { CtParameter<T> parameter = factory.Core().createParameter(); parameter.setType(type); parameter.setSimpleName(name); if (parent != null) { parent.addParameter(parameter); } return parameter; }
@Override public void visitParameter(RtParameter parameter) { final CtParameter ctParameter = factory.Core().createParameter(); ctParameter.setSimpleName(parameter.getName()); ctParameter.setVarArgs(parameter.isVarArgs()); //it is not possible to detect whether parameter is final in runtime // if (parameter.isFinal()) { // ctParameter.addModifier(ModifierKind.FINAL); // } enter(new VariableRuntimeBuilderContext(ctParameter)); super.visitParameter(parameter); exit(); contexts.peek().addParameter(ctParameter); }
/** * Creates a parameter. If the argument have a type == null, we get the type from its binding. A type == null is possible when * this type is implicit like in a lambda where you don't need to specify the type of parameters. * * @param argument * Used to get the name of the parameter, the modifiers, know if it is a var args parameter. * @return a parameter. */ <T> CtParameter<T> createParameter(Argument argument) { CtParameter<T> p = jdtTreeBuilder.getFactory().Core().createParameter(); p.setSimpleName(CharOperation.charToString(argument.name)); p.setVarArgs(argument.isVarArgs()); p.setExtendedModifiers(getModifiers(argument.modifiers, false, false)); if (argument.binding != null && argument.binding.type != null && argument.type == null) { p.setType(jdtTreeBuilder.getReferencesBuilder().<T>getTypeReference(argument.binding.type)); p.getType().setImplicit(argument.type == null); if (p.getType() instanceof CtArrayTypeReference) { ((CtArrayTypeReference) p.getType()).getComponentType().setImplicit(argument.type == null); } } return p; }
/** * Creates a new parameter. */ public <T> CtParameter<T> createParameter(CtExecutable<?> parent, CtTypeReference<T> type, String name) { CtParameter<T> parameter = factory.Core().createParameter(); parameter.setType(type); parameter.setSimpleName(name); if (parent != null) { parent.addParameter(parameter); } return parameter; }
@Override public boolean visit(Argument argument, BlockScope scope) { CtParameter<Object> p = factory.Core().createParameter(); p.setSimpleName(new String(argument.name)); p.setVarArgs(argument.isVarArgs()); p.setModifiers(getModifiers(argument.modifiers)); if (argument.type != null) { p.setType(references.getTypeReference(argument.type.resolvedType)); } else if (argument.binding != null && argument.binding.type != null) { if (argument.binding.type instanceof WildcardBinding) { p.setType(references.getTypeReference((((WildcardBinding) argument.binding.type).bound))); } else { p.setType(references.getTypeReference((argument.binding.type))); } } context.enter(p, argument); if (argument.initialization != null) { argument.initialization.traverse(this, scope); } if (argument.annotations != null) { for (Annotation a : argument.annotations) { // TODO Sorry for that but there is a bug in JDT : https://bugs.eclipse.org/bugs/show_bug.cgi?id=459528 if (isContainsInTypeAnnotation(argument.type.resolvedType, a)) { a.traverse(this, scope); } } } return false; }