public JavacParser createPrivateParser (final Snapshot snapshot) { assert snapshot != null; return snapshot.getSource().getFileObject() != null ? new JavacParser(Collections.singletonList(snapshot), true) : null; }
@Override public void parse(final Snapshot snapshot, final Task task, SourceModificationEvent event) throws ParseException { try { checkSourceModification(event); parseImpl(snapshot, task); } catch (FileObjects.InvalidFileException ife) { //pass - already invalidated in parseImpl } catch (IOException ioe) { throw new ParseException ("JavacParser failure", ioe); //NOI18N } }
switch (this.sourceCount) { case 0: if (shouldParse(task)) { init(task); ciImpl = new CompilationInfoImpl(cpInfo); init (snapshot, task, true); boolean needsFullReparse = true; if (supportsReparse) { if (_changedMethod != null && ciImpl != null) { LOGGER.log(Level.FINE, "\t:trying partial reparse:\n{0}", _changedMethod.first().getText()); //NOI18N needsFullReparse = !reparseMethod(ciImpl, snapshot, _changedMethod.second(), _changedMethod.first().getText()); if (!needsFullReparse) { ciImpl.setChangedMethod(_changedMethod); ciImpl = createCurrentInfo (this, file, root, snapshot, null, null); LOGGER.fine("\t:created new javac"); //NOI18N init (snapshot, task, false); ciImpl = createCurrentInfo(this, file, root, snapshot, ciImpl == null ? null : ciImpl.getJavacTask(), ciImpl == null ? null : ciImpl.getDiagnosticListener());
public CompilationController createCompilationController (final Source s) throws IOException, ParseException { Parameters.notNull("s", s); JavacParserFactory factory = JavacParserFactory.getDefault(); final Snapshot snapshot = s.createSnapshot(); final JavacParser parser = factory.createPrivateParser(snapshot); if (parser == null) return null; final UserTask dummy = new UserTask() { @Override public void run(ResultIterator resultIterator) throws Exception { } }; parser.parse(snapshot,dummy, null); return CompilationController.get(parser.getResult(dummy)); }
new Object[] {currentFile, unit}); logTime (currentFile,currentPhase,(end-start)); currentPhase = Phase.ELEMENTS_RESOLVED; long end = System.currentTimeMillis(); logTime(currentInfo.getFileObject(),currentPhase,(end-start)); currentPhase = Phase.RESOLVED; long end = System.currentTimeMillis (); logTime(currentInfo.getFileObject(),currentPhase,(end-start)); } catch (CancelAbort ca) { currentPhase = Phase.MODIFIED; invalidate(false); } catch (Abort abort) { parserError = currentPhase; } catch (IOException ex) { currentInfo.parserCrashed = currentPhase; dumpSource(currentInfo, ex); throw ex; } catch (RuntimeException | Error ex) { parserError = currentPhase; dumpSource(currentInfo, ex); throw ex; } finally {
LOGGER.log (Level.FINE, "Task {0} has changed ClasspathInfo form: {1} to:{2}", new Object[]{task, cpInfo, providedInfo}); //NOI18N invalidate(true); //Reset initialized, world has changed. assert cachedSnapShot != null || sourceCount == 0; try { parseImpl(cachedSnapShot, task); } catch (FileObjects.InvalidFileException ife) { reachedPhase = moveToPhase(requiredPhase, ciImpl, true); } catch (IOException ioe) { throw new ParseException ("JavacParser failure", ioe); //NOI18N
/** * Returns {@link JavacTaskImpl}, when it doesn't exist * it's created. * @return JavacTaskImpl */ public synchronized JavacTaskImpl getJavacTask() { if (javacTask == null) { diagnosticListener = new DiagnosticListenerImpl(this.root, this.jfo, this.cpInfo); javacTask = JavacParser.createJavacTask(this.file, this.root, this.cpInfo, this.parser, diagnosticListener, null, isDetached); } return javacTask; }
long end = System.currentTimeMillis(); if (fo != null) { logTime (fo,Phase.PARSED,(end-start)); logTime (fo, Phase.ELEMENTS_RESOLVED,0L); logTime (fo,Phase.RESOLVED,(end-start)); assert a = true; if (a) { dumpSource(ci, t);
assert parser != null; this.parser = parser; this.cpInfo = parser.getClasspathInfo(); assert cpInfo != null; this.file = file;
if (!hasResource("java/lang/AssertionError", ClassPath.EMPTY, classPath, srcClassPath)) { // NOI18N LOGGER.log(warnLevel, "Even though the source level of {0} is set to: {1}, java.lang.AssertionError cannot be found on the bootclasspath: {2}\n" + !hasResource("java/lang/StringBuilder", bootClassPath, classPath, srcClassPath)) { //NOI18N LOGGER.log(warnLevel, "Even though the source level of {0} is set to: {1}, java.lang.StringBuilder cannot be found on the bootclasspath: {2}\n" + !hasResource("java/lang/AutoCloseable", bootClassPath, classPath, srcClassPath)) { //NOI18N LOGGER.log(warnLevel, "Even though the source level of {0} is set to: {1}, java.lang.AutoCloseable cannot be found on the bootclasspath: {2}\n" + //NOI18N !hasResource("java/util/stream/Streams", bootClassPath, classPath, srcClassPath)) { //NOI18N LOGGER.log(warnLevel, "Even though the source level of {0} is set to: {1}, java.util.stream.Streams cannot be found on the bootclasspath: {2}\n" + //NOI18N !hasResource("java/util/zip/CRC32C", bootClassPath, classPath, srcClassPath)) { //NOI18N LOGGER.log(warnLevel, "Even though the source level of {0} is set to: {1}, java.util.zip.CRC32C cannot be found on the bootclasspath: {2}\n" + //NOI18N
@NullAllowed final CancelService cancelService, @NullAllowed final APTUtils aptUtils) { return createJavacTask(cpInfo, diagnosticListener, sourceLevel, sourceProfile, true, true, cnih, dcc, cancelService, aptUtils);
public static String reformat(String text, CodeStyle style, int rightMargin) { StringBuilder sb = new StringBuilder(text); try { ClassPath empty = ClassPathSupport.createClassPath(new URL[0]); ClasspathInfo cpInfo = ClasspathInfo.create(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(), empty, empty); JavacTaskImpl javacTask = JavacParser.createJavacTask(cpInfo, null, null, null, null, null, null, null); com.sun.tools.javac.util.Context ctx = javacTask.getContext(); JavaCompiler.instance(ctx).genEndPos = true; CompilationUnitTree tree = javacTask.parse(FileObjects.memoryFileObject("","", text)).iterator().next(); //NOI18N SourcePositions sp = JavacTrees.instance(ctx).getSourcePositions(); TokenSequence<JavaTokenId> tokens = TokenHierarchy.create(text, JavaTokenId.language()).tokenSequence(JavaTokenId.language()); for (Diff diff : Pretty.reformat(text, tokens, new TreePath(tree), sp, style, rightMargin)) { int start = diff.getStartOffset(); int end = diff.getEndOffset(); sb.delete(start, end); String t = diff.getText(); if (t != null && t.length() > 0) { sb.insert(start, t); } } } catch (IOException ioe) { } return sb.toString(); }
@Override public JavacParser createParser(final Collection<Snapshot> snapshots) { assert snapshots != null; if (snapshots.size() == 1) { final FileObject fo = snapshots.iterator().next().getSource().getFileObject(); try { if (fo == null) { return null; } if (fo.getFileSystem().isDefault() && fo.getAttribute("javax.script.ScriptEngine") != null //NOI18N && fo.getAttribute("template") == Boolean.TRUE) { //NOI18N // Do not create javac parser for templates return null; } } catch (FileStateInvalidException fsie) {} } JavacParser parser = new JavacParser(snapshots, false); if (TIMER.isLoggable(Level.FINE)) { LogRecord rec = new LogRecord(Level.FINE, "JavacParser"); rec.setParameters(new Object[] { parser }); TIMER.log(rec); } return parser; }
final JavacTaskImpl javacTask = createJavacTask( cpInfo, diagnosticListener,
private void adjustSpans(Iterable<? extends Tree> original, String code) { if (tree2Tag == null) { return; //nothing to copy } java.util.List<Tree> linearized = new LinkedList<Tree>(); if (!new Linearize().scan(original, linearized) != Boolean.TRUE) { return; //nothing to copy } try { ClassPath empty = ClassPathSupport.createClassPath(new URL[0]); ClasspathInfo cpInfo = ClasspathInfo.create(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(), empty, empty); JavacTaskImpl javacTask = JavacParser.createJavacTask(cpInfo, null, null, null, null, null, null, null); com.sun.tools.javac.util.Context ctx = javacTask.getContext(); JavaCompiler.instance(ctx).genEndPos = true; CompilationUnitTree tree = javacTask.parse(FileObjects.memoryFileObject("", "", code)).iterator().next(); //NOI18N SourcePositions sp = JavacTrees.instance(ctx).getSourcePositions(); ClassTree clazz = (ClassTree) tree.getTypeDecls().get(0); new CopyTags(tree, sp).scan(clazz.getModifiers().getAnnotations(), linearized); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
false, null); final JavacTaskImpl jt = JavacParser.createJavacTask(cpInfo, new DevNullDiagnosticListener(), null, null, null, null, null, null); TreeLoader.preRegister(jt.getContext(), cpInfo, true);
final APTUtils aptUtils = APTUtils.get(srcRoot); final SourceLevelQuery.Result r = SourceLevelQuery.getSourceLevel2(file); final JavacTaskImpl jt = JavacParser.createJavacTask( cpInfo, diagnostics != null ?
jt = JavacParser.createJavacTask( javaContext.getClasspathInfo(), dc,
jt = JavacParser.createJavacTask( javaContext.getClasspathInfo(), dc,
jt = JavacParser.createJavacTask( javaContext.getClasspathInfo(), diagnosticListener,