This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 225528
Collapse All | Expand All

(-)a/classfile/apichanges.xml (+14 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
	<change id="Java7Support">
111
            <api name="general"/>
112
            <summary>Support for Java 7 classfile enhancements.</summary>
113
            <version major="1" minor="40"/>
114
            <date day="13" month="2" year="2013"/>
115
            <author login="jlahoda"/>
116
            <compatibility addition="yes"/>
117
            <description>
118
                Java 7 added a several new constant pool entry types to support the
119
                invokeDynamic instruction. These need to be modeled by the library.
120
            </description>
121
            <class package="org.netbeans.modules.classfile" name="ClassFile"/>
122
            <issue number="225528"/>
123
	</change>
110
	<change id="Java6Support">
124
	<change id="Java6Support">
111
            <api name="general"/>
125
            <api name="general"/>
112
            <summary>Support for Java 6 classfile enhancements.</summary>
126
            <summary>Support for Java 6 classfile enhancements.</summary>
(-)a/classfile/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.classfile/1
2
OpenIDE-Module: org.netbeans.modules.classfile/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/classfile/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/classfile/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.39
4
OpenIDE-Module-Specification-Version: 1.40
5
5
(-)a/classfile/src/org/netbeans/modules/classfile/CPNameAndTypeInfo.java (-33 / +12 lines)
Lines 3-9 Link Here
3
 *
3
 *
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
 *
5
 *
6
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
 * Copyright 1997-2013 Oracle and/or its affiliates. All rights reserved.
7
 *
7
 *
8
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9
 * Other names may be trademarks of their respective owners.
9
 * Other names may be trademarks of their respective owners.
Lines 29-35 Link Here
29
 * Contributor(s):
29
 * Contributor(s):
30
 *
30
 *
31
 * The Original Software is NetBeans. The Initial Developer of the Original
31
 * The Original Software is NetBeans. The Initial Developer of the Original
32
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
32
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2013 Sun
33
 * Microsystems, Inc. All Rights Reserved.
33
 * Microsystems, Inc. All Rights Reserved.
34
 *
34
 *
35
 * If you wish your version of this file to be governed by only the CDDL
35
 * If you wish your version of this file to be governed by only the CDDL
Lines 52-91 Link Here
52
52
53
53
54
/**
54
/**
55
 * A class representing the CONSTANT_NameAndType constant pool type.
55
 * A class representing the CONSTANT_InvokeDynamic constant pool type.
56
 *
56
 *
57
 * @author Thomas Ball
57
 * @author Thomas Ball
58
 * @since 1.40
58
 */
59
 */
59
public class CPNameAndTypeInfo extends CPEntry {
60
public class CPInvokeDynamicInfo extends CPEntry {
60
    int iName;
61
    int iBootstrapMethod;
61
    int iDesc;
62
    int iNameAndType;
62
63
63
    CPNameAndTypeInfo(ConstantPool pool,int iName,int iDesc) {
64
    CPInvokeDynamicInfo(ConstantPool pool,int iBootstrapMethod,int iNameAndType) {
64
	super(pool);
65
	super(pool);
65
        this.iName = iName;
66
        this.iBootstrapMethod = iBootstrapMethod;
66
        this.iDesc = iDesc;
67
        this.iNameAndType = iNameAndType;
67
    }
68
69
    protected CPNameAndTypeInfo(ConstantPool pool) {
70
        super(pool);
71
        iName = CPName.INVALID_INDEX;
72
        iDesc = CPName.INVALID_INDEX;
73
    }
74
75
    public final String getName() {
76
	return ((CPName)pool.cpEntries[iName]).getName();
77
    }
78
79
    void setNameIndex(int index) {
80
	iName = index;
81
    }
82
83
    public final String getDescriptor() {
84
	return ((CPName)pool.cpEntries[iDesc]).getName();
85
    }
86
87
    void setDescriptorIndex(int index) {
88
	iDesc = index;
89
    }
68
    }
90
69
91
    public int getTag() {
70
    public int getTag() {
Lines 94-100 Link Here
94
73
95
    @Override
74
    @Override
96
    public String toString() {
75
    public String toString() {
97
        return getClass().getName() + ": name=" + getName() + //NOI18N
76
        return getClass().getName() + ": bootstrapMethod=" + iBootstrapMethod + //NOI18N
98
            ", descriptor=" + getDescriptor(); //NOI18N
77
            ", nameAndType=" + iNameAndType; //NOI18N
99
    }
78
    }
100
}
79
}
(-)a/classfile/src/org/netbeans/modules/classfile/CPNameAndTypeInfo.java (-34 / +39 lines)
Lines 3-9 Link Here
3
 *
3
 *
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
 *
5
 *
6
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
 * Copyright 1997-2013 Oracle and/or its affiliates. All rights reserved.
7
 *
7
 *
8
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9
 * Other names may be trademarks of their respective owners.
9
 * Other names may be trademarks of their respective owners.
Lines 29-35 Link Here
29
 * Contributor(s):
29
 * Contributor(s):
30
 *
30
 *
31
 * The Original Software is NetBeans. The Initial Developer of the Original
31
 * The Original Software is NetBeans. The Initial Developer of the Original
32
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
32
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2013 Sun
33
 * Microsystems, Inc. All Rights Reserved.
33
 * Microsystems, Inc. All Rights Reserved.
34
 *
34
 *
35
 * If you wish your version of this file to be governed by only the CDDL
35
 * If you wish your version of this file to be governed by only the CDDL
Lines 52-100 Link Here
52
52
53
53
54
/**
54
/**
55
 * A class representing the CONSTANT_NameAndType constant pool type.
55
 * A class representing the CONSTANT_MethodHandle constant pool type.
56
 *
56
 *
57
 * @author Thomas Ball
57
 * @author Thomas Ball
58
 * @since 1.40
58
 */
59
 */
59
public class CPNameAndTypeInfo extends CPEntry {
60
public class CPMethodHandleInfo extends CPEntry {
60
    int iName;
61
    ReferenceKind referenceKind;
61
    int iDesc;
62
    int iReference;
62
63
63
    CPNameAndTypeInfo(ConstantPool pool,int iName,int iDesc) {
64
    CPMethodHandleInfo(ConstantPool pool, int referenceKind,int iReference) {
64
	super(pool);
65
	super(pool);
65
        this.iName = iName;
66
        this.referenceKind = ReferenceKind.from(referenceKind);
66
        this.iDesc = iDesc;
67
        this.iReference = iReference;
67
    }
68
69
    protected CPNameAndTypeInfo(ConstantPool pool) {
70
        super(pool);
71
        iName = CPName.INVALID_INDEX;
72
        iDesc = CPName.INVALID_INDEX;
73
    }
74
75
    public final String getName() {
76
	return ((CPName)pool.cpEntries[iName]).getName();
77
    }
78
79
    void setNameIndex(int index) {
80
	iName = index;
81
    }
82
83
    public final String getDescriptor() {
84
	return ((CPName)pool.cpEntries[iDesc]).getName();
85
    }
86
87
    void setDescriptorIndex(int index) {
88
	iDesc = index;
89
    }
68
    }
90
69
91
    public int getTag() {
70
    public int getTag() {
92
	return ConstantPool.CONSTANT_NameAndType;
71
	return ConstantPool.CONSTANT_MethodHandle;
93
    }
72
    }
94
73
95
    @Override
74
    @Override
96
    public String toString() {
75
    public String toString() {
97
        return getClass().getName() + ": name=" + getName() + //NOI18N
76
        return getClass().getName() + ": kind=" + referenceKind + //NOI18N
98
            ", descriptor=" + getDescriptor(); //NOI18N
77
            ", index=" + iReference; //NOI18N
78
    }
79
    
80
    public enum ReferenceKind {
81
        getField(1),
82
        getStatic(2),
83
        putField(3),
84
        putStatic(4),
85
        invokeVirtual(5),
86
        invokeStatic(6),
87
        invokeSpecial(7),
88
        newInvokeSpecial(8),
89
        invokeInterface(9);
90
        
91
        private final int kindInt;
92
93
        private ReferenceKind(int kindInt) {
94
            this.kindInt = kindInt;
95
        }
96
        
97
        static ReferenceKind from(int referenceKind) {
98
            for (ReferenceKind k : values()) {
99
                if (k.kindInt == referenceKind) return k;
100
            }
101
            
102
            throw new IllegalStateException("Unknown ref kind: " + referenceKind);
103
        }
99
    }
104
    }
100
}
105
}
(-)a/classfile/src/org/netbeans/modules/classfile/CPNameAndTypeInfo.java (-34 / +10 lines)
Lines 3-9 Link Here
3
 *
3
 *
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
 *
5
 *
6
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
 * Copyright 1997-2013 Oracle and/or its affiliates. All rights reserved.
7
 *
7
 *
8
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9
 * Other names may be trademarks of their respective owners.
9
 * Other names may be trademarks of their respective owners.
Lines 29-35 Link Here
29
 * Contributor(s):
29
 * Contributor(s):
30
 *
30
 *
31
 * The Original Software is NetBeans. The Initial Developer of the Original
31
 * The Original Software is NetBeans. The Initial Developer of the Original
32
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
32
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2013 Sun
33
 * Microsystems, Inc. All Rights Reserved.
33
 * Microsystems, Inc. All Rights Reserved.
34
 *
34
 *
35
 * If you wish your version of this file to be governed by only the CDDL
35
 * If you wish your version of this file to be governed by only the CDDL
Lines 52-100 Link Here
52
52
53
53
54
/**
54
/**
55
 * A class representing the CONSTANT_NameAndType constant pool type.
55
 * A class representing the CONSTANT_MethodType constant pool type.
56
 *
56
 *
57
 * @author Thomas Ball
57
 * @author Thomas Ball
58
 * @since 1.40
58
 */
59
 */
59
public class CPNameAndTypeInfo extends CPEntry {
60
public class CPMethodTypeInfo extends CPEntry {
60
    int iName;
61
    int iDescriptor;
61
    int iDesc;
62
62
63
    CPNameAndTypeInfo(ConstantPool pool,int iName,int iDesc) {
63
    CPMethodTypeInfo(ConstantPool pool, int iDescriptor) {
64
	super(pool);
64
	super(pool);
65
        this.iName = iName;
65
        this.iDescriptor = iDescriptor;
66
        this.iDesc = iDesc;
67
    }
68
69
    protected CPNameAndTypeInfo(ConstantPool pool) {
70
        super(pool);
71
        iName = CPName.INVALID_INDEX;
72
        iDesc = CPName.INVALID_INDEX;
73
    }
74
75
    public final String getName() {
76
	return ((CPName)pool.cpEntries[iName]).getName();
77
    }
78
79
    void setNameIndex(int index) {
80
	iName = index;
81
    }
82
83
    public final String getDescriptor() {
84
	return ((CPName)pool.cpEntries[iDesc]).getName();
85
    }
86
87
    void setDescriptorIndex(int index) {
88
	iDesc = index;
89
    }
66
    }
90
67
91
    public int getTag() {
68
    public int getTag() {
92
	return ConstantPool.CONSTANT_NameAndType;
69
	return ConstantPool.CONSTANT_MethodHandle;
93
    }
70
    }
94
71
95
    @Override
72
    @Override
96
    public String toString() {
73
    public String toString() {
97
        return getClass().getName() + ": name=" + getName() + //NOI18N
74
        return getClass().getName() + ": descriptor=" + iDescriptor; //NOI18N
98
            ", descriptor=" + getDescriptor(); //NOI18N
99
    }
75
    }
100
}
76
}
(-)a/classfile/src/org/netbeans/modules/classfile/ConstantPool.java (+23 lines)
Lines 74-79 Link Here
74
    static final int CONSTANT_MethodRef = 10;
74
    static final int CONSTANT_MethodRef = 10;
75
    static final int CONSTANT_InterfaceMethodRef = 11;
75
    static final int CONSTANT_InterfaceMethodRef = 11;
76
    static final int CONSTANT_NameAndType = 12;
76
    static final int CONSTANT_NameAndType = 12;
77
    static final int CONSTANT_MethodHandle = 15;
78
    static final int CONSTANT_MethodType = 16;
79
    static final int CONSTANT_InvokeDynamic = 18;
77
80
78
    CPEntry[] cpEntries;
81
    CPEntry[] cpEntries;
79
    
82
    
Lines 265-270 Link Here
265
              newEntry = new CPNameAndTypeInfo(this, nameIndex, descIndex);
268
              newEntry = new CPNameAndTypeInfo(this, nameIndex, descIndex);
266
              break;
269
              break;
267
          }
270
          }
271
              
272
          case CONSTANT_MethodHandle: {
273
              int kind = cpr.readUnsignedByte();
274
              int index = cpr.readUnsignedShort();
275
              newEntry = new CPMethodHandleInfo(this, kind, index);
276
              break;
277
          }
278
              
279
          case CONSTANT_MethodType: {
280
              int index = cpr.readUnsignedShort();
281
              newEntry = new CPMethodTypeInfo(this, index);
282
              break;
283
          }
284
              
285
          case CONSTANT_InvokeDynamic: {
286
              int bootstrapMethod = cpr.readUnsignedShort();
287
              int nameAndType = cpr.readUnsignedShort();
288
              newEntry = new CPInvokeDynamicInfo(this, bootstrapMethod, nameAndType);
289
              break;
290
          }
268
291
269
          default:
292
          default:
270
              throw new IllegalArgumentException(
293
              throw new IllegalArgumentException(
(-)a/classfile/test/unit/src/regression/JDK8ClassFilesTest.java (+64 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package regression;
43
44
import java.io.InputStream;
45
import junit.framework.TestCase;
46
import org.netbeans.modules.classfile.ClassFile;
47
48
/**
49
 *
50
 * @author lahvac
51
 */
52
public class JDK8ClassFilesTest extends TestCase {
53
    
54
    public JDK8ClassFilesTest(String testName) {
55
        super(testName);
56
    }
57
    
58
    public void testDefenderMethods() throws Exception {
59
        InputStream classData = 
60
            getClass().getResourceAsStream("datafiles/WithLambda.classx");
61
        ClassFile classFile = new ClassFile(classData);
62
        classFile.toString();
63
    }
64
}

Return to bug 225528