Package org.eclipse.jdt.core.dom

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


        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


     @return The type declaration of the proxy class.
     */
    private TypeDeclaration _createProxyClass(AST ast, CompilationUnit root,
            TypeAnalyzerState state) {
        // Create the nested class.
        TypeDeclaration classDeclaration = ast.newTypeDeclaration();
        classDeclaration.setName(ast.newSimpleName(_getProxyName()));

        String rollbackType = getClassName(Rollbackable.class, state, root);
        classDeclaration.superInterfaceTypes().add(
                ast.newSimpleType(createName(ast, rollbackType)));

        // Add a commit method.
        MethodDeclaration commit = ast.newMethodDeclaration();
        commit.setName(ast.newSimpleName(_getCommitMethodName(false)));

        // Add two parameters.
        SingleVariableDeclaration timestamp = ast
                .newSingleVariableDeclaration();
        timestamp.setType(ast.newPrimitiveType(PrimitiveType.LONG));
        timestamp.setName(ast.newSimpleName("timestamp"));
        commit.parameters().add(timestamp);

        // Add a call to the restore method in the enclosing anonymous class.
        MethodInvocation invocation = ast.newMethodInvocation();
        invocation.setName(ast.newSimpleName(_getCommitMethodName(true)));
        invocation.arguments().add(ast.newSimpleName("timestamp"));

        Block body = ast.newBlock();
        body.statements().add(ast.newExpressionStatement(invocation));
        commit.setBody(body);

        commit.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
        commit.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
        classDeclaration.bodyDeclarations().add(commit);

        // Add a restore method.
        MethodDeclaration restore = ast.newMethodDeclaration();
        restore.setName(ast.newSimpleName(_getRestoreMethodName(false)));

        // Add two parameters.
        timestamp = ast.newSingleVariableDeclaration();
        timestamp.setType(ast.newPrimitiveType(PrimitiveType.LONG));
        timestamp.setName(ast.newSimpleName("timestamp"));
        restore.parameters().add(timestamp);

        SingleVariableDeclaration trim = ast.newSingleVariableDeclaration();
        trim.setType(ast.newPrimitiveType(PrimitiveType.BOOLEAN));
        trim.setName(ast.newSimpleName("trim"));
        restore.parameters().add(trim);

        // Add a call to the restore method in the enclosing anonymous class.
        invocation = ast.newMethodInvocation();
        invocation.setName(ast.newSimpleName(_getRestoreMethodName(true)));
        invocation.arguments().add(ast.newSimpleName("timestamp"));
        invocation.arguments().add(ast.newSimpleName("trim"));

        body = ast.newBlock();
        body.statements().add(ast.newExpressionStatement(invocation));
        restore.setBody(body);

        restore.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
        restore.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
        classDeclaration.bodyDeclarations().add(restore);

        // Add a get checkpoint method.
        MethodDeclaration getCheckpoint = ast.newMethodDeclaration();
        String checkpointType = getClassName(Checkpoint.class, state, root);
        getCheckpoint.setName(ast
                .newSimpleName(_getGetCheckpointMethodName(false)));
        getCheckpoint.setReturnType2(createType(ast, checkpointType));
        invocation = ast.newMethodInvocation();
        invocation
                .setName(ast.newSimpleName(_getGetCheckpointMethodName(true)));
        body = ast.newBlock();

        ReturnStatement returnStatement = ast.newReturnStatement();
        returnStatement.setExpression(invocation);
        body.statements().add(returnStatement);
        getCheckpoint.setBody(body);

        getCheckpoint.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
        getCheckpoint.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
        classDeclaration.bodyDeclarations().add(getCheckpoint);

        // Add a set checkpoint method.
        MethodDeclaration setCheckpoint = ast.newMethodDeclaration();
        setCheckpoint.setName(ast
                .newSimpleName(_getSetCheckpointMethodName(false)));
        setCheckpoint.setReturnType2(createType(ast, getClassName(Object.class,
                state, root)));

        // Add a single checkpoint parameter.
        SingleVariableDeclaration checkpoint = ast
                .newSingleVariableDeclaration();
        checkpoint.setType(createType(ast, checkpointType));
        checkpoint.setName(ast.newSimpleName("checkpoint"));
        setCheckpoint.parameters().add(checkpoint);

        // Add a call to the setcheckpoint method in the enclosing anonymous
        // class.
        invocation = ast.newMethodInvocation();
        invocation
                .setName(ast.newSimpleName(_getSetCheckpointMethodName(true)));
        invocation.arguments().add(ast.newSimpleName("checkpoint"));

        // Return this object.
        returnStatement = ast.newReturnStatement();
        returnStatement.setExpression(ast.newThisExpression());

        body = ast.newBlock();
        body.statements().add(ast.newExpressionStatement(invocation));
        body.statements().add(returnStatement);
        setCheckpoint.setBody(body);

        setCheckpoint.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
        setCheckpoint.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
        classDeclaration.bodyDeclarations().add(setCheckpoint);

        classDeclaration.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
        return classDeclaration;
    }
View Full Code Here

        }

        // Add an interface.
        if (!ignore) {
            if (isAnonymous) {
                TypeDeclaration proxy = _createProxyClass(ast, root, state);
                bodyDeclarations.add(proxy);

                if (declarationRecord != null) {
                    declarationRecord._addExtendedDeclaration(proxy);
                }
            } else {
                // Set the class to implement Rollbackable.
                if (node instanceof TypeDeclaration) {
                    String rollbackType = getClassName(Rollbackable.class,
                            state, root);
                    ((TypeDeclaration) node).superInterfaceTypes().add(
                            ast.newSimpleType(createName(ast, rollbackType)));
                }

                if (!isInterface) {
                    // Create a checkpoint field.
                    FieldDeclaration checkpointField = _createCheckpointField(
                            ast, root, state);

                    if (checkpointField != null) {
                        bodyDeclarations.add(0, checkpointField);
                    }

                    // Create a record for the checkpoint field.
                    FieldDeclaration record = _createCheckpointRecord(ast,
                            root, state);

                    if (record != null) {
                        newFields.add(0, record);
                    }
                }
            }
        }

        // Add all the methods and then all the fields.
        if (!ignore) {
            bodyDeclarations.addAll(newMethods);
            bodyDeclarations.addAll(newFields);
        } else {
            if (declarationRecord != null) {
                declarationRecord._addFixedDeclarations(newMethods);
                declarationRecord._addFixedDeclarations(newFields);
            }
        }

        if (isAnonymous && !ignore) {
            // Create a simple initializer.
            Initializer initializer = ast.newInitializer();
            Block body = ast.newBlock();
            initializer.setBody(body);

            MethodInvocation addInvocation = ast.newMethodInvocation();
            addInvocation.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
            addInvocation.setName(ast.newSimpleName("addObject"));

            ClassInstanceCreation proxy = ast.newClassInstanceCreation();
            proxy
                    .setType(ast.newSimpleType(ast
                            .newSimpleName(_getProxyName())));
            addInvocation.arguments().add(proxy);
            body.statements().add(ast.newExpressionStatement(addInvocation));
            bodyDeclarations.add(initializer);
View Full Code Here

            // Do not type check some simple names.
            if (parent instanceof QualifiedName) {
                handle = false;
            } else if (parent instanceof TypeDeclaration) {
                TypeDeclaration type = (TypeDeclaration) parent;

                if (type.getName() == node) {
                    handle = false;
                }
            } else if (parent instanceof BodyDeclaration) {
                handle = false;
            } else if (parent instanceof BreakStatement
View Full Code Here

  public void addFieldAnnotation(String targetClass, String targetField, Class<? extends java.lang.annotation.Annotation> annotation, Map<String, Object> properties) {
    try {
      CompilationUnit cu = compilationUnitCache.getCompilationUnit(targetClass);

      TypeDeclaration typeDeclaration = compilationUnitCache.getTypeDeclaration(targetClass);
      FieldDeclaration[] fields = typeDeclaration.getFields();

      Iterator<FieldDeclaration> iterator = Arrays.asList(fields).iterator();
      while (iterator.hasNext()) {
        FieldDeclaration field = iterator.next();
        if (field.fragments().size() == 0) {
View Full Code Here

  }

  @SuppressWarnings("unchecked")//$NON-NLS-1$
  public void removeInterface(String targetClass, String interfaceToRemove) {
    try {
      TypeDeclaration typeDeclaration = compilationUnitCache.getTypeDeclaration(targetClass);

      Iterator iter = typeDeclaration.superInterfaceTypes().iterator();
      while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof SimpleType) {
          SimpleType type = (SimpleType) obj;
          String qualifiedName = type.resolveBinding().getQualifiedName();
View Full Code Here

  public void removeAbstractModifierFromMethod(String targetClass, String methodName, String[] signature, String methodBody) {
    try {
      String code = methodBody;

      TypeDeclaration typeDeclaration = compilationUnitCache.getTypeDeclaration(targetClass);
      MethodDeclaration methodDeclaration = getMethodDeclaration(typeDeclaration, methodName, signature);
      removeAbstractModifier(methodDeclaration.modifiers());

      List parameters = methodDeclaration.parameters();
      for (int i = 0; i < parameters.size(); i++) {
View Full Code Here

    }
  }

  public boolean classImplements(String targetClass, String targetInterface) {
    try {
      TypeDeclaration typeDeclaration = compilationUnitCache.getTypeDeclaration(targetClass);

      Iterator iter = typeDeclaration.superInterfaceTypes().iterator();
      while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof SimpleType) {
          SimpleType type = (SimpleType) obj;
          String qualifiedName = type.resolveBinding().getQualifiedName();
View Full Code Here

    return false;
  }

  public String getSuperClass(String targetClass) {
    try {
      TypeDeclaration type = compilationUnitCache.getTypeDeclaration(targetClass);
      Type superclassType = type.getSuperclassType();

      if (superclassType == null) {
        return targetClass;
      }
View Full Code Here

  }

  public void addField(String targetClass, String fieldName, String fieldType) {
    try {
      CompilationUnit compilationUnit = compilationUnitCache.getCompilationUnit(targetClass);
      TypeDeclaration typeDeclaration = compilationUnitCache.getTypeDeclaration(targetClass);

      VariableDeclarationFragment variableDeclaration = typeDeclaration.getAST().newVariableDeclarationFragment();
      variableDeclaration.setName(typeDeclaration.getAST().newSimpleName(fieldName));

      FieldDeclaration fieldDeclaration = typeDeclaration.getAST().newFieldDeclaration(variableDeclaration);
      Type type = JDTUtils.createQualifiedType(compilationUnit.getAST(), fieldType);
      fieldDeclaration.setType(type);
      Modifier privateModifier = fieldDeclaration.getAST().newModifier(ModifierKeyword.PRIVATE_KEYWORD);
      fieldDeclaration.modifiers().add(privateModifier);
      typeDeclaration.bodyDeclarations().add(fieldDeclaration);
    } catch (Exception e) {
      warnings.add(String.format(Messages.getString("org.apache.openejb.helper.annotation.warnings.11"), fieldName, targetClass)); //$NON-NLS-1$
    }

  }
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.