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/InnerClass.java (-67 / +28 lines)
Lines 1-9 Link Here
1
/*
1
/*
2
 * InnerClass.java
3
 *
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
 *
3
 *
6
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
7
 *
5
 *
8
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 29-35 Link Here
29
 * Contributor(s):
27
 * Contributor(s):
30
 *
28
 *
31
 * The Original Software is NetBeans. The Initial Developer of the Original
29
 * The Original Software is NetBeans. The Initial Developer of the Original
32
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
 * Software is Sun Microsystems, Inc. Portions Copyright 2013 Sun
33
 * Microsystems, Inc. All Rights Reserved.
31
 * Microsystems, Inc. All Rights Reserved.
34
 *
32
 *
35
 * If you wish your version of this file to be governed by only the CDDL
33
 * If you wish your version of this file to be governed by only the CDDL
Lines 57-143 Link Here
57
 * An InnerClass attribute of a classfile.
55
 * An InnerClass attribute of a classfile.
58
 *
56
 *
59
 * @author  Thomas Ball
57
 * @author  Thomas Ball
58
 * @since 1.40
60
 */
59
 */
61
public final class InnerClass {
60
public final class BootstrapMethod {
62
61
63
    ClassName name;
62
    int methodRef;
64
    ClassName outerClassName;
63
    int[] arguments;
65
    String simpleName;
66
    int access;
67
64
68
    static InnerClass[] loadInnerClasses(DataInputStream in, ConstantPool pool)
65
    static BootstrapMethod[] loadBootstrapMethod(DataInputStream in, ConstantPool pool)
69
      throws IOException {
66
      throws IOException {
70
        int n = in.readUnsignedShort();
67
        int n = in.readUnsignedShort();
71
        InnerClass[] innerClasses = new InnerClass[n];
68
        BootstrapMethod[] innerClasses = new BootstrapMethod[n];
72
        for (int i = 0; i < n; i++)
69
        for (int i = 0; i < n; i++)
73
            innerClasses[i] = new InnerClass(in, pool);
70
            innerClasses[i] = new BootstrapMethod(in, pool);
74
        return innerClasses;
71
        return innerClasses;
75
    }
72
    }
76
73
77
    InnerClass(DataInputStream in, ConstantPool pool) 
74
    BootstrapMethod(DataInputStream in, ConstantPool pool) throws IOException {
78
      throws IOException {
75
        this.methodRef = in.readUnsignedShort();
79
        loadInnerClass(in, pool);
76
        int args = in.readUnsignedShort();
77
        arguments = new int[args];
78
        for (int i = 0; i < args; i++) {
79
            arguments[i] = in.readUnsignedShort();
80
        }
80
    }
81
    }
81
82
82
    private void loadInnerClass(DataInputStream in, ConstantPool pool) 
83
    public int getMethodRef() {
83
      throws IOException {
84
        return methodRef;
84
        int index = in.readUnsignedShort();
85
        name = (index > 0) ? pool.getClass(index).getClassName() : null;
86
        index = in.readUnsignedShort();
87
	outerClassName = (index > 0) ? pool.getClass(index).getClassName() : null;
88
        index = in.readUnsignedShort();
89
        if (index > 0) {
90
            CPUTF8Info entry = (CPUTF8Info)pool.get(index);
91
            simpleName = entry.getName();
92
        }
93
        access = in.readUnsignedShort();
94
    }
85
    }
95
86
96
    /** Returns the name of this class, including its package (if any).
87
    public int[] getArguments() {
97
     * If the compiler didn't define this value, the string 
88
        return arguments.clone();
98
     * "<not defined>" is returned.
99
     * @return the name of this class.
100
     */    
101
    public final ClassName getName() {
102
        return name;
103
    }
104
    
105
    /** Returns the name of the enclosing outer class, including 
106
     *  its package (if any).  
107
     * @return the name of this class, or null if not available.
108
     */    
109
    public final ClassName getOuterClassName() {
110
        return outerClassName;
111
    }
112
113
    /**
114
     * Returns the original simple name as given in the source code.
115
     * If this is an anonymous class, null is returned instead.
116
     * @return the simple name of this class, or null if anonymous.
117
     */
118
    public final String getSimpleName() {
119
        return simpleName;
120
    }
121
122
    /**
123
     * Returns the access flags of this class.
124
     */
125
    public final int getAccess() {
126
        return access;
127
    }
89
    }
128
90
129
    @Override
91
    @Override
130
    public String toString() {
92
    public String toString() {
131
        StringBuffer sb = new StringBuffer();
93
        StringBuilder sb = new StringBuilder();
132
        sb.append("innerclass=");
94
        sb.append("bootstrapmethod=");
133
        sb.append(name);
95
        sb.append(methodRef);
134
        if (simpleName != null) {
96
        sb.append("(");
135
            sb.append(" (");
97
        for (int i = 0; i < arguments.length; i++) {
136
            sb.append(simpleName);
98
            if (i > 0) sb.append(", ");
137
            sb.append(')');
99
            sb.append(arguments[i]);
138
        }
100
        }
139
        sb.append(", outerclass=");
101
        sb.append(")");
140
        sb.append(outerClassName);
141
        return sb.toString();
102
        return sb.toString();
142
    }
103
    }
143
}
104
}
(-)a/classfile/src/org/netbeans/modules/classfile/CPNameAndTypeInfo.java (-34 / +21 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_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() {
92
	return ConstantPool.CONSTANT_NameAndType;
71
	return ConstantPool.CONSTANT_InvokeDynamic;
72
    }
73
    
74
    public int getBootstrapMethod() {
75
        return iBootstrapMethod;
76
    }
77
    
78
    public int getNameAndType() {
79
        return iNameAndType;
93
    }
80
    }
94
81
95
    @Override
82
    @Override
96
    public String toString() {
83
    public String toString() {
97
        return getClass().getName() + ": name=" + getName() + //NOI18N
84
        return getClass().getName() + ": bootstrapMethod=" + iBootstrapMethod + //NOI18N
98
            ", descriptor=" + getDescriptor(); //NOI18N
85
            ", nameAndType=" + iNameAndType; //NOI18N
99
    }
86
    }
100
}
87
}
(-)a/classfile/src/org/netbeans/modules/classfile/CPNameAndTypeInfo.java (-34 / +47 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;
72
    }
73
74
    public ReferenceKind getReferenceKind() {
75
        return referenceKind;
76
    }
77
78
    public int getReference() {
79
        return iReference;
93
    }
80
    }
94
81
95
    @Override
82
    @Override
96
    public String toString() {
83
    public String toString() {
97
        return getClass().getName() + ": name=" + getName() + //NOI18N
84
        return getClass().getName() + ": kind=" + referenceKind + //NOI18N
98
            ", descriptor=" + getDescriptor(); //NOI18N
85
            ", index=" + iReference; //NOI18N
86
    }
87
    
88
    public enum ReferenceKind {
89
        getField(1),
90
        getStatic(2),
91
        putField(3),
92
        putStatic(4),
93
        invokeVirtual(5),
94
        invokeStatic(6),
95
        invokeSpecial(7),
96
        newInvokeSpecial(8),
97
        invokeInterface(9);
98
        
99
        private final int kindInt;
100
101
        private ReferenceKind(int kindInt) {
102
            this.kindInt = kindInt;
103
        }
104
        
105
        static ReferenceKind from(int referenceKind) {
106
            for (ReferenceKind k : values()) {
107
                if (k.kindInt == referenceKind) return k;
108
            }
109
            
110
            throw new IllegalStateException("Unknown ref kind: " + referenceKind);
111
        }
99
    }
112
    }
100
}
113
}
(-)a/classfile/src/org/netbeans/modules/classfile/CPNameAndTypeInfo.java (-34 / +14 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_MethodType;
70
    }
71
72
    public int getDescriptor() {
73
        return iDescriptor;
93
    }
74
    }
94
75
95
    @Override
76
    @Override
96
    public String toString() {
77
    public String toString() {
97
        return getClass().getName() + ": name=" + getName() + //NOI18N
78
        return getClass().getName() + ": descriptor=" + iDescriptor; //NOI18N
98
            ", descriptor=" + getDescriptor(); //NOI18N
99
    }
79
    }
100
}
80
}
(-)a/classfile/src/org/netbeans/modules/classfile/ClassFile.java (+23 lines)
Lines 69-74 Link Here
69
    Method[] methods;
69
    Method[] methods;
70
    String sourceFileName;
70
    String sourceFileName;
71
    InnerClass[] innerClasses;
71
    InnerClass[] innerClasses;
72
    BootstrapMethod[] bootstrapMethods;
72
    private AttributeMap attributes;
73
    private AttributeMap attributes;
73
    private Map<ClassName,Annotation> annotations;
74
    private Map<ClassName,Annotation> annotations;
74
    short majorVersion;
75
    short majorVersion;
Lines 414-419 Link Here
414
	}
415
	}
415
        return Arrays.asList(innerClasses);
416
        return Arrays.asList(innerClasses);
416
    }
417
    }
418
    
419
    /**Return the content of the <code>BootstrapMethods</code> attribute.
420
     * 
421
     * @return 
422
     * @since 1.40
423
     */
424
    public final List<BootstrapMethod> getBootstrapMethods(){
425
	if (bootstrapMethods == null) {
426
	    DataInputStream in = attributes.getStream("BootstrapMethods"); // NOI18N
427
	    if (in != null) {
428
		try {
429
		    bootstrapMethods = 
430
			BootstrapMethod.loadBootstrapMethod(in, constantPool);
431
		    in.close();
432
		} catch (IOException e) {
433
		    throw new InvalidClassFileAttributeException("invalid InnerClasses attribute", e);
434
		}
435
	    } else
436
		bootstrapMethods = new BootstrapMethod[0];
437
	}
438
        return Arrays.asList(bootstrapMethods);
439
    }
417
440
418
    /**
441
    /**
419
     * Returns the major version number of this classfile.
442
     * Returns the major version number of this classfile.
(-)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/org/netbeans/modules/classfile/JDK8ClassFilesTest.java (+80 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 org.netbeans.modules.classfile;
43
44
import java.io.InputStream;
45
import java.util.Arrays;
46
import junit.framework.TestCase;
47
import org.netbeans.modules.classfile.CPMethodHandleInfo.ReferenceKind;
48
49
/**
50
 *
51
 * @author lahvac
52
 */
53
public class JDK8ClassFilesTest extends TestCase {
54
    
55
    public JDK8ClassFilesTest(String testName) {
56
        super(testName);
57
    }
58
    
59
    public void testDefenderMethods() throws Exception {
60
        InputStream classData = 
61
            getClass().getResourceAsStream("datafiles/WithLambda.classx");
62
        ClassFile classFile = new ClassFile(classData);
63
        CPInvokeDynamicInfo invokeDynamic = (CPInvokeDynamicInfo) classFile.getConstantPool().get(2);
64
        assertEquals(ConstantPool.CONSTANT_InvokeDynamic, invokeDynamic.getTag());
65
        BootstrapMethod bootstrapMethod = classFile.getBootstrapMethods().get(invokeDynamic.getBootstrapMethod());
66
        assertEquals("[23, 24, 25]", Arrays.toString(bootstrapMethod.getArguments()));
67
        CPMethodHandleInfo bootstrapMH = (CPMethodHandleInfo) classFile.getConstantPool().get(bootstrapMethod.getMethodRef());
68
        assertEquals(ConstantPool.CONSTANT_MethodHandle, bootstrapMH.getTag());
69
        assertEquals(ReferenceKind.invokeStatic, bootstrapMH.getReferenceKind());
70
        CPMethodInfo bootstrapMethodInfo = (CPMethodInfo) classFile.getConstantPool().get(bootstrapMH.getReference());
71
        assertEquals("CallSite metaFactory(MethodHandles$Lookup,String,MethodType,MethodHandle,MethodHandle,MethodType)", bootstrapMethodInfo.getFullMethodName());
72
        CPNameAndTypeInfo nameAndType = (CPNameAndTypeInfo) classFile.getConstantPool().get(invokeDynamic.getNameAndType());
73
        assertEquals("()Ljava/lang/Runnable;", nameAndType.getDescriptor());
74
        assertEquals("lambda", nameAndType.getName());
75
        CPMethodTypeInfo methodType = (CPMethodTypeInfo) classFile.getConstantPool().get(25);
76
        assertEquals(ConstantPool.CONSTANT_MethodType, methodType.getTag());
77
        CPUTF8Info descriptor = (CPUTF8Info) classFile.getConstantPool().get(methodType.getDescriptor());
78
        assertEquals("()V", descriptor.getName());
79
    }
80
}

Return to bug 225528