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

The following examples show how to use org.netbeans.api.java.source.CompilationInfo#getClasspathInfo() . 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: CreateEnumConstant.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public CreateEnumConstant(CompilationInfo info, String name, Set<Modifier> modifiers, TypeElement target, TypeMirror proposedType, FileObject targetFile) {
    this.name = name;
    this.inFQN = target.getQualifiedName().toString();
    this.cpInfo = info.getClasspathInfo();
    this.targetFile = targetFile;
    this.target = ElementHandle.create(target);
    if (proposedType.getKind() == TypeKind.NULL) {
        TypeElement tel = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
        if (tel != null) {
            proposedType = tel.asType();
            this.proposedType = TypeMirrorHandle.create(proposedType);
        } else {
            this.proposedType = null;
        }
    } else {
        this.proposedType = TypeMirrorHandle.create(proposedType);
    }
}
 
Example 2
Source File: InjectableTreeNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
InjectableTreeNode(FileObject fileObject,
    T element, DeclaredType parentType, boolean disabled , 
    CompilationInfo compilationInfo) 
{
    myFileObject = fileObject;
    myElementHandle = ElementHandle.create(element);
    myElementKind = element.getKind();
    myModifiers = element.getModifiers();
    myCpInfo = compilationInfo.getClasspathInfo();
    isDisabled = disabled;

    setName(element.getSimpleName().toString());
    setIcon(ElementIcons.getElementIcon(element.getKind(), element.getModifiers()));
    setLabel(Utils.format(element, parentType, compilationInfo));
    setFQNLabel(Utils.format(element, parentType, compilationInfo , false, true));
    setToolTip(Utils.format(element, parentType, compilationInfo, true, 
            WebBeansNavigationOptions.isShowFQN()));            
}
 
Example 3
Source File: ElementJavadoc.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ElementJavadoc(CompilationInfo compilationInfo, Element element, final URL url, final Callable<Boolean> cancel) {
    this.cpInfo = compilationInfo.getClasspathInfo();
    this.fileObject = compilationInfo.getFileObject();
    this.handle = element == null ? null : ElementHandle.create(element);
    this.cancel = cancel;
    final StringBuilder header = getElementHeader(element, compilationInfo);
    try {
        //Optimisitic no http
        CharSequence doc = getElementDoc(element, compilationInfo, header, url, true);
        if (doc == null) {
            computeDocURL(Collections.emptyList(), true, cancel);
            doc = header.append(noJavadocFound());
        }
        this.content = new Now(doc.toString());
    } catch (JavadocHelper.RemoteJavadocException re) {
        if (fileObject == null || JavaSource.forFileObject(fileObject) == null) {
            header.append(noJavadocFound());
            this.content = new Now(header.toString());
            return;
        }
        this.content = new FutureTask<>(() -> {
            final JavaSourceUtil.Handle ch = JavaSourceUtil.createControllerHandle(fileObject, null);
            final CompilationController c = (CompilationController) ch.getCompilationController();
            c.toPhase(Phase.RESOLVED);
            final Element el = handle.resolve(c);
            CharSequence doc = getElementDoc(el, c, header, url, false);
            if (doc == null) {
                computeDocURL(Collections.emptyList(), false, cancel);
                doc = header.append(noJavadocFound());
            }
            return doc.toString();
        });
        RP.post((Runnable)this.content);
    }
}
 
Example 4
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 5
Source File: ElementScanningTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addModuleDirectives(
    @NonNull final ModuleElement module,
    @NonNull final Description target,
    @NonNull final Context ctx,
    @NonNull final CompilationInfo info,
    final boolean fqn) {
    target.subs = new HashSet<>();
    for (ModuleElement.Directive dir : module.getDirectives()) {
        if (isImportant(dir)) {
            final ClasspathInfo cpInfo = info.getClasspathInfo();
            final Description dirDesc;
            if (ctx.isSource) {
                final DirectiveTree dt = ctx.getDirectiveTree(dir);
                final TreePathHandle treePathHandle = TreePathHandle.create(TreePath.getPath(info.getCompilationUnit(), dt), info);
                final String name = getDirectiveName(dir, fqn);
                 dirDesc = Description.directive(
                    ui,
                    name,
                    treePathHandle,
                    dir.getKind(),
                    cpInfo,
                    ctx.getStartPosition(dir),
                    OpenAction.openable(treePathHandle, ctx.getFileObject(), name));
            } else {
                dirDesc = Description.directive(
                    ui,
                    getDirectiveName(dir, fqn),
                    dir.getKind(),
                    cpInfo,
                    OpenAction.openable(module, dir, cpInfo));
            }
            dirDesc.htmlHeader = createHtmlHeader(info, dir, fqn);
            target.subs.add(dirDesc);
        }
    }
}
 
Example 6
Source File: CreateFieldFix.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public CreateFieldFix(CompilationInfo info, String name, Set<Modifier> modifiers, TypeElement target, TypeMirror proposedType, FileObject targetFile) {
    this.name = name;
    this.inFQN = Utilities.target2String(target);
    this.cpInfo = info.getClasspathInfo();
    this.modifiers = modifiers;
    this.targetFile = targetFile;
    this.target = ElementHandle.create(target);
    if (proposedType.getKind() == TypeKind.NULL || proposedType.getKind() == TypeKind.NONE) {
        TypeElement te = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
        proposedType = te == null ? null : te.asType();
    }
    this.proposedType = proposedType == null ? null : TypeMirrorHandle.create(proposedType);
    this.remote = !org.openide.util.Utilities.compareObjects(info.getFileObject(), targetFile);
}
 
Example 7
Source File: CreateClassFix.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public CreateInnerClassFix(CompilationInfo info, String name, Set<Modifier> modifiers, TypeElement target, List<? extends TypeMirror> argumentTypes, List<String> argumentNames, TypeMirror superType, ElementKind kind, int numTypeParameters, FileObject targetFile) {
    super(info, modifiers, argumentTypes, argumentNames, superType, kind, numTypeParameters);
    this.name = name;
    this.target = ElementHandle.create(target);
    this.inFQN = Utilities.target2String(target);
    this.cpInfo = info.getClasspathInfo();
    this.targetFile = targetFile;
}
 
Example 8
Source File: ElementDescription.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ElementDescription(CompilationInfo info, Element element, boolean overriddenFlag) {
    this.originalCPInfo = info.getClasspathInfo();
    this.handle = ElementHandle.create(element);
    if (METHOD.equals(element.getKind()) && null != element.getEnclosingElement()) {
        //when showing the implementors/overriders of a method, show the type icon (not the method icon)
        this.imageKind = element.getEnclosingElement().getKind();
    } else {
        this.imageKind = this.handle.getKind();
    }
    this.outtermostElement = ElementHandle.create(SourceUtils.getOutermostEnclosingTypeElement(element));
    this.modifiers = element.getModifiers();
    this.displayName = overriddenFlag ? computeDisplayNameIsOverridden(element) : computeDisplayNameOverrides(element);
    this.overriddenFlag = overriddenFlag;
}
 
Example 9
Source File: CompletionContext.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void init(TokenHierarchy h, CompilationInfo info, FxmlParserResult fxmlResult) {
    this.hierarchy = h;
    this.compilationInfo = info;
    this.cpInfo = info.getClasspathInfo();
    this.fxmlParserResult = fxmlResult;
    processTokens(h);
}
 
Example 10
Source File: RulesManagerImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Map<HintMetadata, ? extends Collection<? extends HintDescription>> readHints(CompilationInfo info, Collection<? extends ClassPath> from, AtomicBoolean cancel) {
    Map<HintMetadata, Collection<HintDescription>> result = new HashMap<HintMetadata, Collection<HintDescription>>(globalHints);

    if (info != null) {
        for (ElementBasedHintProvider provider : Lookup.getDefault().lookupAll(ElementBasedHintProvider.class)) {
            sortByMetadata(provider.computeHints(info), result);
        }
    }
    
    ClassPath compound;
    
    if (from != null) {
        // not cached, probably not invoked that much
        compound = ClassPathSupport.createProxyClassPath(from.toArray(new ClassPath[0]));
    } else {
        OK: if (info != null) {
            synchronized (compoundPathCache) {
                ClasspathInfo cpInfo = info.getClasspathInfo();
                Reference<Holder> cpRef = compoundPathCache.get(cpInfo);
                if (cpRef != null) {
                    Holder cp = cpRef.get();
                    if (cp != null) {
                        compound = cp.compound;
                        break OK;
                    }
                }
                Holder h = new Holder(cpInfo);
                compoundPathCache.put(cpInfo, new WeakReference<>(h));
                compound = h.compound;
            }
        } else {
            compound = ClassPathSupport.createClassPath(new FileObject[0]);
        }
    }

    for (ClassPathBasedHintProvider p : Lookup.getDefault().lookupAll(ClassPathBasedHintProvider.class)) {
        Collection<? extends HintDescription> hints = p.computeHints(compound, cancel);

        if (hints == null || (cancel != null && cancel.get())) return null;
        
        sortByMetadata(hints, result);
    }

    return result;
}