Beispiel #1
0
 /*
  * Package modifiers
  */
 @Override
 public String getPackage() {
   PackageDeclaration pkg = unit.getPackage();
   if (pkg != null) {
     return pkg.getName().getFullyQualifiedName();
   } else {
     return null;
   }
 }
 /*
  * @see ASTVisitor#visit(PackageDeclaration)
  */
 public boolean visit(PackageDeclaration node) {
   if (node.getAST().apiLevel() >= AST.JLS3) {
     if (node.getJavadoc() != null) {
       node.getJavadoc().accept(this);
     }
     for (Iterator it = node.annotations().iterator(); it.hasNext(); ) {
       Annotation p = (Annotation) it.next();
       p.accept(this);
       this.fBuffer.append(" "); // $NON-NLS-1$
     }
   }
   this.fBuffer.append("package "); // $NON-NLS-1$
   node.getName().accept(this);
   this.fBuffer.append(";"); // $NON-NLS-1$
   return false;
 }
Beispiel #3
0
 public static String qualifiedName(TypeDeclaration decl) {
   String name = decl.getName().getIdentifier();
   ASTNode parent = decl.getParent();
   // resolve full name e.g.: A.B
   while (parent != null && parent.getClass() == TypeDeclaration.class) {
     name = ((TypeDeclaration) parent).getName().getIdentifier() + "." + name;
     parent = parent.getParent();
   }
   // resolve fully qualified name e.g.: some.package.A.B
   if (decl.getRoot().getClass() == CompilationUnit.class) {
     CompilationUnit root = (CompilationUnit) decl.getRoot();
     if (root.getPackage() != null) {
       PackageDeclaration pack = root.getPackage();
       name = pack.getName().getFullyQualifiedName() + "." + name;
     }
   }
   return name;
 }
 private void updatePackageStatement(
     CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter, ICompilationUnit cu)
     throws JavaModelException {
   boolean defaultPackage = pkgName.length == 0;
   AST ast = astCU.getAST();
   if (defaultPackage) {
     // remove existing package statement
     PackageDeclaration pkg = astCU.getPackage();
     if (pkg != null) {
       int pkgStart;
       Javadoc javadoc = pkg.getJavadoc();
       if (javadoc != null) {
         pkgStart = javadoc.getStartPosition() + javadoc.getLength() + 1;
       } else {
         pkgStart = pkg.getStartPosition();
       }
       int extendedStart = astCU.getExtendedStartPosition(pkg);
       if (pkgStart != extendedStart) {
         // keep the comments associated with package declaration
         // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=247757
         String commentSource = cu.getSource().substring(extendedStart, pkgStart);
         ASTNode comment =
             rewriter.createStringPlaceholder(commentSource, ASTNode.PACKAGE_DECLARATION);
         rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, comment, null);
       } else {
         rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, null, null);
       }
     }
   } else {
     org.eclipse.jdt.core.dom.PackageDeclaration pkg = astCU.getPackage();
     if (pkg != null) {
       // rename package statement
       Name name = ast.newName(pkgName);
       rewriter.set(pkg, PackageDeclaration.NAME_PROPERTY, name, null);
     } else {
       // create new package statement
       pkg = ast.newPackageDeclaration();
       pkg.setName(ast.newName(pkgName));
       rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, pkg, null);
     }
   }
 }
Beispiel #5
0
 public boolean visit(PackageDeclaration node) {
   if (found(node, node) && this.resolveBinding) this.foundBinding = node.resolveBinding();
   return true;
 }
 public boolean visit(PackageDeclaration node) {
   new JavaNode(
       getCurrentContainer(), JavaNode.PACKAGE, null, node.getStartPosition(), node.getLength());
   return false;
 }
Beispiel #7
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.PackageDeclaration)
  */
 public boolean visit(PackageDeclaration node) {
   Name name = node.getName();
   fPackage = Factory.packageDescriptor(name.getFullyQualifiedName());
   return false;
 }
 /*
  * @see ASTVisitor#visit(PackageDeclaration)
  */
 @Override
 public boolean visit(PackageDeclaration node) {
   doVisitNode(node.getJavadoc());
   doVisitChildren(node.annotations());
   return false;
 }
 @Override
 public boolean visit(PackageDeclaration node) {
   packageName = node.getName().toString();
   return false;
 }
  @SuppressWarnings("unchecked")
  @Before
  public void setUp() {
    manager = ModelManager.getInstance();
    manager.clearModel();

    AST ast2 = AST.newAST(AST.JLS3);
    CompilationUnit cu2 = ast2.newCompilationUnit();
    PackageDeclaration pack2 = ast2.newPackageDeclaration();
    pack2.setName(ast2.newName("be.ac.ua.test.otherpack"));
    cu2.setPackage(pack2);
    TypeDeclaration type2 = ast2.newTypeDeclaration();
    type2.setName(ast2.newSimpleName("Foo"));

    cu2.types().add(type2); // created mock compilationunit containing package and class

    PackageRecorder prec2 = new PackageRecorder(pack2);
    prec2.storeChange(new Add()); // store the package addition
    ClassRecorder crec2 = new ClassRecorder(type2);
    declaredclassadd = new Add();
    crec2.storeChange(declaredclassadd);

    AST ast = AST.newAST(AST.JLS3);
    CompilationUnit cu = ast.newCompilationUnit();
    PackageDeclaration pack = ast.newPackageDeclaration();
    pack.setName(ast.newName(packname));
    cu.setPackage(pack);
    TypeDeclaration type = ast.newTypeDeclaration();
    type.setName(ast.newSimpleName(classname));

    cu.types().add(type);

    PackageRecorder prec = new PackageRecorder(pack);
    prec.storeChange(new Add()); // store the package addition
    ClassRecorder crec = new ClassRecorder(type);
    classadd = new Add();
    crec.storeChange(classadd);

    // Class and package created and changes logged, now create the Field.

    VariableDeclarationFragment frag1 = ast.newVariableDeclarationFragment();
    frag1.setName(ast.newSimpleName(intfieldname));
    FieldDeclaration field = ast.newFieldDeclaration(frag1);
    field.setType(ast.newPrimitiveType(PrimitiveType.INT)); // field has type int
    type.bodyDeclarations().add(field);

    VariableDeclarationFragment frag2 = ast.newVariableDeclarationFragment();
    frag2.setName(ast.newSimpleName(fieldname));
    FieldDeclaration field2 = ast.newFieldDeclaration(frag2);
    field2.setType(ast.newSimpleType(ast.newName(declaredTypeName))); // field has type Foo
    type.bodyDeclarations().add(field2);

    VariableDeclarationFragment frag3 = ast.newVariableDeclarationFragment();
    frag3.setName(ast.newSimpleName(field3Name));
    FieldDeclaration field3 = ast.newFieldDeclaration(frag3);
    field3.setType(ast.newSimpleType(ast.newName("Foo"))); // field has type Foo
    type.bodyDeclarations().add(field3);

    ImportDeclaration imp = ast.newImportDeclaration();
    imp.setName(ast.newName(declaredTypeName));
    cu.imports().add(imp);

    // created mock compilationunit containing package and class

    recorder1 = new FieldRecorder(field);
    recorder2 = new FieldRecorder(field2);
    recorder3 = new FieldRecorder(field3);
  }
 @Override
 public boolean visit(final PackageDeclaration node) {
   currentPackage = node.getName().getFullyQualifiedName();
   return false;
 }