use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.
the class MethodSignatureVisitor method visitTypeVariable.
@Override
public void visitTypeVariable(String typeVariable) {
final EntryMessage message = log.traceEntry("typeVariable={}", typeVariable);
TypeInfo typeInfo;
if (this.typeMap != null && typeMap.containsKey(typeVariable)) {
String val = typeMap.get(typeVariable);
if (val.equals(typeVariable)) {
MethodSignatureVisitor.getTopVisitor(this).typeParameters.add(typeVariable);
typeVariable = ClassNameUtils.CLASS_TYPE_VARIABLE_MARK + typeVariable;
} else {
ClassNameUtils.getTypeVariable(val).ifPresent(tv -> MethodSignatureVisitor.getTopVisitor(this).typeParameters.add(tv));
typeVariable = val;
}
} else {
if (this.classTypeParameters.contains(typeVariable)) {
// mark
MethodSignatureVisitor.getTopVisitor(this).typeParameters.add(typeVariable);
typeVariable = ClassNameUtils.CLASS_TYPE_VARIABLE_MARK + typeVariable;
} else {
MethodSignatureVisitor.getTopVisitor(this).typeParameters.add(typeVariable);
typeVariable = ClassNameUtils.FORMAL_TYPE_VARIABLE_MARK + typeVariable;
}
}
typeInfo = getTypeInfo(typeVariable);
if (this.isReturn) {
if (this.current == null) {
// add direct
typeInfo.isArray = this.isArray;
this.parent.returnType = typeInfo;
} else {
if (this.current.typeParameters == null) {
this.current.typeParameters = new ArrayList<>(4);
}
this.current.typeParameters.add(typeInfo);
}
log.traceExit(message);
return;
}
if (this.isParameter) {
if (isSuper || isExtends) {
if (this.current.typeParameters == null) {
this.current.typeParameters = new ArrayList<>(4);
}
this.current.typeParameters.add(typeInfo);
} else {
if (this.current != null) {
if (this.current.typeParameters == null) {
this.current.typeParameters = new ArrayList<>(4);
}
this.current.typeParameters.add(typeInfo);
} else {
typeInfo.isArray = this.isArray;
this.parent.parameterTypes.add(typeInfo);
}
}
}
log.traceExit(message);
}
use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.
the class MethodSignatureVisitor method visitClassBound.
@Override
public SignatureVisitor visitClassBound() {
final EntryMessage message = log.traceEntry("current={}", this.current);
MethodSignatureVisitor visitor = new MethodSignatureVisitor(this.name, this);
visitor.current = this.formalType;
this.formalType = null;
visitor.isFormalType = true;
visitor.isClassBound = true;
log.traceExit(message);
return visitor;
}
use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.
the class TreeAnalyzer method analyzeParsedTree.
private static void analyzeParsedTree(SourceContext context, @Nullable JCTree tree) throws IOException {
if (isNull(tree)) {
return;
}
JCDiagnostic.DiagnosticPosition pos = tree.pos();
EndPosTable endPosTable = context.getEndPosTable();
int startPos = pos.getStartPosition();
int preferredPos = pos.getPreferredPosition();
int endPos = pos.getEndPosition(endPosTable);
EntryMessage em = log.traceEntry("# class={} preferredPos={} endPos={} expr='{}'", tree.getClass().getSimpleName(), preferredPos, endPos, tree);
if (endPos == -1 && !(tree instanceof JCTree.JCAssign) && !(tree instanceof JCTree.JCIdent)) {
// skip
log.trace("skip expr={}", tree);
log.traceExit(em);
return;
}
if (tree instanceof JCTree.JCVariableDecl) {
analyzeVariableDecl(context, (JCTree.JCVariableDecl) tree, preferredPos, endPos);
} else if (tree instanceof JCTree.JCTypeCast) {
JCTree.JCTypeCast cast = (JCTree.JCTypeCast) tree;
JCTree.JCExpression expression = cast.getExpression();
analyzeParsedTree(context, expression);
if (context.isArgument()) {
getExpressionType(context.getSource(), cast).ifPresent(context::setArgumentFQCN);
}
} else if (tree instanceof JCTree.JCMethodDecl) {
analyzeMethodDecl(context, (JCTree.JCMethodDecl) tree, preferredPos, endPos);
} else if (tree instanceof JCTree.JCClassDecl) {
analyzeInnerClassDecl(context, (JCTree.JCClassDecl) tree, startPos, endPos);
} else if (tree instanceof JCTree.JCBlock) {
JCTree.JCBlock block = (JCTree.JCBlock) tree;
int argumentIndex = context.getArgumentIndex();
context.setArgumentIndex(-1);
analyzeSimpleStatements(context, block.getStatements());
context.setArgumentIndex(argumentIndex);
} else if (tree instanceof JCTree.JCFieldAccess) {
analyzeFieldAccess(context, (JCTree.JCFieldAccess) tree, preferredPos, endPos);
} else if (tree instanceof JCTree.JCArrayAccess) {
JCTree.JCArrayAccess arrayAccess = (JCTree.JCArrayAccess) tree;
analyzeParsedTree(context, arrayAccess.getExpression());
analyzeParsedTree(context, arrayAccess.getIndex());
} else if (tree instanceof JCTree.JCExpressionStatement) {
analyzeExpressionStatement(context, (JCTree.JCExpressionStatement) tree, preferredPos, endPos);
} else if (tree instanceof JCTree.JCLiteral) {
analyzeLiteral(context, (JCTree.JCLiteral) tree, preferredPos, endPos);
} else if (tree instanceof JCTree.JCIdent) {
analyzeIdent(context, (JCTree.JCIdent) tree, preferredPos, endPos);
} else if (tree instanceof JCTree.JCContinue) {
// skip
} else if (tree instanceof JCTree.JCBreak) {
// skip
} else if (tree instanceof JCTree.JCUnary) {
JCTree.JCUnary unary = (JCTree.JCUnary) tree;
JCTree.JCExpression expression = unary.getExpression();
analyzeParsedTree(context, expression);
} else if (tree instanceof JCTree.JCSwitch) {
analyzeSwitch(context, (JCTree.JCSwitch) tree);
} else if (tree instanceof JCTree.JCReturn) {
JCTree.JCReturn ret = (JCTree.JCReturn) tree;
JCTree.JCExpression expression = ret.getExpression();
analyzeParsedTree(context, ret.getExpression());
} else if (tree instanceof JCTree.JCForLoop) {
analyzeForLoop(context, (JCTree.JCForLoop) tree);
} else if (tree instanceof JCTree.JCEnhancedForLoop) {
analyzeEnhancedForLoop(context, (JCTree.JCEnhancedForLoop) tree);
} else if (tree instanceof JCTree.JCTry) {
analyzeTry(context, (JCTree.JCTry) tree);
} else if (tree instanceof JCTree.JCIf) {
JCTree.JCIf ifExpr = (JCTree.JCIf) tree;
JCTree.JCExpression condition = ifExpr.getCondition();
JCTree.JCStatement thenStatement = ifExpr.getThenStatement();
JCTree.JCStatement elseStatement = ifExpr.getElseStatement();
analyzeParsedTree(context, condition);
analyzeParsedTree(context, thenStatement);
analyzeParsedTree(context, elseStatement);
} else if (tree instanceof JCTree.JCParens) {
JCTree.JCParens parens = (JCTree.JCParens) tree;
JCTree.JCExpression expression = parens.getExpression();
analyzeParsedTree(context, expression);
} else if (tree instanceof JCTree.JCNewClass) {
analyzeNewClass(context, (JCTree.JCNewClass) tree, preferredPos, endPos);
} else if (tree instanceof JCTree.JCBinary) {
JCTree.JCBinary binary = (JCTree.JCBinary) tree;
JCTree.JCExpression leftOperand = binary.getLeftOperand();
JCTree.JCExpression rightOperand = binary.getRightOperand();
analyzeParsedTree(context, leftOperand);
analyzeParsedTree(context, rightOperand);
} else if (tree instanceof JCTree.JCMethodInvocation) {
analyzeMethodInvocation(context, (JCTree.JCMethodInvocation) tree, preferredPos, endPos);
} else if (tree instanceof JCTree.JCAssign) {
JCTree.JCAssign assign = (JCTree.JCAssign) tree;
JCTree.JCExpression expression = assign.getExpression();
JCTree.JCExpression variable = assign.getVariable();
analyzeParsedTree(context, variable);
analyzeParsedTree(context, expression);
} else if (tree instanceof JCTree.JCNewArray) {
JCTree.JCNewArray newArray = (JCTree.JCNewArray) tree;
JCTree.JCExpression type = newArray.getType();
analyzeParsedTree(context, type);
List<JCTree.JCExpression> initializes = newArray.getInitializers();
analyzeSimpleExpressions(context, initializes);
List<JCTree.JCExpression> dimensions = newArray.getDimensions();
analyzeSimpleExpressions(context, dimensions);
if (nonNull(newArray.type)) {
getTypeString(context.getSource(), newArray.type).ifPresent(context::setArgumentFQCN);
}
} else if (tree instanceof JCTree.JCPrimitiveTypeTree) {
// skip
} else if (tree instanceof JCTree.JCConditional) {
JCTree.JCConditional conditional = (JCTree.JCConditional) tree;
JCTree.JCExpression condition = conditional.getCondition();
analyzeParsedTree(context, condition);
JCTree.JCExpression trueExpression = conditional.getTrueExpression();
analyzeParsedTree(context, trueExpression);
JCTree.JCExpression falseExpression = conditional.getFalseExpression();
analyzeParsedTree(context, falseExpression);
} else if (tree instanceof JCTree.JCLambda) {
analyzeLambda(context, (JCTree.JCLambda) tree);
} else if (tree instanceof JCTree.JCThrow) {
JCTree.JCThrow jcThrow = (JCTree.JCThrow) tree;
JCTree.JCExpression expression = jcThrow.getExpression();
analyzeParsedTree(context, expression);
} else if (tree instanceof JCTree.JCInstanceOf) {
JCTree.JCInstanceOf jcInstanceOf = (JCTree.JCInstanceOf) tree;
JCTree.JCExpression expression = jcInstanceOf.getExpression();
analyzeParsedTree(context, expression);
JCTree typeTree = jcInstanceOf.getType();
analyzeParsedTree(context, typeTree);
} else if (tree instanceof JCTree.JCMemberReference) {
Source src = context.getSource();
JCTree.JCMemberReference memberReference = (JCTree.JCMemberReference) tree;
JCTree.JCExpression expression = memberReference.getQualifierExpression();
com.sun.tools.javac.util.Name name = memberReference.getName();
String methodName = name.toString();
if (nonNull(expression)) {
analyzeParsedTree(context, expression);
Symbol sym = memberReference.sym;
if (nonNull(sym)) {
// method invoke
int start = expression.getEndPosition(endPosTable) + 2;
Range range = Range.create(src, start, start + methodName.length());
String s = memberReference.toString();
MethodCall methodCall = new MethodCall(s, methodName, preferredPos + 1, range, range);
if (sym instanceof Symbol.MethodSymbol) {
Symbol.MethodSymbol methodSymbol = (Symbol.MethodSymbol) sym;
java.util.List<String> arguments = new ArrayList<>(methodSymbol.getParameters().size());
for (VarSymbol varSymbol : methodSymbol.getParameters()) {
arguments.add(varSymbol.asType().toString());
}
methodCall.setArguments(arguments);
}
Symbol owner = sym.owner;
if (nonNull(owner) && nonNull(owner.type)) {
getTypeString(src, owner.type).ifPresent(fqcn -> methodCall.declaringClass = TreeAnalyzer.markFQCN(src, fqcn));
}
if (nonNull(sym.type)) {
getTypeString(src, sym.type).ifPresent(fqcn -> {
methodCall.returnType = TreeAnalyzer.markFQCN(src, fqcn);
// TODO add args
});
}
src.getCurrentScope().ifPresent(scope -> scope.addMethodCall(methodCall));
}
}
} else if (tree instanceof JCTree.JCWhileLoop) {
JCTree.JCWhileLoop whileLoop = (JCTree.JCWhileLoop) tree;
JCTree.JCExpression condition = whileLoop.getCondition();
analyzeParsedTree(context, condition);
JCTree.JCStatement statement = whileLoop.getStatement();
analyzeParsedTree(context, statement);
} else if (tree instanceof JCTree.JCSynchronized) {
JCTree.JCSynchronized jcSynchronized = (JCTree.JCSynchronized) tree;
JCTree.JCExpression expression = jcSynchronized.getExpression();
analyzeParsedTree(context, expression);
JCTree.JCBlock block = jcSynchronized.getBlock();
analyzeParsedTree(context, block);
} else if (tree instanceof JCTree.JCAssert) {
JCTree.JCAssert jcAssert = (JCTree.JCAssert) tree;
JCTree.JCExpression condition = jcAssert.getCondition();
analyzeParsedTree(context, condition);
JCTree.JCExpression detail = jcAssert.getDetail();
analyzeParsedTree(context, detail);
} else if (tree instanceof JCTree.JCArrayTypeTree) {
JCTree.JCArrayTypeTree arrayTypeTree = (JCTree.JCArrayTypeTree) tree;
JCTree type = arrayTypeTree.getType();
analyzeParsedTree(context, type);
} else if (tree instanceof JCTree.JCDoWhileLoop) {
JCTree.JCDoWhileLoop doWhileLoop = (JCTree.JCDoWhileLoop) tree;
JCTree.JCExpression condition = doWhileLoop.getCondition();
analyzeParsedTree(context, condition);
JCTree.JCStatement statement = doWhileLoop.getStatement();
analyzeParsedTree(context, statement);
} else if (tree instanceof JCTree.JCLabeledStatement) {
JCTree.JCLabeledStatement labeledStatement = (JCTree.JCLabeledStatement) tree;
JCTree.JCStatement statement = labeledStatement.getStatement();
analyzeParsedTree(context, statement);
} else if (tree instanceof JCTree.JCTypeApply) {
JCTree.JCTypeApply typeApply = (JCTree.JCTypeApply) tree;
JCTree type = typeApply.getType();
analyzeParsedTree(context, type);
} else if (tree instanceof JCTree.JCAssignOp) {
JCTree.JCAssignOp assignOp = (JCTree.JCAssignOp) tree;
JCTree.JCExpression expression = assignOp.getExpression();
analyzeParsedTree(context, expression);
} else if (tree instanceof JCTree.JCAnnotation) {
JCTree.JCAnnotation annotation = (JCTree.JCAnnotation) tree;
analyzeSimpleExpressions(context, annotation.getArguments());
JCTree annotationType = annotation.getAnnotationType();
analyzeParsedTree(context, annotationType);
} else if (tree instanceof JCTree.JCSkip) {
// skip
} else if (tree instanceof JCTree.JCErroneous) {
// skip error
} else {
Source src = context.getSource();
log.warn("@@ unknown or broken tree class={} expr={} filePath={}", tree.getClass(), tree, src.filePath);
}
log.traceExit(em);
}
use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.
the class DeclarationSearcher method searchLocalVariable.
private static Optional<Declaration> searchLocalVariable(final Source source, final Integer line, final Integer col, final String symbol) {
final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
final Optional<Variable> variable = source.getVariable(line, col);
final Optional<Declaration> result = variable.map(var -> {
final Declaration declaration = new Declaration(symbol, var.fqcn, Declaration.Type.VAR, var.argumentIndex);
return Optional.of(declaration);
}).orElseGet(() -> searchFieldVar(source, line, symbol));
log.traceExit(entryMessage);
return result;
}
use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.
the class DeclarationSearcher method searchClassOrInterface.
private static Optional<Declaration> searchClassOrInterface(final Source source, final Integer line, final Integer col, final String symbol) {
// TODO need tune
final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
final CachedASMReflector reflector = CachedASMReflector.getInstance();
Optional<Declaration> result;
String fqcn = source.getImportedClassFQCN(symbol, null);
if (fqcn == null) {
if (!source.getPackageName().isEmpty()) {
fqcn = source.getPackageName() + '.' + symbol;
result = reflector.containsClassIndex(fqcn).map(classIndex -> {
final Declaration declaration = new Declaration(symbol, classIndex.getReturnType(), Declaration.Type.CLASS, 0);
return Optional.of(declaration);
}).orElseGet(() -> {
final Set<String> parents = new HashSet<>(8);
for (final ClassScope classScope : source.getClassScopes()) {
final String className = classScope.getFQCN();
parents.add(className);
}
parents.addAll(source.importClasses);
for (final ClassIndex ci : reflector.searchInnerClasses(parents)) {
final String returnType = ci.getReturnType();
if (returnType.endsWith(symbol)) {
final Declaration d = new Declaration(symbol, returnType, Declaration.Type.CLASS, 0);
return Optional.of(d);
}
}
return Optional.empty();
});
} else {
result = Optional.empty();
}
} else {
final Declaration declaration = new Declaration(symbol, fqcn, Declaration.Type.CLASS, 0);
result = Optional.of(declaration);
}
log.traceExit(entryMessage);
return result;
}
Aggregations