protected String getTraceSimpleFileName(final ITypeRoot derivedResource) { IType type = derivedResource.findPrimaryType(); if (type == null) return null; String sourceName = ((BinaryType) type).getSourceFileName(null); if (sourceName == null) return null; // the primary source in the .class file is .java (JSR-45 aka SMAP scenario) if (sourceName.endsWith(".java")) { return traceFileNameProvider.getTraceFromJava(sourceName); } // xtend-as-primary-source-scenario. if (sourceName.endsWith(".xtend")) { String name = type.getElementName(); int index = name.indexOf("$"); if (index > 0) name = name.substring(0, index); return traceFileNameProvider.getTraceFromJava(name + ".java"); } return null; }
protected @Nullable IStorage getGeneratedFileForTraceFile(IStorage traceFile) { if (traceFile instanceof IFile) { IFile file = (IFile) traceFile; String lastSegment = traceFile.getFullPath().lastSegment(); lastSegment = traceFileNameProvider.getJavaFromTrace(lastSegment); return file.getParent().getFile(new Path(lastSegment)); } return null; }
/** * @since 2.3 */ public @Nullable IStorage getTraceFile(IStorage storage) { if (storage instanceof IFile) { IFile file = (IFile) storage; String originLastSegment = file.getFullPath().lastSegment(); IFile traceFile = file.getParent().getFile(new Path(traceFileNameProvider.getTraceFromJava(originLastSegment))); return traceFile; } return null; }
/** * @since 2.4 */ protected void generateTrace(String generatedFile, String outputConfigName, CharSequence contents) { try { if (contents instanceof ITraceRegionProvider) { String traceFileName = traceFileNameProvider.getTraceFromJava(generatedFile); File traceFile = getFile(traceFileName, outputConfigName); OutputStream out = new BufferedOutputStream(new FileOutputStream(traceFile)); try { AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion(); traceSerializer.writeTraceRegionTo(traceRegion, out); } finally { out.close(); } } } catch (FileNotFoundException e) { throw new RuntimeIOException(e); } catch (IOException e) { throw new RuntimeIOException(e); } }