Search in sources :

Example 6 with Mark

use of net.sourceforge.pmd.cpd.Mark in project maven-plugins by apache.

the class CpdReportTest method testWriteNonHtml.

public void testWriteNonHtml() throws Exception {
    File testPom = new File(getBasedir(), "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml");
    CpdReport mojo = (CpdReport) lookupMojo("cpd", testPom);
    assertNotNull(mojo);
    TokenEntry tFirstEntry = new TokenEntry("public java", "MyClass.java", 2);
    TokenEntry tSecondEntry = new TokenEntry("public java", "MyClass3.java", 2);
    String duplicatedCodeFragment = "// ----- duplicated code example -----";
    SourceCode sourceCodeFirst = new SourceCode(new SourceCode.StringCodeLoader(PMD.EOL + duplicatedCodeFragment + PMD.EOL, "MyClass.java"));
    SourceCode sourceCodeSecond = new SourceCode(new SourceCode.StringCodeLoader(PMD.EOL + duplicatedCodeFragment + PMD.EOL, "MyClass3.java"));
    List<Match> tList = new ArrayList<>();
    Mark tFirstMark = new Mark(tFirstEntry);
    tFirstMark.setSourceCode(sourceCodeFirst);
    tFirstMark.setLineCount(1);
    Mark tSecondMark = new Mark(tSecondEntry);
    tSecondMark.setSourceCode(sourceCodeSecond);
    tSecondMark.setLineCount(1);
    Match tMatch = new Match(2, tFirstMark, tSecondMark);
    tList.add(tMatch);
    CPDConfiguration cpdConfiguration = new CPDConfiguration();
    cpdConfiguration.setMinimumTileSize(100);
    cpdConfiguration.setLanguage(new JavaLanguage());
    cpdConfiguration.setEncoding("UTF-8");
    CPD tCpd = new MockCpd(cpdConfiguration, tList.iterator());
    tCpd.go();
    mojo.writeNonHtml(tCpd);
    File tReport = new File("target/test/unit/default-configuration/target/cpd.xml");
    // parseDocument( new BufferedInputStream( new FileInputStream( report ) ) );
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document pmdCpdDocument = builder.parse(tReport);
    assertNotNull(pmdCpdDocument);
    String str = readFile(new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml"));
    assertTrue(lowerCaseContains(str, "MyClass.java"));
    assertTrue(lowerCaseContains(str, "MyClass3.java"));
    assertTrue(lowerCaseContains(str, duplicatedCodeFragment));
}
Also used : SourceCode(net.sourceforge.pmd.cpd.SourceCode) CPDConfiguration(net.sourceforge.pmd.cpd.CPDConfiguration) ArrayList(java.util.ArrayList) Mark(net.sourceforge.pmd.cpd.Mark) JavaLanguage(net.sourceforge.pmd.cpd.JavaLanguage) Document(org.w3c.dom.Document) Match(net.sourceforge.pmd.cpd.Match) TokenEntry(net.sourceforge.pmd.cpd.TokenEntry) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CPD(net.sourceforge.pmd.cpd.CPD) File(java.io.File)

Example 7 with Mark

use of net.sourceforge.pmd.cpd.Mark in project pmd-eclipse-plugin by pmd.

the class CPDViewTooltipListener2 method handleEvent.

/*
     * @see
     * org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
     * Event)
     */
public void handleEvent(Event event) {
    Tree tree = view.getTreeViewer().getTree();
    Point location = new Point(event.x, event.y);
    Shell shell = tree.getShell();
    if (view.inColumn(location) != CPDView2.SOURCE_COLUMN_IDX) {
        shell.setCursor(normalCursor);
        return;
    }
    TreeItem item = tree.getItem(location);
    Mark entry = itemAt(item, location, event.gc);
    if (entry == null) {
        shell.setCursor(normalCursor);
        return;
    }
    switch(event.type) {
        case SWT.MouseDown:
            highlight(matchAt(item), entry);
            break;
        case SWT.MouseMove:
        case SWT.MouseHover:
            shell.setCursor(handCursor);
            break;
        default:
            break;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TreeItem(org.eclipse.swt.widgets.TreeItem) Tree(org.eclipse.swt.widgets.Tree) Mark(net.sourceforge.pmd.cpd.Mark) Point(org.eclipse.swt.graphics.Point)

Example 8 with Mark

use of net.sourceforge.pmd.cpd.Mark in project pmd-eclipse-plugin by pmd.

the class CPDView method setData.

/**
 * Sets input for the table.
 * @param matches CPD Command that contain the matches from the CPD
 */
public void setData(Iterator<Match> matches) {
    List<TreeNode> elements = new ArrayList<TreeNode>();
    if (matches != null) {
        // iterate the matches
        for (int count = 0; matches.hasNext() && count < MAX_MATCHES; count++) {
            Match match = matches.next();
            // create a treenode for the match and add to the list
            // NOPMD by Sven on 02.11.06 11:27
            TreeNode matchNode = new TreeNode(match);
            elements.add(matchNode);
            // create the children of the match
            // NOPMD by Sven on 02.11.06 11:28
            TreeNode[] children = new TreeNode[match.getMarkCount()];
            Iterator<Mark> entryIterator = match.getMarkSet().iterator();
            for (int j = 0; entryIterator.hasNext(); j++) {
                final Mark entry = entryIterator.next();
                // NOPMD by Sven on 02.11.06 11:28
                children[j] = new TreeNode(entry);
                children[j].setParent(matchNode);
            }
            matchNode.setChildren(children);
        }
    }
    // set the children of the rootnode: the matches
    treeViewer.setInput(elements.toArray(new TreeNode[elements.size()]));
}
Also used : TreeNode(org.eclipse.jface.viewers.TreeNode) ArrayList(java.util.ArrayList) Mark(net.sourceforge.pmd.cpd.Mark) Match(net.sourceforge.pmd.cpd.Match)

Aggregations

Mark (net.sourceforge.pmd.cpd.Mark)8 Match (net.sourceforge.pmd.cpd.Match)5 TokenEntry (net.sourceforge.pmd.cpd.TokenEntry)4 ArrayList (java.util.ArrayList)3 File (java.io.File)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 CPD (net.sourceforge.pmd.cpd.CPD)2 CPDConfiguration (net.sourceforge.pmd.cpd.CPDConfiguration)2 JavaLanguage (net.sourceforge.pmd.cpd.JavaLanguage)2 SourceCode (net.sourceforge.pmd.cpd.SourceCode)2 Document (org.w3c.dom.Document)2 HashMap (java.util.HashMap)1 TreeNode (org.eclipse.jface.viewers.TreeNode)1 Point (org.eclipse.swt.graphics.Point)1 Shell (org.eclipse.swt.widgets.Shell)1 Tree (org.eclipse.swt.widgets.Tree)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1