Package org.eclipse.jdt.core.dom

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


        List<Type> newSuperInterfaces = getNewSuperInterfaces(typeDeclaration
                .superInterfaceTypes(), newJavaFileVisitor);
        for (Type newSuperInterface : newSuperInterfaces) {
            if (newSuperInterface.isSimpleType()) {
                SimpleType st = (SimpleType) newSuperInterface;
                Name name = ast.newName(st.getName().getFullyQualifiedName());
                SimpleType newSt = ast.newSimpleType(name);
                typeDeclaration.superInterfaceTypes().add(newSt);
            } else {
                // this shouldn't happen - MyBatis Generator only generates simple names
                throw new ShellException("The Java file merger only supports simple types as super interfaces");
            }
        }

        // set the superclass
        if (newJavaFileVisitor.getSuperclass() != null) {
            if (newJavaFileVisitor.getSuperclass().isSimpleType()) {
                SimpleType st = (SimpleType) newJavaFileVisitor.getSuperclass();
                Name name = ast.newName(st.getName().getFullyQualifiedName());
                SimpleType newSt = ast.newSimpleType(name);
                typeDeclaration.setSuperclassType(newSt);
            } else {
                // this shouldn't happen - MyBatis Generator only generates simple names
                throw new ShellException("The Java file merger only supports simple types as super classes");
            }
        } else {
            typeDeclaration.setSuperclassType(null);
        }

        // interface or class?
        if (newJavaFileVisitor.isInterface()) {
            typeDeclaration.setInterface(true);
        } else {
            typeDeclaration.setInterface(false);
        }

        // reconcile the imports
        List<ImportDeclaration> newImports = getNewImports(cu.imports(), newJavaFileVisitor);
        for (ImportDeclaration newImport : newImports) {
            Name name = ast.newName(newImport.getName().getFullyQualifiedName());
            ImportDeclaration newId = ast.newImportDeclaration();
            newId.setName(name);
            cu.imports().add(newId);
        }
View Full Code Here


        // reconcile the imports
        List<ImportDeclaration> newImports = getNewImports(cu.imports(),
                newJavaFileVisitor);
        for (ImportDeclaration newImport : newImports) {
            Name name = ast
                    .newName(newImport.getName().getFullyQualifiedName());
            ImportDeclaration newId = ast.newImportDeclaration();
            newId.setName(name);
            cu.imports().add(newId);
        }
View Full Code Here

    // colocar imports
    for (CompilationUnit cu : result) {
      ImportVisitor cv = new ImportVisitor();
      cu.accept(cv);
      Name packageName = cu.getPackage().getName();
      // System.out.println("Superclass: " + cv.getSuperClassName());

      List<String> importedPackages = new ArrayList<String>();

      for (CompilationUnit cu2 : result) {
        Name packageToCompare = cu2.getPackage().getName();
        ImportDeclaration importDeclaration = null;
        if (packageName.getFullyQualifiedName().equals(
            packageToCompare.getFullyQualifiedName()))
          continue;
        ImportCheckerVisitor iv = new ImportCheckerVisitor();
        cu2.accept(iv);

        // adiciona o import para super class
        if (iv.getClassName().equals(cv.getSuperClassName())) {
          importDeclaration = importPacakge(packageToCompare);

        }
        // adiciona o import para fields
        else {
          for (String fieldType : cv.getFieldTypes()) {
            if (iv.getClassName().equals(fieldType)) {
              importDeclaration = importPacakge(packageToCompare);
              break;
            }
          }
          if (importDeclaration == null) {
            for (String instanceType : cv.getInstanceTypes()) {
              if (iv.getClassName().equals(instanceType)) {
                importDeclaration = importPacakge(packageToCompare);
                break;
              }
            }
          }

        }

        if (importDeclaration != null
            && !importedPackages.contains(packageToCompare
                .getFullyQualifiedName())) {
          importedPackages.add(packageToCompare
              .getFullyQualifiedName());
          cu.imports().add(importDeclaration);

        }
View Full Code Here

      }
     
      @SuppressWarnings("unchecked")
      List<MemberValuePair> pairs = node.values();
      for (MemberValuePair mvp : pairs) {
        Name attribute = mvp.getName();
        String name = attribute.getFullyQualifiedName();
        if ("groups".equals(name)) {
          Expression value = mvp.getValue();
          // Array?
          if (value instanceof ArrayInitializer) {
            ArrayInitializer ai = (ArrayInitializer) value;
View Full Code Here

    //
    // Remove some JUnit imports.
    //
    List<ImportDeclaration> oldImports = visitor.getJUnitImports();
    for (int i = 0; i < oldImports.size(); i++) {
      Name importName = oldImports.get(i).getName();
      String fqn = importName.getFullyQualifiedName();
      if (IMPORTS_TO_REMOVE.contains(fqn)) {
        result.remove(oldImports.get(i), null);
      }
      for (String s : STATIC_IMPORTS_TO_REMOVE) {
        if (fqn.contains(s)) {
          result.remove(oldImports.get(i), null);
        }
      }
    }
   
    //
    // Add imports as needed
    //
    maybeAddImport(ast, result, astRoot, visitor.hasAsserts(), "org.testng.AssertJUnit");
    maybeAddImport(ast, result, astRoot, visitor.hasFail(), "org.testng.Assert");
    maybeAddImport(ast, result, astRoot, !visitor.getBeforeClasses().isEmpty(),
    "org.testng.annotations.BeforeClass");
    maybeAddImport(ast, result, astRoot, !visitor.getBeforeMethods().isEmpty(),
        "org.testng.annotations.BeforeMethod");
    maybeAddImport(ast, result, astRoot, visitor.hasTestMethods(), "org.testng.annotations.Test");
    maybeAddImport(ast, result, astRoot, !visitor.getAfterMethods().isEmpty(),
        "org.testng.annotations.AfterMethod");
    maybeAddImport(ast, result, astRoot, !visitor.getAfterClasses().isEmpty(),
    "org.testng.annotations.AfterClass");

    //
    // Add static imports
    //
    Set<String> staticImports = visitor.getStaticImports();
    for (String si : staticImports) {
      addImport(ast, result, astRoot, "org.testng.AssertJUnit." + si, true /* static import */);
    }

    //
    // Remove "extends TestCase"
    //
    SimpleType td = visitor.getTestCase();
    if (null != td) {
      result.remove(td, null);
    }

    //
    // Addd the annotations as needed
    //
    maybeAddAnnotations(ast, visitor, result, visitor.getTestMethods(), "Test", null, null);
    maybeAddAnnotations(ast, visitor, result, visitor.getDisabledTestMethods(), "Test", null,
        createDisabledAttribute(ast));
    maybeAddAnnotations(ast, visitor, result, visitor.getBeforeMethods(), "BeforeMethod",
        "@Before" /* annotation to remove */);
    maybeAddAnnotations(ast, visitor, result, visitor.getAfterMethods(), "AfterMethod",
        "@After" /* annotation to remove */);

    //
    // suite() method: remove, comment out or leave untouched, depending on the setting
    //
    SuiteMethodTreatment smt = TestNGPlugin.getPluginPreferenceStore().getSuiteMethodTreatement();

    MethodDeclaration suiteMethod = visitor.getSuite();
    if (smt != SuiteMethodTreatment.DONT_TOUCH && suiteMethod != null) {
      if (smt == SuiteMethodTreatment.REMOVE) {
        // Remove suite()
        result.remove(suiteMethod, null);
      } else {
        // Comment out suite()
        TypeDeclaration type = visitor.getType();
        ListRewrite lr = result.getListRewrite(type, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
        lr.insertBefore(result.createStringPlaceholder("/*", ASTNode.METHOD_DECLARATION),
            suiteMethod, null);
        lr.insertAfter(result.createStringPlaceholder("*/", ASTNode.METHOD_DECLARATION),
            suiteMethod, null);
      }
    }

    //
    // Remove all the nodes that need to be removed
    //
    for (ASTNode n : visitor.getNodesToRemove()) {
      result.remove(n, null);
    }

    //
    // Replace @Ignore with @Test(enabled = false)
    //
    for (Map.Entry<MethodDeclaration, Annotation> e : visitor.getIgnoredMethods().entrySet()) {
      MethodDeclaration md = e.getKey();
      Annotation ignored = e.getValue();
      // Add the @Test(enabled = false)
      NormalAnnotation test = ast.newNormalAnnotation();
      test.setTypeName(ast.newName("Test"));
      MemberValuePair mvp = ast.newMemberValuePair();
      mvp.setName(ast.newSimpleName("enabled"));
      mvp.setValue(ast.newBooleanLiteral(false));
      test.values().add(mvp);
      result.remove(ignored, null);
      ListRewrite lr = result.getListRewrite(md, MethodDeclaration.MODIFIERS2_PROPERTY);
      lr.insertFirst(test, null);
    }

    //
    // Replace "Assert" with "AssertJUnit", unless the method is already imported statically.
    //
    Set<MethodInvocation> asserts = visitor.getAsserts();
    for (MethodInvocation m : asserts) {
      if (! staticImports.contains(m.getName().toString())) {
        Expression exp = m.getExpression();
        Name name = ast.newName("AssertJUnit");
        if (exp != null) {
          result.replace(exp, name, null);
        } else {
          result.set(m, MethodInvocation.EXPRESSION_PROPERTY, name, null);
        }
View Full Code Here

    m_assertMethods.add("assertArrayEquals");
  }

  @Override
  public boolean visit(ImportDeclaration id) {
    Name simpleName = id.getName();
    String name = simpleName.getFullyQualifiedName();
    if (name.indexOf("junit") != -1) {
      int ind = simpleName.toString().indexOf("assert");
      if (id.isStatic() && ind > 0) {
        m_assertStaticImports.add(simpleName.toString().substring(ind));
      }
      m_junitImports.add(id);
    }
    return super.visit(id);
  }
View Full Code Here

      if (locationInfo == null) {
        return Collections.emptyList();
      }

      Name typeName = annotation.getTypeName();
      return getBeanProposals(javaContext, type.getCompilationUnit(), javaContext.getInvocationOffset(),
          typeName.getFullyQualifiedName(), typeName.getStartPosition(), typeName.getLength());
    }

    // }
    // }
    return Collections.emptyList();
View Full Code Here

      isTypeDecl = true;
      return super.visit(typeDecl);
    }

    private boolean matches(Annotation annotation) {
      Name typeName = annotation.getTypeName();
      if (typeName != null) {
        if (invocationOffset >= 0) {
          int startPos = annotation.getStartPosition();
          if (startPos > invocationOffset || startPos + annotation.getLength() < invocationOffset) {
            return false;
          }
        }
        return annotationToMatch == null || typeName.toString().equals(annotationToMatch);
      }
      return false;
    }
View Full Code Here

TOP

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

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.