From 2ebff9157db0753821b7d6eaeff3ceb4414946ef Mon Sep 17 00:00:00 2001 From: jinbokai Date: Tue, 10 Sep 2019 14:17:36 +0800 Subject: [PATCH] REPORT-20328 sonar --- .../ui/rsyntaxtextarea/RSyntaxTextArea.java | 10 +---- .../gui/syntax/ui/rsyntaxtextarea/Style.java | 17 +++++---- .../ui/rsyntaxtextarea/SyntaxScheme.java | 23 +++++------ .../folding/HtmlFoldParser.java | 4 +- .../syntax/ui/rtextarea/RTextAreaBase.java | 38 ++++--------------- .../gui/syntax/ui/rtextarea/SearchEngine.java | 5 ++- ...olatileImageBackgroundPainterStrategy.java | 7 +++- 7 files changed, 40 insertions(+), 64 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java index 3d04602f2..30fc7b871 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java @@ -3016,11 +3016,6 @@ private boolean fractionalFontMetricsEnabled; return he; } - private final boolean equal(LinkGeneratorResult e1, - LinkGeneratorResult e2) { - return e1.getSourceOffset()==e2.getSourceOffset(); - } - @Override public void mouseClicked(MouseEvent e) { if (getHyperlinksEnabled() && isScanningForLinks && @@ -3080,8 +3075,7 @@ private boolean fractionalFontMetricsEnabled; isLinkAtOffset(RSyntaxTextArea.this, offs); if (newResult!=null) { // Repaint if we're at a new link now. - if (linkGeneratorResult==null || - !equal(newResult, linkGeneratorResult)) { + if (linkGeneratorResult==null || newResult.getSourceOffset() != linkGeneratorResult.getSourceOffset()) { repaint(); } linkGeneratorResult = newResult; @@ -3120,4 +3114,4 @@ private boolean fractionalFontMetricsEnabled; } -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/Style.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/Style.java index 496537ae0..0824ceafc 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/Style.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/Style.java @@ -9,6 +9,7 @@ */ package com.fr.design.gui.syntax.ui.rsyntaxtextarea; +import com.fr.log.FineLoggerFactory; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; @@ -123,15 +124,15 @@ public class Style implements Cloneable { Style clone = null; try { clone = (Style)super.clone(); + clone.foreground = foreground; + clone.background = background; + clone.font = font; + clone.underline = underline; + clone.fontMetrics = fontMetrics; } catch (CloneNotSupportedException cnse) { // Never happens - cnse.printStackTrace(); - return null; + FineLoggerFactory.getLogger().error(cnse.getMessage(), cnse); + clone = null; } - clone.foreground = foreground; - clone.background = background; - clone.font = font; - clone.underline = underline; - clone.fontMetrics = fontMetrics; return clone; } @@ -193,4 +194,4 @@ public class Style implements Cloneable { } -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/SyntaxScheme.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/SyntaxScheme.java index 621aeb545..dbaaf4c6f 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/SyntaxScheme.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/SyntaxScheme.java @@ -9,6 +9,7 @@ */ package com.fr.design.gui.syntax.ui.rsyntaxtextarea; +import com.fr.log.FineLoggerFactory; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; @@ -121,17 +122,17 @@ public class SyntaxScheme implements Cloneable, TokenTypes { public Object clone() { SyntaxScheme shcs = null; try { - shcs = (SyntaxScheme)super.clone(); - } catch (CloneNotSupportedException cnse) { // Never happens - cnse.printStackTrace(); - return null; - } - shcs.styles = new Style[styles.length]; - for (int i=0; i or %> - else if (t.startsWith(LANG_END[language])) { + else if (currentFold != null && t.startsWith(LANG_END[language])) { int phpEnd = t.getEndOffset() - 1; currentFold.setEndOffset(phpEnd); Fold parentFold = currentFold.getParent(); @@ -400,4 +400,4 @@ public class HtmlFoldParser implements FoldParser { } -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaBase.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaBase.java index 334d34255..01c9238c6 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaBase.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaBase.java @@ -723,37 +723,13 @@ int currentCaretY; // Used to know when to rehighlight current line. // If we're wrapping lines we need to check the actual y-coordinate // of the caret, not just the line number, since a single logical // line can span multiple physical lines. - if (getLineWrap()) { - try { - Rectangle temp = modelToView(dot); - if (temp!=null) { - currentCaretY = temp.y; - } - } catch (BadLocationException ble) { - ble.printStackTrace(); // Should never happen. + try { + Rectangle temp = modelToView(dot); + if (temp != null) { + currentCaretY = temp.y; } - } - - // No line wrap - we can simply check the line number (quicker). - else { -// Document doc = getDocument(); -// if (doc!=null) { -// Element map = doc.getDefaultRootElement(); -// int caretLine = map.getElementIndex(dot); -// Rectangle alloc = ((RTextAreaUI)getUI()). -// getVisibleEditorRect(); -// if (alloc!=null) -// currentCaretY = alloc.y + caretLine*lineHeight; -// } -// Modified for code folding requirements -try { - Rectangle temp = modelToView(dot); - if (temp!=null) { - currentCaretY = temp.y; - } -} catch (BadLocationException ble) { - ble.printStackTrace(); // Should never happen. -} + } catch (BadLocationException ble) { + ble.printStackTrace(); // Should never happen. } // Repaint current line (to fill in entire highlight), and old line @@ -1211,4 +1187,4 @@ try { } -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/SearchEngine.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/SearchEngine.java index 23cf92964..3bda042ce 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/SearchEngine.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/SearchEngine.java @@ -25,6 +25,7 @@ import javax.swing.text.Caret; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.DocumentRange; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.folding.FoldManager; +import org.jetbrains.annotations.NotNull; /** @@ -174,6 +175,7 @@ public class SearchEngine { * @param forward Whether we're searching forward or backward. * @return The character sequence. */ + @NotNull private static CharSequence getFindInCharSequence(RTextArea textArea, int start, boolean forward) { RDocument doc = (RDocument)textArea.getDocument(); @@ -752,7 +754,6 @@ public class SearchEngine { int start = makeMarkAndDotEqual(textArea, forward); CharSequence findIn = getFindInCharSequence(textArea, start, forward); - if (findIn==null) return new SearchResult(); int markAllCount = 0; if (context.getMarkAll()) { @@ -1014,4 +1015,4 @@ public class SearchEngine { } -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java index c7be420de..f08ab22c3 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java @@ -103,6 +103,9 @@ public class VolatileImageBackgroundPainterStrategy } finally { tracker.removeImage(i, 1); } + if(bgImage == null) { + continue; + } bgImage.getGraphics().drawImage(i, 0,0, null); tracker.addImage(bgImage, 0); try { @@ -114,7 +117,7 @@ public class VolatileImageBackgroundPainterStrategy } finally { tracker.removeImage(bgImage, 0); } - } while (bgImage.contentsLost()); + } while (bgImage != null && bgImage.contentsLost()); } // End of if (master!=null). else { bgImage = null; @@ -137,4 +140,4 @@ public class VolatileImageBackgroundPainterStrategy } -} \ No newline at end of file +}