blob: f9b152ada6c86e8c08dda318eeb49f5360fc17eb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package org.eclipse.jdt.internal.core;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.core.resources.*;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.jdom.*;
/**
* <p>This operation creates an instance method.
*
* <p>Required Attributes:<ul>
* <li>Containing type
* <li>The source code for the method. No verification of the source is
* performed.
* </ul>
*/
public class CreateMethodOperation extends CreateTypeMemberOperation {
protected String[] fParameterTypes;
/**
* When executed, this operation will create a method
* in the given type with the specified source.
*/
public CreateMethodOperation(IType parentElement, String source, boolean force) {
super(parentElement, source, force);
}
/**
* Returns the type signatures of the parameter types of the
* current <code>DOMMethod</code>
*/
protected String[] convertDOMMethodTypesToSignatures() {
if (fParameterTypes == null) {
if (fDOMNode != null) {
String[] domParameterTypes = ((IDOMMethod)fDOMNode).getParameterTypes();
if (domParameterTypes != null) {
fParameterTypes = new String[domParameterTypes.length];
// convert the DOM types to signatures
int i;
for (i = 0; i < fParameterTypes.length; i++) {
fParameterTypes[i] = Signature.createTypeSignature(domParameterTypes[i].toCharArray(), false);
}
}
}
}
return fParameterTypes;
}
/**
* @see CreateTypeMemberOperation#generateElementDOM
*/
protected IDOMNode generateElementDOM() throws JavaModelException {
if (fDOMNode == null) {
fDOMNode = (new DOMFactory()).createMethod(fSource);
if (fDOMNode == null) { //syntactically incorrect source
fDOMNode = generateSyntaxIncorrectDOM();
}
if (fAlteredName != null && fDOMNode != null) {
fDOMNode.setName(fAlteredName);
}
}
return fDOMNode;
}
/**
* @see CreateElementInCUOperation#generateResultHandle
*/
protected IJavaElement generateResultHandle() {
String[] types = convertDOMMethodTypesToSignatures();
String name;
if (((IDOMMethod) fDOMNode).isConstructor()) {
name = fDOMNode.getParent().getName();
} else {
name = fDOMNode.getName();
}
return getType().getMethod(name, types);
}
/**
* @see CreateElementInCUOperation#getMainTaskName
*/
public String getMainTaskName(){
return "Creating a method...";
}
/**
* @see CreateTypeMemberOperation#verifyNameCollision
*/
protected IJavaModelStatus verifyNameCollision() {
if (fDOMNode != null) {
IType type = getType();
String name = fDOMNode.getName();
if (name == null) { //constructor
name = type.getElementName();
}
String[] types = convertDOMMethodTypesToSignatures();
if (type.getMethod(name, types).exists()) {
return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION);
}
}
return JavaModelStatus.VERIFIED_OK;
}
}
|