Examples of AstEditor


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

  }

  private boolean setHeightString(int height) throws Exception {
    MethodInvocation invocation = m_window.getMethodInvocation("setHeight(java.lang.String)");
    if (invocation != null) {
      AstEditor editor = m_window.getEditor();
      editor.replaceExpression(
          (Expression) invocation.arguments().get(0),
          "\"" + Integer.toString(height) + "px\"");
      return true;
    }
    // not found
View Full Code Here

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

    /**
     * Generates getter/setter for exposing property.
     */
    private void expose(boolean isPublic) throws Exception {
      AstEditor editor = getFormEditor();
      TypeDeclaration typeDeclaration = getFormTypeDeclaration();
      //
      BodyDeclarationTarget methodTarget = new BodyDeclarationTarget(typeDeclaration, false);
      String modifierSource = isPublic ? "public" : "protected";
      String name = NameSupport.ensureName(m_object);
      // getter
      {
        String header = modifierSource + " " + m_propertyTypeName + " " + m_exposedGetter + "()";
        String body =
            MessageFormat.format("return {0}.{1}();", name, m_accessor.getGetter().getName());
        editor.addMethodDeclaration(header, ImmutableList.of(body), methodTarget);
      }
      // setter
      {
        String header =
            MessageFormat.format(
                "{0} void {1}({2} {3})",
                modifierSource,
                m_exposedSetter,
                m_propertyTypeName,
                m_exposedSetterParameter);
        String body =
            MessageFormat.format(
                "{0}.{1}({2});",
                name,
                m_accessor.getSetter().getName(),
                m_exposedSetterParameter);
        editor.addMethodDeclaration(header, ImmutableList.of(body), methodTarget);
      }
    }
View Full Code Here

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

      String heightString) throws Exception {
    // may be setRect(left, top, width, height)
    List<MethodInvocation> invocations = getMethodInvocations("setRect(int,int,int,int)");
    if (!invocations.isEmpty()) {
      MethodInvocation invocation = invocations.get(0);
      AstEditor editor = m_object.getEditor();
      {
        Integer widthInteger = getIntegerValue(widthString);
        Integer heightInteger = getIntegerValue(heightString);
        // replace "int" width/height
        if (widthHas && heightHas) {
          if (widthInteger != null && heightInteger != null) {
            editor.replaceInvocationArgument(invocation, 2, widthInteger.toString());
            editor.replaceInvocationArgument(invocation, 3, heightInteger.toString());
            return;
          }
        }
        // replace "int" width
        if (widthHas && !heightHas) {
          if (widthInteger != null) {
            editor.replaceInvocationArgument(invocation, 2, widthInteger.toString());
            return;
          }
        }
        // replace "int" height
        if (heightHas && !widthHas) {
          if (heightInteger != null) {
            editor.replaceInvocationArgument(invocation, 3, heightInteger.toString());
            return;
          }
        }
      }
      // replace with "moveTo"
      {
        List<Expression> arguments = DomGenerics.arguments(invocation);
        String args =
            editor.getSource(arguments.get(0)) + ", " + editor.getSource(arguments.get(1));
        m_object.addMethodInvocation("moveTo(int,int)", args);
        // remove "setRect"
        editor.removeEnclosingStatement(invocation);
      }
    }
    // continue
    super.setSize0_addInvocation(target, widthHas, heightHas, widthString, heightString);
  }
View Full Code Here

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

        String nameAttribute = getNameAttribute();
        m_object.getElement().setAttribute(nameAttribute, null);
      }
      // update Java
      {
        AstEditor editor = getEditor();
        TypeDeclaration typeDeclaration = editor.getPrimaryType();
        // remove handlers
        for (MethodDeclaration methodDeclaration : typeDeclaration.getMethods()) {
          if (EventHandlerProperty.isObjectHandler(methodDeclaration, name)) {
            editor.removeBodyDeclaration(methodDeclaration);
          }
        }
        // remove field
        VariableDeclaration variable = getBinderField(typeDeclaration, name);
        FieldDeclaration field = AstNodeUtils.getEnclosingFieldDeclaration(variable);
        editor.removeBodyDeclaration(field);
      }
    }
  }
View Full Code Here

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

  /**
   * Sets new name for "@UiField" of the widget.
   */
  private void setName(String name) throws Exception {
    AstEditor editor = getEditor();
    TypeDeclaration typeDeclaration = editor.getPrimaryType();
    // prepare "old" state
    String oldName = getName();
    VariableDeclaration oldVariable = getBinderField(typeDeclaration, oldName);
    // set "ui:field" attribute
    {
      String nameAttribute = getNameAttribute();
      m_object.setAttribute(nameAttribute, name);
    }
    // update Java
    if (oldVariable != null) {
      IType modelType = m_context.getFormType();
      IField modelField = modelType.getField(oldName);
      RenameSupport renameSupport =
          RenameSupport.create(modelField, name, RenameSupport.UPDATE_REFERENCES);
      renameSupport.perform(DesignerPlugin.getShell(), DesignerPlugin.getActiveWorkbenchWindow());
      return;
    } else {
      Class<?> componentClass = m_object.getDescription().getComponentClass();
      String source =
          "@com.google.gwt.uibinder.client.UiField "
              + ReflectionUtils.getCanonicalName(componentClass)
              + " "
              + name
              + ";";
      BodyDeclarationTarget target = getNewFieldTarget(typeDeclaration);
      editor.addFieldDeclaration(source, target);
    }
  }
View Full Code Here

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

    // may be no support for @UiField
    if (!UiBinderParser.hasUiFieldUiFactorySupport(m_context.getJavaProject())) {
      throw new DesignerException(IExceptionConstants.UI_FIELD_FACTORY_FEATURE);
    }
    // prepare AST
    AstEditor editor = getEditor();
    // configure EditorState
    EditorState.get(editor).initialize(
        GwtToolkitDescription.INSTANCE.getId(),
        m_object.getContext().getClassLoader());
    // prepare name
View Full Code Here

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

   */
  public void addUiFieldJava(Class<?> fieldClass,
      String fieldTypeName,
      String name,
      String initializer) throws Exception {
    AstEditor editor = getEditor();
    TypeDeclaration typeDeclaration = editor.getPrimaryType();
    // prepare source lines
    List<String> lines;
    {
      lines = Lists.newArrayList();
      String source = "@com.google.gwt.uibinder.client.UiField(provided=true) ";
      source += fieldTypeName + " " + name + " = " + initializer + ";";
      Collections.addAll(lines, StringUtils.split(source, '\n'));
    }
    // add field
    BodyDeclarationTarget target = getNewFieldTarget(typeDeclaration);
    editor.addFieldDeclaration(lines, target);
    // add new JField into "form" JType
    addFormJField(fieldClass, name);
  }
View Full Code Here

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

        }
      }
    });
    // add TypeDeclaration fields
    {
      AstEditor editor = getEditor();
      TypeDeclaration typeDeclaration = editor.getPrimaryType();
      for (FieldDeclaration fieldDeclaration : typeDeclaration.getFields()) {
        for (VariableDeclarationFragment fragment : DomGenerics.fragments(fieldDeclaration)) {
          String name = fragment.getName().getIdentifier();
          resultSet.add(name);
        }
View Full Code Here

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

  @Override
  protected void morph_source(T newComponent) throws Exception {
    super.morph_source(newComponent);
    // replace ui-field type
    AstEditor formEditor = newComponent.getContext().getFormEditor();
    if (!StringUtils.isEmpty(uiFieldName) && formEditor != null) {
      //NameSupport.setName(newComponent, uiFieldName);
      TypeDeclaration typeDeclaration = formEditor.getPrimaryType();
      VariableDeclaration variableDeclaration =
          NameSupport.getBinderField(typeDeclaration, uiFieldName);
      if (variableDeclaration != null) {
        formEditor.replaceVariableType(
            variableDeclaration,
            ReflectionUtils.getCanonicalName(newComponent.getDescription().getComponentClass()));
        formEditor.saveChanges(true);
      }
    }
  }
View Full Code Here

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

    return Collections.emptyList();
  }

  public void synchronizeObserves() throws Exception {
    // prepare editor
    AstEditor editor = m_javaInfoRoot.getEditor();
    // prepare node
    TypeDeclaration rootNode = JavaInfoUtils.getTypeDeclaration(m_javaInfoRoot);
    if (rootNode == null) {
      // use first type declaration from compilation unit
      CompilationUnit astUnit = editor.getAstUnit();
      rootNode = (TypeDeclaration) astUnit.types().get(0);
    }
    // synchronize
    for (ObserveTypeContainer container : m_containers) {
      container.synchronizeObserves(m_javaInfoRoot, editor, rootNode);
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.