1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package jdk.nashorn.api.tree; 26 27 import java.util.List; 28 import java.util.stream.Collectors; 29 import jdk.nashorn.internal.ir.FunctionNode; 30 import jdk.nashorn.internal.ir.IdentNode; 31 import jdk.nashorn.internal.ir.Module; 32 import static jdk.nashorn.api.tree.ModuleTreeImpl.identOrNull; 33 34 final class ExportEntryTreeImpl extends TreeImpl implements ExportEntryTree { 35 private final long startPos, endPos; 36 private final IdentifierTree exportName; 37 private final IdentifierTree moduleRequest; 38 private final IdentifierTree importName; 39 private final IdentifierTree localName; 40 41 private ExportEntryTreeImpl(final long startPos, final long endPos, 42 final IdentifierTree exportName, 43 final IdentifierTree moduleRequest, 44 final IdentifierTree importName, 45 final IdentifierTree localName) { 46 super(null); // no underlying Node! 47 this.startPos = startPos; 48 this.endPos = endPos; 49 this.exportName = exportName; 50 this.moduleRequest = moduleRequest; 51 this.importName = importName; 52 this.localName = localName; 53 } 54 55 private static ExportEntryTreeImpl createExportEntry(final Module.ExportEntry entry) { 56 return new ExportEntryTreeImpl(entry.getStartPosition(), 57 entry.getEndPosition(), 58 identOrNull(entry.getExportName()), 59 identOrNull(entry.getModuleRequest()), 60 identOrNull(entry.getImportName()), 61 identOrNull(entry.getLocalName())); 62 } 63 64 static List<ExportEntryTreeImpl> createExportList(final List<Module.ExportEntry> exportList) { 65 return exportList.stream(). 66 map(ExportEntryTreeImpl::createExportEntry). 67 collect(Collectors.toList()); 68 } 69 70 @Override 71 public Kind getKind() { 72 return Tree.Kind.EXPORT_ENTRY; 73 } 74 75 @Override 76 public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) { 77 return visitor.visitExportEntry(this, data); 78 } 79 80 @Override 81 public long getStartPosition() { 82 return startPos; 83 } 84 85 @Override 86 public long getEndPosition() { 87 return endPos; 88 } 89 90 @Override 91 public IdentifierTree getExportName() { 92 return exportName; 93 } 94 95 @Override 96 public IdentifierTree getModuleRequest() { 97 return moduleRequest; 98 } 99 100 @Override 101 public IdentifierTree getImportName() { 102 return importName; 103 } 104 105 @Override 106 public IdentifierTree getLocalName() { 107 return localName; 108 } 109 }