Package org.eclipse.jdt.core.dom

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


    return UIManager.getCrossPlatformLookAndFeelClassName();
  }

  private void parseEventListener(CompilationUnit cunit, WidgetAdapter adapter) throws ParserException {
    EventSetDescriptor[] esds = adapter.getBeanInfo().getEventSetDescriptors();
    TypeDeclaration type = (TypeDeclaration) cunit.types().get(0);
    if (esds != null && esds.length > 0) {
      for (EventSetDescriptor esd : esds) {
        factory.parseEventListener(adapter, type, esd);
      }
    }
View Full Code Here


    String name = getMethodName.substring(GET.length());
    name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
    return name;
  }
  public static String getGetMethodName(CompilationUnit cunit, final String fieldName){
    TypeDeclaration type = (TypeDeclaration) cunit.types().get(0);
    final String[]ret=new String[1];
    type.accept(new ASTVisitor(){
      @Override
      public boolean visit(ReturnStatement node) {
        Expression exp = node.getExpression();
        if(exp!=null&&exp instanceof SimpleName){
          String retName = ((SimpleName)exp).getFullyQualifiedName();
View Full Code Here

      ASTParser parser = ASTParser.newParser(AST.JLS3);
      parser.setSource(icunit);
      CompilationUnit cunit = (CompilationUnit) parser.createAST(null);
      cunit.recordModifications();
      AST ast = cunit.getAST();
      TypeDeclaration typeDec = (TypeDeclaration) cunit.types().get(0);
      List list = typeDec.superInterfaceTypes();
      Name name = ast.newName(cName);
      Type interfaceType = ast.newSimpleType(name);
      list.add(interfaceType);
      TextEdit edits = cunit.rewrite(document, icunit.getJavaProject()
          .getOptions(true));
View Full Code Here

    uberReturn = new EclipseCFGNode(null);
    uberReturn.setName("(uber-return)");
    createEdge(uberReturn, method);

    if (node.isConstructor()) {
      TypeDeclaration type = (TypeDeclaration) node.getParent();
      for (FieldDeclaration field : type.getFields()) {
        if (!Modifier.isStatic(field.getModifiers()))
          field.accept(this);
      }
    }
View Full Code Here

    createEdge(uberReturn, method);

    if (node.isConstructor()) {
      ITypeBinding parentClass = node.resolveBinding().getDeclaringClass();
      if (parentClass.isClass()) { //ignore enums or annotations, as they have constructors but not fields
        TypeDeclaration type = (TypeDeclaration) node.getParent();
        for (FieldDeclaration field : type.getFields()) {
          if (!Modifier.isStatic(field.getModifiers()))
            field.accept(this);
        }
      }
    }
View Full Code Here

    if (resultCompilationUnit != null) {
      BodyDeclaration typeDec = null;
      for (Object typeObject : resultCompilationUnit.types()) {
        BodyDeclaration typeBodyDec = (BodyDeclaration) typeObject;
        if (typeBodyDec.getNodeType() == BodyDeclaration.TYPE_DECLARATION) {
          TypeDeclaration type = (TypeDeclaration) typeBodyDec;
          if (type.getName().getFullyQualifiedName()
              .equals(getProperty(ResultProperty.NAME)))
            typeDec = type;
        }
        if (typeBodyDec.getNodeType() == BodyDeclaration.ENUM_DECLARATION) {
          EnumDeclaration type = (EnumDeclaration) typeBodyDec;
          if (type.getName().getFullyQualifiedName()
              .equals(getProperty(ResultProperty.NAME)))
            typeDec = type;
        }
      }
      return typeDec;
View Full Code Here

      String uri = new String(source);
      Search search = CodeConjurer.getInstance().getActiveEditorSearch();
      BodyDeclaration selectedElement = search.getSearchResult()
          .find(uri);
      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

    if (resultCompilationUnit != null) {
      BodyDeclaration declaration = null;
      for (Object typeObject : resultCompilationUnit.types()) {
        BodyDeclaration typeBodyDec = (BodyDeclaration) typeObject;
        if (typeBodyDec.getNodeType() == BodyDeclaration.TYPE_DECLARATION) {
          TypeDeclaration type = (TypeDeclaration) typeBodyDec;
          String typeName = type.getName().getFullyQualifiedName();
          String reportedName = getProperty(ResultProperty.NAME);
          if (typeName.equals(reportedName))
            declaration = type;
        }
        if (typeBodyDec.getNodeType() == BodyDeclaration.ENUM_DECLARATION) {
          EnumDeclaration type = (EnumDeclaration) typeBodyDec;
          if (type.getName().getFullyQualifiedName()
              .equals(getProperty(ResultProperty.NAME)))
            declaration = type;
        }
      }
      return copyProperties(declaration);
View Full Code Here

          .find(uri);

      // Insert class
      if (selectedElement.getNodeType() == BodyDeclaration.TYPE_DECLARATION) {
        monitor.beginTask("Insert class into package", 2);
        TypeDeclaration typeDec = (TypeDeclaration) selectedElement;

        String adapterCode = null;

        // If this is a result from test-driven search and an adapter is
        // present, use it.
        if (Integer.parseInt((String) typeDec
            .getProperty(ResultProperty.SEARCH_KIND.name())) == Search.TEST_DRIVEN_SEARCH) {
          adapterCode = (String) typeDec
              .getProperty(ResultProperty.TEST_RESULT.name());
          if (adapterCode.contains("<adapter>false</adapter>")) {
            adapterCode = null; // Only if an adapter is necessary,
                      // we leave this value set
          }
        }

        String name = typeDec.getName().toString();
        String sourceCode = (String) selectedElement
            .getProperty(ResultProperty.RAW_SOURCE.name());

        /** Indicates if an adapter was created */
        boolean adapted = false;

        /* Insert the adapter if the user wishes */
        if (Activator.getDefault().getPreferenceStore()
            .getBoolean(PreferenceConstants.P_SHOW_ADAPTER)) {
          if (adapterCode != null) {
            adapterCode = adapterCode
                .replace(
                    "merobase_auto_generated_package_for_adaptation",
                    pkg.getElementName());

            monitor.subTask("Insert adapter class");
            // Find out the name of the adapter
            ASTParser parser = ASTParser.newParser(AST.JLS3);
            parser.setSource(adapterCode.toCharArray());
            CompilationUnit astRoot = (CompilationUnit) parser
                .createAST(null);
            List<TypeDeclaration> typeList = astRoot.types();
            if (typeList != null && typeList.size() > 0) {
              TypeDeclaration adapterType = (TypeDeclaration) typeList
                  .get(0);
              insertType(pkg, adapterType.getName().toString(),
                  adapterCode, true, monitor);
            }
            monitor.worked(1);

            monitor.subTask("Check for adaptee package");
            IPackageFragmentRoot pkgRoot = (IPackageFragmentRoot) pkg
                .getParent();
            String pkgname = pkg.getElementName();
            // pkgRoot.open(monitor);
            IPackageFragment adapteePkg = pkgRoot
                .createPackageFragment(pkgname + "."
                    + "adaptee", true, monitor);

            monitor.subTask("Insert adaptee with functionality");
            /* Insert the adaptee class */
            insertType(adapteePkg, name, sourceCode, true, monitor);
            monitor.worked(1);

            logger.debug("Check for interfaces");

            for (Object typeDecO : typeDec.superInterfaceTypes()) {
              Type tDec = (Type) typeDecO;
              logger.debug("Implements " + tDec);
              StringBuilder iface = new StringBuilder("package "
                  + adapteePkg.getElementName() + ";"
                  + System.getProperty("line.separator"));
              iface.append(System.getProperty("line.separator")
                  + "/** Automatically generated interface dependency */"
                  + System.getProperty("line.separator"));
              iface.append("public interface " + tDec + "{}");
              // The interfaces should not be opened
              insertType(adapteePkg, tDec.toString(),
                  iface.toString(), false, monitor);
            }

            adapted = true;
          }
        }

        // Insert the result without adapter
        if (!adapted) {
          insertType(pkg, name, sourceCode, true, monitor);
          monitor.worked(1);
        }

      }
      if (selectedElement.getNodeType() == BodyDeclaration.METHOD_DECLARATION) {
        MethodDeclaration methodDec = (MethodDeclaration) selectedElement;
        IWorkbenchWindow window = PluginUI.getWindow();
        if (window == null)
          return Status.CANCEL_STATUS;
        Shell shell = window.getShell();
        if (shell == null)
          return Status.CANCEL_STATUS;
        Display display = shell.getDisplay();
        if (display == null)
          return Status.CANCEL_STATUS;

        AskForClassNameThread askForClass = new AskForClassNameThread();
        display.syncExec(askForClass);
        String className = askForClass.getClassName();

        if (className != null) {
          if (className.contains(".")) {
            className = className.substring(0,
                className.indexOf("."));
          }

          // Create new CompilationUnit
          try {
            AST ast = AST.newAST(AST.JLS3);
            CompilationUnit unit = ast.newCompilationUnit();
            PackageDeclaration packageDeclaration = ast
                .newPackageDeclaration();
            packageDeclaration.setName(ast.newSimpleName(pkg
                .getElementName()));
            unit.setPackage(packageDeclaration);
            TypeDeclaration type = ast.newTypeDeclaration();
            Javadoc comment = ast.newJavadoc();
            TagElement tag = ast.newTagElement();
            TextElement text = ast.newTextElement();
            text.setText("Generated class for method "
                + methodDec.getName());
            tag.fragments().add(text);
            comment.tags().add(tag);
            type.setJavadoc(comment);
            type.setInterface(false);
            type.modifiers()
                .add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
            type.setName(ast.newSimpleName(className));
            type.bodyDeclarations().add(
                BodyDeclaration.copySubtree(type.getAST(),
                    methodDec));
            unit.types().add(type);

            String source = unit.toString();
            pkg.createCompilationUnit(className + ".java", source,
View Full Code Here

      StringBuffer signature = new StringBuffer();
      signature.append(typeDeclaration.getName().getFullyQualifiedName());

      typeDeclaration.setProperty("Signature", signature.toString());

      TypeDeclaration dropTypeDec = (TypeDeclaration) ASTNode
          .copySubtree(astRoot.getAST(), typeDeclaration);

      // creation of ASTRewrite
      AST ast = astRoot.getAST();
      ASTRewrite rewrite = ASTRewrite.create(ast);

      // description of the change
      for (Object typeObj : astRoot.types()) {
        if (typeObj instanceof TypeDeclaration) {
          TypeDeclaration typeDec = (TypeDeclaration) typeObj;
          if (typeDec.getName().toString()
              .equals(dropTypeDec.getName().toString())) {
            logger.debug("Replace existing type declaration");
            if (Activator
                .getDefault()
                .getPreferenceStore()
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.