private RefactoringStatus checkExpression() throws JavaScriptModelException {
    RefactoringStatus result = new RefactoringStatus();
    result.merge(checkExpressionBinding());
    if (result.hasFatalError()) return result;
    checkAllStaticFinal();

    IExpressionFragment selectedExpression = getSelectedExpression();
    Expression associatedExpression = selectedExpression.getAssociatedExpression();
    if (associatedExpression instanceof NullLiteral)
      result.merge(
          RefactoringStatus.createFatalErrorStatus(
              RefactoringCoreMessages.ExtractConstantRefactoring_null_literals));
    else if (!ConstantChecks.isLoadTimeConstant(selectedExpression))
      result.merge(
          RefactoringStatus.createFatalErrorStatus(
              RefactoringCoreMessages.ExtractConstantRefactoring_not_load_time_constant));
    else if (associatedExpression instanceof SimpleName) {
      if (associatedExpression.getParent() instanceof QualifiedName
              && associatedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
          || associatedExpression.getParent() instanceof FieldAccess
              && associatedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
        return RefactoringStatus.createFatalErrorStatus(
            RefactoringCoreMessages.ExtractConstantRefactoring_select_expression);
    }

    return result;
  }
 /*
  * @see ASTVisitor#visit(ConstructorInvocation)
  */
 public boolean visit(ConstructorInvocation node) {
   if (node.getAST().apiLevel() >= AST.JLS3) {
     if (!node.typeArguments().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
         Type t = (Type) it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(","); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(">"); // $NON-NLS-1$
     }
   }
   this.fBuffer.append("this("); // $NON-NLS-1$
   for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
     Expression e = (Expression) it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(");"); // $NON-NLS-1$
   return false;
 }
 /*
  * @see ASTVisitor#visit(FunctionInvocation)
  */
 public boolean visit(FunctionInvocation node) {
   if (node.getExpression() != null) {
     node.getExpression().accept(this);
     this.fBuffer.append("."); // $NON-NLS-1$
   }
   if (node.getAST().apiLevel() >= AST.JLS3) {
     if (!node.typeArguments().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
         Type t = (Type) it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(","); // $NON-NLS-1$
         }
       }
       this.fBuffer.append(">"); // $NON-NLS-1$
     }
   }
   SimpleName name = node.getName();
   if (name != null) name.accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
     Expression e = (Expression) it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   return false;
 }
 public boolean visit(ListExpression node) {
   for (Iterator it = node.expressions().iterator(); it.hasNext(); ) {
     Expression e = (Expression) it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   return false;
 }
 /*
  * @see ASTVisitor#visit(ArrayInitializer)
  */
 public boolean visit(ArrayInitializer node) {
   this.fBuffer.append("["); // $NON-NLS-1$
   for (Iterator it = node.expressions().iterator(); it.hasNext(); ) {
     Expression e = (Expression) it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append("]"); // $NON-NLS-1$
   return false;
 }
 public boolean visit(FunctionInvocation node) {
   Expression receiver = node.getExpression();
   if (receiver == null) {
     SimpleName name = node.getName();
     if (fIgnoreBinding == null
         || (name != null && !Bindings.equals(fIgnoreBinding, name.resolveBinding())))
       node.getName().accept(this);
   } else {
     receiver.accept(this);
   }
   accept(node.arguments());
   return false;
 }
 /*
  * @see ASTVisitor#visit(InfixExpression)
  */
 public boolean visit(InfixExpression node) {
   node.getLeftOperand().accept(this);
   this.fBuffer.append(' '); // for cases like x= i - -1; or x= i++ + ++i;
   this.fBuffer.append(node.getOperator().toString());
   this.fBuffer.append(' ');
   node.getRightOperand().accept(this);
   final List extendedOperands = node.extendedOperands();
   if (extendedOperands.size() != 0) {
     this.fBuffer.append(' ');
     for (Iterator it = extendedOperands.iterator(); it.hasNext(); ) {
       this.fBuffer.append(node.getOperator().toString()).append(' ');
       Expression e = (Expression) it.next();
       e.accept(this);
     }
   }
   return false;
 }
  //	 !!! -- same as in ExtractTempRefactoring
  private boolean isLiteralNodeSelected() throws JavaScriptModelException {
    IExpressionFragment fragment = getSelectedExpression();
    if (fragment == null) return false;
    Expression expression = fragment.getAssociatedExpression();
    if (expression == null) return false;
    switch (expression.getNodeType()) {
      case ASTNode.BOOLEAN_LITERAL:
      case ASTNode.CHARACTER_LITERAL:
      case ASTNode.NULL_LITERAL:
      case ASTNode.NUMBER_LITERAL:
      case ASTNode.UNDEFINED_LITERAL:
      case ASTNode.REGULAR_EXPRESSION_LITERAL:
        return true;

      default:
        return false;
    }
  }
 /*
  * @see ASTVisitor#visit(ForStatement)
  */
 public boolean visit(ForStatement node) {
   this.fBuffer.append("for ("); // $NON-NLS-1$
   for (Iterator it = node.initializers().iterator(); it.hasNext(); ) {
     Expression e = (Expression) it.next();
     e.accept(this);
   }
   this.fBuffer.append("; "); // $NON-NLS-1$
   if (node.getExpression() != null) {
     node.getExpression().accept(this);
   }
   this.fBuffer.append("; "); // $NON-NLS-1$
   for (Iterator it = node.updaters().iterator(); it.hasNext(); ) {
     Expression e = (Expression) it.next();
     e.accept(this);
   }
   this.fBuffer.append(") "); // $NON-NLS-1$
   node.getBody().accept(this);
   return false;
 }
 /**
  * @return proposed variable names (may be empty, but not null). The first proposal should be used
  *     as "best guess" (if it exists).
  */
 public String[] guessConstantNames() {
   if (fGuessedConstNames == null) {
     try {
       Expression expression = getSelectedExpression().getAssociatedExpression();
       if (expression != null) {
         ITypeBinding binding = expression.resolveTypeBinding();
         fGuessedConstNames =
             StubUtility.getVariableNameSuggestions(
                 StubUtility.CONSTANT_FIELD,
                 fCu.getJavaScriptProject(),
                 binding,
                 expression,
                 Arrays.asList(getExcludedVariableNames()));
       }
     } catch (JavaScriptModelException e) {
     }
     if (fGuessedConstNames == null) fGuessedConstNames = new String[0];
   }
   return fGuessedConstNames;
 }
 /*
  * @see ASTVisitor#visit(ArrayCreation)
  */
 public boolean visit(ArrayCreation node) {
   this.fBuffer.append("new "); // $NON-NLS-1$
   ArrayType at = node.getType();
   int dims = at.getDimensions();
   Type elementType = at.getElementType();
   elementType.accept(this);
   for (Iterator it = node.dimensions().iterator(); it.hasNext(); ) {
     this.fBuffer.append("["); // $NON-NLS-1$
     Expression e = (Expression) it.next();
     e.accept(this);
     this.fBuffer.append("]"); // $NON-NLS-1$
     dims--;
   }
   // add empty "[]" for each extra array dimension
   for (int i = 0; i < dims; i++) {
     this.fBuffer.append("[]"); // $NON-NLS-1$
   }
   if (node.getInitializer() != null) {
     node.getInitializer().accept(this);
   }
   return false;
 }
 /*
  * @see ASTVisitor#visit(ClassInstanceCreation)
  */
 public boolean visit(ClassInstanceCreation node) {
   if (node.getExpression() != null) {
     node.getExpression().accept(this);
     this.fBuffer.append("."); // $NON-NLS-1$
   }
   this.fBuffer.append("new "); // $NON-NLS-1$
   //		if (node.getAST().apiLevel() == AST.JLS2) {
   //			node.getName().accept(this);
   //		}
   //		if (node.getAST().apiLevel() >= AST.JLS3) {
   //			if (!node.typeArguments().isEmpty()) {
   //				this.fBuffer.append("<");//$NON-NLS-1$
   //				for (Iterator it= node.typeArguments().iterator(); it.hasNext();) {
   //					Type t= (Type) it.next();
   //					t.accept(this);
   //					if (it.hasNext()) {
   //						this.fBuffer.append(",");//$NON-NLS-1$
   //					}
   //				}
   //				this.fBuffer.append(">");//$NON-NLS-1$
   //			}
   //			node.getType().accept(this);
   //		}
   node.getMember().accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
     Expression e = (Expression) it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   if (node.getAnonymousClassDeclaration() != null) {
     node.getAnonymousClassDeclaration().accept(this);
   }
   return false;
 }
 private static boolean isStringExpression(Expression expression) {
   ITypeBinding binding = expression.resolveTypeBinding();
   return binding.getQualifiedName().equals("String"); // $NON-NLS-1$
 }