public InputStream openSource(SourceLineAnnotation source) throws IOException { SourceFile sourceFile = findSourceFile(source); return sourceFile.getInputStream(); }
/** * Open an input stream on a source file in given package. * * @param packageName * the name of the package containing the class whose source file * is given * @param fileName * the unqualified name of the source file * @return an InputStream on the source file * @throws IOException * if a matching source file cannot be found */ public InputStream openSource(String packageName, String fileName) throws IOException { SourceFile sourceFile = findSourceFile(packageName, fileName); return sourceFile.getInputStream(); }
public SourceFile findSourceFile(SourceLineAnnotation source) throws IOException { return findSourceFile(source.getPackageName(), getOrGuessSourceFile(source)); }
private String fileNameFor(final String packageName, final String sourceName) { String result; SourceFinder sourceFinder = AnalysisContext.currentAnalysisContext().getSourceFinder(); try { result = sourceFinder.findSourceFile(packageName, sourceName).getFullFileName(); } catch (IOException e) { result = packageName.replace('.', File.separatorChar) + File.separatorChar + sourceName; } return result; }
private void copySourceForAnnotation(BugAnnotation ann) { SourceLineAnnotation sourceAnnotation; if (ann instanceof BugAnnotationWithSourceLines) { sourceAnnotation = ((BugAnnotationWithSourceLines) ann).getSourceLines(); } else if (ann instanceof SourceLineAnnotation) { sourceAnnotation = (SourceLineAnnotation) ann; } else { return; } if (sourceAnnotation == null) { return; } if (sourceAnnotation.isUnknown()) { return; } String fullName = SourceFinder.getPlatformName(sourceAnnotation); SourceFile sourceFile; try { sourceFile = sourceFinder.findSourceFile(sourceAnnotation); } catch (IOException e) { if (couldNotFind.add(fullName)) { System.out.println("Did not find " + fullName); } return; } if (copied.add(fullName)) { copySourceFile(fullName, sourceFile); } }
String pkgName = line.getPackageName(); try { fullPath = sourceFinder.findSourceFile(pkgName, line.getSourceFile()).getFullFileName(); } catch (IOException e) { if ("".equals(pkgName)) {
SourceFile sourceFile = sourceFinder.findSourceFile(srcLine.getPackageName(), srcLine.getSourceFile()); int startLine = srcLine.getStartLine();
SourceLineAnnotation srcLine = SourceLineAnnotation.fromVisitedInstructionRange(this, lastPC, getPC()); SourceFinder sourceFinder = AnalysisContext.currentAnalysisContext().getSourceFinder(); SourceFile sourceFile = sourceFinder.findSourceFile(srcLine.getPackageName(), srcLine.getSourceFile());
try { SourceFinder mySourceFinder = project.getSourceFinder(); String fullPath = new File(mySourceFinder.findSourceFile(this).getFullFileName()).getCanonicalPath(); String myRelativeSourceBase = relativeSourceBase.get(); if (fullPath.startsWith(myRelativeSourceBase) && fullPath.length() > myRelativeSourceBase.length()) {
public InputStream openSource(SourceLineAnnotation source) throws IOException { SourceFile sourceFile = findSourceFile(source); return sourceFile.getInputStream(); }
/** * Open an input stream on a source file in given package. * * @param packageName * the name of the package containing the class whose source file * is given * @param fileName * the unqualified name of the source file * @return an InputStream on the source file * @throws IOException * if a matching source file cannot be found */ public InputStream openSource(String packageName, String fileName) throws IOException { SourceFile sourceFile = findSourceFile(packageName, fileName); return sourceFile.getInputStream(); }
private boolean sourceCodeExists(@Nonnull SourceLineAnnotation note) { try { mainFrame.getProject().getSourceFinder().findSourceFile(note); } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } return true; }
public SourceFile findSourceFile(SourceLineAnnotation source) throws IOException { return findSourceFile(source.getPackageName(), getOrGuessSourceFile(source)); }
private String findSourceFile(final Project project, final SourceFinder sourceFinder, final SourceLineAnnotation sourceLine) { try { SourceFile sourceFile = sourceFinder.findSourceFile(sourceLine); return sourceFile.getFullFileName(); } catch (IOException exception) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Can't resolve absolute file name for file " + sourceLine.getSourceFile() + ", dir list = " + project.getSourceDirList().toString()); return sourceLine.getPackageName().replace(DOT, SLASH) + SLASH + sourceLine.getSourceFile(); } }
private String findSourceFile(final Project project, final SourceFinder sourceFinder, final SourceLineAnnotation sourceLine) { try { SourceFile sourceFile = sourceFinder.findSourceFile(sourceLine); return sourceFile.getFullFileName(); } catch (IOException exception) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Can't resolve absolute file name for file " + sourceLine.getSourceFile() + ", dir list = " + project.getSourceDirList().toString()); return sourceLine.getPackageName().replace(DOT, SLASH) + SLASH + sourceLine.getSourceFile(); } }
private String findSourceFile(final Project project, final SourceFinder sourceFinder, final SourceLineAnnotation sourceLine) { try { SourceFile sourceFile = sourceFinder.findSourceFile(sourceLine); return sourceFile.getFullFileName(); } catch (IOException exception) { StringBuilder sb = new StringBuilder("Can't resolve absolute file name for file "); sb.append(sourceLine.getSourceFile()); if (isFirstError) { sb.append(", dir list = "); sb.append( project.getSourceDirList()); isFirstError = false; } Logger.getLogger(getClass().getName()).log(Level.WARNING, sb.toString()); return sourceLine.getPackageName().replace(DOT, SLASH) + SLASH + sourceLine.getSourceFile(); } }
private String fileNameFor(final String packageName, final String sourceName) { String result; SourceFinder sourceFinder = AnalysisContext.currentAnalysisContext().getSourceFinder(); try { result = sourceFinder.findSourceFile(packageName, sourceName).getFullFileName(); } catch (IOException e) { result = packageName.replace('.', File.separatorChar) + File.separatorChar + sourceName; } return result; }
private void copySourceForAnnotation(BugAnnotation ann) { SourceLineAnnotation sourceAnnotation; if (ann instanceof BugAnnotationWithSourceLines) { sourceAnnotation = ((BugAnnotationWithSourceLines) ann).getSourceLines(); } else if (ann instanceof SourceLineAnnotation) { sourceAnnotation = (SourceLineAnnotation) ann; } else { return; } if (sourceAnnotation == null) { return; } if (sourceAnnotation.isUnknown()) { return; } String fullName = SourceFinder.getPlatformName(sourceAnnotation); SourceFile sourceFile; try { sourceFile = sourceFinder.findSourceFile(sourceAnnotation); } catch (IOException e) { if (couldNotFind.add(fullName)) { System.out.println("Did not find " + fullName); } return; } if (copied.add(fullName)) { copySourceFile(fullName, sourceFile); } }
if (srcLineAnnotation != null) { SourceFinder sourceFinder = AnalysisContext.currentAnalysisContext().getSourceFinder(); SourceFile sourceFile = sourceFinder.findSourceFile(srcLineAnnotation.getPackageName(), srcLineAnnotation.getSourceFile()); try (BufferedReader sourceReader = new BufferedReader(new InputStreamReader(sourceFile.getInputStream(), StandardCharsets.UTF_8))) {
@Nonnull private JavaSourceDocument getDocument(SourceLineAnnotation source) { try { SourceFile sourceFile = frame.getProject().getSourceFinder().findSourceFile(source); String fullFileName = sourceFile.getFullFileName(); SoftReference<JavaSourceDocument> resultReference = map.get(fullFileName); JavaSourceDocument result = null; if (resultReference != null) { result = resultReference.get(); } if (result != null) { return result; } try { InputStream in = sourceFile.getInputStream(); result = new JavaSourceDocument(source.getClassName(), SourceCharset.bufferedReader(in), sourceFile); } catch (Exception e) { result = JavaSourceDocument.UNKNOWNSOURCE; Debug.println(e); // e.printStackTrace(); } map.put(fullFileName, new SoftReference<JavaSourceDocument>(result)); return result; } catch (Exception e) { Debug.println(e); // e.printStackTrace(); return JavaSourceDocument.UNKNOWNSOURCE; } }