ImportDeclaration id = ast.newImportDeclaration(); String classToImport = "path.to.some.class"; id.setName(ast.newName(classToImport.split("\\.")));
id.setName(ast.newName(new String[] { "java", "util", "Set" })); cu.imports().add(id);
/** * Creates an invocation of a method that takes zero or one argument * * @param receiver the receiver name * @param methodName the method name * @param argument the argument, can be <code>null</code> if the method does not take any arguments * @return MethodInvocation in following form: <code>expression.methodName(argument)</code> */ protected MethodInvocation createMethodInvocation(String receiver, String methodName, Expression argument) { return createMethodInvocation(fAst.newName(receiver), methodName, argument); }
/** * Creates an invocation of a method that takes zero or one argument * * @param receiver the receiver name * @param methodName the method name * @param argument the argument, can be <code>null</code> if the method does not take any arguments * @return MethodInvocation in following form: <code>expression.methodName(argument)</code> */ protected MethodInvocation createMethodInvocation(String receiver, String methodName, Expression argument) { return createMethodInvocation(fAst.newName(receiver), methodName, argument); }
@Override public AnnotationSource<O> setName(final String className) { annotation.setTypeName(ast.newName(className)); return this; }
@Override public AnnotationSource<O> setName(final String className) { annotation.setTypeName(ast.newName(className)); return this; }
@SuppressWarnings("unchecked") private Expression aggregate(final AST ast, final Expression publisher, final Expression subscriber) { // new AggregatePublishSubscriber<>(publish, subscribe) final SimpleType type = ast.newSimpleType(ast.newName("de.dentrassi.asyncapi.util.AggregatePublishSubscriber")); final ParameterizedType pt = ast.newParameterizedType(type); final ClassInstanceCreation cic = ast.newClassInstanceCreation(); cic.setType(pt); cic.arguments().add(publisher); cic.arguments().add(subscriber); return cic; }
private void addExceptionsToNewConstructor(MethodDeclaration newConstructor) { IMethodBinding constructorBinding= getSuperConstructorBinding(); if (constructorBinding == null) return; ITypeBinding[] exceptions= constructorBinding.getExceptionTypes(); for (int i= 0; i < exceptions.length; i++) { Name exceptionTypeName= fAnonymousInnerClassNode.getAST().newName(Bindings.getNameComponents(exceptions[i])); newConstructor.thrownExceptions().add(exceptionTypeName); } }
private void addNullAnnotation(ASTNode varDecl, ChildListPropertyDescriptor modifiers2Property, ASTRewrite rewrite, String nonNullType, AST ast) { ListRewrite listRewrite= rewrite.getListRewrite(varDecl, modifiers2Property); Annotation newAnnotation= ast.newMarkerAnnotation(); newAnnotation.setTypeName(ast.newName(nonNullType)); listRewrite.insertLast(newAnnotation, null); // null annotation is last modifier, directly preceding the type } }
/** * Add the appropriate import statement, then shorten the annotation's * name before adding it to the declaration. */ protected void addAnnotationAndImport(ModifiedDeclaration declaration, Annotation annotation) { declaration.addImport(this.annotationName); annotation.setTypeName(declaration.getAST().newName(this.shortAnnotationName())); this.addAnnotation(declaration, annotation); }
public static SingleVariableDeclaration createParameter(final AST ast, final String typeName, final String name, final ModifierKeyword... keywords) { final SingleVariableDeclaration arg = ast.newSingleVariableDeclaration(); arg.setName(ast.newSimpleName(name)); arg.setType(ast.newSimpleType(ast.newName(typeName))); make(arg, keywords); return arg; }
@SuppressWarnings("unchecked") @Override public O setPackage(final String name) { if (unit.getPackage() == null) { unit.setPackage(unit.getAST().newPackageDeclaration()); } unit.getPackage().setName(unit.getAST().newName(name)); return (O) this; }
private Expression createQualifiedReadAccessExpressionForEnclosingInstance(AST ast) { ThisExpression expression= ast.newThisExpression(); expression.setQualifier(ast.newName(new String[] { fType.getElementName()})); FieldAccess access= ast.newFieldAccess(); access.setExpression(expression); access.setName(ast.newSimpleName(fEnclosingInstanceFieldName)); return access; }
@Override public O setPackage(final String name) { if (unit.getPackage() == null) { unit.setPackage(unit.getAST().newPackageDeclaration()); } unit.getPackage().setName(unit.getAST().newName(name)); return (O) this; }
private Expression createQualifiedReadAccessExpressionForEnclosingInstance(AST ast) { ThisExpression expression= ast.newThisExpression(); expression.setQualifier(ast.newName(new String[] { fType.getElementName()})); FieldAccess access= ast.newFieldAccess(); access.setExpression(expression); access.setName(ast.newSimpleName(fEnclosingInstanceFieldName)); return access; }
private Expression createFieldAccess(ParameterInfo pi, AST ast, Expression qualifier) { if (qualifier instanceof Name) { Name name= (Name) qualifier; //create FQN for IPOR return ast.newName(JavaModelUtil.concatenateName(name.getFullyQualifiedName(), pi.getNewName())); } FieldAccess fa= ast.newFieldAccess(); fa.setName(ast.newSimpleName(pi.getNewName())); fa.setExpression(qualifier); return fa; }
public Type createType(boolean asTopLevelClass, CompilationUnitRewrite cuRewrite, int position) { String qualifier= asTopLevelClass ? fPackage : fEnclosingType; String concatenateName= JavaModelUtil.concatenateName(qualifier, fClassName); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); ContextSensitiveImportRewriteContext context= createParameterClassAwareContext(asTopLevelClass, cuRewrite, position); String addedImport= importRewrite.addImport(concatenateName, context); cuRewrite.getImportRemover().registerAddedImport(addedImport); AST ast= cuRewrite.getAST(); return ast.newSimpleType(ast.newName(addedImport)); }
private Expression createFieldAccess(ParameterInfo pi, AST ast, Expression qualifier) { if (qualifier instanceof Name) { Name name= (Name) qualifier; //create FQN for IPOR return ast.newName(JavaModelUtil.concatenateName(name.getFullyQualifiedName(), pi.getNewName())); } FieldAccess fa= ast.newFieldAccess(); fa.setName(ast.newSimpleName(pi.getNewName())); fa.setExpression(qualifier); return fa; }
public Type createType(boolean asTopLevelClass, CompilationUnitRewrite cuRewrite, int position) { String qualifier= asTopLevelClass ? fPackage : fEnclosingType; String concatenateName= JavaModelUtil.concatenateName(qualifier, fClassName); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); ContextSensitiveImportRewriteContext context= createParameterClassAwareContext(asTopLevelClass, cuRewrite, position); String addedImport= importRewrite.addImport(concatenateName, context); cuRewrite.getImportRemover().registerAddedImport(addedImport); AST ast= cuRewrite.getAST(); return ast.newSimpleType(ast.newName(addedImport)); }
private Expression createAccessExpressionToEnclosingInstanceFieldText(ASTNode node, IBinding binding, AbstractTypeDeclaration declaration) { if (Modifier.isStatic(binding.getModifiers())) return node.getAST().newName(JavaModelUtil.getTypeQualifiedName(fType.getDeclaringType())); else if ((isInAnonymousTypeInsideInputType(node, declaration) || isInLocalTypeInsideInputType(node, declaration) || isInNonStaticMemberTypeInsideInputType(node, declaration))) return createQualifiedReadAccessExpressionForEnclosingInstance(node.getAST()); else return createReadAccessExpressionForEnclosingInstance(node.getAST()); }