Examples of AstEditor


Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

      String methodSignature = viewClassName + " get" + viewName + "()";
      // prepare AstEditor
      IPackageFragment factoryPackageFragment = getPackage(root, clientFactoryPackageName);
      ICompilationUnit factoryUnit =
          factoryPackageFragment.getCompilationUnit(clientFactoryClassName + ".java");
      AstEditor editor = new AstEditor(factoryUnit);
      TypeDeclaration factoryPrimaryType = editor.getPrimaryType();
      BodyDeclarationTarget bodyDeclarationTarget =
          new BodyDeclarationTarget(factoryPrimaryType, false);
      // modifying ...
      MethodDeclaration methodDeclaration;
      if (factoryPrimaryType.isInterface()) {
        // interface
        String methodHeader = "public " + methodSignature + ";";
        methodDeclaration = editor.addMethodDeclaration(methodHeader, null, bodyDeclarationTarget);
      } else if (AstNodeUtils.isAbstract(factoryPrimaryType)) {
        // abstract class
        String methodHeader = "public abstract " + methodSignature + ";";
        methodDeclaration = editor.addMethodDeclaration(methodHeader, null, bodyDeclarationTarget);
      } else {
        // regular class
        String methodHeader = "public " + methodSignature;
        final List<String> lines = Lists.newArrayList("return null; // FIXME");
        methodDeclaration = editor.addMethodDeclaration(methodHeader, lines, bodyDeclarationTarget);
      }
      editor.resolveImports(methodDeclaration);
      editor.saveChanges(true);
      // create file from templates
      IFile file =
          createFileFromTemplate(
              packageFragment,
              className + ".java",
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

   * @return located PlaceController getter or <code>null</code> if non.
   */
  private static MethodDeclaration getFactoryPlaceController(ICompilationUnit compilationUnit)
      throws Exception {
    if (compilationUnit != null && compilationUnit.exists()) {
      AstEditor editor = new AstEditor(compilationUnit);
      TypeDeclaration typeDeclaration = editor.getPrimaryType();
      MethodDeclaration[] methodDeclarations = typeDeclaration.getMethods();
      for (MethodDeclaration methodDeclaration : methodDeclarations) {
        Type returnType = methodDeclaration.getReturnType2();
        if (returnType != null
            && methodDeclaration.parameters().size() == 0
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

  private void createVirtualLayoutData(WidgetInfo widget) throws Exception {
    Object dataObject = getDefaultVirtualDataObject();
    // create model
    JavaInfo layoutData;
    {
      AstEditor editor = getContainer().getEditor();
      CreationSupport creationSupport = new VirtualLayoutDataCreationSupport(widget, dataObject);
      layoutData = JavaInfoUtils.createJavaInfo(editor, getLayoutDataClass(), creationSupport);
    }
    // configure
    layoutData.setVariableSupport(new VirtualLayoutDataVariableSupport(layoutData));
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

      if (methodName.equals(arrayObjectInfo.getCaption())) {
        return arrayObjectInfo;
      }
    }
    // prepare for create "arrayInfo"
    AstEditor editor = containerInfo.getEditor();
    MethodInvocation methodInvocation =
        containerInfo.addMethodInvocation(methodName + "(" + itemClassName + "[])", "new "
            + itemClassName
            + "[] { }");
    ArrayCreation arrayCreation = (ArrayCreation) DomGenerics.arguments(methodInvocation).get(0);
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

      methodLines.add("//");
      methodLines.add("postInitializeBindings();");
    }
    //
    JavaInfo javaInfoRoot = provider.getJavaInfoRoot();
    AstEditor editor = javaInfoRoot.getEditor();
    TypeDeclaration typeDeclaration = JavaInfoUtils.getTypeDeclaration(javaInfoRoot);
    BodyDeclarationTarget target = new BodyDeclarationTarget(typeDeclaration, null, false);
    MethodDeclaration lastInfoMethod = getLastInfoDeclaration(javaInfoRoot);
    //
    if (m_initDataBindings != null) {
      editor.removeBodyDeclaration(m_initDataBindings);
    }
    m_initDataBindings =
        editor.addMethodDeclaration(createMethodHeader(lastInfoMethod), methodLines, target);
    // check call initDataBindings() after creation all components
    ensureInvokeInitDataBindings(editor, lastInfoMethod);
  }
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

          //
          Map<String, Class<?>> classes = Maps.newHashMap();
          m_classes.put(beanClass, classes);
          //
          Set<String> uniqueProperties = Sets.newHashSet();
          AstEditor editor = new AstEditor(compilationUnit);
          editor.getAstUnit().accept(new PropertiesVisitor(uniqueProperties, classes));
          //
          Class<?> superClass = beanClass.getSuperclass();
          if (superClass != null) {
            uniqueProperties.addAll(getStringProperties(superClass));
            //
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

   * @return the {@link AstEditor} for Java source.
   */
  public AstEditor getFormEditor() throws Exception {
    long currentModificationStamp = m_formFile.getModificationStamp();
    if (m_formEditor == null || currentModificationStamp != m_formFileModification) {
      m_formEditor = new AstEditor(m_formType.getCompilationUnit());
      m_formFileModification = currentModificationStamp;
    }
    return m_formEditor;
  }
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

    }
  }

  private void command_BOUNDS_setLocation(CanvasInfo canvas, Point location) throws Exception {
    Assert.isNotNull(location);
    AstEditor editor = canvas.getEditor();
    String xString = getRectString(location.x);
    String yString = getRectString(location.y);
    // setRect(int,int,int,int)
    {
      MethodInvocation invocation = canvas.getMethodInvocation("setRect(int,int,int,int)");
      if (invocation != null) {
        editor.replaceInvocationArgument(invocation, 0, xString);
        editor.replaceInvocationArgument(invocation, 1, yString);
        return;
      }
    }
    // moveTo(int,int)
    {
      MethodInvocation invocation = canvas.getMethodInvocation("moveTo(int,int)");
      if (invocation != null) {
        editor.replaceInvocationArgument(invocation, 0, xString);
        editor.replaceInvocationArgument(invocation, 1, yString);
        return;
      }
    }
    // no existing location invocations, generate moveTo(int,int)
    removeLocationInvocations(canvas);
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

    // setRect(int,int,int,int)
    {
      MethodInvocation invocation = canvas.getMethodInvocation("setRect(int,int,int,int)");
      if (invocation != null) {
        List<Expression> invocationArguments = DomGenerics.arguments(invocation);
        AstEditor editor = canvas.getEditor();
        // add setSize()
        {
          String wString = editor.getSource(invocationArguments.get(2));
          String hString = editor.getSource(invocationArguments.get(3));
          String arguments = wString + ", " + hString;
          canvas.addMethodInvocation("resizeTo(int,int)", arguments);
        }
        // remove setRect()
        editor.removeEnclosingStatement(invocation);
      }
    }
  }
View Full Code Here

Examples of org.eclipse.wb.internal.core.utils.ast.AstEditor

    canvas.removeMethodInvocations("setTop(java.lang.String)");
  }

  private void command_BOUNDS_setSize(CanvasInfo canvas, Dimension size) throws Exception {
    Assert.isNotNull(size);
    AstEditor editor = canvas.getEditor();
    String wString = getRectString(size.width);
    String hString = getRectString(size.height);
    // moveTo(int,int)
    {
      MethodInvocation invocation = canvas.getMethodInvocation("moveTo(int,int)");
      if (invocation != null) {
        StatementTarget target;
        {
          Statement statement = AstNodeUtils.getEnclosingStatement(invocation);
          target = new StatementTarget(statement, true);
        }
        {
          String xString = editor.getSource(DomGenerics.arguments(invocation).get(0));
          String yString = editor.getSource(DomGenerics.arguments(invocation).get(1));
          String arguments = xString + ", " + yString + ", " + wString + ", " + hString;
          canvas.addMethodInvocation(target, "setRect(int,int,int,int)", arguments);
        }
        editor.removeEnclosingStatement(invocation);
        return;
      }
    }
    // no special case, just set size
    canvas.getSizeSupport().setSize(size);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.