Java Code Examples for org.openide.util.Pair#first()
The following examples show how to use
org.openide.util.Pair#first() .
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: CreateElement.java From netbeans with Apache License 2.0 | 6 votes |
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 2
Source File: ClassPath.java From netbeans with Apache License 2.0 | 6 votes |
private void listenOnRoots (final List<Pair<ClassPath.Entry,Pair<FileObject,File>>> roots) { final Set<File> listenOn = new HashSet<>(); for (Pair<ClassPath.Entry,Pair<FileObject,File>> p : roots) { final ClassPath.Entry entry = p.first(); final FileObject fo = p.second().first(); if (fo != null) { root2Filter.put(fo, entry.filter); } final File file = p.second().second(); if (file != null) { listenOn.add(file); } } final RootsListener rL = this.getRootsListener(); if (rL != null) { rL.addRoots (listenOn); } }
Example 3
Source File: WatchesModel.java From netbeans with Apache License 2.0 | 6 votes |
@Override public boolean isLeaf(TreeModel original, Object node) throws UnknownTypeException { if (node == ROOT) { return false; } else if (node instanceof Watch) { V8Value value; Pair<V8Value, String> ew; synchronized (evaluatedWatches) { ew = evaluatedWatches.get((Watch) node); } if (ew != null) { value = ew.first(); } else { value = null; } return !hasChildren(value); } else { return super.isLeaf(node); } }
Example 4
Source File: CodeceptionTestLocator.java From netbeans with Apache License 2.0 | 5 votes |
private List<Locations.Offset> filterPhpFiles(FileObject sourceRoot, Collection<Pair<FileObject, Integer>> files) { List<Locations.Offset> results = new ArrayList<>(files.size()); for (Pair<FileObject, Integer> pair : files) { FileObject fileObject = pair.first(); if (FileUtils.isPhpFile(fileObject) && FileUtil.isParentOf(sourceRoot, fileObject)) { results.add(new Locations.Offset(fileObject, pair.second())); } } return results; }
Example 5
Source File: NetworkSupport.java From netbeans with Apache License 2.0 | 5 votes |
private static void doDownload(String url, File target, Pair<InputStream, Integer> downloadSetup, @NullAllowed ProgressHandle progressHandle) throws IOException, InterruptedException { if (progressHandle != null) { progressHandle.progress(Bundle.NetworkSupport_progress_download(url)); } try (InputStream is = downloadSetup.first()) { copyToFile(is, target, progressHandle, downloadSetup.second()); } catch (IOException ex) { // error => ensure file is deleted if (!target.delete()) { // nothing we can do about it } throw ex; } }
Example 6
Source File: GoToPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void delegateScrollingKey(KeyEvent ev) { final Pair<String,JComponent> p = listActionFor(ev); if (p == null) { return; } final String action = p.first(); final JComponent target = p.second(); // Wrap around if ( "selectNextRow".equals(action) && matchesList.getSelectedIndex() == matchesList.getModel().getSize() -1 ) { matchesList.setSelectedIndex(0); matchesList.ensureIndexIsVisible(0); return; } else if ( "selectPreviousRow".equals(action) && matchesList.getSelectedIndex() == 0 ) { int last = matchesList.getModel().getSize() - 1; matchesList.setSelectedIndex(last); matchesList.ensureIndexIsVisible(last); return; } // Plain delegation Action a = target.getActionMap().get(action); if (a != null) { a.actionPerformed(new ActionEvent(target, 0, action)); } }
Example 7
Source File: ModuleNamesTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override public BinaryForSourceQuery.Result findBinaryRoots(URL sourceRoot) { final Reference<BinR> rr = emmittedBinRs.get(sourceRoot); BinR r; if (rr != null && (r=rr.get()) != null) { return r; } final Pair<URL,URL> current = root; if (current != null && current.first().equals(sourceRoot)) { r = new BinR(current.first()); emmittedBinRs.put(sourceRoot, new WeakReference<>(r)); return r; } return null; }
Example 8
Source File: CreateJREPanel.java From netbeans with Apache License 2.0 | 5 votes |
@CheckForNull public static List<String> configure( @NonNull File destFolder) { Parameters.notNull("destFolder", destFolder); //NOI18N final Pair<List<String>,String> data = configureImpl(null, null, destFolder); return data == null ? null : data.first(); }
Example 9
Source File: ELHyperlinkProvider.java From netbeans with Apache License 2.0 | 5 votes |
@Override public String getTooltipText(Document doc, int offset, HyperlinkType type) { Pair<Node, ELElement> nodeAndElement = resolveNodeAndElement(doc, offset, new AtomicBoolean()); if (nodeAndElement != null) { if (nodeAndElement.first() instanceof AstString) { // could be a resource bundle key return getTooltipTextForBundleKey(nodeAndElement); } else { return getTooltipTextForElement(nodeAndElement); } } return null; }
Example 10
Source File: CssDeclarationFinder.java From netbeans with Apache License 2.0 | 5 votes |
@Override public OffsetRange getReferenceSpan(Document doc, int caretOffset) { Pair<OffsetRange, FutureParamTask<DeclarationLocation, EditorFeatureContext>> declarationLocation = CssModuleSupport.getDeclarationLocation(doc, caretOffset, new FeatureCancel()); if(declarationLocation != null) { taskRef.set(declarationLocation.second()); return declarationLocation.first(); } return OffsetRange.NONE; }
Example 11
Source File: J2SEPlatformCustomizer.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Icon icon = null; if (value instanceof URL) { Pair<String,Icon> p = getDisplayName((URL)value); value = p.first(); icon = p.second(); } final Component res = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); setIcon(icon); return res; }
Example 12
Source File: ExternalExecutable.java From netbeans with Apache License 2.0 | 5 votes |
/** * Parse command which can be just binary or binary with parameters. * As a parameter separator, "-" or "/" is used. * @param command command to parse, can be {@code null}. */ public ExternalExecutable(String command) { Pair<String, List<String>> parsedCommand = parseCommand(command); executable = parsedCommand.first(); parameters = parsedCommand.second(); this.command = command.trim(); }
Example 13
Source File: GoToPanelImpl.java From netbeans with Apache License 2.0 | 5 votes |
private void delegateScrollingKey(KeyEvent ev) { final Pair<String,JComponent> p = listActionFor(ev); if (p == null) { return; } final String action = p.first(); final JComponent target = p.second(); // Wrap around if ( "selectNextRow".equals(action) && matchesList.getSelectedIndex() == matchesList.getModel().getSize() -1 ) { matchesList.setSelectedIndex(0); matchesList.ensureIndexIsVisible(0); return; } else if ( "selectPreviousRow".equals(action) && matchesList.getSelectedIndex() == 0 ) { int last = matchesList.getModel().getSize() - 1; matchesList.setSelectedIndex(last); matchesList.ensureIndexIsVisible(last); return; } // Plain delegation final Action a = target.getActionMap().get(action); if (a != null) { a.actionPerformed(new ActionEvent(target, 0, action)); } }
Example 14
Source File: AnnotationHolder.java From netbeans with Apache License 2.0 | 4 votes |
private void updateAnnotationOnLine(Position line, boolean synchronous) throws BadLocationException { List<ErrorDescription> errorDescriptions = getErrorsForLine(line, false); if (errorDescriptions == null) errorDescriptions = Collections.emptyList(); else errorDescriptions = new ArrayList<>(errorDescriptions); Severity mostImportantSeverity = Severity.HINT; String customType = null; for (Iterator<ErrorDescription> it = errorDescriptions.iterator(); it.hasNext();) { ErrorDescription ed = it.next(); List<Position> positions = errors2Lines.get(ed); if (positions == null || positions.isEmpty() || positions.get(0) != line) { it.remove(); } else { if (mostImportantSeverity.compareTo(ed.getSeverity()) > 0) { mostImportantSeverity = ed.getSeverity(); } customType = ed.getCustomType(); } } if (errorDescriptions.isEmpty()) { //nothing to do, remove old: ParseErrorAnnotation ann = line2Annotations.remove(line); if (ann != null) { detachAnnotation(ann, synchronous); } return; } Pair<FixData, String> fixData = buildUpFixDataForLine(line); ParseErrorAnnotation pea; if (customType == null) { pea = new ParseErrorAnnotation( mostImportantSeverity, fixData.first(), fixData.second(), line, this); } else { pea = new ParseErrorAnnotation( mostImportantSeverity, customType, fixData.first(), fixData.second(), line, this); } ParseErrorAnnotation previous = line2Annotations.put(line, pea); if (previous != null) { detachAnnotation(previous, synchronous); } attachAnnotation(line, pea, synchronous); }
Example 15
Source File: ClientSideProjectWizardIterator.java From netbeans with Apache License 2.0 | 4 votes |
@NbBundle.Messages({ "ClientSideProjectWizardIterator.progress.creatingProject=Creating project", "ClientSideProjectWizardIterator.error.noSources=<html>Source folder cannot be created.<br><br>Use <i>Resolve Project Problems...</i> action to repair the project.", "ClientSideProjectWizardIterator.error.noSiteRoot=<html>Site Root folder cannot be created.<br><br>Use <i>Resolve Project Problems...</i> action to repair the project.", }) @Override public Set<FileObject> instantiate(ProgressHandle handle) throws IOException { handle.start(); handle.progress(Bundle.ClientSideProjectWizardIterator_progress_creatingProject()); Set<FileObject> files = new LinkedHashSet<>(); File projectDirectory = FileUtil.normalizeFile((File) wizardDescriptor.getProperty(Wizard.PROJECT_DIRECTORY)); String name = (String) wizardDescriptor.getProperty(Wizard.NAME); if (!projectDirectory.isDirectory() && !projectDirectory.mkdirs()) { throw new IOException("Cannot create project directory"); //NOI18N } FileObject dir = FileUtil.toFileObject(projectDirectory); CommonProjectHelper projectHelper = ClientSideProjectUtilities.setupProject(dir, name); // Always open top dir as a project: files.add(dir); ClientSideProject project = (ClientSideProject) FileOwnerQuery.getOwner(projectHelper.getProjectDirectory()); Pair<FileObject, FileObject> folders = wizard.instantiate(files, handle, wizardDescriptor, project); FileObject sources = folders.first(); FileObject siteRoot = folders.second(); if (sources != null) { // main file FileObject mainFile = sources.getFileObject("main.js"); // NOI18N if (mainFile != null) { files.add(mainFile); } } else if (wizard.hasSources()) { errorOccured(Bundle.ClientSideProjectWizardIterator_error_noSources()); } if (siteRoot != null) { // index file FileObject indexFile = siteRoot.getFileObject("index", "html"); // NOI18N if (indexFile != null) { files.add(indexFile); } } else if (wizard.hasSiteRoot()) { errorOccured(Bundle.ClientSideProjectWizardIterator_error_noSiteRoot()); } File parent = projectDirectory.getParentFile(); if (parent != null && parent.exists()) { ProjectChooser.setProjectsFolder(parent); } handle.finish(); wizard.logUsage(wizardDescriptor, dir, sources, siteRoot); return files; }
Example 16
Source File: NodeJsSupport.java From netbeans with Apache License 2.0 | 4 votes |
@NbBundle.Messages({ "# {0} - project name", "PreferencesListener.sync.title=Node.js ({0})", "PreferencesListener.sync.error=Cannot write changed start file/arguments to package.json.", "PreferencesListener.sync.done=Start file/arguments synced to package.json.", }) void startScriptChanged(String newStartFile, final String newStartArgs) { final String projectDir = project.getProjectDirectory().getNameExt(); if (!preferences.isEnabled()) { LOGGER.log(Level.FINE, "Start file/args change ignored in project {0}, node.js not enabled in project {0}", projectDir); return; } if (!preferences.isSyncEnabled()) { LOGGER.log(Level.FINE, "Start file/args change ignored in project {0}, sync not enabled", projectDir); return; } if (!StringUtils.hasText(newStartFile) && !StringUtils.hasText(newStartArgs)) { LOGGER.log(Level.FINE, "Start file/args change ignored in project {0}, new file and args are empty", projectDir); return; } String relNewStartFile = newStartFile; String relPath = PropertyUtils.relativizeFile(FileUtil.toFile(project.getProjectDirectory()), new File(newStartFile)); if (relPath != null) { relNewStartFile = relPath; } if (!packageJson.exists()) { LOGGER.log(Level.FINE, "Start file/args change ignored in project {0}, package.json not exist", projectDir); return; } LOGGER.log(Level.FINE, "Processing Start file/args change in project {0}", projectDir); Map<String, Object> content = packageJson.getContent(); if (content == null) { LOGGER.log(Level.FINE, "Start file/args change ignored in project {0}, package.json has no or invalid content", projectDir); return; } String startFile = null; String startArgs = null; String startScript = packageJson.getContentValue(String.class, PackageJson.FIELD_SCRIPTS, PackageJson.FIELD_START); if (startScript != null) { Pair<String, String> startInfo = NodeJsUtils.parseStartFile(startScript); startFile = startInfo.first(); startArgs = startInfo.second(); } if (Objects.equals(startFile, relNewStartFile) && Objects.equals(startArgs, newStartArgs)) { LOGGER.log(Level.FINE, "Start file/args change ignored in project {0}, file and args same as in package.json", projectDir); return; } final String projectName = NodeJsUtils.getProjectDisplayName(project); if (preferences.isAskSyncEnabled()) { final String relNewStartFileRef = relNewStartFile; Notifications.askSyncChanges(project, new Runnable() { @Override public void run() { RP.post(new Runnable() { @Override public void run() { changeStartScript(relNewStartFileRef, newStartArgs, projectName, projectDir); } }); } }, new Runnable() { @Override public void run() { preferences.setSyncEnabled(false); LOGGER.log(Level.FINE, "Start file/args change ignored in project {0}, cancelled by user", projectDir); } }); } else { changeStartScript(relNewStartFile, newStartArgs, projectName, projectDir); } }
Example 17
Source File: Utilities.java From netbeans with Apache License 2.0 | 4 votes |
/** * Utility method which creates a map of property name to PropertyDefinition for * a properties file defining the css properties * * the syntax of the file: * * propertyName=valueGrammar * * Example: * * outline-style=auto | <border-style> * * @param sourcePath - an absolute path to the resource properties file relative to the module base */ public static Map<String, PropertyDefinition> parsePropertyDefinitionFile(String sourcePath, CssModule module) { Map<String, PropertyDefinition> properties = new HashMap<>(); //why not use NbBundle.getBundle()? - we need the items in the natural source order Collection<Pair<String, String>> parseBundle = PropertiesReader.parseBundle(sourcePath); PropertyCategory category = PropertyCategory.DEFAULT; for(Pair<String, String> pair : parseBundle) { String name = pair.first(); String value = pair.second(); if(name.startsWith("$")) { //property category if(CATEGORY_META_PROPERTY_NAME.equalsIgnoreCase(name)) { try { category = PropertyCategory.valueOf(value.toUpperCase()); } catch (IllegalArgumentException e) { Logger.getAnonymousLogger().log(Level.INFO, String.format("Unknown property category name %s in %s properties definition file. Served by %s css module.", value, sourcePath, module.getSpecificationURL()), e); } } else { //unknown meta property Logger.getAnonymousLogger().log(Level.INFO, null, new IllegalArgumentException(String.format("Unknown meta property %s in %s properties definition file. Served by %s css module.", name, sourcePath, module.getSpecificationURL()))); } } else { //parse bundle key - there might be more properties separated by semicolons StringTokenizer nameTokenizer = new StringTokenizer(name, ";"); //NOI18N while (nameTokenizer.hasMoreTokens()) { String parsed_name = nameTokenizer.nextToken().trim(); PropertyDefinition prop = new PropertyDefinition(parsed_name, value, category, module); properties.put(parsed_name, prop); } } } return properties; }
Example 18
Source File: WatchesModel.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Object getValueAt(Object node, String columnID) throws UnknownTypeException { if (node instanceof Watch) { Watch watch = (Watch) node; Pair<V8Value, String> ew; synchronized (evaluatedWatches) { ew = evaluatedWatches.get(watch); } if (ew != null) { if (ew.second() != null) { if (WATCH_VALUE_COLUMN_ID.equals(columnID) || WATCH_TO_STRING_COLUMN_ID.equals(columnID)) { return toHTML(ew.second(), true, false, Color.red); } else if (WATCH_TYPE_COLUMN_ID.equals(columnID)) { return ""; } } else { V8Value value = ew.first(); if (value != null) { if (WATCH_VALUE_COLUMN_ID.equals(columnID) || WATCH_TO_STRING_COLUMN_ID.equals(columnID)) { return toHTML(V8Evaluator.getStringValue(value)); } else if (WATCH_TYPE_COLUMN_ID.equals(columnID)) { return toHTML(V8Evaluator.getStringType(value)); } } } } if (WATCH_VALUE_COLUMN_ID.equals(columnID) || WATCH_TO_STRING_COLUMN_ID.equals(columnID)) { return (watch.isEnabled()) ? "N/A" : ""; } else if(WATCH_TYPE_COLUMN_ID.equals(columnID)) { return ""; } } else { if (WATCH_VALUE_COLUMN_ID.equals(columnID)) { return super.getValueAt(node, LOCALS_VALUE_COLUMN_ID); } else if(WATCH_TYPE_COLUMN_ID.equals(columnID)) { return super.getValueAt(node, LOCALS_TYPE_COLUMN_ID); } else if (WATCH_TO_STRING_COLUMN_ID.equals(columnID) || LOCALS_TO_STRING_COLUMN_ID.equals(columnID)) { return super.getValueAt(node, LOCALS_TO_STRING_COLUMN_ID); } } throw new UnknownTypeException(node); }
Example 19
Source File: ClassBreakpointPanel.java From netbeans with Apache License 2.0 | 4 votes |
/** Creates new form LineBreakpointPanel */ public ClassBreakpointPanel (ClassLoadUnloadBreakpoint b) { breakpoint = b; initComponents (); String className = ""; // NOI18N String[] cf = b.getClassFilters (); className = ClassBreakpointPanel.concatClassFilters(cf); ResourceBundle bundle = NbBundle.getBundle(ClassBreakpointPanel.class); String tooltipText = bundle.getString("TTT_TF_Class_Breakpoint_Class_Name"); Pair<JScrollPane, JEditorPane> editorCC = addClassNameEditorCC(JavaClassNbDebugEditorKit.MIME_TYPE, pSettings, className, tooltipText); spClassName = editorCC.first(); epClassName = editorCC.second(); epClassName.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_Method_Breakpoint_ClassName")); epClassName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_Class_Breakpoint_ClassName")); HelpCtx.setHelpIDString(epClassName, HELP_ID); jLabel3.setLabelFor(spClassName); cbBreakpointType.addItem (bundle.getString("LBL_Class_Breakpoint_Type_Prepare")); cbBreakpointType.addItem (bundle.getString("LBL_Class_Breakpoint_Type_Unload")); cbBreakpointType.addItem (bundle.getString("LBL_Class_Breakpoint_Type_Prepare_or_Unload")); switch (b.getBreakpointType ()) { case ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED: cbBreakpointType.setSelectedIndex (0); break; case ClassLoadUnloadBreakpoint.TYPE_CLASS_UNLOADED: cbBreakpointType.setSelectedIndex (1); break; case ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED_UNLOADED: cbBreakpointType.setSelectedIndex (2); break; } conditionsPanel = new ConditionsPanel(HELP_ID); conditionsPanel.setupConditionPaneContext(); cPanel.add(conditionsPanel, "Center"); conditionsPanel.showExclusionClassFilter(true); conditionsPanel.showCondition(false); conditionsPanel.setClassExcludeFilter(b.getClassExclusionFilters()); conditionsPanel.setHitCountFilteringStyle(b.getHitCountFilteringStyle()); conditionsPanel.setHitCount(b.getHitCountFilter()); actionsPanel = new ActionsPanel (b); pActions.add (actionsPanel, "Center"); // <RAVE> // The help IDs for the AddBreakpointPanel panels have to be different from the // values returned by getHelpCtx() because they provide different help // in the 'Add Breakpoint' dialog and when invoked in the 'Breakpoints' view putClientProperty("HelpID_AddBreakpointPanel", HELP_ID); // NOI18N // </RAVE> }
Example 20
Source File: NBJRTArchiveRootProvider.java From netbeans with Apache License 2.0 | 4 votes |
@Override @CheckForNull public URL getArchiveFile(@NonNull final URL url) { final Pair<URL,String> p = NBJRTUtil.parseURL(url); return p != null ? p.first() : null; }