KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > jdom > DOMMethod


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core.jdom;
12
13 import org.eclipse.jdt.core.Flags;
14 import org.eclipse.jdt.core.IJavaElement;
15 import org.eclipse.jdt.core.IType;
16 import org.eclipse.jdt.core.Signature;
17 import org.eclipse.jdt.core.compiler.CharOperation;
18 import org.eclipse.jdt.core.jdom.*;
19 import org.eclipse.jdt.internal.core.util.Messages;
20 import org.eclipse.jdt.internal.core.util.CharArrayBuffer;
21 import org.eclipse.jdt.internal.core.util.Util;
22 /**
23  * DOMMethod provides an implementation of IDOMMethod.
24  *
25  * @see IDOMMethod
26  * @see DOMNode
27  * @deprecated The JDOM was made obsolete by the addition in 2.0 of the more
28  * powerful, fine-grained DOM/AST API found in the
29  * org.eclipse.jdt.core.dom package.
30  */

31 // TODO (jerome) - add implementation support for 1.5 features
32
class DOMMethod extends DOMMember implements IDOMMethod {
33
34     /**
35      * Contains the return type of the method when the
36      * return type has been altered from the contents
37      * in the document, otherwise <code>null</code>.
38      */

39     protected String JavaDoc fReturnType;
40
41     /**
42      * The original inclusive source range of the
43      * method's return type in the document, or -1's
44      * if no return type is present in the document.
45      * If the return type of this method is qualified with
46      * '[]' following the parameter list, this array has
47      * four entries. In this case, the last two entries
48      * of the array are the inclusive source range of
49      * the array qualifiers.
50      */

51     protected int[] fReturnTypeRange;
52
53     /**
54      * Contains the textual representation of the method's
55      * parameter list, including open and closing parentheses
56      * when the parameters had been altered from the contents
57      * in the document, otherwise <code>null</code>.
58      */

59     protected char[] fParameterList;
60
61     /**
62      * The original inclusive source range of the
63      * method's parameter list in the document.
64      */

65     protected int[] fParameterRange;
66
67     /**
68      * Contains the textual representation of the method's
69      * exception list when the exceptions had been altered
70      * from the contents in the document, otherwise
71      * <code>null</code>. The exception list is a comment
72      * delimited list of exceptions, not including the "throws"
73      * keyword.
74      */

75     protected char[] fExceptionList;
76
77     /**
78      * The original inclusive source range of the
79      * method's exception list in the document.
80      */

81     protected int[] fExceptionRange;
82     
83     /**
84      * Contains the method's body when the body has
85      * been altered from the contents in the document,
86      * otherwise <code>null</code>. The body includes everything
87      * between and including the enclosing braces, and trailing
88      * whitespace.
89      */

90     protected String JavaDoc fBody;
91
92     /**
93      * The original inclusive source range of the
94      * method's body.
95      */

96     protected int[] fBodyRange;
97
98
99     /**
100      * Names of parameters in the method parameter list,
101      * or <code>null</code> if the method has no parameters.
102      */

103     protected String JavaDoc[] fParameterNames;
104
105     /**
106      * Types of parameters in the method parameter list,
107      * or <code>null</code> if the method has no parameters.
108      */

109     protected String JavaDoc[] fParameterTypes;
110
111     /**
112      * The exceptions the method throws, or <code>null</code>
113      * if the method throws no exceptions.
114      */

115     protected String JavaDoc[] fExceptions;
116
117     /**
118      * The formal type parameters.
119      * @since 3.0
120      */

121     protected String JavaDoc[] fTypeParameters = CharOperation.NO_STRINGS;
122
123     /**
124      * Default value for this attotation type member (only),
125      * or <code>null</code> if none.
126      * @since 3.0
127      */

128     protected String JavaDoc fDefaultValue = null;
129     
130 /**
131  * Constructs an empty method node.
132  */

133 DOMMethod() {
134     // Constructs an empty method node
135
}
136 /**
137  * Creates a new detailed METHOD document fragment on the given range of the document.
138  *
139  * @param document - the document containing this node's original contents
140  * @param sourceRange - a two element array of integers describing the
141  * entire inclusive source range of this node within its document.
142  * Contents start on and include the character at the first position.
143  * Contents end on and include the character at the last position.
144  * An array of -1's indicates this node's contents do not exist
145  * in the document.
146  * @param name - the identifier portion of the name of this node, or
147  * <code>null</code> if this node does not have a name
148  * @param nameRange - a two element array of integers describing the
149  * entire inclusive source range of this node's name within its document,
150  * including any array qualifiers that might immediately follow the name
151  * or -1's if this node does not have a name.
152  * @param commentRange - a two element array describing the comments that precede
153  * the member declaration. The first matches the start of this node's
154  * sourceRange, and the second is the new-line or first non-whitespace
155  * character following the last comment. If no comments are present,
156  * this array contains two -1's.
157  * @param flags - an integer representing the modifiers for this member. The
158  * integer can be analyzed with org.eclipse.jdt.core.Flags
159  * @param modifierRange - a two element array describing the location of
160  * modifiers for this member within its source range. The first integer
161  * is the first character of the first modifier for this member, and
162  * the second integer is the last whitespace character preceeding the
163  * next part of this member declaration. If there are no modifiers present
164  * in this node's source code (that is, package default visibility), this array
165  * contains two -1's.
166  * @param isConstructor - true if the method is a contructor, otherwise false
167  * @param returnType - the normalized return type of this method
168  * @param returnTypeRange - a two element array describing the location of the
169  * return type within the method's source range. The first integer is is
170  * the position of the first character in the return type, and the second
171  * integer is the position of the last character in the return type.
172  * For constructors, the contents of this array are -1's.
173  * If the return type of this method is qualified with '[]' following the
174  * parameter list, this array has four entries. In this case, the last
175  * two entries of the array are the inclusive source range of the array
176  * qualifiers.
177  * @param parameterTypes - an array of parameter types in the method declaration
178  * or <code>null</code> if the method has no parameters
179  * @param parameterNames - an array of parameter names in the method declaration
180  * or <code>null</code> if the method has no parameters
181  * @param parameterRange - a two element array describing the location of the
182  * parameter list in the method. The first integer is the location of the
183  * open parenthesis and the second integer is the location of the closing
184  * parenthesis.
185  * @param exceptions - an array of the names of exceptions thrown by this method
186  * or <code>null</code> if the method throws no exceptions
187  * @param exceptionRange - a two element array describing the location of the
188  * exception list in the method declaration. The first integer is the position
189  * of the first character in the first exception the method throws, and the
190  * second integer is the position of the last character of the last exception
191  * this method throws.
192  * @param bodyRange - a two element array describing the location of the method's body.
193  * The first integer is the first character following the method's
194  * parameter list, or exception list (if present). The second integer is the location
195  * of the last character in the method's source range.
196  */

197 DOMMethod(char[] document, int[] sourceRange, String JavaDoc name, int[] nameRange, int[] commentRange, int flags, int[] modifierRange, boolean isConstructor, String JavaDoc returnType, int[] returnTypeRange, String JavaDoc[] parameterTypes, String JavaDoc[] parameterNames, int[] parameterRange, String JavaDoc[] exceptions, int[] exceptionRange, int[] bodyRange) {
198     super(document, sourceRange, name, nameRange, commentRange, flags, modifierRange);
199
200     setMask(MASK_IS_CONSTRUCTOR, isConstructor);
201     fReturnType= returnType;
202     fReturnTypeRange= returnTypeRange;
203     fParameterTypes= parameterTypes;
204     fParameterNames= parameterNames;
205     fParameterRange= parameterRange;
206     fExceptionRange= exceptionRange;
207     fExceptions= exceptions;
208     setHasBody(true);
209     fBodyRange= bodyRange;
210     setMask(MASK_DETAILED_SOURCE_INDEXES, true);
211     
212 }
213 /**
214  * Creates a new simple METHOD document fragment on the given range of the document.
215  *
216  * @param document - the document containing this node's original contents
217  * @param sourceRange - a two element array of integers describing the
218  * entire inclusive source range of this node within its document.
219  * Contents start on and include the character at the first position.
220  * Contents end on and include the character at the last position.
221  * An array of -1's indicates this node's contents do not exist
222  * in the document.
223  * @param name - the identifier portion of the name of this node, or
224  * <code>null</code> if this node does not have a name
225  * @param nameRange - a two element array of integers describing the
226  * entire inclusive source range of this node's name within its document,
227  * including any array qualifiers that might immediately follow the name
228  * or -1's if this node does not have a name.
229  * @param flags - an integer representing the modifiers for this member. The
230  * integer can be analyzed with org.eclipse.jdt.core.Flags
231  * @param isConstructor - true if the method is a contructor, otherwise false
232  * @param returnType - the normalized return type of this method
233  * @param parameterTypes - an array of parameter types in the method declaration
234  * or <code>null</code> if the method has no parameters
235  * @param parameterNames - an array of parameter names in the method declaration
236  * or <code>null</code> if the method has no parameters
237  * @param exceptions - an array of the names of exceptions thrown by this method
238  * or <code>null</code> if the method throws no exceptions
239  */

240 DOMMethod(char[] document, int[] sourceRange, String JavaDoc name, int[] nameRange, int flags, boolean isConstructor, String JavaDoc returnType, String JavaDoc[] parameterTypes, String JavaDoc[] parameterNames, String JavaDoc[] exceptions) {
241     this(document, sourceRange, name, nameRange, new int[] {-1, -1}, flags, new int[] {-1, -1}, isConstructor, returnType, new int[] {-1, -1}, parameterTypes, parameterNames, new int[] {-1, -1}, exceptions, new int[] {-1, -1}, new int[] {-1, -1});
242     setMask(MASK_DETAILED_SOURCE_INDEXES, false);
243 }
244 /**
245  * @see IDOMMethod#addException(String)
246  */

247 public void addException(String JavaDoc name) throws IllegalArgumentException JavaDoc {
248     if (name == null) {
249         throw new IllegalArgumentException JavaDoc(Messages.dom_nullExceptionType);
250     }
251     if (fExceptions == null) {
252         fExceptions= new String JavaDoc[1];
253         fExceptions[0]= name;
254     } else {
255         fExceptions= appendString(fExceptions, name);
256     }
257     setExceptions(fExceptions);
258 }
259 /**
260  * @see IDOMMethod#addParameter(String, String)
261  */

262 public void addParameter(String JavaDoc type, String JavaDoc name) throws IllegalArgumentException JavaDoc {
263     if (type == null) {
264         throw new IllegalArgumentException JavaDoc(Messages.dom_nullTypeParameter);
265     }
266     if (name == null) {
267         throw new IllegalArgumentException JavaDoc(Messages.dom_nullNameParameter);
268     }
269     if (fParameterNames == null) {
270         fParameterNames= new String JavaDoc[1];
271         fParameterNames[0]= name;
272     } else {
273         fParameterNames= appendString(fParameterNames, name);
274     }
275     if (fParameterTypes == null) {
276         fParameterTypes= new String JavaDoc[1];
277         fParameterTypes[0]= type;
278     } else {
279         fParameterTypes= appendString(fParameterTypes, type);
280     }
281     setParameters(fParameterTypes, fParameterNames);
282 }
283 /**
284  * @see DOMMember#appendMemberBodyContents(CharArrayBuffer)
285  */

286 protected void appendMemberBodyContents(CharArrayBuffer buffer) {
287     if (fBody != null) {
288         buffer.append(fBody);
289     } else {
290         buffer.append(fDocument, fBodyRange[0], fBodyRange[1] + 1 - fBodyRange[0]);
291     }
292 }
293 /**
294  * @see DOMMember#appendMemberDeclarationContents(CharArrayBuffer)
295  */

296 protected void appendMemberDeclarationContents(CharArrayBuffer buffer) {
297
298     if (isConstructor()) {
299         buffer
300             .append(getConstructorName())
301             .append(fDocument, fNameRange[1] + 1, fParameterRange[0] - fNameRange[1] - 1);
302     } else {
303         buffer.append(getReturnTypeContents());
304         if (fReturnTypeRange[0] >= 0) {
305             buffer.append(fDocument, fReturnTypeRange[1] + 1, fNameRange[0] - fReturnTypeRange[1] - 1);
306         } else {
307             buffer.append(' ');
308         }
309         buffer
310             .append(getNameContents())
311             .append(fDocument, fNameRange[1] + 1, fParameterRange[0] - fNameRange[1] - 1);
312     }
313     if (fParameterList != null) {
314         buffer.append(fParameterList);
315     } else {
316         buffer.append(fDocument, fParameterRange[0], fParameterRange[1] + 1 - fParameterRange[0]);
317     }
318     int start;
319     if (hasTrailingArrayQualifier() && isReturnTypeAltered()) {
320         start= fReturnTypeRange[3] + 1;
321     } else {
322         start= fParameterRange[1] + 1;
323     }
324     if (fExceptions != null) {
325         // add 'throws' keyword
326
if (fExceptionRange[0] >= 0) {
327             buffer.append(fDocument, start, fExceptionRange[0] - start);
328         } else {
329             buffer.append(" throws "); //$NON-NLS-1$
330
}
331         // add exception list
332
if (fExceptionList != null) {
333             buffer.append(fExceptionList);
334             // add space before body
335
if (fExceptionRange[0] >= 0) {
336                 buffer.append(fDocument, fExceptionRange[1] + 1, fBodyRange[0] - fExceptionRange[1] - 1);
337             } else {
338                 buffer.append(fDocument, fParameterRange[1] + 1, fBodyRange[0] - fParameterRange[1] - 1);
339             }
340         } else {
341             // add list and space before body
342
buffer.append(fDocument, fExceptionRange[0], fBodyRange[0] - fExceptionRange[0]);
343         }
344     } else {
345         // add space before body
346
if (fExceptionRange[0] >= 0) {
347             buffer.append(fDocument, fExceptionRange[1] + 1, fBodyRange[0] - fExceptionRange[1] - 1);
348         } else {
349             buffer.append(fDocument, start, fBodyRange[0] - start);
350         }
351     }
352     
353 }
354 /**
355  * @see DOMMember#appendSimpleContents(CharArrayBuffer)
356  */

357 protected void appendSimpleContents(CharArrayBuffer buffer) {
358     // append eveything before my name
359
buffer.append(fDocument, fSourceRange[0], fNameRange[0] - fSourceRange[0]);
360     // append my name
361
if (isConstructor()) {
362         buffer.append(getConstructorName());
363     } else {
364         buffer.append(fName);
365     }
366     // append everything after my name
367
buffer.append(fDocument, fNameRange[1] + 1, fSourceRange[1] - fNameRange[1]);
368 }
369 /**
370  * @see IDOMMethod#getBody()
371  */

372 public String JavaDoc getBody() {
373     becomeDetailed();
374     if (hasBody()) {
375         if (fBody != null) {
376             return fBody;
377         } else {
378             return new String JavaDoc(fDocument, fBodyRange[0], fBodyRange[1] + 1 - fBodyRange[0]);
379         }
380     } else {
381         return null;
382     }
383 }
384 /**
385  * Returns the simple name of the enclsoing type for this constructor.
386  * If the constuctor is not currently enclosed in a type, the original
387  * name of the constructor as found in the documnent is returned.
388  */

389 protected String JavaDoc getConstructorName() {
390
391     if (isConstructor()) {
392         if (getParent() != null) {
393             return getParent().getName();
394         } else {
395             // If there is no parent use the original name
396
return new String JavaDoc(getNameContents());
397         }
398     } else {
399         return null;
400     }
401     
402 }
403 /**
404  * @see DOMNode#getDetailedNode()
405  */

406 protected DOMNode getDetailedNode() {
407     return (DOMNode)getFactory().createMethod(getContents());
408 }
409 /**
410  * @see IDOMMethod#getExceptions()
411  */

412 public String JavaDoc[] getExceptions() {
413     return fExceptions;
414 }
415 protected char[] generateFlags() {
416     char[] flags= Flags.toString(getFlags() & ~Flags.AccVarargs).toCharArray();
417     if (flags.length == 0) {
418         return flags;
419     } else {
420         return CharOperation.concat(flags, new char[] {' '});
421     }
422 }/**
423  * @see IDOMNode#getJavaElement
424  */

425 public IJavaElement getJavaElement(IJavaElement parent) throws IllegalArgumentException JavaDoc {
426     if (parent.getElementType() == IJavaElement.TYPE) {
427         // translate parameter types to signatures
428
String JavaDoc[] sigs= null;
429         if (fParameterTypes != null) {
430             sigs= new String JavaDoc[fParameterTypes.length];
431             int i;
432             for (i= 0; i < fParameterTypes.length; i++) {
433                 sigs[i]= Signature.createTypeSignature(fParameterTypes[i].toCharArray(), false);
434             }
435         }
436         String JavaDoc name= null;
437         if (isConstructor()) {
438             name= getConstructorName();
439         } else {
440             name= getName();
441         }
442         return ((IType)parent).getMethod(name, sigs);
443     } else {
444         throw new IllegalArgumentException JavaDoc(Messages.element_illegalParent);
445     }
446 }
447 /**
448  * @see DOMMember#getMemberDeclarationStartPosition()
449  */

450 protected int getMemberDeclarationStartPosition() {
451     if (fReturnTypeRange[0] >= 0) {
452         return fReturnTypeRange[0];
453     } else {
454         return fNameRange[0];
455     }
456 }
457 /**
458  * @see IDOMNode#getName()
459  */

460 public String JavaDoc getName() {
461     if (isConstructor()) {
462         return null;
463     } else {
464         return super.getName();
465     }
466 }
467 /**
468  * @see IDOMNode#getNodeType()
469  */

470 public int getNodeType() {
471     return IDOMNode.METHOD;
472 }
473 /**
474  * @see IDOMMethod#getParameterNames()
475  */

476 public String JavaDoc[] getParameterNames() {
477     return fParameterNames;
478 }
479 /**
480  * @see IDOMMethod#getParameterTypes()
481  */

482 public String JavaDoc[] getParameterTypes() {
483     return fParameterTypes;
484 }
485 /**
486  * @see IDOMMethod#getReturnType()
487  */

488 public String JavaDoc getReturnType() {
489     if (isConstructor()) {
490         return null;
491     } else {
492         return fReturnType;
493     }
494 }
495 /**
496  * Returns the source code to be used for this method's return type
497  */

498 protected char[] getReturnTypeContents() {
499     if (isConstructor()) {
500         return null;
501     } else {
502         if (isReturnTypeAltered()) {
503             return fReturnType.toCharArray();
504         } else {
505             return CharOperation.subarray(fDocument, fReturnTypeRange[0], fReturnTypeRange[1] + 1);
506         }
507
508     }
509 }
510 /**
511  * Returns true if this method's return type has
512  * array qualifiers ('[]') following the parameter list.
513  */

514 protected boolean hasTrailingArrayQualifier() {
515     return fReturnTypeRange.length > 2;
516 }
517 /**
518  * @see IDOMMethod#isConstructor()
519  */

520 public boolean isConstructor() {
521     return getMask(MASK_IS_CONSTRUCTOR);
522 }
523 /**
524  * Returns true if this method's return type has been altered
525  * from the original document contents.
526  */

527 protected boolean isReturnTypeAltered() {
528     return getMask(MASK_RETURN_TYPE_ALTERED);
529 }
530 /**
531  * @see IDOMNode#isSignatureEqual(IDOMNode)
532  *
533  * <p>Two methods have equal signatures if there names are the same
534  * and their parameter types are the same.
535  */

536 public boolean isSignatureEqual(IDOMNode node) {
537     boolean ok= node.getNodeType() == getNodeType();
538     if (ok) {
539         IDOMMethod method= (IDOMMethod)node;
540         ok = (isConstructor() && method.isConstructor()) ||
541             (!isConstructor() && !method.isConstructor());
542         if (ok && !isConstructor()) {
543             ok= getName().equals(method.getName());
544         }
545         if (!ok) {
546             return false;
547         }
548         
549         String JavaDoc[] types= method.getParameterTypes();
550         if (fParameterTypes == null || fParameterTypes.length == 0) {
551             // this method has no parameters
552
if (types == null || types.length == 0) {
553                 // the other method has no parameters either
554
return true;
555             }
556         } else {
557             // this method has parameters
558
if (types == null || types.length == 0) {
559                 // the other method has no parameters
560
return false;
561             }
562             if (fParameterTypes.length != types.length) {
563                 // the methods have a different number of parameters
564
return false;
565             }
566             int i;
567             for (i= 0; i < types.length; i++) {
568                 if (!fParameterTypes[i].equals(types[i])) {
569                     return false;
570                 }
571             }
572             return true;
573         }
574     }
575     return false;
576     
577 }
578 /**
579  * @see DOMNode
580  */

581 protected DOMNode newDOMNode() {
582     return new DOMMethod();
583 }
584 /**
585  * Offsets all the source indexes in this node by the given amount.
586  */

587 protected void offset(int offset) {
588     super.offset(offset);
589     offsetRange(fBodyRange, offset);
590     offsetRange(fExceptionRange, offset);
591     offsetRange(fParameterRange, offset);
592     offsetRange(fReturnTypeRange, offset);
593 }
594 /**
595  * @see IDOMMethod#setBody
596  */

597 public void setBody(String JavaDoc body) {
598     becomeDetailed();
599     fragment();
600     fBody= body;
601     setHasBody(body != null);
602     if (!hasBody()) {
603         fBody= ";" + Util.getLineSeparator(body, null); //$NON-NLS-1$
604
}
605 }
606 /**
607  * Sets the end of the body range
608  */

609 void setBodyRangeEnd(int end) {
610     fBodyRange[1] = end;
611 }
612 /**
613  * @see IDOMMethod#setConstructor(boolean)
614  */

615 public void setConstructor(boolean b) {
616     becomeDetailed();
617     setMask(MASK_IS_CONSTRUCTOR, b);
618     fragment();
619 }
620 /**
621  * @see IDOMMethod#setExceptions(String[])
622  */

623 public void setExceptions(String JavaDoc[] names) {
624     becomeDetailed();
625     if (names == null || names.length == 0) {
626         fExceptions= null;
627     } else {
628         fExceptions= names;
629         CharArrayBuffer buffer = new CharArrayBuffer();
630         char[] comma = new char[] {',', ' '};
631         for (int i = 0, length = names.length; i < length; i++) {
632             if (i > 0)
633                 buffer.append(comma);
634             buffer.append(names[i]);
635         }
636         fExceptionList= buffer.getContents();
637     }
638     fragment();
639 }
640 /**
641  * @see IDOMMethod#setName
642  */

643 public void setName(String JavaDoc name) {
644     if (name == null) {
645         throw new IllegalArgumentException JavaDoc(Messages.element_nullName);
646     } else {
647         super.setName(name);
648     }
649 }
650 /**
651  * @see IDOMMethod#setParameters(String[], String[])
652  */

653 public void setParameters(String JavaDoc[] types, String JavaDoc[] names) throws IllegalArgumentException JavaDoc {
654     becomeDetailed();
655     if (types== null || names == null) {
656         if (types == null && names == null) {
657             fParameterTypes= null;
658             fParameterNames= null;
659             fParameterList= new char[] {'(',')'};
660         } else {
661             throw new IllegalArgumentException JavaDoc(Messages.dom_mismatchArgNamesAndTypes);
662         }
663     } else if (names.length != types.length) {
664         throw new IllegalArgumentException JavaDoc(Messages.dom_mismatchArgNamesAndTypes);
665     } else if (names.length == 0) {
666         setParameters(null, null);
667     } else {
668         fParameterNames= names;
669         fParameterTypes= types;
670         CharArrayBuffer parametersBuffer = new CharArrayBuffer();
671         parametersBuffer.append("("); //$NON-NLS-1$
672
char[] comma = new char[] {',', ' '};
673         for (int i = 0; i < names.length; i++) {
674             if (i > 0) {
675                 parametersBuffer.append(comma);
676             }
677             parametersBuffer
678                 .append(types[i])
679                 .append(' ')
680                 .append(names[i]);
681         }
682         parametersBuffer.append(')');
683         fParameterList= parametersBuffer.getContents();
684     }
685     fragment();
686 }
687 /**
688  * @see IDOMMethod#setReturnType(String)
689  */

690 public void setReturnType(String JavaDoc name) throws IllegalArgumentException JavaDoc {
691     if (name == null) {
692         throw new IllegalArgumentException JavaDoc(Messages.dom_nullReturnType);
693     }
694     becomeDetailed();
695     fragment();
696     setReturnTypeAltered(true);
697     fReturnType= name;
698 }
699 /**
700  * Sets the state of this method declaration as having
701  * the return type altered from the original document.
702  */

703 protected void setReturnTypeAltered(boolean typeAltered) {
704     setMask(MASK_RETURN_TYPE_ALTERED, typeAltered);
705 }
706 /**
707  */

708 protected void setSourceRangeEnd(int end) {
709     super.setSourceRangeEnd(end);
710     fBodyRange[1]= end;
711 }
712 /**
713  * @see DOMNode#shareContents(DOMNode)
714  */

715 protected void shareContents(DOMNode node) {
716     super.shareContents(node);
717     DOMMethod method= (DOMMethod)node;
718     fBody= method.fBody;
719     fBodyRange= rangeCopy(method.fBodyRange);
720     fExceptionList= method.fExceptionList;
721     fExceptionRange= rangeCopy(method.fExceptionRange);
722     fExceptions= method.fExceptions;
723     fParameterList= method.fParameterList;
724     fParameterNames= method.fParameterNames;
725     fParameterRange= rangeCopy(method.fParameterRange);
726     fParameterTypes= method.fParameterTypes;
727     fReturnType= method.fReturnType;
728     fReturnTypeRange= rangeCopy(method.fReturnTypeRange);
729 }
730 /**
731  * @see IDOMNode#toString()
732  */

733 public String JavaDoc toString() {
734     if (isConstructor()) {
735         return "CONSTRUCTOR"; //$NON-NLS-1$
736
} else {
737         return "METHOD: " + getName(); //$NON-NLS-1$
738
}
739 }
740
741 /**
742  * @see IDOMMethod#setDefault(java.lang.String)
743  * @since 3.0
744  */

745 public void setDefault(String JavaDoc defaultValue) {
746     this.fDefaultValue = defaultValue;
747 }
748
749 /**
750  * @see IDOMMethod#getDefault()
751  * @since 3.0
752  */

753 public String JavaDoc getDefault() {
754     return this.fDefaultValue;
755 }
756
757 /**
758  * @see IDOMMethod#getTypeParameters()
759  * @since 3.0
760  */

761 public String JavaDoc[] getTypeParameters() {
762     return this.fTypeParameters;
763 }
764
765 /**
766  * @see IDOMMethod#setTypeParameters(java.lang.String[])
767  * @since 3.0
768  */

769 public void setTypeParameters(String JavaDoc[] typeParameters) {
770     this.fTypeParameters = typeParameters;
771 }
772 }
773
Popular Tags