org.openide.util.Pair Java Examples

The following examples show how to use org.openide.util.Pair. 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: ScanStartedTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testScanFinishedAfterScanStartedWithInternalException() throws Exception {
    assertTrue(GlobalPathRegistry.getDefault().getPaths(FOO_SOURCES).isEmpty());

    handler.internalException = Pair.<String,RuntimeException>of(
            factory2.getIndexerName(),
            new RuntimeException());    //Symulate internal exception

    //Testing classpath registration
    globalPathRegistry_register(FOO_SOURCES,new ClassPath[]{cp1});
    assertFalse(handler.await(RepositoryUpdaterTest.NEGATIVE_TIME));
    assertEquals(0, handler.getBinaries().size());
    assertNull(handler.getSources());
    assertEquals(1, factory1.scanStartedCount.get());
    assertEquals(0, factory2.scanStartedCount.get());
    assertEquals(0, factory3.scanStartedCount.get());
    assertEquals(1, factory1.scanFinishedCount.get());
    assertEquals(0, factory2.scanFinishedCount.get());
    assertEquals(0, factory3.scanFinishedCount.get());
}
 
Example #2
Source File: PlatformNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getHtmlDisplayName () {
    final Pair<String,JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return null;
    }
    final JavaPlatform jp = platHolder.second();
    if (jp == null || !jp.isValid()) {
        String displayName = this.getDisplayName();
        try {
            displayName = XMLUtil.toElementContent(displayName);
        } catch (CharConversionException ex) {
            // OK, no annotation in this case
            return null;
        }
        return "<font color=\"#A40000\">" + displayName + "</font>"; //NOI18N
    } else {
        return null;
    }
}
 
Example #3
Source File: CompilationInfo.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns tree which was reparsed by an incremental reparse.
 * When the source file wasn't parsed yet or the parse was a full parse
 * this method returns null.
 * <p class="nonnormative">
 * Currently the leaf tree is a MethodTree but this may change in the future.
 * Client of this method is responsible to check the corresponding TreeKind
 * to find out if it may perform on the changed subtree or it needs to
 * reprocess the whole tree.
 * </p>
 * @return {@link TreePath} or null
 * @since 0.31
 */
public @CheckForNull @CheckReturnValue TreePath getChangedTree () {
    checkConfinement();
    if (JavaSource.Phase.PARSED.compareTo (impl.getPhase())>0) {
        return null;
    }
    final Pair<DocPositionRegion,MethodTree> changedTree = impl.getChangedTree();
    if (changedTree == null) {
        return null;
    }
    final CompilationUnitTree cu = impl.getCompilationUnit();
    if (cu == null) {
        return null;
    }
    return TreePath.getPath(cu, changedTree.second());
}
 
Example #4
Source File: CachingArchiveProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the given boot classpath root has the the ct.sym equivalent.
 * @param root the root to check
 * @return true if there is a ct.sym folder corresponding to given boot classpath
 * root
 */
public boolean hasCtSym (@NonNull final URL root) {
    final URL fileURL = FileUtil.getArchiveFile(root);
    if (fileURL == null) {
        return false;
    }
    final File f;
    try {
        f = BaseUtilities.toFile(fileURL.toURI());
    } catch (URISyntaxException ex) {
        return false;
    }
    if (f == null || !f.exists()) {
        return false;
    }
    final Pair<File, String> res = mapJarToCtSym(f);
    return res.second() != null;

}
 
Example #5
Source File: CachingArchiveProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
private Pair<File,String> mapJarToCtSym(
    @NonNull final File file) {
    if (USE_CT_SYM && NAME_RT_JAR.equals(file.getName())) {
        final FileObject fo = FileUtil.toFileObject(file);
        if (fo != null) {
            for (JavaPlatform jp : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
                for (FileObject jdkFolder : jp.getInstallFolders()) {
                    if (FileUtil.isParentOf(jdkFolder, fo)) {
                        final FileObject ctSym = jdkFolder.getFileObject(PATH_CT_SYM);
                        File ctSymFile;
                        if (ctSym != null && (ctSymFile = FileUtil.toFile(ctSym)) != null) {
                            return Pair.<File,String>of(ctSymFile,PATH_RT_JAR_IN_CT_SYM);
                        }
                    }
                }
            }
        }
    }
    return Pair.<File,String>of(file, null);
}
 
Example #6
Source File: URIMapper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Pair<String, String> encodedPathMappingPair(Pair<String, String> pathMapping) {
    String resName = pathMapping.first();
    resName = resName.replace('\\', '/'); //NOI18N
    final String[] elements = resName.split("/"); //NOI18N
    final StringBuilder sb = new StringBuilder(200);
    for (int i = 0; i < elements.length; i++) {
        String element = elements[i];
        boolean skip = false;
        if (i == 0 && element.length() == 2 && element.charAt(1) == ':') { //NOI18N
            skip = true;
        }
        if (!skip) {
            try {
                element = URLEncoder.encode(element, "UTF-8"); // NOI18N
                element = element.replace("+", "%20"); // NOI18N
            } catch (UnsupportedEncodingException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
        sb.append(element);
        if (i < elements.length - 1) {
            sb.append('/');
        }
    }
    return Pair.of(sb.toString(), pathMapping.second());
}
 
Example #7
Source File: BinaryAnalyser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<Pair<ElementHandle<TypeElement>,Long>> loadCRCs(final File indexFolder) throws IOException {
    List<Pair<ElementHandle<TypeElement>,Long>> result = new LinkedList<Pair<ElementHandle<TypeElement>, Long>>();
    final File file = new File (indexFolder,CRC);
    if (file.canRead()) {
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));   //NOI18N

        try {
            String line;
            while ((line=in.readLine())!=null) {
                final String[] parts = line.split("=");    //NOI18N
                if (parts.length == 2) {
                    try {
                        final ElementHandle<TypeElement> handle = ElementHandleAccessor.getInstance().create(ElementKind.OTHER, parts[0]);
                        final Long crc = Long.parseLong(parts[1]);
                        result.add(Pair.of(handle, crc));
                    } catch (NumberFormatException e) {
                        //Log and pass
                    }
                }
            }
        } finally {
            in.close();
        }
    }
    return result;
}
 
Example #8
Source File: BootCPNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getDisplayName() {
    final Pair<String, JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return Bundle.TXT_UnknownPlatform();
    }
    String name;
    final JavaPlatform jp = platHolder.second();
    if (jp != null) {
        if (jp.isValid()) {
            name = jp.getDisplayName();
        } else {
            name = Bundle.FMT_BrokenPlatform(jp.getDisplayName());
        }
    } else {
        String platformId = platHolder.first();
        if (platformId == null) {
            name = Bundle.TXT_BrokenPlatform();
        } else {
            name = Bundle.FMT_BrokenPlatform(platformId);
        }
    }
    return name;
}
 
Example #9
Source File: RunAsLocalWeb.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void advancedButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
    RunAsWebAdvanced.Properties props = new RunAsWebAdvanced.Properties(
            getValue(PhpProjectProperties.DEBUG_URL),
            hintLabel.getText(),
            getValue(PhpProjectProperties.DEBUG_PATH_MAPPING_REMOTE),
            getValue(PhpProjectProperties.DEBUG_PATH_MAPPING_LOCAL),
            getValue(PhpProjectProperties.DEBUG_PROXY_HOST),
            getValue(PhpProjectProperties.DEBUG_PROXY_PORT));
    RunAsWebAdvanced advanced = new RunAsWebAdvanced(project, props);
    if (advanced.open()) {
        Pair<String, String> pathMapping = advanced.getPathMapping();
        Pair<String, String> debugProxy = advanced.getDebugProxy();
        RunAsLocalWeb.this.putValue(PhpProjectProperties.DEBUG_URL, advanced.getDebugUrl().name());
        RunAsLocalWeb.this.putValue(PhpProjectProperties.DEBUG_PATH_MAPPING_REMOTE, pathMapping.first());
        RunAsLocalWeb.this.putValue(PhpProjectProperties.DEBUG_PATH_MAPPING_LOCAL, pathMapping.second());
        RunAsLocalWeb.this.putValue(PhpProjectProperties.DEBUG_PROXY_HOST, debugProxy.first());
        RunAsLocalWeb.this.putValue(PhpProjectProperties.DEBUG_PROXY_PORT, debugProxy.second());
    }
}
 
Example #10
Source File: ELHyperlinkProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getTooltipTextForElement(final Pair<Node, ELElement> pair) {
    final String[] result = new String[1];
    final FileObject file = pair.second().getSnapshot().getSource().getFileObject();
    ClasspathInfo cp = ELTypeUtilities.getElimplExtendedCPI(file);
    try {
        JavaSource.create(cp, file).runUserActionTask(new Task<CompilationController>() {

            @Override
            public void run(CompilationController cc) throws Exception {
                cc.toPhase(JavaSource.Phase.RESOLVED);
                final Element resolvedElement = ELTypeUtilities.resolveElement(CompilationContext.create(file, cc), pair.second(), pair.first());
                if (resolvedElement == null) {
                    return;
                }
                DisplayNameElementVisitor dnev = new DisplayNameElementVisitor(cc);
                dnev.visit(resolvedElement, Boolean.TRUE);
                result[0] = "<html><body>" + dnev.result.toString(); //NOI18N
            }
        }, true);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return result[0];
}
 
Example #11
Source File: ClusteredIndexables.java    From netbeans with Apache License 2.0 6 votes vote down vote up
It(
    @NonNull final Iterator<? extends String> outOfOrderIt,
    @NullAllowed final ClusteredIndexables deleteIndexables,
    @NonNull final BitSet deleteFromDeleted,
    @NullAllowed final ClusteredIndexables indexIndexables,
    @NonNull final BitSet deleteFromIndex,
    @NullAllowed final Pair<Long,StackTraceElement[]> attachDeleteStackTrace,
    @NullAllowed final Pair<Long, StackTraceElement[]> attachIndexStackTrace,
    @NullAllowed final Pair<Long, StackTraceElement[]> detachDeleteStackTrace,
    @NullAllowed final Pair<Long, StackTraceElement[]> detachIndexStackTrace) {
    this.outOfOrderIt = outOfOrderIt;
    this.deleteIndexables = deleteIndexables;
    this.deleteFromDeleted = deleteFromDeleted;
    this.indexIndexables = indexIndexables;
    this.deleteFromIndex = deleteFromIndex;
    this.attachDeleteStackTrace = attachDeleteStackTrace;
    this.attachIndexStackTrace = attachIndexStackTrace;
    this.detachDeleteStackTrace = detachDeleteStackTrace;
    this.detachIndexStackTrace = detachIndexStackTrace;
}
 
Example #12
Source File: Authentication.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static MethodList fromStorageString(String methodsList) {
    List<Pair<Method, Boolean>> pairs = new ArrayList<>();
    String[] parts = methodsList.split(","); // NOI18N
    for(int i = 0; i < parts.length; i++) {
        String part = parts[i];
        if (!part.isEmpty()) {
            String name;
            boolean enabled;
            if (part.endsWith("#1")) { // NOI18N
                name = part.substring(0, part.length() - 2);
                enabled = true;
            } else if (part.endsWith("#0")) { // NOI18N
                name = part.substring(0, part.length() - 2);
                enabled = false;
            } else {
                name = part;
                enabled = true;
            }
            Method method = Method.byID(name);
            if (method != null) {
                pairs.add(Pair.of(method, enabled));
            }
        }
    }
    return new MethodList(pairs);
}
 
Example #13
Source File: UnusedAssignmentOrBranch.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.bugs.UnusedAssignmentOrBranch.unusedAssignment", description = "#DESC_org.netbeans.modules.java.hints.bugs.UnusedAssignmentOrBranch.unusedAssignment", category="bugs", id=UNUSED_ASSIGNMENT_ID, options={Options.QUERY}, suppressWarnings="UnusedAssignment")
@TriggerPatterns({
    @TriggerPattern("$var = $value"),
    @TriggerPattern("$mods$ $type $var = $value;")
})
public static ErrorDescription unusedAssignment(final HintContext ctx) {
    final String unusedAssignmentLabel = NbBundle.getMessage(UnusedAssignmentOrBranch.class, "LBL_UNUSED_ASSIGNMENT_LABEL");
    Pair<Set<Tree>, Set<Element>> computedAssignments = computeUsedAssignments(ctx);
    
    if (ctx.isCanceled() || computedAssignments == null) return null;

    final CompilationInfo info = ctx.getInfo();
    final Set<Tree> usedAssignments = computedAssignments.first();
    final Set<Element> usedVariables = computedAssignments.second();
    Element var = info.getTrees().getElement(ctx.getVariables().get("$var"));
    TreePath valuePath = ctx.getVariables().get("$value");
    Tree value = (valuePath == null ? ctx.getPath() : valuePath).getLeaf();

    if (var != null && LOCAL_VARIABLES.contains(var.getKind()) && !usedAssignments.contains(value) && usedVariables.contains(var)) {
        return ErrorDescriptionFactory.forTree(ctx, value, unusedAssignmentLabel);
    }

    return null;
}
 
Example #14
Source File: ProjectOperations.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void rememberDependencies() {
    final AntArtifactProvider aap = project.getLookup().lookup(AntArtifactProvider.class);
    if (aap == null) {
        return;
    }
    final Map<URI,Pair<AntArtifact,URI>> artifacts = createArtifactsMap(aap);
    final Set<Project> dependencies = new HashSet<>();
    for (Project prj : OpenProjects.getDefault().getOpenProjects()) {
        final SubprojectProvider spp = prj.getLookup().lookup(SubprojectProvider.class);
        if (spp != null && spp.getSubprojects().contains(project)) {
            dependencies.add(prj);
        }
    }
    Collection<Dependency> toFix = new ArrayList<>();
    for (Project depProject : dependencies) {
        for (SourceGroup sg : ProjectUtils.getSources(depProject).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
            Set<URI> roots = classPathURIs(ClassPath.getClassPath(sg.getRootFolder(), ClassPath.COMPILE));
            for (Map.Entry<URI,Pair<AntArtifact,URI>> e : artifacts.entrySet()) {
                if (roots.contains(e.getKey())) {
                    final Dependency dep = new Dependency(
                            depProject,
                            sg,
                            e.getValue().first(),
                            e.getValue().second());
                    if (dep.remove()) {
                        toFix.add(dep);
                    }
                }
            }
        }
    }
    dependenciesToFix = toFix;
}
 
Example #15
Source File: IndexBinaryWorkPool.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@NonNull
public Pair<Boolean,Collection<? extends URL>> execute(
        @NonNull final Function<URL,Boolean> fnc,
        @NonNull final Callable<Boolean> cancel,
        @NonNull final Collection<? extends URL> binaries) {
    final CompletionService<URL> cs = new ExecutorCompletionService<URL>(RP);
    int submitted = 0;
    for (URL binary : binaries) {
        cs.submit(new Task(binary,fnc, cancel));
        submitted++;
    }
    final Collection<URL> result = new ArrayDeque<URL>();
    //Don't break the cycle when is canceled,
    //rather wait for all submitted task, they should die fast.
    //The break will cause logging of wrong number of scanned roots.
    for (int i=0; i< submitted; i++) {
        try {                    
            final Future<URL> becomeURL = cs.take();
            final URL url = becomeURL.get();
            if (url != null) {
                result.add(url);
            }
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    boolean success;
    try {
        success = !cancel.call();
    } catch (Exception e) {
        Exceptions.printStackTrace(e);
        success = false;
    }
    LOG.log(Level.FINER, "Canceled: {0}", !success);  //NOI18N
    return Pair.<Boolean,Collection<? extends URL>>of(success,result);
}
 
Example #16
Source File: HierarchyTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void refresh() {
    final Object selItem = historyCombo.getSelectedItem();
    if (selItem instanceof Pair) {
        final Pair<URI,ElementHandle<TypeElement>> pair = (Pair<URI,ElementHandle<TypeElement>>)selItem;
        schedule(new Callable<Pair<URI, ElementHandle<TypeElement>>>() {
            @Override
            public Pair<URI, ElementHandle<TypeElement>> call() throws Exception {
                return pair;
            }
        });
    }
}
 
Example #17
Source File: Models.java    From netbeans with Apache License 2.0 5 votes vote down vote up
MutableListModelImpl(
        @NullAllowed final Comparator<T> comparator,
        @NullAllowed final Filter<T> filter,
        @NullAllowed final Factory<? extends T, Pair<? extends T, ? extends T>> attrCopier) {
    this.comparator = comparator;
    this.filter = filter;
    this.attrCopier = attrCopier;
    items = included = Collections.<T>emptyList();
    if (this.comparator instanceof StateFullComparator) {
        ((StateFullComparator)this.comparator).addChangeListener(this);
    }
    if (this.filter != null) {
        this.filter.addChangeListener(this);
    }
}
 
Example #18
Source File: ClassMemberPanelUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void select(@NonNull final Pair<URI,ElementHandle<TypeElement>> pair) {
    Mutex.EVENT.readAccess(new Runnable() {
        @Override
        public void run() {
            ignoreEvents = true;
            try {
                historyCombo.getModel().setSelectedItem(pair);
            } finally {
                ignoreEvents = false;
            }
        }
    });
}
 
Example #19
Source File: SourceAnalyzerFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@CheckForNull
public  Void visitParameterizedType(@NonNull final ParameterizedTypeTree node, @NonNull final Map<Pair<BinaryName,String>, UsagesData<String>> p) {
    scan(node.getType(), p);
    State currState = this.state;
    this.state = State.GT;
    scan(node.getTypeArguments(), p);
    this.state = currState;
    return null;
}
 
Example #20
Source File: TreeLoaderOutputFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private static Pair<Location,URL> baseLocation(@NonNull final Location loc) {
    if (ModuleLocation.isInstance(loc)) {
        final ModuleLocation ml = ModuleLocation.cast(loc);
        return Pair.of(ml.getBaseLocation(), ml.getModuleRoots().iterator().next());
    } else {
        return Pair.of(loc,null);
    }
}
 
Example #21
Source File: ProjectRunnerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private static ClassPath translate(
        @NonNull final ClassPath cp,
        @NonNull final Map<URL,Pair<URL,FileObject[]>> dictionary) {
    final List<URL> roots = new ArrayList<>(cp.entries().size());
    for (ClassPath.Entry e : cp.entries()) {
        final URL orig = e.getURL();
        final SourceForBinaryQuery.Result2 res = SourceForBinaryQuery.findSourceRoots2(orig);
        if (res.preferSources()) {
            final FileObject[] srcs = res.getRoots();
            for (FileObject src : srcs) {
                try {
                    final URL cacheURL = BaseUtilities.toURI(
                            JavaIndex.getClassFolder(src.toURL())).toURL();
                    dictionary.put(cacheURL,Pair.of(orig,res.getRoots()));
                    roots.add(cacheURL);
                } catch (IOException ioe) {
                    Exceptions.printStackTrace(ioe);
                }
            }
        } else {
            dictionary.put(orig, Pair.of(orig,res.getRoots()));
            roots.add(orig);
        }
    }
    return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
}
 
Example #22
Source File: NBAttrTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNETBEANS_228() throws Exception {
    String code = "package test; public class Test { Object t() { return new Undef() { public void test() { test(); } }; } }";
    Pair<JavacTask, CompilationUnitTree> parsed = compile(code);

    new TreePathScanner<Void, Void>() {
        public Void visitMethodInvocation(MethodInvocationTree tree, Void p) {
            Trees trees = Trees.instance(parsed.first());
            assertNotNull(trees.getElement(getCurrentPath()));
            return super.visitMethodInvocation(tree, p);
        }
    }.scan(parsed.second(), null);
}
 
Example #23
Source File: MultiModuleFileBuiltQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized boolean isCurrentPath(@NonNull final ClassPath cp) {
    for (Pair<ClassPath,PropertyChangeListener> p : currentPaths) {
        if (p.first() == cp) {
            return true;
        }
    }
    return false;
}
 
Example #24
Source File: GoToPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean boundScrollingKey(KeyEvent ev) {
    final Pair<String,JComponent> p = listActionFor(ev);
    if (p == null) {
        return false;
    }
    String action = p.first();
    // See BasicListUI, MetalLookAndFeel:
    return "selectPreviousRow".equals(action) || // NOI18N
    "selectNextRow".equals(action) || // NOI18N
    "selectPreviousRowExtendSelection".equals(action) ||    //NOI18N
    "selectNextRowExtendSelection".equals(action) || //NOI18N
    "scrollUp".equals(action) || // NOI18N
    "scrollDown".equals(action); // NOI18N
}
 
Example #25
Source File: ModuleDescription.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static ModuleRepository getModules(FileObject project) throws Exception {
    Pair<FileObject, Pair<Boolean, Boolean>> jdkRootAndType = findJDKRoot(project);

    if (jdkRootAndType == null)
        return null;

    FileObject jdkRoot = jdkRootAndType.first();

    ModuleRepository repository;
    
    synchronized (ModuleDescription.class) {
        repository = jdkRoot2Repository.get(jdkRoot.toURI());
    }

    if (repository != null)
        return repository;

    boolean hasModuleInfos;
    List<ModuleDescription> moduleDescriptions;
    FileObject modulesXML = BuildUtils.getFileObject(jdkRoot, "modules.xml");

    if (modulesXML != null) {
        moduleDescriptions = new ArrayList<>();
        readModulesXml(modulesXML, moduleDescriptions);
        readModulesXml(BuildUtils.getFileObject(jdkRoot, "closed/modules.xml"), moduleDescriptions);
        hasModuleInfos = false;
    } else {
        moduleDescriptions = readModuleInfos(jdkRoot);
        hasModuleInfos = true;
    }

    if (moduleDescriptions.isEmpty())
        return null;
    
    synchronized (ModuleDescription.class) {
        jdkRoot2Repository.put(jdkRoot.toURI(), repository = new ModuleRepository(jdkRoot, hasModuleInfos, jdkRootAndType.second().first(), jdkRootAndType.second().second(), moduleDescriptions));
    }

    return repository;
}
 
Example #26
Source File: GradleSourcesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
SourceGroup createSourceGroup(boolean unique, String group, File dir,
        SourceType lang) {
    SourceGroup ret = cache.get(Pair.of(lang, dir));
    if (ret == null) {
        String msgKey = group + "." + lang.name();
        String groupKey = sourceGroupName(msgKey, dir);
        String sgDisplayName = !"gatling".equals(group) //NOI18N
                ? sourceGroupDisplayName(unique, group, dir, lang)
                : gatlingSourceGroupDisplayName(unique, dir, lang);
        ret = new GradleSourceGroup(FileUtil.toFileObject(dir), groupKey, sgDisplayName);
        cache.put(Pair.of(lang, dir), ret);
    }
    return ret;
}
 
Example #27
Source File: PhpExecutable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static Pair<String, List<String>> parseCommand(String command) {
    if (command == null) {
        // avoid NPE
        command = ""; // NOI18N
    }
    // try to find program (search for " -" or " /" after space)
    String[] tokens = command.split(" * (?=\\-|/)", 2); // NOI18N
    if (tokens.length == 1) {
        LOGGER.log(Level.FINE, "Only program given (no parameters): {0}", command);
        return Pair.of(tokens[0].trim(), Collections.<String>emptyList());
    }
    Pair<String, List<String>> parsedCommand = Pair.of(tokens[0].trim(), Arrays.asList(Utilities.parseParameters(tokens[1].trim())));
    LOGGER.log(Level.FINE, "Parameters parsed: {0} {1}", new Object[] {parsedCommand.first(), parsedCommand.second()});
    return parsedCommand;
}
 
Example #28
Source File: JsParserTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testBrokenModule() throws Exception {
    Pair<FunctionNode, Integer> result = parse("function x() {\n"
            + "\n"
            + "}\n"
            + "\n"
            + "export {\n");
    assertNotNull(result.first());
    assertEquals(1, result.second().intValue());
}
 
Example #29
Source File: LibrariesNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@NonNull
public Collection<SourceGroup> apply(@NonNull final Pair<File,Collection<? super URL>> param) {
    final Collection<File> modules = ModulesFinder.INSTANCE.apply(param.first());
    return modules.stream()
            .map((f) -> createFileSourceGroup(f, param.second()))
            .filter((sg) -> sg != null)
            .collect(Collectors.toList());
}
 
Example #30
Source File: CachingArchiveProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private static URI toURI(@NonNull final Pair<File,String> path) {
    try {
        final URL root = FileUtil.getArchiveRoot(BaseUtilities.toURI(path.first()).toURL());
        return new URI(String.format(
            "%s%s", //NOI18N
            root.toExternalForm(),
            PATH_RT_JAR_IN_CT_SYM));
    } catch (MalformedURLException | URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}