Java Code Examples for org.netbeans.api.java.source.CompilationInfo#get()

The following examples show how to use org.netbeans.api.java.source.CompilationInfo#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaSourceAccessor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void run(@NonNull Result result, SchedulerEvent event) {
    Parameters.notNull("result", result);   //NOI18N
    final CompilationInfo info = CompilationInfo.get(result);
    if (info == null) {
        throw new IllegalArgumentException(String.format("Result %s [%s] does not provide CompilationInfo",    //NOI18N
                result.toString(),
                result.getClass().getName()));
    }
    try {
        JavaSourceAccessor.getINSTANCE().setJavaSource(info, javaSource);
        this.task.run(info);
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 2
Source File: ResourceStringFoldProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean processResult(Parser.Result result) {
    CompilationInfo info = CompilationInfo.get(result);
    if (info == null) {
        return false;
    }
    CompilationController ctrl = CompilationController.get(result);
    if (ctrl != null) {
        try {
            ctrl.toPhase(JavaSource.Phase.RESOLVED);
        } catch (IOException ex) {
            return false;
        }
    }
    if (loader == null) {
        loader = new ResourceStringLoader(this);
    }
    V v = new V(info, getFile(), this);
    v.setDescriptions(messages);
    v.scan(info.getCompilationUnit(), null);
    return true;
}
 
Example 3
Source File: SourcePathCheck.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@org.netbeans.api.annotations.common.SuppressWarnings(value={"DMI_COLLECTION_OF_URLS"}, justification="URLs have never host part")    //NOI18N
public void run(final Result result, final SchedulerEvent event) {
    final CompilationInfo info = CompilationInfo.get(result);
    final ClasspathInfo cpInfo = info.getClasspathInfo();
    if (cpInfo != null) {
        final ClassPath src = cpInfo.getClassPath(PathKind.SOURCE);
        final ClassPath boot = cpInfo.getClassPath(PathKind.BOOT);
        final ClassPath compile = cpInfo.getClassPath(PathKind.COMPILE);
        if (!isIncomplete(src, boot, compile)) {
            final ClassPath cachedSrc = ClasspathInfoAccessor.getINSTANCE().getCachedClassPath(cpInfo, PathKind.SOURCE);
            try {
                final Set<URL> unknown = new HashSet<URL>();
                if (cachedSrc.entries().isEmpty() && !src.entries().isEmpty()) {
                    for (ClassPath.Entry entry : src.entries()) {
                        final URL url = entry.getURL();
                        if (!this.factory.firedFor.contains(url) &&
                                !JavaIndex.hasSourceCache(url,false) &&
                                FileOwnerQuery.getOwner(url.toURI()) != null) {
                            unknown.add(url);
                            this.factory.firedFor.add(url);
                        }
                    }
                }
                if (!unknown.isEmpty()) {
                    PathRegistry.getDefault().registerUnknownSourceRoots(src, unknown);
                }
            } catch (URISyntaxException e) {
                Exceptions.printStackTrace(e);
            }
        }
    }
}
 
Example 4
Source File: MarkOccurrencesHighlighterBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run (Result parseResult, SchedulerEvent event) {
    resume();

    CompilationInfo info = CompilationInfo.get(parseResult);

    if (info == null) {
        return ;
    }

    Document doc = parseResult.getSnapshot().getSource().getDocument(false);
    
    process(info, doc, event);
}
 
Example 5
Source File: BreadCrumbsScanningTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Result result, SchedulerEvent event) {
    cancel.set(false);

    CompilationInfo info = CompilationInfo.get(result);
    if (info == null) {
        return;
    }

    Document doc = info.getSnapshot().getSource().getDocument(false);
    if (doc == null) {
        return;
    }

    if (!BreadcrumbsController.areBreadCrumsEnabled(doc)) return ;
    
    int caretPosition = event instanceof CursorMovedSchedulerEvent
            ? ((CursorMovedSchedulerEvent) event).getCaretOffset()
            : CaretAwareJavaSourceTaskFactory.getLastPosition(result.getSnapshot().getSource().getFileObject()); //XXX

    if (cancel.get()) {
        return;
    }

    BreadcrumbsElement[] rootAndSelection = rootAndSelection(info, caretPosition, cancel);
    
    if (cancel.get() || rootAndSelection == null) {
        return ;
    }

    BreadcrumbsController.setBreadcrumbs(doc, rootAndSelection[1]);
    
    info.putCachedValue(BreadCrumbsScanningTask.class, rootAndSelection[0], CacheClearPolicy.ON_CHANGE);
}
 
Example 6
Source File: ErrorHintsProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Result result, SchedulerEvent event) {
    resume();

    CompilationInfo info = CompilationInfo.get(result);

    if (info == null) {
        return ;
    }

    Document doc = result.getSnapshot().getSource().getDocument(false);
    
    if (doc == null) {
        Logger.getLogger(ErrorHintsProvider.class.getName()).log(Level.FINE, "SemanticHighlighter: Cannot get document!");
        return ;
    }

    long version = DocumentUtilities.getDocumentVersion(doc);
    String mimeType = result.getSnapshot().getSource().getMimeType();
    
    long start = System.currentTimeMillis();

    try {
        List<ErrorDescription> errors = computeErrors(info, doc, mimeType);

        if (errors == null) //meaning: cancelled
            return ;
        EmbeddedHintsCollector.setAnnotations(result.getSnapshot(), errors);

        ErrorPositionRefresherHelper.setVersion(doc, errors);
        
        long end = System.currentTimeMillis();

        Logger.getLogger("TIMER").log(Level.FINE, "Java Hints",
                new Object[]{info.getFileObject(), end - start});
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
 
Example 7
Source File: ComputeAnnotations.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Result result, SchedulerEvent event) {
    cancel.set(false);
    
    CompilationInfo info = CompilationInfo.get(result);

    if (info.getChangedTree() != null) {
        //XXX: currently only method bodies are rebuilt.
        return ;
    }
    
    long start = System.currentTimeMillis();
    StyledDocument doc = (StyledDocument) result.getSnapshot().getSource().getDocument(false);

    if (doc == null) {
        return ;
    }
    
    List<IsOverriddenAnnotation> annotations = computeAnnotations(info, doc);

    if (cancel.get()) return ;
    
    AnnotationsHolder holder = AnnotationsHolder.get(info.getFileObject());

    if (holder != null) {
        holder.setNewAnnotations(annotations);
    }

    long end = System.currentTimeMillis();

    Logger.getLogger("TIMER").log(Level.FINE, "Is Overridden Annotations", new Object[] {info.getFileObject(), end - start});
}
 
Example 8
Source File: SemanticHighlighterBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Result result, SchedulerEvent event) {
    CompilationInfo info = CompilationInfo.get(result);
    
    if (info == null) {
        return ;
    }
    
    cancel.set(false);
    
    final Document doc = result.getSnapshot().getSource().getDocument(false);
    
    if (!verifyDocument(doc)) return;

    process(info, doc);
}
 
Example 9
Source File: JShellOptions2.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void classNameChanged(ActionEvent ac) {
    final String s = source.getText().trim();
    if (s.equals(oldText)) {
        return;
    }
    if (loaderSelect.getSelectedItem() == LoaderPolicy.SYSTEM) {
        return;
    }
    
    class UT extends UserTask implements ClasspathInfo.Provider {

        @Override
        public ClasspathInfo getClasspathInfo() {
            return JShellOptions2.this.getClasspathInfo();
        }
        
        @Override
        public void run(ResultIterator resultIterator) throws Exception {
            CompilationInfo cc = CompilationInfo.get(resultIterator.getParserResult());
            TypeElement tel = cc.getElements().getTypeElement(s);
            if (tel != null) {
                targetClass = ElementHandle.create(tel);
                return;
            } else {
                targetClass = null;
            }
        }
    }
    try {
        ParserManager.parse("text/x-java", new UT());
    } catch (ParseException ex) {
        Exceptions.printStackTrace(ex);
    }
    this.message = null;
    if (targetClass == null) {
        this.message = Bundle.ERR_ClassNameInvalid();
    } else {
        changedOptions.put(PropertyNames.JSHELL_CLASSNAME, s);
    }
    updateMembers();
    oldText = s;
    if (disableUpdates) {
        return;
    }
    storeChanges();
}
 
Example 10
Source File: JSEmbeddingProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Parser.Result t, SchedulerEvent se) {
    canceled.set(false);
    final CompilationInfo ci = CompilationInfo.get(t);
    colorizeJSB(ci);
}