Skip to content

Commit

Permalink
Lint: minor structural refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Kriegisch <[email protected]>
  • Loading branch information
kriegaex committed Apr 12, 2024
1 parent cb13d8b commit b5ff094
Showing 1 changed file with 36 additions and 56 deletions.
92 changes: 36 additions & 56 deletions org.aspectj.matcher/src/main/java/org/aspectj/weaver/Lint.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
package org.aspectj.weaver;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -138,70 +138,55 @@ public class Lint {
public final Kind missingAspectForReweaving = new Kind("missingAspectForReweaving",
"aspect {0} cannot be found when reweaving {1}");

private static Trace trace = TraceFactory.getTraceFactory().getTrace(Lint.class);
private static final Trace trace = TraceFactory.getTraceFactory().getTrace(Lint.class);

public Lint(World world) {
if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.enter("<init>", this, world);
}
this.world = world;
if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.exit("<init>");
}
}

public void setAll(String messageKind) {
if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.enter("setAll", this, messageKind);
}
setAll(getMessageKind(messageKind));
if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.exit("setAll");
}
}

private void setAll(IMessage.Kind messageKind) {
for (Kind kind : kinds.values()) {
for (Kind kind : kinds.values())
kind.setKind(messageKind);
}
}

public void setFromMap(Map<String,String> lintOptionsMap) {
for (String key: lintOptionsMap.keySet()) {
String value = lintOptionsMap.get(key);
Kind kind = kinds.get(key);
if (kind == null) {
if (kind == null)
MessageUtil.error(world.getMessageHandler(), WeaverMessages.format(WeaverMessages.XLINT_KEY_ERROR, key));
} else {
else
kind.setKind(getMessageKind(value));
}
}
}

public void setFromProperties(File file) {
if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.enter("setFromProperties", this, file);
}
InputStream s = null;
try {
s = new FileInputStream(file);
try (InputStream s = Files.newInputStream(file.toPath())) {
setFromProperties(s);
} catch (IOException ioe) {
MessageUtil.error(world.getMessageHandler(),
WeaverMessages.format(WeaverMessages.XLINT_LOAD_ERROR, file.getPath(), ioe.getMessage()));
} finally {
if (s != null) {
try {
s.close();
} catch (IOException e) {
// ignore
}
}
}
catch (IOException ioe) {
MessageUtil.error(
world.getMessageHandler(),
WeaverMessages.format(WeaverMessages.XLINT_LOAD_ERROR, file.getPath(), ioe.getMessage())
);
}

if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.exit("setFromProperties");
}
}

public void loadDefaultProperties() {
Expand All @@ -212,7 +197,8 @@ public void loadDefaultProperties() {
}
try {
setFromProperties(s);
} catch (IOException ioe) {
}
catch (IOException ioe) {
MessageUtil.error(world.getMessageHandler(),
WeaverMessages.format(WeaverMessages.XLINTDEFAULT_LOAD_PROBLEM, ioe.getMessage()));
} finally {
Expand All @@ -234,11 +220,10 @@ private void setFromProperties(InputStream s) throws IOException {
public void setFromProperties(Properties properties) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Kind kind = kinds.get(entry.getKey());
if (kind == null) {
if (kind == null)
MessageUtil.error(world.getMessageHandler(), WeaverMessages.format(WeaverMessages.XLINT_KEY_ERROR, entry.getKey()));
} else {
else
kind.setKind(getMessageKind((String) entry.getValue()));
}
}
}

Expand All @@ -252,34 +237,31 @@ public Kind getLintKind(String name) {

// temporarily suppress the given lint messages
public void suppressKinds(Collection<Kind> lintKind) {
if (lintKind.isEmpty()) {
if (lintKind.isEmpty())
return;
}
for (Kind k : lintKind) {
for (Kind k : lintKind)
k.setSuppressed(true);
}
}

// remove any suppression of lint warnings in place
public void clearAllSuppressions() {
for (Kind k : kinds.values()) {
for (Kind k : kinds.values())
k.setSuppressed(false);
}
}

public void clearSuppressions(Collection<Lint.Kind> lintKinds) {
for (Kind k : lintKinds) {
for (Kind k : lintKinds)
k.setSuppressed(false);
}
}

private IMessage.Kind getMessageKind(String v) {
if (v.equals("ignore")) {
return null;
} else if (v.equals("warning")) {
return IMessage.WARNING;
} else if (v.equals("error")) {
return IMessage.ERROR;
switch (v) {
case "ignore":
return null;
case "warning":
return IMessage.WARNING;
case "error":
return IMessage.ERROR;
}

MessageUtil.error(world.getMessageHandler(), WeaverMessages.format(WeaverMessages.XLINT_VALUE_ERROR, v));
Expand Down Expand Up @@ -328,19 +310,17 @@ public void setKind(IMessage.Kind kind) {
}

public void signal(String info, ISourceLocation location) {
if (kind == null) {
if (kind == null)
return;
}

String text = MessageFormat.format(message, new Object[] { info });
String text = MessageFormat.format(message, info);
text += " [Xlint:" + name + "]";
world.getMessageHandler().handleMessage(new LintMessage(text, kind, location, null, getLintKind(name)));
}

public void signal(String[] infos, ISourceLocation location, ISourceLocation[] extraLocations) {
if (kind == null) {
if (kind == null)
return;
}

String text = MessageFormat.format(message, (Object[]) infos);
text += " [Xlint:" + name + "]";
Expand Down

0 comments on commit b5ff094

Please sign in to comment.