com.igormaznitsa.meta.common.utils.Assertions Java Examples
The following examples show how to use
com.igormaznitsa.meta.common.utils.Assertions.
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: MMPsiParser.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
private void parseHeader(@Nonnull final PsiBuilder builder) { boolean doLoop = true; while (doLoop && !builder.eof()) { final PsiBuilder.Marker marker = builder.mark(); if (builder.getTokenType() == null) { marker.drop(); } else { final IElementType token = builder.getTokenType(); if (token == MMTokens.HEADER_DELIMITER) { marker.done(token); doLoop = false; } else if (token == MMTokens.HEADER_LINE || token == MMTokens.UNKNOWN || token == MMTokens.WHITE_SPACE || token == MMTokens.ATTRIBUTES) { marker.done(token); } else { throw Assertions.fail("Unexpected header token : " + token); } } builder.advanceLexer(); } }
Example #2
Source File: MacOSXAppHandlerOld.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Override public boolean registerPlatformMenuEvent(@Nonnull final PlatformMenuEvent event, @Nonnull final PlatformMenuAction action) { this.actions.put(event, Assertions.assertNotNull(action)); switch (event) { case ABOUT: { this.application.setEnabledAboutMenu(true); } break; case PREFERENCES: { this.application.setEnabledPreferencesMenu(true); } break; } return true; }
Example #3
Source File: DefaultIDEBridge.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Override @Nonnull public Icon loadIcon(@Nonnull final String path, @Nonnull final Class<?> klazz) { Image image; synchronized (IMAGE_CACHE) { image = IMAGE_CACHE.get(path); if (image == null) { final InputStream in = klazz.getClassLoader().getResourceAsStream(Assertions.assertNotNull("Icon path must not be null", removeStartSlash(path))); if (in == null) { throw new IllegalArgumentException("Can't find icon resource : " + path); } try { image = ImageIO.read(in); } catch (IOException ex) { throw new IllegalArgumentException("Can't load icon resource : " + path, ex); } IMAGE_CACHE.put(path, image); } } return new ImageIcon(image); }
Example #4
Source File: SciaRetoBridge.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Override @Nonnull public Icon loadIcon(@Nonnull final String path, @Nonnull final Class<?> klazz) { Image image; synchronized (IMAGE_CACHE) { image = IMAGE_CACHE.get(path); if (image == null) { final InputStream in = klazz.getClassLoader().getResourceAsStream(Assertions.assertNotNull("Icon path must not be null", removeStartSlash(path))); //NOI18N if (in == null) { throw new IllegalArgumentException("Can't find icon resource : " + path); //NOI18N } try { image = ImageIO.read(in); } catch (IOException ex) { throw new IllegalArgumentException("Can't load icon resource : " + path, ex); //NOI18N } IMAGE_CACHE.put(path, image); } } return new ImageIcon(image); }
Example #5
Source File: PlainTextEditor.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
public void replaceSelection(@Nonnull final String clipboardText) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { final SelectionModel model = Assertions.assertNotNull(getEditor()).getSelectionModel(); final int start = model.getSelectionStart(); final int end = model.getSelectionEnd(); getDocument().replaceString(start, end, ""); getDocument().insertString(start, clipboardText); } }, null, null, UndoConfirmationPolicy.DEFAULT, getDocument()); } }); }
Example #6
Source File: PNGImageExporter.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Nullable private BufferedImage makeImage(@Nonnull final PluginContext context, @Nullable final JComponent options) throws IOException { if (options instanceof HasOptions) { final HasOptions opts = (HasOptions) options; this.flagExpandAllNodes = Boolean.parseBoolean(opts.getOption(Options.KEY_EXPAND_ALL)); this.flagDrawBackground = Boolean.parseBoolean(opts.getOption(Options.KEY_DRAW_BACK)); } else { for (final Component compo : Assertions.assertNotNull(options).getComponents()) { if (compo instanceof JCheckBox) { final JCheckBox cb = (JCheckBox) compo; if ("unfold".equalsIgnoreCase(cb.getActionCommand())) { this.flagExpandAllNodes = cb.isSelected(); } else if ("back".equalsIgnoreCase(cb.getActionCommand())) { this.flagDrawBackground = cb.isSelected(); } } } } final MindMapPanelConfig newConfig = new MindMapPanelConfig(context.getPanelConfig(), false); newConfig.setDrawBackground(this.flagDrawBackground); newConfig.setScale(1.0f); return MindMapPanel.renderMindMapAsImage(context.getPanel().getModel(), newConfig, flagExpandAllNodes, RenderQuality.QUALITY); }
Example #7
Source File: Novamind2MindMapImporter.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Nullable TopicReference findForTopicId(@Nonnull TopicReference startTopicRef, @Nonnull final String contentTopicId) { TopicReference result = null; if (contentTopicId.equals(Assertions.assertNotNull(startTopicRef.getContentTopic()).getId())) { result = startTopicRef; } else { for (final ParsedContent.TopicReference c : startTopicRef.getChildren()) { result = findForTopicId(c, contentTopicId); if (result != null) { break; } } } return result; }
Example #8
Source File: NbIDEBridge.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Override @Nonnull public Icon loadIcon(@Nonnull final String path, @Nonnull final Class<?> klazz) { Image image; synchronized (IMAGE_CACHE) { image = IMAGE_CACHE.get(path); if (image == null) { final InputStream in = klazz.getClassLoader().getResourceAsStream(Assertions.assertNotNull("Icon path must not be null", removeStartSlash(path))); if (in == null) { throw new IllegalArgumentException("Can't find icon resource : " + path); } try { image = ImageIO.read(in); } catch (IOException ex) { throw new IllegalArgumentException("Can't load icon resource : " + path, ex); } IMAGE_CACHE.put(path, image); } } return new ImageIcon(image); }
Example #9
Source File: PluginClassLoader.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
public PluginClassLoader(@Nonnull final File pluginFile) throws IOException { super(new URL[] {Assertions.assertNotNull(pluginFile).toURI().toURL()}, PluginClassLoader.class.getClassLoader()); this.pluginFile = pluginFile; this.connection = (JarURLConnection) new URL("jar", "", pluginFile.toURI() + "!/").openConnection(); final Manifest manifest = this.connection.getManifest(); Map<String, String> detectedAttributes = null; if (manifest != null) { final Attributes pluginAttributes = manifest.getEntries().get("nb-mindmap-plugin"); if (pluginAttributes != null) { detectedAttributes = new HashMap<String, String>(); for (final Object key : pluginAttributes.keySet()) { final String keyAsText = key.toString(); detectedAttributes.put(keyAsText, pluginAttributes.getValue(keyAsText)); } } } if (detectedAttributes == null) { throw new IllegalArgumentException("File is not a NB mind map plugin"); } this.attributes = Collections.unmodifiableMap(detectedAttributes); this.apiVersion = new Version(this.attributes.get(Attribute.API.getAttrName())); }
Example #10
Source File: CoggleMM2MindMapImporter.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Override @Nullable public MindMap doImport(@Nonnull final PluginContext context) throws Exception { final File file = this.selectFileForExtension(context, Texts.getString("MMDImporters.CoggleMM2MindMap.openDialogTitle"), null, "mm", "Coggle MM files (.MM)", Texts.getString("MMDImporters.ApproveImport")); if (file == null) { return null; } final Document document = Utils.loadXmlDocument(new FileInputStream(file), "UTF-8", true); final MindMap result = new MindMap(true); Assertions.assertNotNull(result.getRoot()).setText("Empty"); final Element root = document.getDocumentElement(); if ("map".equals(root.getTagName())) { final List<Element> nodes = Utils.findDirectChildrenForName(root, "node"); if (!nodes.isEmpty()) { parseTopic(result, null, result.getRoot(), nodes.get(0)); } } else { throw new IllegalArgumentException("File is not Coggle mind map"); } return result; }
Example #11
Source File: MoveUI.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Override public Problem checkParameters() { final FileObject fo = Assertions.assertNotNull(this.panel).getTarget(); if (fo!=null){ this.refactoring.setTarget(Lookups.fixed(fo.toURL())); }else{ this.refactoring.setTarget(Lookup.EMPTY); } return this.refactoring.checkParameters(); }
Example #12
Source File: Topic.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
public void setExtra(@MustNotContainNull @Nonnull final Extra<?>... extras) { this.map.lock(); try { for (final Extra<?> e : Assertions.assertDoesntContainNull(extras)) { this.extras.put(e.getType(), e); } } finally { this.map.unlock(); } }
Example #13
Source File: MoveUI.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Override public Problem setParameters() { final FileObject fo = Assertions.assertNotNull(this.panel).getTarget(); if (fo != null) { this.refactoring.setTarget(Lookups.fixed(fo.toURL())); } else { this.refactoring.setTarget(Lookup.EMPTY); } return this.refactoring.checkParameters(); }
Example #14
Source File: MMDPrintOptions.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
/** * Set scale. * * @param value new scale, must be great than zero. * @return this instance */ @Nonnull public MMDPrintOptions setScale(final double value) { Assertions.assertTrue("Must be >0.0d", value > 0.0d); this.scale = value; return this; }
Example #15
Source File: MMDPrintOptions.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
/** * Set maximum vertical pages * * @param pages number of pages in column, must be 1 or great * @return this instance */ @Nonnull public MMDPrintOptions setPagesInColumn(final int pages) { Assertions.assertTrue("Must be >=1", pages >= 1); this.vertPages = pages; return this; }
Example #16
Source File: MMDPrintOptions.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
/** * Set maximum horizontal pages * * @param pages number of pages in row, must be 1 or great * @return this instance */ @Nonnull public MMDPrintOptions setPagesInRow(final int pages) { Assertions.assertTrue("Must be >=1", pages >= 1); this.horzPages = pages; return this; }
Example #17
Source File: NbUtils.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Nonnull public static Clipboard findClipboard() { Clipboard result = Lookup.getDefault().lookup(ExClipboard.class); if (result == null) { result = Toolkit.getDefaultToolkit().getSystemClipboard(); } return Assertions.assertNotNull("Clipbard is not found", result); }
Example #18
Source File: Topic.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
public void setText(@Nonnull final String text) { this.map.lock(); try { this.text = Assertions.assertNotNull(text); } finally { this.map.unlock(); } }
Example #19
Source File: MindMap.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
public MindMap(@Nonnull final Reader reader) throws IOException { final String text = IOUtils.toString(Assertions.assertNotNull(reader)); final MindMapLexer lexer = new MindMapLexer(); lexer.start(text, 0, text.length(), MindMapLexer.TokenType.HEAD_LINE); Topic rootTopic = null; boolean process = true; while (process) { final int oldLexerPosition = lexer.getCurrentPosition().getOffset(); lexer.advance(); final boolean lexerPositionWasNotChanged = oldLexerPosition == lexer.getCurrentPosition().getOffset(); final MindMapLexer.TokenType token = lexer.getTokenType(); if (token == null || lexerPositionWasNotChanged) { throw new IllegalArgumentException("Wrong format of mind map, end of header is not found"); } switch (token) { case HEAD_LINE: continue; case ATTRIBUTE: { fillMapByAttributes(lexer.getTokenText(), this.attributes); } break; case HEAD_DELIMITER: { process = false; rootTopic = Topic.parse(this, lexer); } break; default: break; } } this.root = rootTopic; this.attributes.put(GENERATOR_VERSION_NAME, FORMAT_VERSION); }
Example #20
Source File: MindMapPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Nonnull public MindMap getModel() { this.lock(); try { return Assertions.assertNotNull("Model is not provided, it must not be null!", this.model); } finally { this.unlock(); } }
Example #21
Source File: Topic.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
public boolean removeExtra(@Nonnull @MustNotContainNull final Extra.ExtraType... types) { this.map.lock(); try { boolean result = false; for (final Extra.ExtraType e : Assertions.assertDoesntContainNull(types)) { result |= this.extras.remove(e) != null; } return result; } finally { this.map.unlock(); } }
Example #22
Source File: MindMapPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
public void addMindMapListener(@Nonnull final MindMapListener l) { if (this.lockIfNotDisposed()) { try { this.mindMapListeners.add(Assertions.assertNotNull(l)); } finally { this.unlock(); } } }
Example #23
Source File: MindMapPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
public void removeMindMapListener(@Nonnull final MindMapListener l) { if (this.lockIfNotDisposed()) { try { this.mindMapListeners.remove(Assertions.assertNotNull(l)); } finally { this.unlock(); } } }
Example #24
Source File: MindMapPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
/** * Unlock the panel. it will not throw any exception if the panel is disposed. * * @throws AssertionError if the panel is locked by another thread */ public void unlock() { if (this.panelLocker != null) { Assertions.assertTrue("Panel must be held by the current thread", this.panelLocker.isHeldByCurrentThread()); this.panelLocker.unlock(); } }
Example #25
Source File: Freemind2MindMapImporter.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Override @Nullable public MindMap doImport(@Nonnull final PluginContext context) throws Exception { final File file = this.selectFileForExtension(context, Texts.getString("MMDImporters.Freemind2MindMap.openDialogTitle"), null, "mm", "Freemind files (.MM)", Texts.getString("MMDImporters.ApproveImport")); if (file == null) { return null; } final Document document = Utils.loadHtmlDocument(new FileInputStream(file), "UTF-8", true); final XPath xpath = XPathFactory.newInstance().newXPath(); final Element rootElement = (Element) xpath.evaluate("/html/body/map", document, XPathConstants.NODE); if (rootElement == null) { throw new IllegalArgumentException("Can't parse freemind file as xhtml"); } final Map<String, Topic> idTopicMap = new HashMap<>(); final Map<String, String> linksMap = new HashMap<>(); final MindMap resultedMap = new MindMap(true); resultedMap.setAttribute(MindMapPanel.ATTR_SHOW_JUMPS, "true"); final List<Element> list = Utils.findDirectChildrenForName(rootElement, "node"); if (list.isEmpty()) { Assertions.assertNotNull(resultedMap.getRoot()).setText("Empty"); } else { parseTopic(file.getParentFile(), resultedMap, null, resultedMap.getRoot(), list.get(0), idTopicMap, linksMap); } for (final Map.Entry<String, String> l : linksMap.entrySet()) { final Topic start = idTopicMap.get(l.getKey()); final Topic end = idTopicMap.get(l.getValue()); if (start != null && end != null) { start.setExtra(ExtraTopic.makeLinkTo(resultedMap, end)); } } return resultedMap; }
Example #26
Source File: Topic.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private Topic(@Nonnull final MindMap map, @Nonnull final String text, @Nonnull @MayContainNull final Extra<?>... extras) { this.map = Assertions.assertNotNull(map); this.text = Assertions.assertNotNull(text); for (final Extra<?> e : extras) { if (e != null) { this.extras.put(e.getType(), e); } } }
Example #27
Source File: NodeFileOrFolder.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Nonnull public NodeFileOrFolder addFile(@Nonnull final File file, final boolean showHiddenFiles) throws IOException { Assertions.assertTrue("Unexpected state!", this.folderFlag && file.getParentFile().equals(this.makeFileForNode())); //NOI18N final NodeFileOrFolder result = new NodeFileOrFolder(this, file.isDirectory(), file.getName(), showHiddenFiles, !Files.isWritable(file.toPath())); this.children.add(0, result); Collections.sort(this.children, this); return result; }
Example #28
Source File: MMPsiParser.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private boolean parseExtraBlock(@Nonnull final PsiBuilder builder) { // read type final PsiBuilder.Marker type = builder.mark(); if (builder.getTokenType() != MMTokens.EXTRA_TYPE) { throw Assertions.fail("Unexpected token " + builder.getTokenType()); } builder.advanceLexer(); type.done(MMTokens.EXTRA_TYPE); boolean dataFound = false; // read body while (!builder.eof()) { final PsiBuilder.Marker marker = builder.mark(); if (builder.eof() || builder.getTokenType() == null) { marker.drop(); break; } else { final IElementType token = builder.getTokenType(); if (token == MMTokens.TOPIC_LEVEL || token == MMTokens.EXTRA_TYPE) { marker.rollbackTo(); return true; } else if (token == MMTokens.EXTRA_BODY || token == MMTokens.WHITE_SPACE) { if (dataFound && token == MMTokens.EXTRA_BODY) { builder.advanceLexer(); marker.done(MMTokens.UNKNOWN); break; } else { builder.advanceLexer(); marker.done(token); dataFound = dataFound || token == MMTokens.EXTRA_BODY; } } else { marker.done(MMTokens.UNKNOWN); break; } } } return false; }
Example #29
Source File: NodeProjectGroup.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
void notifyProjectStateChanged(@Nonnull final NodeProject project) { Assertions.assertTrue("Must belong the group", project.getGroup() == this); final TreeModelEvent event = new TreeModelEvent(this, new TreePath(new Object[]{this, project})); Utils.safeSwingCall(new Runnable() { @Override public void run() { for (final TreeModelListener l : listeners) { l.treeStructureChanged(event); } } }); }
Example #30
Source File: MMDEditor.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Override protected void onLoadContent(@Nonnull final TextFile textFile) throws IOException { final MindMap map = new MindMap(new StringReader(textFile.readContentAsUtf8())); this.mindMapPanel.setModel(Assertions.assertNotNull(map), false); this.undoStorage.clearRedo(); this.undoStorage.clearUndo(); this.title.setChanged(false); this.scrollPane.revalidate(); }