public RetryWhenScanFinished(CompilationInfo ci, ElementHandle elHandle) { if (ci != null && ci.getSnapshot() != null) { source = ci.getSnapshot().getSource(); } this.elHandle = elHandle; }
@Override public void run() { try { ModificationResult.runModificationTask(Collections.singletonList(info.getSnapshot().getSource()), new UserTask() { @Override public void run(ResultIterator resultIterator) throws Exception { WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult()); copy.toPhase(Phase.ELEMENTS_RESOLVED); Element elementToImport = handle.resolve(copy); if (elementToImport == null) { // the text was possibly changed ? return; } copy.rewrite(copy.getCompilationUnit(), GeneratorUtilities.get(copy).addImports(copy.getCompilationUnit(), Collections.singleton(elementToImport))); } }).commit(); } catch (Exception e) { Exceptions.printStackTrace(e); } } });
public void moveToOffset(long inputOffset) { final int offset = info.getSnapshot().getOriginalOffset((int) inputOffset);
public DiffContext(CompilationInfo copy, Set<Tree> syntheticTrees) { this.tokenSequence = copy.getTokenHierarchy().tokenSequence(JavaTokenId.language()); this.mainCode = this.origText = copy.getText(); this.style = getCodeStyle(copy); this.context = JavaSourceAccessor.getINSTANCE().getJavacTask(copy).getContext(); this.mainUnit = this.origUnit = (JCCompilationUnit) copy.getCompilationUnit(); this.trees = copy.getTrees(); this.doc = copy.getSnapshot().getSource().getDocument(false); //TODO: true or false? this.positionConverter = copy.getPositionConverter(); this.file = copy.getFileObject(); this.syntheticTrees = syntheticTrees; this.textLength = copy.getSnapshot() == null ? Integer.MAX_VALUE : copy.getSnapshot().getOriginalOffset(copy.getSnapshot().getText().length()); this.blockSequences = new BlockSequences(this.tokenSequence, doc, textLength); this.forceInitialComment = false; }
/** * Note: the constructor is only used when creating new compilation units; a special flag will be set up, so an initial comment is not skipped. */ public DiffContext(CompilationInfo copy, CompilationUnitTree cut, String code, PositionConverter positionConverter, FileObject file, Set<Tree> syntheticTrees, CompilationUnitTree mainUnit, String mainCode) { this.tokenSequence = TokenHierarchy.create(code, JavaTokenId.language()).tokenSequence(JavaTokenId.language()); this.origText = code; this.style = getCodeStyle(copy); this.context = JavaSourceAccessor.getINSTANCE().getJavacTask(copy).getContext(); this.origUnit = (JCCompilationUnit) cut; this.trees = copy.getTrees(); this.doc = null; this.positionConverter = positionConverter; this.file = file; this.syntheticTrees = syntheticTrees; this.mainUnit = (JCCompilationUnit) mainUnit; this.mainCode = mainCode; this.textLength = copy.getSnapshot() == null ? Integer.MAX_VALUE : copy.getSnapshot().getOriginalOffset(copy.getSnapshot().getText().length()); this.blockSequences = new BlockSequences(this.tokenSequence, doc, textLength); this.forceInitialComment = true; }
int offset = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tArgs.get(0)); offset = info.getSnapshot().getOriginalOffset(offset);
/** * @see #dumpOutOfSyncError(org.netbeans.modules.parsing.api.Snapshot, int, com.sun.source.tree.Tree, javax.lang.model.element.Element, org.netbeans.api.lexer.TokenSequence, com.sun.javadoc.Doc, boolean) dumpOutOfSyncError */ public static void dumpOutOfSyncError(CompilationInfo javac, TokenSequence<JavadocTokenId> ts, Doc jdoc, boolean throwNotLogException) { Element elm = javac.getElementUtilities().elementFor(jdoc); Tree tree = elm != null ? javac.getTrees().getTree(elm) : null; dumpOutOfSyncError(javac.getSnapshot(), dumpOffset(ts), tree, elm, ts, jdoc, throwNotLogException); }
Doc jdoc = el != null? javac.getElementUtilities().javaDocFor(el): null; if (isInvalidDocInstance(jdoc, jdts)) { dumpOutOfSyncError(javac.getSnapshot(), offset, leaf, el, jdts, jdoc, false); jdoc = null;
protected List<int[]> processImpl(CompilationInfo info, Preferences node, Document doc, int caretPosition) { caretPosition = info.getSnapshot().getEmbeddedOffset(caretPosition);