Add JVM compiler support.
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * If you wish your version of this file to be governed by only the CDDL
25 * or only the GPL Version 2, indicate your decision by adding
26 * "[Contributor] elects to include this software in this distribution
27 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28 * single choice of license, a recipient has the option to distribute
29 * your version of this file under either the CDDL, the GPL Version 2 or
30 * to extend the choice of license to its licensees as provided above.
31 * However, if you add GPL Version 2 code and therefore, elected the GPL
32 * Version 2 license, then the option applies only if the new code is
33 * made subject to such option by the copyright holder.
37 * Portions Copyrighted 2008 Sun Microsystems, Inc.
39 package org.netbeans.modules.ada.editor;
41 import org.netbeans.api.annotations.common.CheckForNull;
42 import org.netbeans.modules.ada.editor.ast.nodes.Expression;
43 import org.netbeans.modules.ada.editor.ast.nodes.FormalParameter;
44 import org.netbeans.modules.ada.editor.ast.nodes.Identifier;
45 import org.netbeans.modules.ada.editor.ast.nodes.MethodDeclaration;
46 import org.netbeans.modules.ada.editor.ast.nodes.MethodInvocation;
47 import org.netbeans.modules.ada.editor.ast.nodes.NameBase;
48 import org.netbeans.modules.ada.editor.ast.nodes.PackageBody;
49 import org.netbeans.modules.ada.editor.ast.nodes.PackageName;
50 import org.netbeans.modules.ada.editor.ast.nodes.PackageSpecification;
51 import org.netbeans.modules.ada.editor.ast.nodes.SubprogramBody;
52 import org.netbeans.modules.ada.editor.ast.nodes.SubprogramSpecification;
53 import org.netbeans.modules.ada.editor.ast.nodes.TypeAccess;
54 import org.netbeans.modules.ada.editor.ast.nodes.TypeDeclaration;
55 import org.netbeans.modules.ada.editor.ast.nodes.TypeName;
56 import org.netbeans.modules.ada.editor.ast.nodes.Variable;
59 * Based on org.netbeans.modules.php.editor.CodeUtils
61 * @author Andrea Lucarelli
63 public class CodeUtils {
65 public static final String FUNCTION_TYPE_PREFIX = "@fn:";
66 public static final String PROCEDURE_TYPE_PREFIX = "@prc:";
67 public static final String METHOD_TYPE_PREFIX = "@mtd:";
72 public static String extractPackageName(PackageName pkgName) {
73 Expression name = pkgName.getPackageName();
75 assert name instanceof Identifier :
76 "unsupported type of PackageName.getName(): " + name.getClass().getName();
78 return (name instanceof Identifier) ? ((Identifier) name).getName() : "";//NOI18N
81 public static String extractPackageName(PackageSpecification pkgSpecification) {
82 return pkgSpecification.getName().getName();
85 public static String extractPackageName(PackageBody pkgBody) {
86 return pkgBody.getName().getName();
89 public static String extractSubprogramName(SubprogramSpecification subprogramSpecification){
90 return subprogramSpecification.getSubprogramName().getName();
93 public static String extractProcedureName(SubprogramBody subprogramBody){
94 return subprogramBody.getSubprogramSpecification().getSubprogramName().getName();
97 public static String extractMethodName(MethodDeclaration methodDeclaration) {
98 return methodDeclaration.getMethodName();
102 public static String extractVariableName(Variable var) {
103 if (var.getName() instanceof Identifier) {
104 Identifier id = (Identifier) var.getName();
105 StringBuilder varName = new StringBuilder();
107 varName.append(id.getName());
108 return varName.toString();
115 public static String extractTypeName(TypeDeclaration var) {
116 if (var.getTypeName() instanceof Identifier) {
117 Identifier id = (Identifier) var.getTypeName();
118 StringBuilder varName = new StringBuilder();
120 varName.append(id.getName());
121 return varName.toString();
128 public static String extractTypeName(NameBase type) {
129 if (type instanceof TypeName) {
130 Identifier id = ((TypeName)type).getTypeName();
131 StringBuilder typeName = new StringBuilder();
132 typeName.append(id.getName());
133 return typeName.toString();
134 } else if (type instanceof TypeAccess) {
135 NameBase name = ((TypeAccess) type).getMember();
136 return extractTypeName(name);
143 public static TypeName extractType(NameBase type) {
144 if (type instanceof TypeName) {
145 return (TypeName)type;
146 } else if (type instanceof TypeAccess) {
147 NameBase name = ((TypeAccess) type).getMember();
148 return extractType(name);
154 public static String getParamDisplayName(FormalParameter param) {
155 Variable var = param.getParameterName();
156 StringBuilder paramName = new StringBuilder();
158 Identifier id = (Identifier) var.getName();
159 paramName.append(id.getName());
161 return paramName.length() == 0 ? null : paramName.toString();