List of usage examples for com.google.gwt.core.ext.linker CompilationResult getSymbolMap
public abstract SymbolData[] getSymbolMap();
From source file:com.ait.toolkit.node.dev.linker.NodeJsSymbolStoreLinker.java
License:Open Source License
@Override protected void addPreloadCode(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, CompilationResult result, DefaultTextOutput out) throws UnableToCompleteException { super.addPreloadCode(logger, context, artifacts, result, out); //add the symbols out.print("//--- BEGIN SYMBOL MAPPING ---"); out.newline();/* ww w . j a va 2s .c o m*/ out.print("//create symbol mapping object"); out.newline(); StringBuilder objectJs = new StringBuilder(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader( NodeJsSymbolStoreLinker.class.getResourceAsStream("SymbolStoreObject.js"))); String line = reader.readLine(); while (line != null) { line = line.replace("${objectName}", ClientSymbolStore.GLOBAL_JS_OBJECT_NAME); line = line.replace("${classesName}", ClientSymbolStore.CLASSES_MAP_NAME); line = line.replace("${methodsName}", ClientSymbolStore.METHODS_MAP_NAME); line = line.replace("${fieldsName}", ClientSymbolStore.FIELDS_MAP_NAME); objectJs.append(line).append("\n"); line = reader.readLine(); } } catch (IOException e) { logger.log(Type.ERROR, "Can't read local file", e); throw new UnableToCompleteException(); } finally { try { reader.close(); } catch (Exception ignore) { } } out.print(objectJs.toString()); out.newline(); out.print("//add symbols"); for (SymbolData symbol : result.getSymbolMap()) { out.newline(); out.print("global."); out.print(ClientSymbolStore.GLOBAL_JS_OBJECT_NAME); out.print("._add("); out.print(buildSymbolJson(symbol)); out.print(");"); } out.newline(); out.print("//--- END SYMBOL MAPPING ---"); out.newline(); }
From source file:com.didactilab.gwt.phprpc.linker.PhpClientOracleLinker.java
License:Apache License
@Override public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation) throws UnableToCompleteException { if (onePermutation) { artifacts = new ArtifactSet(artifacts); Map<String, List<String>> allSerializableFields = new HashMap<String, List<String>>(); for (RpcDataArtifact data : artifacts.find(RpcDataArtifact.class)) { allSerializableFields.putAll(data.getOperableFields()); }//from w ww. j av a2 s.c o m for (CompilationResult result : artifacts.find(CompilationResult.class)) { PhpWebClientOracleBuilder builder = new PhpWebClientOracleBuilder(); for (Map.Entry<String, List<String>> entry : allSerializableFields.entrySet()) { builder.setSerializableFields(entry.getKey(), entry.getValue()); } for (SymbolData symbolData : result.getSymbolMap()) { String castableTypeMapString = (symbolData.getCastableTypeMap() == null) ? null : symbolData.getCastableTypeMap().toJs(); builder.add(symbolData.getSymbolName(), symbolData.getJsniIdent(), symbolData.getClassName(), symbolData.getMemberName(), symbolData.getQueryId(), new CastableTypeDataImpl(castableTypeMapString)); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { builder.store(out); } catch (IOException e) { // Should generally not happen logger.log(TreeLogger.ERROR, "Unable to store deRPC data", e); throw new UnableToCompleteException(); } SyntheticArtifact a = emitBytes(logger, out.toByteArray(), result.getStrongName() + SUFFIX); artifacts.add(a); } } return artifacts; }
From source file:gwt.ns.webworker.linker.WorkerCompilationLinker.java
License:Apache License
/** * Searches for all instances of a placeholder String in a * CompilationResult. If found, they are replaced as specified and a * new CompilationResult, with a newly generated strong name, is returned. * If no occurrences were found, the original CompilationResult is * returned./* w w w. ja va2 s . c o m*/ * * @param logger * @param result CompilationResult to process * @param placeholder String to be replaced * @param replacement String to insert in place of placeholder * * @return A CompilationResult suitable for emitting */ public CompilationResult replacePlaceholder(TreeLogger logger, CompilationResult result, String placeholder, String replacement) { boolean needsMod = false; String[] js = result.getJavaScript(); StringBuffer[] jsbuf = new StringBuffer[js.length]; for (int i = 0; i < jsbuf.length; i++) { jsbuf[i] = new StringBuffer(js[i]); } // search and replace in all fragments for (StringBuffer fragment : jsbuf) { needsMod |= replaceAll(fragment, placeholder, replacement); } // by default, returning unaltered result CompilationResult toReturn = result; // code has been altered, need to create new CompilationResult if (needsMod) { logger.log(TreeLogger.SPAM, "Compilation permutation " + result.getPermutationId() + " being modified."); // new js for compilation result byte[][] newcode = new byte[jsbuf.length][]; for (int i = 0; i < jsbuf.length; i++) { newcode[i] = Util.getBytes(jsbuf[i].toString()); } // new strong name String strongName = Util.computeStrongName(newcode); // same symbolMap copied over since none altered // symbolMap a little more complicated // can only get deserialized version, need to reserialize // code from com.google.gwt.dev.jjs.JavaToJavaScriptCompiler // TODO: turns out this can get pretty bad. Workaround? SymbolData[] symbolMap = result.getSymbolMap(); byte[] serializedSymbolMap; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Util.writeObjectToStream(baos, (Object) symbolMap); serializedSymbolMap = baos.toByteArray(); } catch (IOException e) { // should still never happen logger.log(TreeLogger.ERROR, "IOException while reserializing " + "SymbolMap."); throw new RuntimeException("Should never happen with in-memory stream", e); } StandardCompilationResult altered = new StandardCompilationResult(strongName, newcode, serializedSymbolMap, result.getStatementRanges(), result.getPermutationId()); // need to copy permutation properties to new result for (Map<SelectionProperty, String> propertyMap : result.getPropertyMap()) { altered.addSelectionPermutation(propertyMap); } toReturn = altered; logger.log(TreeLogger.SPAM, "Compilation permuation " + toReturn.getPermutationId() + " altered to include path to worker script(s)."); } return toReturn; }
From source file:org.gwtnode.dev.linker.GwtNodeSymbolStoreLinker.java
License:Apache License
@Override protected void addPreloadCode(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, CompilationResult result, DefaultTextOutput out) throws UnableToCompleteException { super.addPreloadCode(logger, context, artifacts, result, out); //add the symbols out.print("//--- BEGIN SYMBOL MAPPING ---"); out.newline();//www . j a v a 2 s .c o m out.print("//create symbol mapping object"); out.newline(); StringBuilder objectJs = new StringBuilder(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader( GwtNodeSymbolStoreLinker.class.getResourceAsStream("SymbolStoreObject.js"))); String line = reader.readLine(); while (line != null) { line = line.replace("${objectName}", ClientSymbolStore.GLOBAL_JS_OBJECT_NAME); line = line.replace("${classesName}", ClientSymbolStore.CLASSES_MAP_NAME); line = line.replace("${methodsName}", ClientSymbolStore.METHODS_MAP_NAME); line = line.replace("${fieldsName}", ClientSymbolStore.FIELDS_MAP_NAME); objectJs.append(line).append("\n"); line = reader.readLine(); } } catch (IOException e) { logger.log(Type.ERROR, "Can't read local file", e); throw new UnableToCompleteException(); } finally { try { reader.close(); } catch (Exception ignore) { } } out.print(objectJs.toString()); out.newline(); out.print("//add symbols"); for (SymbolData symbol : result.getSymbolMap()) { out.newline(); out.print("global."); out.print(ClientSymbolStore.GLOBAL_JS_OBJECT_NAME); out.print("._add("); out.print(buildSymbolJson(symbol)); out.print(");"); } out.newline(); out.print("//--- END SYMBOL MAPPING ---"); out.newline(); }