Switched to Eclipse 2.1 development; eliminated JTidy package => now standalone plugin
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / codeassist / select / SelectionOnMessageSend.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.codeassist.select;
12
13 /*
14  * Selection node build by the parser in any case it was intending to
15  * reduce a message send containing the cursor.
16  * e.g.
17  *
18  *      class X {
19  *    void foo() {
20  *      this.[start]bar[end](1, 2)
21  *    }
22  *  }
23  *
24  *      ---> class X {
25  *         void foo() {
26  *           <SelectOnMessageSend:this.bar(1, 2)>
27  *         }
28  *       }
29  *
30  */
31
32 import net.sourceforge.phpdt.internal.compiler.ast.MessageSend;
33 import net.sourceforge.phpdt.internal.compiler.ast.ThisReference;
34 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
35 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
36 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
37
38 public class SelectionOnMessageSend extends MessageSend {
39
40         public TypeBinding resolveType(BlockScope scope) {
41                 super.resolveType(scope);
42
43                 // tolerate some error cases
44                 if(binding == null ||
45                                         !(binding.isValidBinding() || 
46                                                 binding.problemId() == ProblemReasons.NotVisible
47                                                 || binding.problemId() == ProblemReasons.InheritedNameHidesEnclosingName
48                                                 || binding.problemId() == ProblemReasons.NonStaticReferenceInConstructorInvocation
49                                                 || binding.problemId() == ProblemReasons.NonStaticReferenceInStaticContext)) {
50                         throw new SelectionNodeFound();
51                 } else {
52                         throw new SelectionNodeFound(binding);
53                 }
54         }
55
56         public String toStringExpression() {
57                 String s = "<SelectOnMessageSend:"; //$NON-NLS-1$
58                 if (receiver != ThisReference.ThisImplicit)
59                         s = s + receiver.toStringExpression() + "."; //$NON-NLS-1$
60                 s = s + new String(selector) + "("; //$NON-NLS-1$
61                 if (arguments != null) {
62                         for (int i = 0; i < arguments.length; i++) {
63                                 s += arguments[i].toStringExpression();
64                                 if (i != arguments.length - 1) {
65                                         s += ", "; //$NON-NLS-1$
66                                 }
67                         };
68                 }
69                 s = s + ")>"; //$NON-NLS-1$
70                 return s;
71         }
72 }