Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.TypeDeclaration


        return Status.OK_STATUS;
      }

      // Insert class
      if (selectedElement.getNodeType() == BodyDeclaration.TYPE_DECLARATION) {
        TypeDeclaration typeDec = (TypeDeclaration) selectedElement;
        String name = typeDec.getName().toString();
        String sourceCode = (String) selectedElement
            .getProperty(ResultProperty.RAW_SOURCE.name());

        // If a CompilatonUnit with the same name exists and is
        // opened, we must close it before overwrite.
View Full Code Here


    protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
        assert rewrite != null;
        assert workingUnit != null;
        assert bug != null;

        TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
        FieldDeclaration field = getFieldDeclaration(type, bug.getPrimaryField());

        Modifier finalModifier = workingUnit.getAST().newModifier(getModifierToAdd());

        ListRewrite modRewrite = rewrite.getListRewrite(field, FieldDeclaration.MODIFIERS2_PROPERTY);
View Full Code Here

    protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
        assert rewrite != null;
        assert workingUnit != null;
        assert bug != null;

        TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
        MethodDeclaration method = getMethodDeclaration(type, bug.getPrimaryMethod());

        AST ast = rewrite.getAST();

        SuperMethodInvocation superCall = createSuperMethodInvocation(rewrite, method);
View Full Code Here

    @Override
    public boolean visit(Javadoc node) {
      try {
        if (node.getParent() instanceof TypeDeclaration) {
          TypeDeclaration parent = (TypeDeclaration) node.getParent();
       
          if (parentMatches(parent, cls)) {         
            for (Object o : node.tags()) {
              TagElement tag = (TagElement) o;
              JavadocTagElement docs = handleTagFragment(tag, cls);
View Full Code Here

    List<?> types = astNode.types();
    for (int i = 0; i < types.size(); i++) {
      AbstractTypeDeclaration declaration = (AbstractTypeDeclaration) types
          .get(i);
      if (declaration instanceof TypeDeclaration) {
        TypeDeclaration typeDeclaration = (TypeDeclaration) declaration;
        IType type = ((ICompilationUnit) getJavaElement())
            .getType(typeDeclaration.getName().getIdentifier());
        AbstractMetricElement next = new TypeMetric(type
            .getHandleIdentifier(), typeDeclaration, analyzer);
        if (next != null)
          addChild(next);
        else
View Full Code Here

            }
          }
          inner = new EnumMetric(types[i].getHandleIdentifier(),
              enumDecl, analyzer);
        } else {
          TypeDeclaration typeDecl = null;
          for (TypeDeclaration decl : typeDecls) {
            if (decl.getName().toString().compareTo(
                types[i].getElementName()) == 0) {
              typeDecl = decl;
              break;
View Full Code Here

        ImportDeclaration importDecl = ast.newImportDeclaration();
        importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
        astRoot.imports().add(importDecl);

        // Add Async to the name
        TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
        String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName() + "Async"; //$NON-NLS-1$
        aRemoteService.setName(astRoot.getAST().newSimpleName(remoteServiceAsyncName));

        // Remote all interfaces
        aRemoteService.superInterfaceTypes().clear();

        // Change methods, fields and inner classes
        List bodyDeclarations = aRemoteService.bodyDeclarations();
        List declarationsToDelete = new ArrayList();
        for (Iterator k = bodyDeclarations.iterator(); k.hasNext();) {

          Object currDeclaration = k.next();
View Full Code Here

        ImportDeclaration importDecl = ast.newImportDeclaration();
        importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
        astRoot.imports().add(importDecl);

        // Add Async to the name
        TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
        String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName()+"Async"; //$NON-NLS-1$
        aRemoteService.setName(astRoot.getAST().newSimpleName(remoteServiceAsyncName));
       
        // Remote all interfaces
        aRemoteService.superInterfaceTypes().clear();
       
        // Change methods, fields and inner classes
        List bodyDeclarations = aRemoteService.bodyDeclarations();
        List declarationsToDelete = new ArrayList();
        for (Iterator k = bodyDeclarations.iterator(); k.hasNext();) {
         
          Object currDeclaration = k.next();
         
View Full Code Here

      superTypeName = superType.toString();
    }
    /*
     * build the new class using AST
     */
    TypeDeclaration newType = ast.newTypeDeclaration();
    newType.setInterface(node.isInterface());
    newType.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
    newType.setName(ast.newSimpleName(node.getName().getIdentifier()));
    newType.setSuperclassType(ast.newSimpleType(ast.newSimpleName(superTypeName)));
    /*
     * create the get and set methods only
     */
    MethodDeclaration[] methods = node.getMethods();
    setMethods = new ArrayList<MethodDeclaration>();
    getMethods = new ArrayList<MethodDeclaration>();

    for (MethodDeclaration method : methods){
      if (method.isConstructor()) // it is a constructor
        continue;
     
      if (method.thrownExceptions().size() > 0) // it throws exceptions
        continue;
     
      if ((method.getModifiers() & Modifier.PUBLIC) == 0) // is not public
        continue;
     
      if (method.getName().getIdentifier().startsWith("get")) {
        MethodDeclaration newMethod = copyMethodDeclaration(newType.getAST(), method);
        getMethods.add(method);
        /*
         * the statement
         */
        org.eclipse.jdt.core.dom.Block block = ast.newBlock();
        MethodInvocation methodInvocation = ast.newMethodInvocation();
        methodInvocation.setName(ast.newSimpleName("get"));
       
        /*
         * the parameter
         */
        String thePropertyKey = method.getName().toString().substring(3);
        StringLiteral literal = ast.newStringLiteral();
        literal.setLiteralValue(thePropertyKey);
       
        methodInvocation.arguments().add(literal);
       
        /*
         * the return statement
         */
        ReturnStatement returnStatement = ast.newReturnStatement();
        returnStatement.setExpression(methodInvocation);

        block.statements().add(returnStatement); //add the return statement to the block
        newMethod.setBody(block); // add the block to the method
        newType.bodyDeclarations().add(newMethod); //add the method to the type
       
      }
      if (method.getName().getIdentifier().startsWith("set")) {
        List<SingleVariableDeclaration> parameters = method.parameters();
        if (parameters.size() != 1)
          continue;
        setMethods.add(method);
        MethodDeclaration newMethod = copyMethodDeclaration(newType.getAST(), method);
        SingleVariableDeclaration oldParameter = parameters.get(0);
        SimpleName paramName = oldParameter.getName();
        /*
         * the statement
         */
        org.eclipse.jdt.core.dom.Block block = ast.newBlock();
        MethodInvocation methodInvocation = ast.newMethodInvocation();
        methodInvocation.setName(ast.newSimpleName("set"));
       
        /*
         * the parameters
         */
        String thePropertyKey = method.getName().toString().substring(3);
        StringLiteral literal = ast.newStringLiteral();
        literal.setLiteralValue(thePropertyKey);
        methodInvocation.arguments().add(literal);
        methodInvocation.arguments().add(paramName.copySubtree(newMethod.getAST(), paramName));
       
        ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
        block.statements().add(expressionStatement);
         
        newMethod.setBody(block); // add the block to the method
        newType.bodyDeclarations().add(newMethod); //add the method to the type
       
      }
    }
   

   
   
    /*
     * create the new class
     */
    try {
      IType newClass = this.newCompilationUnit.createType(newType.toString(), null, true, null);
     
      /*
       * add a new method to the original class. this method makes the new object from the old
       */
      // creation of a Document
View Full Code Here

    // Modify imports (+AsyncCallback, -RemoteService, -*Exception)
    updateImports(astRoot, ast);

    // Add Async to the name
    TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
    String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName() + "Async"; //$NON-NLS-1$
    aRemoteService.setName(astRoot.getAST().newSimpleName(remoteServiceAsyncName));

    // Remote all interfaces
    aRemoteService.superInterfaceTypes().clear();

    updateModifier(aRemoteService);

    // Change methods, fields and inner classes
    List bodyDeclarations = aRemoteService.bodyDeclarations();
    List declarationsToDelete = new ArrayList();
    for (Iterator k = bodyDeclarations.iterator(); k.hasNext();) {

      Object currDeclaration = k.next();

View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.TypeDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.