~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateMethodOperation.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *     QNX Software Systems - Initial API and implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.cdt.internal.core.model;
12
 
 
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;
19
 
 
20
 
/**
21
 
 * <p>This operation creates an instance method. 
22
 
 *
23
 
 * <p>Required Attributes:<ul>
24
 
 *  <li>Containing type
25
 
 *  <li>The source code for the method. No verification of the source is
26
 
 *      performed.
27
 
 * </ul>
28
 
 */
29
 
public class CreateMethodOperation extends CreateMemberOperation {
30
 
        /**
31
 
         * Parameter types of the element.
32
 
         */
33
 
        protected String[] fParameterTypes;
34
 
 
35
 
        /**
36
 
         * The source code for the new member.
37
 
         */
38
 
        protected String fSource;
39
 
 
40
 
 
41
 
        /**
42
 
         * When executed, this operation will create a method
43
 
         * in the given type with the specified source.
44
 
         */
45
 
        public CreateMethodOperation(IStructure parentElement, String name, String returnType, String source, String[] parameters, boolean force) {
46
 
                super(parentElement, name, returnType, force);
47
 
                fParameterTypes = parameters;
48
 
                fSource = source;
49
 
        }
50
 
 
51
 
        /**
52
 
         * @see CreateElementInTUOperation#generateResultHandle
53
 
         */
54
 
        @Override
55
 
        protected ICElement generateResultHandle() {
56
 
                //TODO: what about collisions, we need the signature here.
57
 
                return getStructure().getMethod(fName);
58
 
        }
59
 
 
60
 
        /**
61
 
         * @see CreateElementInTUOperation#getMainTaskName
62
 
         */
63
 
        @Override
64
 
        public String getMainTaskName(){
65
 
                return CoreModelMessages.getString("operation.createMethodProgress"); //$NON-NLS-1$
66
 
        }
67
 
 
68
 
        /**
69
 
         * @see CreateMemberOperation#verifyNameCollision
70
 
         */
71
 
        @Override
72
 
        protected ICModelStatus verifyNameCollision() {
73
 
                ICModelStatus status = super.verify();
74
 
                if (!status.isOK()) {
75
 
                        return status;
76
 
                }
77
 
                if (fSource == null) {
78
 
                        return new CModelStatus(ICModelStatusConstants.INVALID_CONTENTS);
79
 
                }
80
 
                if (!fForce) {
81
 
                        //check for name collisions
82
 
                        //if (node == null) {
83
 
                        //      return new CModelStatus(ICModelStatusConstants.INVALID_CONTENTS);
84
 
                        //      }
85
 
                        //} catch (CModelException cme) {
86
 
                        //}
87
 
                }
88
 
 
89
 
                return CModelStatus.VERIFIED_OK;
90
 
        }
91
 
 
92
 
        /* (non-Javadoc)
93
 
         * @see org.eclipse.cdt.internal.core.model.CreateElementInTUOperation#generateElement(org.eclipse.cdt.core.model.ITranslationUnit)
94
 
         */
95
 
        @Override
96
 
        protected String generateElement(ITranslationUnit unit) throws CModelException {
97
 
                StringBuffer sb = new StringBuffer();
98
 
                sb.append(fReturnType);
99
 
                sb.append(' ');
100
 
                sb.append(fName);
101
 
                sb.append('(');
102
 
                if (fParameterTypes != null) {
103
 
                        for (int i = 0; i < fParameterTypes.length; ++i) {
104
 
                                if (i != 0) {
105
 
                                        sb.append(',').append(' ');
106
 
                                }
107
 
                                sb.append(fParameterTypes[i]);
108
 
                        }
109
 
                }
110
 
                sb.append(')').append(' ').append('{').append(Util.LINE_SEPARATOR);
111
 
                sb.append(fSource);
112
 
                sb.append(Util.LINE_SEPARATOR).append('}').append(Util.LINE_SEPARATOR);
113
 
                return sb.toString();
114
 
        }
115
 
 
116
 
}