1
/*******************************************************************************
2
* Copyright (c) 2000, 2008 QNX Software Systems 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
9
* QNX Software Systems - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.core.model;
13
import org.eclipse.cdt.core.model.CModelException;
14
import org.eclipse.cdt.core.model.ICElement;
15
import org.eclipse.cdt.core.model.ICModelStatus;
16
import org.eclipse.cdt.core.model.ICModelStatusConstants;
17
import org.eclipse.cdt.core.model.IStructure;
18
import org.eclipse.cdt.core.model.ITranslationUnit;
21
* <p>This operation creates an instance method.
23
* <p>Required Attributes:<ul>
25
* <li>The source code for the method. No verification of the source is
29
public class CreateMethodOperation extends CreateMemberOperation {
31
* Parameter types of the element.
33
protected String[] fParameterTypes;
36
* The source code for the new member.
38
protected String fSource;
42
* When executed, this operation will create a method
43
* in the given type with the specified source.
45
public CreateMethodOperation(IStructure parentElement, String name, String returnType, String source, String[] parameters, boolean force) {
46
super(parentElement, name, returnType, force);
47
fParameterTypes = parameters;
52
* @see CreateElementInTUOperation#generateResultHandle
55
protected ICElement generateResultHandle() {
56
//TODO: what about collisions, we need the signature here.
57
return getStructure().getMethod(fName);
61
* @see CreateElementInTUOperation#getMainTaskName
64
public String getMainTaskName(){
65
return CoreModelMessages.getString("operation.createMethodProgress"); //$NON-NLS-1$
69
* @see CreateMemberOperation#verifyNameCollision
72
protected ICModelStatus verifyNameCollision() {
73
ICModelStatus status = super.verify();
77
if (fSource == null) {
78
return new CModelStatus(ICModelStatusConstants.INVALID_CONTENTS);
81
//check for name collisions
83
// return new CModelStatus(ICModelStatusConstants.INVALID_CONTENTS);
85
//} catch (CModelException cme) {
89
return CModelStatus.VERIFIED_OK;
93
* @see org.eclipse.cdt.internal.core.model.CreateElementInTUOperation#generateElement(org.eclipse.cdt.core.model.ITranslationUnit)
96
protected String generateElement(ITranslationUnit unit) throws CModelException {
97
StringBuffer sb = new StringBuffer();
98
sb.append(fReturnType);
102
if (fParameterTypes != null) {
103
for (int i = 0; i < fParameterTypes.length; ++i) {
105
sb.append(',').append(' ');
107
sb.append(fParameterTypes[i]);
110
sb.append(')').append(' ').append('{').append(Util.LINE_SEPARATOR);
112
sb.append(Util.LINE_SEPARATOR).append('}').append(Util.LINE_SEPARATOR);
113
return sb.toString();