1 /*******************************************************************************
 
   2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
 
   3  * All rights reserved. This program and the accompanying materials 
 
   4  * are made available under the terms of the Common Public License v0.5 
 
   5  * which accompanies this distribution, and is available at
 
   6  * http://www.eclipse.org/legal/cpl-v05.html
 
   9  *     IBM Corporation - initial API and implementation
 
  10  ******************************************************************************/
 
  11 package net.sourceforge.phpdt.internal.codeassist.complete;
 
  14  * Completion node build by the parser in any case it was intending to
 
  15  * reduce an allocation expression containing the cursor.
 
  16  * If the allocation expression is not qualified, the enclosingInstance field
 
  22  *      new Bar(1, 2, [cursor]
 
  28  *           <CompleteOnAllocationExpression:new Bar(1, 2)>
 
  32  * The source range is always of length 0.
 
  33  * The arguments of the allocation expression are all the arguments defined
 
  37 import net.sourceforge.phpdt.internal.compiler.ast.*;
 
  38 import net.sourceforge.phpdt.internal.compiler.lookup.*;
 
  40 public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
 
  41 public TypeBinding resolveType(BlockScope scope) {
 
  42         TypeBinding typeBinding = null;
 
  43         if (enclosingInstance != null) {
 
  44                 TypeBinding enclosingType = enclosingInstance.resolveType(scope);
 
  45                 if (!(enclosingType instanceof ReferenceBinding)) {
 
  46                         scope.problemReporter().illegalPrimitiveOrArrayTypeForEnclosingInstance(enclosingType, enclosingInstance);
 
  47                         throw new CompletionNodeFound();
 
  49                 typeBinding = ((SingleTypeReference) type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType);
 
  50                 if (!(typeBinding instanceof ReferenceBinding))
 
  51                         throw new CompletionNodeFound(); // no need to continue if its an array or base type
 
  52                 if (typeBinding.isInterface()) // handle the anonymous class definition case
 
  53                         typeBinding = scope.getJavaLangObject();
 
  55                 typeBinding = type.resolveType(scope);
 
  56                 if (!(typeBinding instanceof ReferenceBinding))
 
  57                         throw new CompletionNodeFound(); // no need to continue if its an array or base type
 
  60         throw new CompletionNodeFound(this, typeBinding, scope);
 
  62 public String toStringExpression(int tab) {
 
  64                 ((this.enclosingInstance == null) ? 
 
  65                         "<CompleteOnAllocationExpression:" :  //$NON-NLS-1$
 
  66                         "<CompleteOnQualifiedAllocationExpression:") +  //$NON-NLS-1$
 
  67                 super.toStringExpression(tab) + ">"; //$NON-NLS-1$