Skip to content

Commit

Permalink
Add reference command
Browse files Browse the repository at this point in the history
  • Loading branch information
mopemope committed Jun 26, 2017
1 parent e22b1bb commit 3287def
Show file tree
Hide file tree
Showing 44 changed files with 1,014 additions and 210 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ dependencies {


test {
jvmArgs = ["-XX:SoftRefLRUPolicyMSPerMB=50", "-XX:+UseConcMarkSweepGC", "-Xverify:none", "-Xms256m", "-Xmx2G"]

jvmArgs = ["-XX:SoftRefLRUPolicyMSPerMB=50", "-XX:+UseConcMarkSweepGC", "-Xverify:none"]
testLogging {
events "PASSED", "FAILED", "SKIPPED"
exceptionFormat "full"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/meghanada/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void main(String args[]) throws ParseException, IOException {
new Thread(
() -> {
log.info("shutdown server");
Config.load().showMemory();
Config.showMemory();
}));

System.setProperty("home", Config.getInstalledPath().getParentFile().getCanonicalPath());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/meghanada/analyze/AccessSymbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

public abstract class AccessSymbol implements Serializable {

private static final long serialVersionUID = -1404691982810815085L;
static final int SCOPE_LIMIT = 32;

private static final long serialVersionUID = -1404691982810815085L;
public String declaringClass;
public String scope = "";
public String name;
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/meghanada/analyze/ClassScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import jetbrains.exodus.entitystore.Entity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.EntryMessage;

public class ClassScope extends TypeScope {

public static final String ENTITY_TYPE = "ClassScope";
private static final long serialVersionUID = -7970631189101348627L;
private static final Logger log = LogManager.getLogger(ClassScope.class);
public final List<ClassScope> classScopes = new ArrayList<>(1);
Expand Down Expand Up @@ -196,18 +194,6 @@ public Collection<AccessSymbol> getAccessSymbols() {
return result;
}

void setEntityProps(Entity entity) {
Range range = this.range;
entity.setProperty("fqcn", this.getFQCN());
entity.setProperty("name", this.name);
entity.setProperty("isEnum", this.isEnum);
entity.setProperty("isInterface", this.isInterface);
entity.setProperty("beginLine", range.begin.line);
entity.setProperty("beginColumn", range.begin.column);
entity.setProperty("endLine", range.end.line);
entity.setProperty("endColumn", range.end.column);
}

public List<ClassScope> getClassScopes() {
return classScopes;
}
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/meghanada/analyze/FieldAccess.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package meghanada.analyze;

import static java.util.Objects.nonNull;
import static java.util.Objects.requireNonNull;

import jetbrains.exodus.entitystore.Entity;

public class FieldAccess extends AccessSymbol {

public static final String ENTITY_TYPE = "FieldAccess";
private static final long serialVersionUID = -1933640313689982694L;
public boolean isEnum;

Expand All @@ -19,22 +13,4 @@ public FieldAccess(final String name, final int pos, final Range range) {
public boolean match(int line, int column) {
return this.range.begin.line == line && this.containsColumn(column);
}

void setEntityProps(Entity entity) {

requireNonNull(this.returnType, this.toString());
Range range = this.range;

entity.setProperty("declaringClass", this.declaringClass);
entity.setProperty("name", this.name);
if (nonNull(this.returnType)) {
entity.setProperty("returnType", this.returnType);
}

entity.setProperty("beginLine", range.begin.line);
entity.setProperty("beginColumn", range.begin.column);

entity.setProperty("endLine", range.end.line);
entity.setProperty("endColumn", range.end.column);
}
}
34 changes: 12 additions & 22 deletions src/main/java/meghanada/analyze/MethodCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@

import java.util.Collections;
import java.util.List;
import jetbrains.exodus.entitystore.Entity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class MethodCall extends AccessSymbol {

public static final String ENTITY_TYPE = "MethodCall";
public static final String ARGS_ENTITY_TYPE = "Arguments";
private static final long serialVersionUID = -2434830191914184294L;
private static final Logger log = LogManager.getLogger(MethodCall.class);
public Range nameRange;
public List<String> arguments = Collections.emptyList();
boolean constructor;
private List<String> arguments = Collections.emptyList();

public MethodCall(final String name, final int pos, final Range nameRange, final Range range) {
super(name, pos, range);
this.nameRange = nameRange;
}

public MethodCall(
final String name,
final int pos,
final Range nameRange,
final Range range,
boolean constructor) {
this(name, pos, nameRange, range);
this.constructor = constructor;
}

public MethodCall(
final String scope,
final String name,
Expand Down Expand Up @@ -58,22 +66,4 @@ public boolean match(int line, int column) {
public boolean nameContains(final int column) {
return this.nameRange.begin.column <= column && column <= this.nameRange.end.column;
}

void setEntityProps(Entity entity) {

Range range = this.nameRange;

if (nonNull(this.declaringClass)) {
entity.setProperty("declaringClass", this.declaringClass);
}
entity.setProperty("name", this.name);
if (nonNull(this.returnType)) {
entity.setProperty("returnType", this.returnType);
}
entity.setProperty("beginLine", range.begin.line);
entity.setProperty("beginColumn", range.begin.column);

entity.setProperty("endLine", range.end.line);
entity.setProperty("endColumn", range.end.column);
}
}
18 changes: 13 additions & 5 deletions src/main/java/meghanada/analyze/MethodScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class MethodScope extends BlockScope {
private static final long serialVersionUID = -6957893688780569397L;
private static final Logger log = LogManager.getLogger(MethodScope.class);

public final List<String> parameters = new ArrayList<>(3);
public String name;
public Range nameRange;
public boolean isConstructor;
public String returnType;
private final List<String> parameters = new ArrayList<>(3);
protected String name;
protected String returnType;
private Range nameRange;
private boolean isConstructor;

public MethodScope(
final String name, @Nullable final Range nameRange, final int pos, final Range range) {
Expand Down Expand Up @@ -165,4 +165,12 @@ public String toString() {
.add("parameters", parameters)
.toString();
}

public List<String> getParameters() {
return parameters;
}

public boolean isConstructor() {
return isConstructor;
}
}
2 changes: 1 addition & 1 deletion src/main/java/meghanada/analyze/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected String getScopeType() {
return "Class";
case "MethodScope":
final MethodScope methodScope = (MethodScope) this;
return methodScope.isConstructor ? "Constructor" : "Method";
return methodScope.isConstructor() ? "Constructor" : "Method";
default:
return "Block";
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/meghanada/analyze/TreeAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ private void analyzeNewClass(
final Range nameRange = Range.create(src, start, end);

final Range range = Range.create(src, preferredPos + 4, endPos);
final MethodCall methodCall = new MethodCall(name, preferredPos, nameRange, range);
final MethodCall methodCall = new MethodCall(name, preferredPos, nameRange, range, true);

final Type type = identifier.type;
this.getTypeString(src, type)
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/meghanada/analyze/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.google.common.base.MoreObjects;
import java.io.Serializable;
import jetbrains.exodus.entitystore.Entity;
import meghanada.reflect.CandidateUnit;
import meghanada.reflect.FieldDescriptor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Variable implements Serializable {

public static final String ENTITY_TYPE = "Variable";

private static final long serialVersionUID = 5911384112219223687L;
private static Logger log = LogManager.getLogger(Variable.class);

Expand Down Expand Up @@ -51,21 +48,4 @@ public boolean isDecl() {
public CandidateUnit toCandidateUnit() {
return FieldDescriptor.createVar("", this.name, this.fqcn);
}

void setEntityProps(Entity entity) {

Range range = this.range;

entity.setProperty("fqcn", this.fqcn);
entity.setProperty("name", this.name);
entity.setProperty("isDef", this.isDef);
entity.setProperty("isParameter", this.isParameter);
entity.setProperty("isField", this.isField);

entity.setProperty("beginLine", range.begin.line);
entity.setProperty("beginColumn", range.begin.column);

entity.setProperty("endLine", range.end.line);
entity.setProperty("endColumn", range.end.column);
}
}
32 changes: 21 additions & 11 deletions src/main/java/meghanada/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.google.common.base.Stopwatch;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigValueFactory;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -32,7 +33,7 @@ public class Config {
private static final Logger log = LogManager.getLogger(Config.class);
private static Config config;

private final com.typesafe.config.Config c;
private com.typesafe.config.Config c;
private boolean debug;
private List<String> includeList;
private List<String> excludeList;
Expand Down Expand Up @@ -169,6 +170,18 @@ public static File getInstalledPath() {
}
}

public static void showMemory() {
final Runtime runtime = Runtime.getRuntime();
final float maxMemory = runtime.maxMemory() / 1024 / 1024;
final float totalMemory = runtime.totalMemory() / 1024 / 1024;
final float usedMemory = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024;
log.info(
"memory usage (used/total/max): {}MB / {}MB / {}MB",
String.format("%.2f", usedMemory),
String.format("%.2f", totalMemory),
String.format("%.2f", maxMemory));
}

public List<String> gradlePrepareCompileTask() {
final String tasks = c.getString(GRADLE_PREPARE_COMPILE_TASK);
final String[] split = StringUtils.split(tasks, ",");
Expand Down Expand Up @@ -329,16 +342,13 @@ public int getSourceCacheSize() {
return c.getInt("source-cache-size");
}

public void showMemory() {
final Runtime runtime = Runtime.getRuntime();
final float maxMemory = runtime.maxMemory() / 1024 / 1024;
final float totalMemory = runtime.totalMemory() / 1024 / 1024;
final float usedMemory = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024;
log.info(
"memory usage (used/total/max): {}MB / {}MB / {}MB",
String.format("%.2f", usedMemory),
String.format("%.2f", totalMemory),
String.format("%.2f", maxMemory));
public void update(String key, Object newVal) {
com.typesafe.config.Config newConfig = c.withValue(key, ConfigValueFactory.fromAnyRef(newVal));
this.c = newConfig;
}

public boolean useAOSPStyle() {
return c.getBoolean("aosp-style");
}

@FunctionalInterface
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/meghanada/docs/declaration/Declaration.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public String toString() {
return MoreObjects.toStringHelper(this)
.add("symbol", scopeInfo)
.add("declaration", signature)
.add("declaration", signature)
.add("type", type)
.add("argumentIndex", argumentIndex)
.toString();
}

Expand Down
21 changes: 18 additions & 3 deletions src/main/java/meghanada/formatter/JavaFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import meghanada.config.Config;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jface.text.BadLocationException;
Expand All @@ -22,11 +23,25 @@
public class JavaFormatter {

private static final Pattern NEW_LINE = Pattern.compile("\n");
private static final Formatter googleFormatter =
new Formatter(JavaFormatterOptions.defaultOptions());
private static Formatter googleFormatter = null;

private JavaFormatter() {}

private static Formatter getGoogleFormatter() {
if (googleFormatter != null) {
return googleFormatter;
}

if (Config.load().useAOSPStyle()) {
googleFormatter =
new Formatter(
JavaFormatterOptions.builder().style(JavaFormatterOptions.Style.AOSP).build());
} else {
googleFormatter = new Formatter(JavaFormatterOptions.defaultOptions());
}
return googleFormatter;
}

public static Properties getPropertiesFromXML(File xmlFile) {
final XMLInputFactory factory = XMLInputFactory.newInstance();
final Properties properties = new Properties();
Expand All @@ -50,7 +65,7 @@ public static Properties getPropertiesFromXML(File xmlFile) {

public static String formatGoogleStyle(final String content) {
try {
return googleFormatter.formatSource(content);
return getGoogleFormatter().formatSource(content);
} catch (FormatterException e) {
return content;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/meghanada/junit/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private void runJunit(String arg, Request request) {
stopwatch.stop()));
System.out.println("Success");
}

System.out.println(Strings.repeat("-", 80));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/meghanada/location/LocationSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private Optional<Location> getMethodLocationFromProject(
return false;
}
final MethodScope methodScope = (MethodScope) bs;
final List<String> parameters = methodScope.parameters;
final List<String> parameters = methodScope.getParameters();
return ClassNameUtils.compareArgumentType(arguments, parameters);
})
.map(MethodScope.class::cast)
Expand Down
Loading

0 comments on commit 3287def

Please sign in to comment.