Examples of AstEditor


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

  ////////////////////////////////////////////////////////////////////////////
  /**
   * @return the {@link ClassLoader} of active {@link JavaInfo} hierarchy.
   */
  private static ClassLoader getEditorLoader() {
    AstEditor editor = EditorState.getActiveJavaInfo().getEditor();
    return EditorState.get(editor).getEditorLoader();
  }
View Full Code Here

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

    @Override
    public void setValue(Object value) throws Exception {
      final MethodInvocation invocation = getInvocation();
      final List<Expression> arguments = DomGenerics.arguments(invocation);
      final AstEditor editor = m_this.getEditor();
      // prepare new value
      String newValue = (String) value;
      // process empty string as null
      if (StringUtils.isEmpty(newValue)) {
        newValue = null;
      }
      // remove value
      if (newValue == null) {
        if (arguments.size() == 2) {
          ExecutionUtils.run(m_this, new RunnableEx() {
            public void run() throws Exception {
              editor.removeInvocationArgument(invocation, 1);
            }
          });
        }
      }
      // set value
      if (newValue != null) {
        final String valueSource = StringConverter.INSTANCE.toJavaSource(m_this, newValue);
        if (arguments.size() == 1) {
          // add argument
          ExecutionUtils.run(m_this, new RunnableEx() {
            public void run() throws Exception {
              editor.addInvocationArgument(invocation, 1, valueSource);
            }
          });
        } else {
          // replace argument
          ExecutionUtils.run(m_this, new RunnableEx() {
            public void run() throws Exception {
              editor.replaceExpression(arguments.get(1), valueSource);
              // may be was not String argument
              editor.replaceInvocationBinding(invocation);
            }
          });
        }
      }
    }
View Full Code Here

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

    }

    @Override
    public void setValue(Object valueObject) throws Exception {
      String valueString = valueObject instanceof String ? (String) valueObject : null;
      final AstEditor editor = m_this.getEditor();
      final MethodInvocation invocation = getInvocation();
      final String signaturePrefix = "setColumnWidth(com.google.gwt.user.cellview.client.Column,";
      // remove value
      if (StringUtils.isEmpty(valueString)) {
        if (invocation != null) {
          ExecutionUtils.run(m_this, new RunnableEx() {
            public void run() throws Exception {
              editor.removeEnclosingStatement(invocation);
            }
          });
        }
        return;
      }
      // new value
      if (invocation == null) {
        final String valueSource = StringConverter.INSTANCE.toJavaSource(m_this, valueString);
        ExecutionUtils.run(m_this, new RunnableEx() {
          public void run() throws Exception {
            StatementTarget target = new StatementTarget(getAssociation().getStatement(), false);
            String signature = signaturePrefix + "java.lang.String)";
            String argumentsSource = TemplateUtils.format("{0}, {1}", m_this, valueSource);
            MethodInvocation newInvocation =
                getParentJava().addMethodInvocation(target, signature, argumentsSource);
            addRelatedNodes(newInvocation);
          }
        });
        return;
      }
      // update value
      final List<Expression> arguments = DomGenerics.arguments(invocation);
      // setColumnWidth(Column,String)
      {
        String signature = signaturePrefix + "java.lang.String)";
        if (AstNodeUtils.isMethodInvocation(invocation, signature)) {
          final String valueSource = StringConverter.INSTANCE.toJavaSource(m_this, valueString);
          ExecutionUtils.run(m_this, new RunnableEx() {
            public void run() throws Exception {
              editor.replaceExpression(arguments.get(1), valueSource);
            }
          });
        }
      }
      // setColumnWidth(Column,double,Unit)
      {
        String typeNameUnit = "com.google.gwt.dom.client.Style.Unit";
        String signature = signaturePrefix + "double," + typeNameUnit + ")";
        if (AstNodeUtils.isMethodInvocation(invocation, signature)) {
          // prepare "value" and "unit"
          double sizeValue;
          Object sizeUnit;
          try {
            sizeValue = getValueFromSizeString(valueString);
            sizeUnit = getUnitFromSizeString(valueString);
          } catch (Throwable e) {
            return;
          }
          // no unit
          if (sizeUnit == null) {
            return;
          }
          // apply "value" and "unit"
          final String valueSource = DoubleConverter.INSTANCE.toJavaSource(m_this, sizeValue);
          final String unitSource = typeNameUnit + "." + sizeUnit.toString();
          ExecutionUtils.run(m_this, new RunnableEx() {
            public void run() throws Exception {
              editor.replaceExpression(arguments.get(1), valueSource);
              editor.replaceExpression(arguments.get(2), unitSource);
            }
          });
        }
      }
    }
View Full Code Here

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

      locationSet = true;
    }
    // if no location set yet, try to update add()
    if (!locationSet && !force_setWidgetPosition) {
      for (MethodInvocation invocation : getInvocations("add(%widget%)", widget)) {
        AstEditor editor = getEditor();
        String argsSource = editor.getSource(DomGenerics.arguments(invocation).get(0));
        argsSource += xyString;
        editor.replaceInvocationArguments(invocation, ImmutableList.of(argsSource));
        locationSet = true;
        // related nodes
        addRelatedNodes(invocation);
        widget.addRelatedNodes(invocation);
      }
View Full Code Here

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

     * Configures {@link ColumnInfo} to don't be sortable and removes {@link Comparator}.
     */
    protected void removeInvocation(final MethodInvocation invocation) {
      ExecutionUtils.run(m_this, new RunnableEx() {
        public void run() throws Exception {
          AstEditor editor = m_this.getEditor();
          getPropertyByTitle("sortable").setValue(UNKNOWN_VALUE);
          editor.removeEnclosingStatement(invocation);
        }
      });
    }
View Full Code Here

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

    /**
     * @return the not <code>null</code>, existing name of <code>ListHandler</code> instance, which
     *         is used for sorting of this <code>CellTable</code>.
     */
    private String getListHandlerName(String rowTypeName) throws Exception {
      AstEditor editor = m_this.getEditor();
      // try to find visible ListHandler instance
      {
        int position = getCreationSupport().getNode().getStartPosition();
        CompilationUnit astUnit = editor.getAstUnit();
        List<VariableDeclaration> variables =
            AstNodeUtils.getVariableDeclarationsVisibleAt(astUnit, position);
        for (VariableDeclaration variable : variables) {
          ITypeBinding typeBinding = AstNodeUtils.getTypeBinding(variable);
          if (AstNodeUtils.isSuccessorOf(
              typeBinding,
              "com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler")) {
            if (isListHandlerForThisTable(variable)) {
              return variable.getName().getIdentifier();
            }
          }
        }
      }
      // prepare name for ListHandler instance
      String listHandlerName = editor.getUniqueVariableName(-1, "sortHandler", null);
      // declare ListHandler field
      {
        String source =
            MessageFormat.format(
                "private {0}<{1}> {2} = new {0}<{1}>(java.util.Collections.<{1}>emptyList());",
                "com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler",
                rowTypeName,
                listHandlerName);
        TypeDeclaration targetType = JavaInfoUtils.getTypeDeclaration(m_this);
        BodyDeclarationTarget target = new BodyDeclarationTarget(targetType, true);
        editor.addFieldDeclaration(source, target);
      }
      // add cellTable.addColumnSortHandler(sortHandler);
      getParentJava().addMethodInvocation(
          "addColumnSortHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.Handler)",
          listHandlerName);
View Full Code Here

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

  private boolean setSizeExpression(String signature, int index, String expression)
      throws Exception {
    MethodInvocation invocation = m_widget.getMethodInvocation(signature);
    if (invocation != null) {
      AstEditor editor = m_widget.getEditor();
      editor.replaceInvocationArgument(invocation, index, expression);
      return true;
    }
    return false;
  }
View Full Code Here

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

    return null;
  }

  @Override
  public boolean setExpression(final JavaInfo javaInfo, final String source) throws Exception {
    final AstEditor editor = javaInfo.getEditor();
    // check for existing invocation
    {
      final Expression expression = getExpression(javaInfo);
      if (expression != null) {
        if (source != null) {
          ExecutionUtils.run(javaInfo, new RunnableEx() {
            public void run() throws Exception {
              editor.replaceExpression(expression, source);
            }
          });
        } else {
          ExecutionUtils.run(javaInfo, new RunnableEx() {
            public void run() throws Exception {
              editor.removeEnclosingStatement(expression);
            }
          });
        }
        return true;
      }
View Full Code Here

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

            "Exception during creation of: {0}. See \"Open error log\" for details.",
            CodeUtils.getShortClass(clazz.getName()));
    // script
    String script;
    {
      AstEditor editor = EditorState.getActiveJavaInfo().getEditor();
      ComponentDescription description = ComponentDescriptionHelper.getDescription(editor, clazz);
      script = description.getParameter("placeholderScript");
    }
    // variables
    Map<String, Object> variables = Maps.newTreeMap();
View Full Code Here

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

  public void command_CREATE(WidgetInfo widget, TreeItemInfo nextItem) throws Exception {
    command_CREATE_Widget(this, widget);
  }

  static void command_CREATE_Widget(JavaInfo host, WidgetInfo widget) throws Exception {
    AstEditor editor = host.getEditor();
    // prepare CreationSupport for TreeItem
    CreationSupport creationSupport;
    {
      String signature = "addItem(com.google.gwt.user.client.ui.Widget)";
      String source = "addItem((com.google.gwt.user.client.ui.Widget) null)";
      creationSupport = new ImplicitFactoryCreationSupport(host, signature, source);
    }
    // add TreeItem
    TreeItemInfo item =
        (TreeItemInfo) JavaInfoUtils.createJavaInfo(
            editor,
            "com.google.gwt.user.client.ui.TreeItem",
            creationSupport);
    JavaInfoUtils.add(item, null, host, null);
    // prepare added invocation
    MethodInvocation invocation = (MethodInvocation) item.getCreationSupport().getNode();
    item.setAssociation(new InvocationVoidAssociation(invocation));
    // configure Widget
    {
      NodeTarget target = new NodeTarget(new StatementTarget(invocation, true));
      Expression widgetExpression =
          editor.replaceInvocationArgument(
              invocation,
              0,
              widget.getCreationSupport().add_getSource(target));
      widget.getCreationSupport().add_setSourceExpression(widgetExpression);
      widget.setVariableSupport(new EmptyVariableSupport(widget, widgetExpression));
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.