Java Code Examples for org.openide.util.Pair#of()

The following examples show how to use org.openide.util.Pair#of() . 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: ProjectPropertiesSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * @return instance of Pair<String, String> or null
 */
private static Pair<String, String> getCopySupportPair(PhpProject project) {
    Pair<String, String> copySupportPair = null;
    if (ProjectPropertiesSupport.isCopySourcesEnabled(project)) {
        File copyTarget = ProjectPropertiesSupport.getCopySourcesTarget(project);
        if (copyTarget != null && copyTarget.exists()) {
            FileObject copySourceFo = ProjectPropertiesSupport.getSourcesDirectory(project);
            if (copySourceFo != null) {
                File copySource = FileUtil.toFile(copySourceFo);
                if (copySource != null && copySource.exists()) {
                    copySupportPair = Pair.of(copyTarget.getAbsolutePath(), copySource.getAbsolutePath());
                }
            }
        }
    }
    return copySupportPair;
}
 
Example 2
Source File: CreateElement.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static List<Fix> prepareCreateInnerClassFix(CompilationInfo info, TreePath invocation, TypeElement target, Set<Modifier> modifiers, String simpleName, List<? extends ExpressionTree> realArguments, TypeMirror superType, ElementKind kind, int numTypeParameters) {
       Pair<List<? extends TypeMirror>, List<String>> formalArguments = invocation != null ? Utilities.resolveArguments(info, invocation, realArguments, target) : Pair.<List<? extends TypeMirror>, List<String>>of(null, null);

       if (formalArguments == null) {
           return Collections.<Fix>emptyList();
       }

//IZ 111048 -- don't offer anything if target file isn't writable
if (!Utilities.isTargetWritable(target, info))
    return Collections.<Fix>emptyList();

       FileObject targetFile = SourceUtils.getFile(target, info.getClasspathInfo());

       if (targetFile == null)
           return Collections.<Fix>emptyList();
       final CreateInnerClassFix fix = new CreateInnerClassFix(info, simpleName, modifiers, target, formalArguments.first(), formalArguments.second(), superType, kind, numTypeParameters, targetFile);
       fix.setPriority(PRIO_INNER);
       return Collections.<Fix>singletonList(fix);
   }
 
Example 3
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 4
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static ClassPath getSourceClassPathFor(FileObject file) {
    Pair<FileObject,Reference<ClassPath>> ce = rootCache;
    ClassPath cp;
    if (ce != null &&
        (cp = ce.second().get()) != null &&
        ce.first().equals(cp.findOwnerRoot(file))) {
        return cp;
    }
    for (String sourceCP : PathRecognizerRegistry.getDefault().getSourceIds()) {
        cp = ClassPath.getClassPath(file, sourceCP);
        if (cp != null) {
            final FileObject root = cp.findOwnerRoot(file);
            if (root != null) {
                rootCache = Pair.<FileObject,Reference<ClassPath>>of(
                    root,
                    new WeakReference<ClassPath>(cp));
            }
            return cp;
        }
    }
    return null;
}
 
Example 5
Source File: ToolTipAnnotation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Pair<String, Object> evaluate(String expression, DebuggerEngine engine) throws CancellationException {
    Debugger d = engine.lookupFirst(null, Debugger.class);
    if (d == null || !d.isSuspended()) {
        return null;
    }
    CallFrame currentCallFrame = d.getCurrentCallFrame();
    VariablesModel.ScopedRemoteObject sv = Evaluator.evaluateExpression(currentCallFrame, expression, true);
    Object tooltipVariable = null;
    String tooltipText;
    if (sv != null) {
        RemoteObject var = sv.getRemoteObject();
        String value = getStringValue(var);
        Type type = var.getType();
        if (type == Type.OBJECT) {
            tooltipVariable = sv;
            // TODO: add obj ID
        }
        if (type != Type.UNDEFINED) {
            tooltipText = expression + " = " + value;
        } else {
            tooltipText = var.getDescription();
            if (tooltipText == null) {
                tooltipText = Bundle.var_undefined(expression);
            }
        }
    } else {
        throw new CancellationException();
    }
    return Pair.of(tooltipText, tooltipVariable);
}
 
Example 6
Source File: SelectJavadocTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@CheckForNull
private Pair<FileObject,ElementJavadoc> getJavaDoc() {
    final Node node = lookupProvider.getLookup().lookup(Node.class);
    if (node == null) {
        return null;
    }
    final TreePathHandle tph = node.getLookup().lookup(TreePathHandle.class);
    if (tph == null) {
        return null;
    }
    final FileObject fo = node.getLookup().lookup(FileObject.class);
    if (fo == null) {
        return null;
    }
    final JavaSource js = JavaSource.forFileObject(fo);
    if (js == null) {
        return null;
    }
    handle = tph.getElementHandle();
    try {
        js.runUserActionTask(this, true);
    } catch (IOException ioE) {
        Exceptions.printStackTrace(ioE);
        return null;
    }
    return Pair.<FileObject,ElementJavadoc>of(fo, doc);
}
 
Example 7
Source File: PayaraConfiguration.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get new Payara resources file name for creation.
 * <p/>
 * @param module  Java EE module (project).
 * @param version Resources file names depend on Payara server version.
 * @return Payara resources file to be created.
 */
public static final Pair<File, Boolean> getNewResourceFile(
        final J2eeModule module, final PayaraVersion version) {
    final int index = versionToNewResourceFilesIndex(version);
    if (PayaraVersion.lt(version, PayaraVersion.PF_4_1_144)) {
        return Pair.of(new File(module.getResourceDirectory(), RESOURCE_FILES[index]), false);
    }
    final String name = resourceFilePath(module, RESOURCE_FILES[index]);
    return Pair.of(module.getDeploymentConfigurationFile(name), true);
}
 
Example 8
Source File: ModuleNamesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void register(
        @NonNull final URL srcRoot,
        @NonNull final URL binRoot) {
    this.root = Pair.of(srcRoot, binRoot);
    emmittedSrcRs.values().stream()
            .map(Reference::get)
            .filter((r) -> r != null)
            .forEach(SrcR::changed);
    emmittedBinRs.values().stream()
            .map(Reference::get)
            .filter((r) -> r != null)
            .forEach(BinR::changed);
}
 
Example 9
Source File: ActionsUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * split getProjectsFromLookup( Lookup lookup, String command ) into 2 calls
 * to allow FOQ.getOwner to be called outside of AWT
 * @param lookup
 * @return 
 */
public static Pair<List<Project>, List<FileObject>> mineFromLookup(Lookup lookup) {
    List<Project> result = new ArrayList<Project>(); // XXX or use OpenProjectList.projectByDisplayName?
    for (Project p : lookup.lookupAll(Project.class)) {
        result.add(p);
    }
    List<FileObject> result2 = new ArrayList<FileObject>();
    for (DataObject dObj : lookup.lookupAll(DataObject.class)) {
        result2.add(dObj.getPrimaryFile());
    }
    return Pair.of(result, result2);
}
 
Example 10
Source File: ExternalExecutable.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(BaseUtilities.parseParameters(tokens[1].trim())));
    LOGGER.log(Level.FINE, "Parameters parsed: {0} {1}", new Object[] {parsedCommand.first(), parsedCommand.second()});
    return parsedCommand;
}
 
Example 11
Source File: ProcessorGenerated.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void register(
    @NonNull final URL forSource,
    @NonNull final javax.tools.FileObject file,
    @NonNull final Type type) {
    if (!canWrite()) {
        return;
    }
    LOG.log(
        Level.FINE,
        "Generated: {0} from: {1} type: {2}",   //NOI18N
        new Object[]{
            file.toUri(),
            forSource,
            type
    });
    Pair<Set<javax.tools.FileObject>,Set<javax.tools.FileObject>> insertInto =
            generated.get(forSource);
    if (insertInto == null) {
        insertInto = Pair.<Set<javax.tools.FileObject>,Set<javax.tools.FileObject>>of(
                new HashSet<javax.tools.FileObject>(),
                new HashSet<javax.tools.FileObject>());
        generated.put(forSource, insertInto);
    }
    switch (type) {
        case SOURCE:
            insertInto.first().add(file);
            break;
        case RESOURCE:
            insertInto.second().add(file);
            break;
        default:
            throw new IllegalArgumentException();
    }
}
 
Example 12
Source File: LibraryProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Sorts the library versions (in a descending order).
 *
 * @param versions versions to sort.
 */
private static void sort(Library.Version[] versions) {
    Pair<Library.Version, Version>[] pairs = new Pair[versions.length];
    for (int i = 0; i < versions.length; i++) {
        Library.Version libraryVersion = versions[i];
        Version version = Version.parse(libraryVersion.getName());
        pairs[i] = Pair.of(libraryVersion, version);
    }
    Arrays.sort(pairs, VERSION_COMPARATOR);
    for (int i = 0; i < versions.length; i++) {
        versions[i] = pairs[i].first();
    }
}
 
Example 13
Source File: DockerAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Pair<String, String> getHostHeader() throws MalformedURLException {
    URL url = getUrl();
    int port = url.getPort();
    if (port <= 0) {
        return Pair.of("Host", url.getHost()); // NOI18N
    } else {
        return Pair.of("Host", url.getHost() + ":" + port); // NOI18N
    }
}
 
Example 14
Source File: KarmaExecutable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static Pair<String, Integer> getOutputFileLine(String line) {
    Matcher matcher = OUTPUT_FILE_LINE_PATTERN.matcher(line);
    if (!matcher.find()) {
        return null;
    }
    String file = matcher.group("FILE"); // NOI18N
    if (!new File(file).isFile()) {
        // incomplete path
        return null;
    }
    return Pair.of(file, Integer.valueOf(matcher.group("LINE"))); // NOI18N
}
 
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 Function<URL,Boolean> fnc,
        @NonNull Callable<Boolean> cancel,
        @NonNull Collection<? extends URL> binaries) {
    final Collection<URL> result = new ArrayDeque<URL>(binaries.size());
    boolean success = true;
    try {
        for (URL binary : binaries) {
            if (cancel.call()) {
                success = false;
                break;
            }
            if (fnc.apply(binary)) {
                result.add(binary);
            } else {
                success = false;
                break;
            }
        }
    } catch (Exception ce) {
        success = false;
    }
    LOG.log(Level.FINER, "Canceled: {0}", !success);  //NOI18N
    return Pair.<Boolean,Collection<? extends URL>>of(success,result);
}
 
Example 16
Source File: GoToPanelImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@CheckForNull
private Pair<String,JComponent> listActionFor(KeyEvent ev) {
    InputMap map = matchesList.getInputMap();
    Object o = map.get(KeyStroke.getKeyStrokeForEvent(ev));
    if (o instanceof String) {
        return Pair.<String,JComponent>of((String)o, matchesList);
    }
    map = matchesScrollPane1.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    o = map.get(KeyStroke.getKeyStrokeForEvent(ev));
    if (o instanceof String) {
        return Pair.<String,JComponent>of((String)o, matchesScrollPane1);
    }
    return null;
}
 
Example 17
Source File: CslTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected final Pair<EditHistory,String> getEditHistory(String initialText, EditHistory history, String... edits) {
    assertNotNull("Must provide a list of edits", edits);
    assertTrue("Should be an even number of edit events: pairs of caret, insert/remove", edits.length % 2 == 0);

    String modifiedText = initialText;
    for (int i = 0, n = edits.length; i < n; i += 2) {
        String caretLine = edits[i];
        String event = edits[i+1];
        int caretOffset = getCaretOffset(modifiedText, caretLine);

        assertTrue(event + " must start with " + INSERT + " or " + REMOVE,
                event.startsWith(INSERT) || event.startsWith(REMOVE));
        if (event.startsWith(INSERT)) {
            event = event.substring(INSERT.length());
            history.insertUpdate(new TestDocumentEvent(caretOffset, event.length()));
            modifiedText = modifiedText.substring(0, caretOffset) + event + modifiedText.substring(caretOffset);
        } else {
            assertTrue(event.startsWith(REMOVE));
            event = event.substring(REMOVE.length());
            assertTrue(modifiedText.regionMatches(caretOffset, event, 0, event.length()));
            history.removeUpdate(new TestDocumentEvent(caretOffset, event.length()));
            modifiedText = modifiedText.substring(0, caretOffset) + modifiedText.substring(caretOffset+event.length());
        }
    }

    return Pair.<EditHistory,String>of(history, modifiedText);
}
 
Example 18
Source File: CompilePanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Pair<String,JavaPlatform> getSelPlatform () {
    String platformId = project.getLookup().lookup(AuxiliaryProperties.class).
            get(Constants.HINT_JDK_PLATFORM, true);
    return Pair.of(platformId,BootClassPathImpl.getActivePlatform(platformId));
}
 
Example 19
Source File: BinaryAnalyserTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Pair<ElementHandle<TypeElement>,Long> create (String name, long crc) {
    return Pair.<ElementHandle<TypeElement>,Long>of(ElementHandle.createTypeElementHandle(ElementKind.CLASS, name),crc);
}
 
Example 20
Source File: LibrariesNode.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Sets bootstrap libraries to display under the platform node.
 * In case when project's bootstrap libraries differ from {@link JavaPlatform}'s bootstrap libraries
 * this method can be used to override the shown {@link JavaPlatform}'s libraries.
 * @param bootPath the libraries to show
 * @return the {@link Builder}
 * @since 1.68
 */
@NonNull
public Builder setBootPath(@NonNull final ClassPath bootPath) {
    Parameters.notNull("bootPath", bootPath);   //NOI18N            
    this.boot = Pair.<Pair<String,String>,ClassPath>of(boot.first(),bootPath);
    return this;
}