-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #941 from guwirth/refactor/cpd
replace deprecated cpd mapping
- Loading branch information
Showing
13 changed files
with
292 additions
and
187 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
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
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
50 changes: 0 additions & 50 deletions
50
sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxCpdMapping.java
This file was deleted.
Oops, something went wrong.
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
61 changes: 0 additions & 61 deletions
61
sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxTokenizer.java
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cpd/CxxCpdVisitor.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,83 @@ | ||
/* | ||
* Sonar C++ Plugin (Community) | ||
* Copyright (C) 2010-2016 SonarOpenCommunity | ||
* http://github.com/SonarOpenCommunity/sonar-cxx | ||
* | ||
* This program 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 3 of the License, or (at your option) any later version. | ||
* | ||
* This program 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 program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.plugins.cxx.cpd; | ||
|
||
import java.io.File; | ||
import javax.annotation.Nullable; | ||
|
||
import com.sonar.sslr.api.AstAndTokenVisitor; | ||
import com.sonar.sslr.api.AstNode; | ||
import com.sonar.sslr.api.GenericTokenType; | ||
import com.sonar.sslr.api.Grammar; | ||
import com.sonar.sslr.api.Token; | ||
import org.sonar.squidbridge.SquidAstVisitor; | ||
|
||
import org.sonar.api.batch.fs.InputFile; | ||
import org.sonar.api.batch.fs.TextRange; | ||
import org.sonar.api.batch.sensor.SensorContext; | ||
import org.sonar.api.batch.sensor.cpd.NewCpdTokens; | ||
import org.sonar.cxx.api.CxxTokenType; | ||
|
||
public class CxxCpdVisitor extends SquidAstVisitor<Grammar> implements AstAndTokenVisitor { | ||
|
||
private final SensorContext sensorContext; | ||
private InputFile inputFile; | ||
private NewCpdTokens cpdTokens; | ||
|
||
public CxxCpdVisitor(SensorContext sensorContext) { | ||
this.sensorContext = sensorContext; | ||
} | ||
|
||
@Override | ||
public void visitFile(@Nullable AstNode astNode) { | ||
File file = getContext().getFile(); | ||
inputFile = sensorContext.fileSystem().inputFile(sensorContext.fileSystem().predicates().is(file)); | ||
cpdTokens = sensorContext.newCpdTokens().onFile(inputFile); | ||
} | ||
|
||
@Override | ||
public void leaveFile(@Nullable AstNode astNode) { | ||
cpdTokens.save(); | ||
} | ||
|
||
@Override | ||
public void visitToken(Token token) { | ||
if (!token.isGeneratedCode()) { | ||
String text; | ||
if (token.getType().equals(CxxTokenType.NUMBER)) { | ||
text = "_N"; | ||
} else if (token.getType().equals(CxxTokenType.STRING)) { | ||
text = "_S"; | ||
} else if (token.getType().equals(CxxTokenType.CHARACTER)) { | ||
text = "_C"; | ||
} else if (token.getType().equals(GenericTokenType.IDENTIFIER)) { | ||
text = "_I"; | ||
} else if (token.getType().equals(GenericTokenType.EOF)) { | ||
return; | ||
} else { | ||
text = token.getValue(); | ||
} | ||
|
||
TextRange range = inputFile.newRange(token.getLine(), token.getColumn(), token.getLine(), token.getColumn() + token.getValue().length()); | ||
cpdTokens.addToken(range, text); | ||
} | ||
} | ||
|
||
} |
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
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
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
48 changes: 0 additions & 48 deletions
48
sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/CxxTokenizerTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.