-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show details rule when click on annotation, add rule name on details,…
… open browser when click on hyperlink in details
- Loading branch information
1 parent
2fa3ec5
commit e7dfa61
Showing
17 changed files
with
373 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 71 additions & 60 deletions
131
src/main/java/fr/philippefichet/sonarlint/netbeans/SonarLintAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,71 @@ | ||
/* | ||
* sonarlint4netbeans: SonarLint integration for Apache Netbeans | ||
* Copyright (C) 2019 Philippe FICHET. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301 USA | ||
*/ | ||
package fr.philippefichet.sonarlint.netbeans; | ||
|
||
import org.openide.text.Annotation; | ||
|
||
/** | ||
* | ||
* @author FICHET Philippe | ||
*/ | ||
public class SonarLintAnnotation extends Annotation { | ||
|
||
private static final String ANNOTATION_TYPE = "fr-philippefichet-sonarlint-netbeans-annotation"; | ||
private final long startOffest; | ||
private final int length; | ||
private final String shortDescription; | ||
|
||
public SonarLintAnnotation(String shortDescription, long startOffest, int length) { | ||
super(); | ||
this.startOffest = startOffest; | ||
this.length = length; | ||
this.shortDescription = shortDescription; | ||
} | ||
|
||
public long getStartOffest() { | ||
return startOffest; | ||
} | ||
|
||
public int getLength() { | ||
return length; | ||
} | ||
|
||
@Override | ||
public String getAnnotationType() { | ||
return ANNOTATION_TYPE; | ||
} | ||
|
||
@Override | ||
public String getShortDescription() { | ||
return shortDescription; | ||
} | ||
|
||
} | ||
/* | ||
* sonarlint4netbeans: SonarLint integration for Apache Netbeans | ||
* Copyright (C) 2019 Philippe FICHET. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301 USA | ||
*/ | ||
package fr.philippefichet.sonarlint.netbeans; | ||
|
||
import org.openide.text.Annotation; | ||
|
||
/** | ||
* | ||
* @author FICHET Philippe | ||
*/ | ||
public class SonarLintAnnotation extends Annotation { | ||
|
||
public static final String ANNOTATION_TYPE = "fr-philippefichet-sonarlint-netbeans-annotation"; | ||
private final long startOffest; | ||
private final int length; | ||
private final String shortDescription; | ||
private final String ruleKey; | ||
private final String ruleName; | ||
|
||
public SonarLintAnnotation(String ruleKey, String ruleName, long startOffest, int length) { | ||
super(); | ||
this.startOffest = startOffest; | ||
this.length = length; | ||
this.shortDescription = ruleKey + "\n" + ruleName + "\nClick to show details"; | ||
this.ruleKey = ruleKey; | ||
this.ruleName = ruleName; | ||
} | ||
|
||
public long getStartOffest() { | ||
return startOffest; | ||
} | ||
|
||
public int getLength() { | ||
return length; | ||
} | ||
|
||
@Override | ||
public String getAnnotationType() { | ||
return ANNOTATION_TYPE; | ||
} | ||
|
||
@Override | ||
public String getShortDescription() { | ||
return shortDescription; | ||
} | ||
|
||
public String getRuleKey() { | ||
return ruleKey; | ||
} | ||
|
||
public String getRuleName() { | ||
return ruleName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/fr/philippefichet/sonarlint/netbeans/SonarLintGlyphAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (C) 2020 Philippe FICHET. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301 USA | ||
*/ | ||
package fr.philippefichet.sonarlint.netbeans; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.util.Optional; | ||
import java.util.logging.Logger; | ||
import javax.swing.AbstractAction; | ||
import static javax.swing.Action.NAME; | ||
import javax.swing.JEditorPane; | ||
import javax.swing.text.BadLocationException; | ||
import javax.swing.text.Document; | ||
import org.netbeans.api.editor.document.LineDocumentUtils; | ||
import org.netbeans.editor.AnnotationDesc; | ||
import org.netbeans.editor.Annotations; | ||
import org.netbeans.editor.BaseDocument; | ||
import org.openide.ErrorManager; | ||
import org.openide.loaders.DataObject; | ||
import org.openide.util.NbBundle; | ||
import org.openide.windows.TopComponent; | ||
import org.openide.windows.WindowManager; | ||
|
||
/** | ||
* | ||
* @author FICHET Philippe <philippe.fichet@laposte.net> | ||
*/ | ||
public class SonarLintGlyphAction extends AbstractAction | ||
{ | ||
private static final Logger LOG = Logger.getLogger(SonarLintGlyphAction.class.getCanonicalName()); | ||
|
||
public SonarLintGlyphAction() { | ||
LOG.severe("SonarLintGlyphAction"); | ||
putValue(NAME, | ||
NbBundle.getMessage( | ||
SonarLintGlyphAction.class, | ||
"SonarLintGlyphAction.TXT_GlyphActionName" // NOI18N | ||
) | ||
); | ||
putValue("supported-annotation-types", new String[] { | ||
SonarLintAnnotation.ANNOTATION_TYPE | ||
}); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
JEditorPane editorPane = (JEditorPane)e.getSource(); | ||
final Document doc = editorPane.getDocument(); | ||
if (doc instanceof BaseDocument) { | ||
final int currentPosition = editorPane.getCaretPosition(); | ||
final Annotations annotations = ((BaseDocument) doc).getAnnotations(); | ||
final DataObject od = (DataObject) doc.getProperty(Document.StreamDescriptionProperty); | ||
if (od == null) { | ||
return; | ||
} | ||
|
||
doc.render(() -> { | ||
try { | ||
int line = LineDocumentUtils.getLineIndex((BaseDocument)doc, currentPosition); | ||
AnnotationDesc desc = annotations.getActiveAnnotation(line); | ||
Optional<SonarLintAnnotation> sonarLintAnnotation = SonarLintAnnotationHandler.getSonarLintAnnotation( | ||
od.getPrimaryFile(), | ||
desc.getOffset(), | ||
desc.getLength(), | ||
desc.getShortDescription() | ||
); | ||
sonarLintAnnotation.ifPresent(sla -> { | ||
TopComponent topComponent = WindowManager.getDefault().findTopComponent("SonarRuleDetailsTopComponent"); | ||
if (topComponent instanceof SonarRuleDetailsTopComponent) { | ||
SonarRuleDetailsTopComponent sonarRuleDetailsTopComponent = (SonarRuleDetailsTopComponent)topComponent; | ||
sonarRuleDetailsTopComponent.open(); | ||
sonarRuleDetailsTopComponent.requestActive(); | ||
sonarRuleDetailsTopComponent.requestFocusInWindow(); | ||
sonarRuleDetailsTopComponent.setSonarRuleKeyFilter(sla.getRuleKey()); | ||
} | ||
}); | ||
} catch (BadLocationException ex) { | ||
ErrorManager.getDefault().notify(ex); | ||
} | ||
}); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.