001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.instrumentation;
042:
043: import org.netbeans.lib.profiler.client.ClientUtils;
044: import org.netbeans.lib.profiler.utils.Wildcards;
045: import java.util.ArrayList;
046: import java.util.List;
047:
048: /**
049: *
050: * @author Tomas Hurka
051: */
052: class RootMethods {
053: //~ Instance fields ----------------------------------------------------------------------------------------------------------
054:
055: // In case of multiple roots, here we have 1 to 1 correspondence between classNames, methodNames and methodSignatures
056: // E.g. we may have X,foo,() and X,bar,() as the respective elements of these three arrays.
057: String[] classNames;
058: boolean[] classesWildcard;
059: boolean[] markerMethods;
060: String[] methodNames;
061: String[] methodSignatures;
062:
063: //~ Constructors -------------------------------------------------------------------------------------------------------------
064:
065: RootMethods(ClientUtils.SourceCodeSelection[] roots) {
066: classNames = new String[roots.length];
067: methodNames = new String[roots.length];
068: methodSignatures = new String[roots.length];
069: classesWildcard = new boolean[roots.length];
070: markerMethods = new boolean[roots.length];
071:
072: for (int i = 0; i < roots.length; i++) {
073: ClientUtils.SourceCodeSelection s = roots[i];
074:
075: if (s.definedViaSourceLines()) {
076: classNames = new String[] { s.getClassName() };
077: } else if (s.definedViaMethodName()) {
078: // Convert all the class names into slash form
079: String rootName = classNames[i] = s.getClassName()
080: .replace('.', '/').intern(); // NOI18N
081: //System.err.println("root rootName: "+rootName);
082:
083: if (Wildcards.isPackageWildcard(rootName)) {
084: classesWildcard[i] = true;
085:
086: //System.err.println("Uses wildcard: "+rootClasses[i]);
087: // root method name and signature is not used in this case
088: } else {
089: methodNames[i] = s.getMethodName().intern();
090: methodSignatures[i] = s.getMethodSignature()
091: .intern();
092: classesWildcard[i] = false;
093: }
094: } else { // The third case, when no root methods or code region is defined ("Instrument all spawned threads")
095: classNames = methodNames = methodSignatures = new String[0];
096: }
097:
098: markerMethods[i] = s.isMarkerMethod();
099: }
100: }
101:
102: //~ Methods ------------------------------------------------------------------------------------------------------------------
103:
104: List /*<String>*/getRootClassNames() {
105: if (classNames.length > 0) {
106: List rootClasses = new ArrayList();
107:
108: for (int i = 0; i < classNames.length; i++) {
109: String name = classNames[i].replace('/', '.'); // NOI18N;
110:
111: if (!rootClasses.contains(name)) {
112: rootClasses.add(name);
113: }
114: }
115:
116: return rootClasses;
117: }
118:
119: return null;
120: }
121: }
|