Browse Source

Lint: minor structural refactoring

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tags/V1_9_22_1
Alexander Kriegisch 1 month ago
parent
commit
b5ff0942c3
1 changed files with 36 additions and 56 deletions
  1. 36
    56
      org.aspectj.matcher/src/main/java/org/aspectj/weaver/Lint.java

+ 36
- 56
org.aspectj.matcher/src/main/java/org/aspectj/weaver/Lint.java View File

package org.aspectj.weaver; package org.aspectj.weaver;


import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
public final Kind missingAspectForReweaving = new Kind("missingAspectForReweaving", public final Kind missingAspectForReweaving = new Kind("missingAspectForReweaving",
"aspect {0} cannot be found when reweaving {1}"); "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) { public Lint(World world) {
if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.enter("<init>", this, world); trace.enter("<init>", this, world);
}
this.world = world; this.world = world;
if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.exit("<init>"); trace.exit("<init>");
}
} }


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


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


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


public void setFromProperties(File file) { public void setFromProperties(File file) {
if (trace.isTraceEnabled()) {
if (trace.isTraceEnabled())
trace.enter("setFromProperties", this, file); trace.enter("setFromProperties", this, file);
}
InputStream s = null;
try {
s = new FileInputStream(file);
try (InputStream s = Files.newInputStream(file.toPath())) {
setFromProperties(s); 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"); trace.exit("setFromProperties");
}
} }


public void loadDefaultProperties() { public void loadDefaultProperties() {
} }
try { try {
setFromProperties(s); setFromProperties(s);
} catch (IOException ioe) {
}
catch (IOException ioe) {
MessageUtil.error(world.getMessageHandler(), MessageUtil.error(world.getMessageHandler(),
WeaverMessages.format(WeaverMessages.XLINTDEFAULT_LOAD_PROBLEM, ioe.getMessage())); WeaverMessages.format(WeaverMessages.XLINTDEFAULT_LOAD_PROBLEM, ioe.getMessage()));
} finally { } finally {
public void setFromProperties(Properties properties) { public void setFromProperties(Properties properties) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) { for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Kind kind = kinds.get(entry.getKey()); Kind kind = kinds.get(entry.getKey());
if (kind == null) {
if (kind == null)
MessageUtil.error(world.getMessageHandler(), WeaverMessages.format(WeaverMessages.XLINT_KEY_ERROR, entry.getKey())); MessageUtil.error(world.getMessageHandler(), WeaverMessages.format(WeaverMessages.XLINT_KEY_ERROR, entry.getKey()));
} else {
else
kind.setKind(getMessageKind((String) entry.getValue())); kind.setKind(getMessageKind((String) entry.getValue()));
}
} }
} }




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


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


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


private IMessage.Kind getMessageKind(String v) { 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)); MessageUtil.error(world.getMessageHandler(), WeaverMessages.format(WeaverMessages.XLINT_VALUE_ERROR, v));
} }


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


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


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


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

Loading…
Cancel
Save