Skip to content

Commit

Permalink
commit reworked ScalaTokenizerTest and test files
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneszink committed Nov 10, 2014
1 parent 40276b0 commit 7645715
Show file tree
Hide file tree
Showing 60 changed files with 3,189 additions and 3,229 deletions.
136 changes: 68 additions & 68 deletions src/main/java/org/sonar/plugins/scala/ScalaPlugin.java
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
/*
* Sonar Scala Plugin
* Copyright (C) 2011 - 2014 All contributors
* [email protected]
*
* 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 02
*/
package org.sonar.plugins.scala;

import java.util.ArrayList;
import java.util.List;

import org.sonar.api.Extension;
import org.sonar.api.SonarPlugin;
import org.sonar.plugins.scala.colorization.ScalaColorizerFormat;
import org.sonar.plugins.scala.language.Scala;
import org.sonar.plugins.scala.sensor.BaseMetricsSensor;
import org.sonar.plugins.scala.surefire.SurefireSensor;

/**
* This class is the entry point for all extensions made by the
* Sonar Scala Plugin.
*
* @author Felix Müller
* @since 0.1
*/
public class ScalaPlugin extends SonarPlugin {

public List<Class<? extends Extension>> getExtensions() {
final List<Class<? extends Extension>> extensions = new ArrayList<Class<? extends Extension>>();
extensions.add(Scala.class);
extensions.add(ScalaColorizerFormat.class);
extensions.add(BaseMetricsSensor.class);
extensions.add(SurefireSensor.class);

return extensions;
}

@Override
public String toString() {
return getClass().getSimpleName();
}

public static String getPathToScalaLibrary() {
return getPathByResource("scala/package.class");
}

/**
* Godin: during execution of Sonar Batch all dependencies of a plugin are downloaded and
* available locally as JAR-files, so we can use this kind of hack to locate JARs.
*/
private static String getPathByResource(String name) {
String path = ScalaPlugin.class.getClassLoader().getResource(name).getPath();
return path.substring("file:".length(), path.lastIndexOf('!'));
}
}
/*
* Sonar Scala Plugin
* Copyright (C) 2011 - 2014 All contributors
* [email protected]
*
* 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 02
*/
package org.sonar.plugins.scala;

import java.util.ArrayList;
import java.util.List;

import org.sonar.api.Extension;
import org.sonar.api.SonarPlugin;
import org.sonar.plugins.scala.colorization.ScalaColorizerFormat;
import org.sonar.plugins.scala.language.Scala;
import org.sonar.plugins.scala.sensor.BaseMetricsSensor;
import org.sonar.plugins.scala.surefire.SurefireSensor;

/**
* This class is the entry point for all extensions made by the
* Sonar Scala Plugin.
*
* @author Felix Müller
* @since 0.1
*/
public class ScalaPlugin extends SonarPlugin {

public List<Class<? extends Extension>> getExtensions() {
final List<Class<? extends Extension>> extensions = new ArrayList<Class<? extends Extension>>();
extensions.add(Scala.class);
extensions.add(ScalaColorizerFormat.class);
extensions.add(BaseMetricsSensor.class);
extensions.add(SurefireSensor.class);

return extensions;
}

@Override
public String toString() {
return getClass().getSimpleName();
}

public static String getPathToScalaLibrary() {
return getPathByResource("scala/package.class");
}

/**
* Godin: during execution of Sonar Batch all dependencies of a plugin are downloaded and
* available locally as JAR-files, so we can use this kind of hack to locate JARs.
*/
private static String getPathByResource(String name) {
String path = ScalaPlugin.class.getClassLoader().getResource(name).getPath();
return path.substring("file:".length(), path.lastIndexOf('!'));
}
}
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
/*
* Sonar Scala Plugin
* Copyright (C) 2011 - 2014 All contributors
* [email protected]
*
* 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 02
*/
package org.sonar.plugins.scala.colorization;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.sonar.api.web.CodeColorizerFormat;
import org.sonar.colorizer.CDocTokenizer;
import org.sonar.colorizer.CppDocTokenizer;
import org.sonar.colorizer.JavaAnnotationTokenizer;
import org.sonar.colorizer.JavadocTokenizer;
import org.sonar.colorizer.KeywordsTokenizer;
import org.sonar.colorizer.LiteralTokenizer;
import org.sonar.colorizer.Tokenizer;
import org.sonar.plugins.scala.language.Scala;

/**
* This class extends Sonar for code colorization of Scala source.
*
* @author Felix Müller
* @since 0.1
*/
public class ScalaColorizerFormat extends CodeColorizerFormat {

private static final String END_SPAN_TAG = "</span>";

private static final List<Tokenizer> TOKENIZERS = Arrays.asList(
new LiteralTokenizer("<span class=\"s\">", END_SPAN_TAG),
new KeywordsTokenizer("<span class=\"k\">", END_SPAN_TAG, ScalaKeywords.getAllKeywords()),
new CDocTokenizer("<span class=\"cd\">", END_SPAN_TAG),
new CppDocTokenizer("<span class=\"cppd\">", END_SPAN_TAG),
new JavadocTokenizer("<span class=\"j\">", END_SPAN_TAG),
new JavaAnnotationTokenizer("<span class=\"a\">", END_SPAN_TAG));

public ScalaColorizerFormat() {
super(Scala.KEY);
}

@Override
public List<Tokenizer> getTokenizers() {
return Collections.unmodifiableList(TOKENIZERS);
}
/*
* Sonar Scala Plugin
* Copyright (C) 2011 - 2014 All contributors
* [email protected]
*
* 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 02
*/
package org.sonar.plugins.scala.colorization;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.sonar.api.web.CodeColorizerFormat;
import org.sonar.colorizer.CDocTokenizer;
import org.sonar.colorizer.CppDocTokenizer;
import org.sonar.colorizer.JavaAnnotationTokenizer;
import org.sonar.colorizer.JavadocTokenizer;
import org.sonar.colorizer.KeywordsTokenizer;
import org.sonar.colorizer.LiteralTokenizer;
import org.sonar.colorizer.Tokenizer;
import org.sonar.plugins.scala.language.Scala;

/**
* This class extends Sonar for code colorization of Scala source.
*
* @author Felix Müller
* @since 0.1
*/
public class ScalaColorizerFormat extends CodeColorizerFormat {

private static final String END_SPAN_TAG = "</span>";

private static final List<Tokenizer> TOKENIZERS = Arrays.asList(
new LiteralTokenizer("<span class=\"s\">", END_SPAN_TAG),
new KeywordsTokenizer("<span class=\"k\">", END_SPAN_TAG, ScalaKeywords.getAllKeywords()),
new CDocTokenizer("<span class=\"cd\">", END_SPAN_TAG),
new CppDocTokenizer("<span class=\"cppd\">", END_SPAN_TAG),
new JavadocTokenizer("<span class=\"j\">", END_SPAN_TAG),
new JavaAnnotationTokenizer("<span class=\"a\">", END_SPAN_TAG));

public ScalaColorizerFormat() {
super(Scala.KEY);
}

@Override
public List<Tokenizer> getTokenizers() {
return Collections.unmodifiableList(TOKENIZERS);
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/*
* Sonar Scala Plugin
* Copyright (C) 2011 - 2014 All contributors
* [email protected]
*
* 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 02
*/
package org.sonar.plugins.scala.colorization;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
* This is a helper class for collecting every Scala keyword.
*
* @author Felix Müller
* @since 0.1
*/
public final class ScalaKeywords {

private static final Set<String> KEYWORDS = new HashSet<String>(Arrays.asList(
"abstract", "assert", "case", "catch", "class", "def", "do", "else", "extends", "false",
"final", "finally", "for", "forSome", "if", "implicit", "import", "lazy", "match", "new",
"null", "object", "override", "package", "private", "protected", "requires", "return",
"sealed", "super", "this", "throw", "trait", "true", "try", "type", "val", "var", "while",
"with", "yield", "_", ":", "=", "=>", "<-", "<:", "<%", ">:", "#", "@"
));

private ScalaKeywords() {
// to prevent instantiation
}

public static Set<String> getAllKeywords() {
return Collections.unmodifiableSet(KEYWORDS);
}
/*
* Sonar Scala Plugin
* Copyright (C) 2011 - 2014 All contributors
* [email protected]
*
* 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 02
*/
package org.sonar.plugins.scala.colorization;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
* This is a helper class for collecting every Scala keyword.
*
* @author Felix Müller
* @since 0.1
*/
public final class ScalaKeywords {

private static final Set<String> KEYWORDS = new HashSet<String>(Arrays.asList(
"abstract", "assert", "case", "catch", "class", "def", "do", "else", "extends", "false",
"final", "finally", "for", "forSome", "if", "implicit", "import", "lazy", "match", "new",
"null", "object", "override", "package", "private", "protected", "requires", "return",
"sealed", "super", "this", "throw", "trait", "true", "try", "type", "val", "var", "while",
"with", "yield", "_", ":", "=", "=>", "<-", "<:", "<%", ">:", "#", "@"
));

private ScalaKeywords() {
// to prevent instantiation
}

public static Set<String> getAllKeywords() {
return Collections.unmodifiableSet(KEYWORDS);
}
}
Loading

0 comments on commit 7645715

Please sign in to comment.