Skip to content

Commit

Permalink
dsldevkit#22: SCA configuration
Browse files Browse the repository at this point in the history
 - Phase 1 of "Fix potential PMD violations"

Issue: dsldevkit#22
  • Loading branch information
[email protected] authored and [email protected] committed Dec 20, 2017
1 parent 755fecd commit 49676a8
Show file tree
Hide file tree
Showing 67 changed files with 142 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Class<? extends ILocationInFileProvider> bindILocationInFileProvider() {

@Override
public void configureIScopeProviderDelegate(final com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(XImportSectionNamespaceScopeProvider.class);
binder.bind(IScopeProvider.class).annotatedWith(Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(XImportSectionNamespaceScopeProvider.class);
}

/** @return a strategy for selecting the objects to export in Index */
Expand Down Expand Up @@ -121,7 +121,7 @@ public Class<? extends XExpressionHelper> bindXExpressionHelper() {

@Override
public void configureLinkingIScopeProvider(final com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(org.eclipse.xtext.linking.LinkingScopeProviderBinding.class).to(CheckScopeProvider.class);
binder.bind(IScopeProvider.class).annotatedWith(org.eclipse.xtext.linking.LinkingScopeProviderBinding.class).to(CheckScopeProvider.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public final class CheckGenModelUtil {

private static final String GENMODEL_EXTENSION = "genmodel";
private static final String GENMODEL_EXTENSION = "genmodel"; //$NON-NLS-1$
/** Class-wide logger. */
private static final Logger LOGGER = Logger.getLogger(CheckGenModelUtil.class);

Expand All @@ -57,7 +57,7 @@ private CheckGenModelUtil() {

/**
* Returns the qualified package interface name for the given epackage (model).
*
*
* @param ePackage
* the model
* @return the package interface name
Expand All @@ -81,7 +81,7 @@ public static String getQualifiedPackageInterfaceName(final EPackage ePackage) {

/**
* Returns the genmodel for the given model element.
*
*
* @param eModelElement
* the model element
* @return the genmodel
Expand All @@ -93,7 +93,7 @@ public static GenModel findGenModel(final EModelElement eModelElement) {
/**
* Finds the GenPackage for a given EModelElement and ResourceSet. If the EPackage of given model element
* is the EcorePackage.eINSTANCE, <code>null</code> is returned.
*
*
* @param eModelElement
* the e model element
* @param resourceSet
Expand Down Expand Up @@ -121,15 +121,15 @@ public static GenModel findGenModel(final EModelElement eModelElement, final Res
try {
resultGenModel = getGenModelUsingHeuristics(ePackage);
} catch (final IllegalStateException e) {
LOGGER.error(NLS.bind("Exception in findGenModel ({0})", eModelElement), e);
LOGGER.error(NLS.bind("Exception in findGenModel ({0})", eModelElement), e); //$NON-NLS-1$
}

return resultGenModel;
}

/**
* Returns the genpackage for the given epackage.
*
*
* @param ePackage
* the model
* @return the genpackage
Expand All @@ -142,7 +142,7 @@ public static GenPackage findGenPackage(final EPackage ePackage) {

/**
* Loads the given resource, and if it contains a GenModel for the given ePackage, resturns that.
*
*
* @param uri
* to load resource from
* @param ePackage
Expand All @@ -168,7 +168,7 @@ private static GenModel loadGenModel(final URI uri, final EPackage ePackage, fin

/**
* Returns the genmodel for the given EPackage.
*
*
* @param ePackage
* the model element
* @return the genmodel
Expand All @@ -183,7 +183,7 @@ private static GenModel getGenModelUsingHeuristics(final EPackage ePackage) {

final URIConverter uriConverter = resourceSet.getURIConverter();
URI uri = uriConverter.normalize(res.getURI());
final URI originalURI = uri;
final URI originalURI = uri; // NOPMD - We want the value before reassignment
URI baseURI = uri.trimFileExtension();
uri = baseURI.appendFileExtension(GENMODEL_EXTENSION);
uri = uriConverter.normalize(uri);
Expand All @@ -208,14 +208,14 @@ private static GenModel getGenModelUsingHeuristics(final EPackage ePackage) {
}
}
if (result == null) {
throw new IllegalStateException("No genmodel found for " + originalURI);
throw new IllegalStateException("No genmodel found for " + originalURI); //$NON-NLS-1$
}
return result;
}

/**
* Given a base URI, figure out which {@link IFolder}, if any, it refers to.
*
*
* @param baseURI
* to find the folder(s) for; must not be {@code null}
* @return an array of all folders mapping to that URI, or an empty array if none do.
Expand Down Expand Up @@ -244,7 +244,7 @@ private static IContainer[] determineContainersToCheck(final URI baseURI) {
/**
* Given an array of {@link IContainers}, searches through all *.genmodel files in all {@link IFolders}, ignoring nested folders, trying to find a
* {@link GenModel} for the given {@link EPackage}.
*
*
* @param containers
* To search, may be empty, but must not be {@code null}
* @param baseURI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ private CheckUtil() {
/**
* Converts a string into an identifier by removing all characters that are not
* allowed.
*
*
* @param source
* any string
* @return a string stripped from illegal characters
*/
public static String toIdentifier(final String source) {
StringBuilder result = new StringBuilder();
if (source == null) {
return null;
} else if (source.length() == 0 || !Character.isJavaIdentifierStart(source.charAt(0))) {
return "";
return ""; //$NON-NLS-1$
}
result.append(source.charAt(0));

StringBuilder result = new StringBuilder(source.charAt(0));
boolean space = false;
for (Character c : source.substring(1).toCharArray()) {
if (Character.isJavaIdentifierPart(c)) {
Expand All @@ -51,11 +49,10 @@ public static String toIdentifier(final String source) {

/**
* Gets the service registry class name used to create a text file in META-INF/services.
*
*
* @return the service registry class name
*/
public static String serviceRegistryClassName() {
return ICheckValidatorStandaloneSetup.class.getName();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
@ComposedChecks(validators = {ClasspathBasedChecks.class, FormalParameterChecks.class, ApiAccessChecks.class})
public class CheckJavaValidator extends AbstractCheckJavaValidator {

private static final String CHECK = "Check";
private static final String CHECK = "Check"; //$NON-NLS-1$

@Inject
private CheckGeneratorExtensions generatorExtensions;
Expand Down Expand Up @@ -123,11 +123,11 @@ public void checkFormalParameterTypeConformance(final FormalParameter parameter)
private static final Set<String> BASE_TYPE_NAMES = ImmutableSet.of("java.lang.String", "java.lang.Integer", "java.lang.Boolean"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static final Set<String> ALLOWED_TYPE_NAMES = ImmutableSet.<String> builder() //
.addAll(BASE_TYPE_NAMES) //
.add("boolean", "int") //
.add("boolean", "int") // //$NON-NLS-1$ //$NON-NLS-2$
.addAll(Iterables.transform(BASE_TYPE_NAMES, new Function<String, String>() {
@Override
public String apply(final String base) {
return "java.util.List<" + base + '>';
return "java.util.List<" + base + '>'; //$NON-NLS-1$
}
})) //
.build();
Expand Down Expand Up @@ -500,12 +500,12 @@ public void checkIssuedBindings(final XIssueExpression expression) {
if (generatorExtensions.issuedCheck(expression) == null) {
return;
}
int boundParameters = expression.getMessageParameters().size();
String message = generatorExtensions.issuedCheck(expression).getMessage();
if (Strings.isEmpty(message)) {
return;
}
try {
int boundParameters = expression.getMessageParameters().size();
int requiredBindings = new MessageFormat(message).getFormatsByArgumentIndex().length;

if (boundParameters != requiredBindings) {
Expand Down Expand Up @@ -742,7 +742,7 @@ public void checkDefaultSeverityInRange(final com.avaloq.tools.ddk.check.check.C
SeverityKind temp = minSeverity;
while (temp != null && temp.compareTo(maxSeverity) <= 0) {
issueCodes.add(temp.getName());
temp = com.avaloq.tools.ddk.check.check.SeverityKind.get(temp.getValue() + 1);
temp = SeverityKind.get(temp.getValue() + 1);
}

String[] codes = issueCodes.toArray(new String[issueCodes.size()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;

import com.avaloq.tools.ddk.check.lib.IIndex;
import com.avaloq.tools.ddk.xtext.scoping.ContainerQuery;
import com.avaloq.tools.ddk.xtext.scoping.IDomain;
import com.avaloq.tools.ddk.check.lib.IIndex;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
Expand All @@ -46,6 +46,7 @@ protected Index() {
}

/** {@inheritDoc} */
@Override
public IIndex.Query newQuery(final EClass type, final String namePattern) {
if (type == null || namePattern == null || namePattern.length() == 0) {
throw new IllegalArgumentException(Messages.Index_NullArgumentInQuery);
Expand All @@ -54,6 +55,7 @@ public IIndex.Query newQuery(final EClass type, final String namePattern) {
}

/** {@inheritDoc} */
@Override
public IIndex.Query newQuery(final EClass type, final QualifiedName namePattern) {
if (type == null || namePattern == null || namePattern.isEmpty()) {
throw new IllegalArgumentException(Messages.Index_NullArgumentInQuery);
Expand All @@ -71,7 +73,7 @@ private static final class Query implements IIndex.Query {

/**
* Creates a new query for a type, using a given domain mapper and name converter.
*
*
* @param mapper
* to use
* @param nameConverter
Expand All @@ -90,29 +92,30 @@ protected Query(final IDomain.Mapper mapper, final IQualifiedNameConverter nameC
* <p>
* <em>Note:</em> throws {@link IllegalArgumentException} if the name pattern has a wildcard, but not at the end.
* </p>
*
*
* @param namePattern
* to look for, may end in a wildcard "*".
* @return the query.
*/
protected Query withName(final String namePattern) {
private Query withName(final String namePattern) {
realQuery.name(namePattern);
return this;
}

/**
* Restricts the query to match only index entries with a given name pattern.
*
*
* @param namePattern
* to look for.
* @return the query.
*/
protected Query withName(final QualifiedName namePattern) {
private Query withName(final QualifiedName namePattern) {
realQuery.name(namePattern);
return this;
}

/** {@inheritDoc} */
@Override
public Query withData(final String key, final String value) {
if (key == null || value == null) {
throw new IllegalArgumentException(Messages.Index_NullQueryData);
Expand All @@ -122,11 +125,13 @@ public Query withData(final String key, final String value) {
}

/** {@inheritDoc} */
@Override
public Iterable<IIndex.Entry> run(final EObject context) {
if (context == null) {
throw new IllegalArgumentException(Messages.Index_NullQueryContext);
}
return Iterables.transform(realQuery.execute(context), new Function<IEObjectDescription, IIndex.Entry>() {
@Override
public IIndex.Entry apply(final IEObjectDescription desc) {
return new Entry(context, nameConverter, desc);
}
Expand All @@ -146,7 +151,7 @@ private static final class Entry implements IIndex.Entry {
/**
* Creates a new wrapper for an IEObjectDescription, using the given name converter and query context object. The context object is used to resolve the
* EObject, if needed.
*
*
* @param context
* of the query that produced this result
* @param nameConverter
Expand All @@ -161,21 +166,25 @@ protected Entry(final EObject context, final IQualifiedNameConverter nameConvert
}

/** {@inheritDoc} */
@Override
public String getName() {
return nameConverter.toString(getQualifiedName());
}

/** {@inheritDoc} */
@Override
public QualifiedName getQualifiedName() {
return delegate.getQualifiedName();
}

/** {@inheritDoc} */
@Override
public EClass getType() {
return delegate.getEClass();
}

/** {@inheritDoc} */
@Override
public EObject getModelObject() {
EObject result = delegate.getEObjectOrProxy();
if (result != null && result.eIsProxy()) {
Expand All @@ -185,6 +194,7 @@ public EObject getModelObject() {
}

/** {@inheritDoc} */
@Override
public String[] getDataKeys() {
String[] result = delegate.getUserDataKeys();
if (result == null) {
Expand All @@ -194,6 +204,7 @@ public String[] getDataKeys() {
}

/** {@inheritDoc} */
@Override
public String getData(final String key) {
if (key == null) {
throw new IllegalArgumentException(Messages.Index_NullKeyInEntry);
Expand All @@ -202,6 +213,7 @@ public String getData(final String key) {
}

/** {@inheritDoc} */
@Override
public String getSourceName() {
final URI uri = delegate.getEObjectURI().trimFragment();
final String name = uri.lastSegment();
Expand All @@ -215,4 +227,3 @@ public String getSourceName() {

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public abstract class AbstractModelLocation implements IModelLocation {

private static final Logger LOG = org.apache.log4j.Logger.getLogger(AbstractModelLocation.class);
private static final Logger LOG = Logger.getLogger(AbstractModelLocation.class);

private final URL catalogUrl;

Expand All @@ -37,6 +37,7 @@ public AbstractModelLocation(final URL catalogUrl) {
}

/** {@inheritDoc} */
@Override
public InputStream getCatalogStream() {
InputStream stream = null;
try {
Expand All @@ -48,16 +49,19 @@ public InputStream getCatalogStream() {
}

/** {@inheritDoc} */
@Override
public String getCatalogPath() {
return catalogUrl.getPath();
}

/** {@inheritDoc} */
@Override
public URL getCatalogUrl() {
return catalogUrl;
}

/** {@inheritDoc} */
@Override
public URI getCatalogUri() {
try {
return catalogUrl.toURI();
Expand All @@ -67,4 +71,3 @@ public URI getCatalogUri() {
}

}

Loading

0 comments on commit 49676a8

Please sign in to comment.