use of org.eclipse.jdt.core.dom.ConstructorInvocation in project eap-additional-testsuite by jboss-set.
the class MethodInfo method blockIterate.
private static void blockIterate(final Block block, final CompilationUnit cu, HashMap<String, String> blockDeclarations) {
List<Statement> statements = new ArrayList<>();
HashMap<String, String> bDeclarations = new HashMap();
bDeclarations.putAll(blockDeclarations);
if (block != null) {
statements = block.statements();
}
for (Statement s : statements) {
s.accept(new ASTVisitor() {
public boolean visit(SingleVariableDeclaration node) {
String name = node.getName().toString();
String type = node.getType().toString();
bDeclarations.put(name, type);
ArrayList<String> types0 = new ArrayList<>();
String type2 = null;
do {
if (type.contains("[")) {
type = type.replaceAll("\\[\\]", "");
if (type.contains("[")) {
type = type.substring(0, type.indexOf("["));
}
}
if (type.contains("<")) {
String type3 = type;
type = type.substring(0, type.indexOf("<"));
if (type3.substring(type3.indexOf("<") + 1).startsWith("<>") || type3.substring(type.indexOf("<") + 1).startsWith("<T>")) {
type2 = null;
} else {
type2 = type3.substring(type3.indexOf("<") + 1, type3.lastIndexOf(">"));
if (type2.contains(",")) {
if (type2.substring(0, type2.indexOf(",")).contains("<")) {
types0.add(type2);
} else {
types0.add(type2.substring(0, type2.indexOf(",")));
types0.add(type2.substring(type2.indexOf(",") + 1));
}
} else {
types0.add(type2);
}
}
}
types.addAll(Arrays.asList(type.split(" extends ")));
if (types0.size() != 0) {
type = types0.remove(0);
} else {
type = null;
}
} while (type != null);
return true;
}
public boolean visit(VariableDeclarationStatement node) {
String name = node.fragments().get(0).toString().split("=")[0].trim();
String type = node.getType().toString();
bDeclarations.put(name, type);
ArrayList<String> types0 = new ArrayList<>();
String type2 = null;
do {
if (type.contains("[")) {
type = type.replaceAll("\\[\\]", "");
if (type.contains("[")) {
type = type.substring(0, type.indexOf("["));
}
}
if (type.contains("<")) {
String type3 = type;
type = type.substring(0, type.indexOf("<"));
if (type3.substring(type3.indexOf("<") + 1).startsWith("<>") || type3.substring(type.indexOf("<") + 1).startsWith("<T>")) {
type2 = null;
} else {
type2 = type3.substring(type3.indexOf("<") + 1, type3.lastIndexOf(">"));
if (type2.contains(",")) {
if (type2.substring(0, type2.indexOf(",")).contains("<")) {
types0.add(type2);
} else {
types0.add(type2.substring(0, type2.indexOf(",")));
types0.add(type2.substring(type2.indexOf(",") + 1));
}
} else {
types0.add(type2);
}
}
}
types.addAll(Arrays.asList(type.split(" extends ")));
if (types0.size() != 0) {
type = types0.remove(0);
} else {
type = null;
}
} while (type != null);
return true;
}
public boolean visit(SimpleType node) {
String type = node.getName().toString();
String name = node.getName().toString();
bDeclarations.put(name, type);
ArrayList<String> types0 = new ArrayList<>();
String type2 = null;
do {
if (type.contains("[")) {
type = type.replaceAll("\\[\\]", "");
if (type.contains("[")) {
type = type.substring(0, type.indexOf("["));
}
}
if (type.contains("<")) {
String type3 = type;
type = type.substring(0, type.indexOf("<"));
if (type3.substring(type3.indexOf("<") + 1).startsWith("<>") || type3.substring(type.indexOf("<") + 1).startsWith("<T>")) {
type2 = null;
} else {
type2 = type3.substring(type3.indexOf("<") + 1, type3.lastIndexOf(">"));
if (type2.contains(",")) {
if (type2.substring(0, type2.indexOf(",")).contains("<")) {
types0.add(type2);
} else {
types0.add(type2.substring(0, type2.indexOf(",")));
types0.add(type2.substring(type2.indexOf(",") + 1));
}
} else {
types0.add(type2);
}
}
}
types.addAll(Arrays.asList(type.split(" extends ")));
if (types0.size() != 0) {
type = types0.remove(0);
} else {
type = null;
}
} while (type != null);
return true;
}
public boolean visit(ClassInstanceCreation node) {
ClassInfo clInfo = new ClassInfo();
clInfo.className = node.getType().toString();
List params = node.arguments();
for (Object s : params) {
boolean resolved = true;
String arg = ((Expression) s).toString();
if (arg.contains("[") && !arg.contains("\"")) {
arg = arg.substring(0, arg.indexOf("["));
}
if (arg.startsWith("\"") && arg.endsWith("\"")) {
arg = "String";
} else if (arg.startsWith("\'") && arg.endsWith("\'")) {
arg = "Character";
} else if (arg.contains("+") && (arg.contains("\"") || arg.contains("\'"))) {
arg = "String";
} else if (arg.contains("instanceof")) {
arg = arg.substring(arg.indexOf("instanceof") + 11);
} else if (bDeclarations.containsKey(arg)) {
arg = bDeclarations.get(arg);
} else if (arg.equals("true") || arg.equals("false")) {
arg = "Boolean";
} else if (arg.contains("==") || arg.contains(">") || arg.contains("<") || arg.contains("!=") || arg.contains(">=") || arg.contains("<=")) {
arg = "Boolean";
} else if (arg.contains("TimeUnit.SECONDS")) {
arg = "Numeric";
} else if (arg.contains(".class") && !arg.contains(".className")) {
arg = arg.replaceAll(".class", "");
} else if (arg.startsWith("new ")) {
arg = arg.replaceAll("new ", "");
if (arg.contains("(")) {
arg = arg.substring(0, arg.indexOf("("));
} else if (arg.contains("[")) {
arg = arg.substring(0, arg.indexOf("["));
}
} else if (NumberUtils.isNumber(arg)) {
arg = "Numeric";
} else if ((arg.contains("-") || arg.contains("+") || arg.contains("*")) && !arg.contains("\"") && !arg.contains("NAME")) {
arg = "Numeric";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("String")) {
arg = "String";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".is")) {
arg = "Boolean";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".contains")) {
arg = "Boolean";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Int")) {
arg = "Integer";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Double")) {
arg = "Double";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Boolean")) {
arg = "Boolean";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".equals")) {
arg = "Boolean";
} else {
resolved = false;
if (!arg.contains(".") && !arg.contains("(") && !arg.contains(")")) {
typesNotResolved.add(arg);
} else {
methodsNotResolved.add(arg);
}
}
clInfo.params.add(arg);
clInfo.isResolvedParam.add(resolved);
}
classInstanceCreations.add(clInfo);
return true;
}
public boolean visit(ConstructorInvocation node) {
List params = node.arguments();
for (Object s : params) {
boolean resolved = true;
String arg = ((Expression) s).toString();
if (arg.contains("[") && !arg.contains("\"")) {
arg = arg.substring(0, arg.indexOf("["));
}
if (arg.startsWith("\"") && arg.endsWith("\"")) {
arg = "String";
} else if (arg.startsWith("\'") && arg.endsWith("\'")) {
arg = "Character";
} else if (arg.contains("+") && (arg.contains("\"") || arg.contains("\'"))) {
arg = "String";
} else if (arg.contains("instanceof")) {
arg = arg.substring(arg.indexOf("instanceof") + 11);
} else if (bDeclarations.containsKey(arg)) {
arg = bDeclarations.get(arg);
} else if (arg.equals("true") || arg.equals("false")) {
arg = "Boolean";
} else if (arg.contains("==") || arg.contains(">") || arg.contains("<") || arg.contains("!=") || arg.contains(">=") || arg.contains("<=")) {
arg = "Boolean";
} else if (arg.contains("TimeUnit.SECONDS")) {
arg = "Numeric";
} else if (arg.contains(".class") && !arg.contains(".className")) {
arg = arg.replaceAll(".class", "");
} else if (arg.startsWith("new ")) {
arg = arg.replaceAll("new ", "");
if (arg.contains("(")) {
arg = arg.substring(0, arg.indexOf("("));
}
} else if (NumberUtils.isNumber(arg)) {
arg = "Numeric";
} else if ((arg.contains("-") || arg.contains("+") || arg.contains("*")) && !arg.contains("\"") && !arg.contains("NAME")) {
arg = "Numeric";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("String")) {
arg = "String";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".is")) {
arg = "Boolean";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".contains")) {
arg = "Boolean";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Int")) {
arg = "Integer";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Double")) {
arg = "Double";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Boolean")) {
arg = "Boolean";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".equals")) {
arg = "Boolean";
} else {
resolved = false;
if (!arg.contains(".") && !arg.contains("(") && !arg.contains(")")) {
typesNotResolved.add(arg);
} else {
methodsNotResolved.add(arg);
}
}
}
return true;
}
public boolean visit(MethodInvocation node) {
MethodInfo mInfo = new MethodInfo();
mInfo.expression = node.getExpression() != null ? node.getExpression().toString() : "";
mInfo.initialexpression = mInfo.expression;
mInfo.methodName = node.getName().toString();
// System.out.println("ccc " + mInfo.initialexpression + " " + mInfo.methodName);
boolean methodUnResolved = false;
if (node.getExpression() != null) {
mInfo.expression = node.getExpression().toString().replaceAll("this.", "");
if (mInfo.expression.startsWith("\"") && mInfo.expression.endsWith("\"")) {
mInfo.expression = "String";
} else if (mInfo.expression.equals("this")) {
mInfo.expression = "";
} else if (mInfo.expression.startsWith("new ")) {
mInfo.expression = mInfo.expression.replaceAll("new ", "");
if (mInfo.expression.contains("(")) {
mInfo.expression = mInfo.expression.substring(0, mInfo.expression.indexOf("("));
}
}
if (mInfo.expression.contains("[")) {
mInfo.expression = mInfo.expression.substring(0, mInfo.expression.indexOf("["));
}
if (!bDeclarations.containsKey(mInfo.expression)) {
methodsNotResolved.add(node.getExpression().toString() + "." + node.getName() + "(" + node.arguments() + ")");
methodUnResolved = true;
} else if (bDeclarations.get(mInfo.expression) != null) {
if (!bDeclarations.get(mInfo.expression).contains("<")) {
mInfo.expression = bDeclarations.get(mInfo.expression);
} else {
mInfo.expression = bDeclarations.get(mInfo.expression).substring(0, bDeclarations.get(mInfo.expression).indexOf("<"));
}
}
if (mInfo.expression.contains(".") && Character.isLowerCase(mInfo.expression.substring(0, mInfo.expression.indexOf(".")).charAt(0)) && bDeclarations.containsKey(mInfo.expression.substring(0, mInfo.expression.indexOf(".")))) {
mInfo.expression = bDeclarations.get(mInfo.expression.substring(0, mInfo.expression.indexOf("."))) + mInfo.expression.substring(mInfo.expression.indexOf("."));
}
}
List params = node.arguments();
// System.out.println("params : " + params);
for (Object s : params) {
// System.out.println("param " + s);
boolean resolved = true;
boolean isMatrix = false;
boolean noMatrix = false;
String arg = ((Expression) s).toString();
mInfo.initialparams.add(arg);
if (arg.contains("[") && arg.indexOf("]") == arg.length() - 1 && !arg.contains("\"")) {
if (arg.endsWith("[]")) {
isMatrix = true;
} else
noMatrix = true;
arg = arg.substring(0, arg.indexOf("["));
}
if (arg.startsWith("this."))
arg = arg.replaceFirst("this.", "");
if (arg.startsWith("class "))
arg = arg.replaceFirst("class ", "");
if (arg.startsWith("\"") && arg.endsWith("\"")) {
arg = "String";
} else if (arg.endsWith("toString()")) {
arg = "String";
} else if (arg.startsWith("(")) {
arg = arg.substring(1, arg.indexOf(")"));
} else if (arg.startsWith("\'") && arg.endsWith("\'")) {
arg = "Character";
} else if (arg.contains("+") && (arg.contains("\"") || arg.contains("\'"))) {
arg = "String";
} else if (arg.contains("instanceof")) {
arg = arg.substring(arg.indexOf("instanceof") + 11);
} else if (bDeclarations.containsKey(arg)) {
arg = bDeclarations.get(arg);
if (arg.contains("[") && noMatrix)
arg = arg.substring(0, arg.indexOf("["));
} else if (arg.equals("true") || arg.equals("false")) {
arg = "Boolean";
} else if (arg.contains("==") || arg.contains(">") || arg.contains("<") || arg.contains("!=") || arg.contains(">=") || arg.contains("<=") || arg.contains("||")) {
arg = "Boolean";
} else if (arg.contains("TimeUnit.SECONDS")) {
arg = "Numeric";
} else if (arg.contains(".class") && !arg.contains(".className")) {
arg = arg.replaceAll(".class", "");
} else if (arg.startsWith("new ")) {
arg = arg.replaceAll("new ", "");
if (arg.contains("(")) {
arg = arg.substring(0, arg.lastIndexOf("("));
}
if (arg.contains("{")) {
arg = arg.substring(0, arg.indexOf("{"));
}
} else if (NumberUtils.isNumber(arg)) {
arg = "Numeric";
} else if ((arg.contains("-") || arg.contains("+") || arg.contains("*")) && !arg.contains("\"") && !arg.contains("NAME")) {
arg = "Numeric";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("String")) {
arg = "String";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".is")) {
arg = "Boolean";
} else if (arg.contains(".contains")) {
arg = arg.substring(0, arg.lastIndexOf("("));
if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".contains("))
arg = "Boolean";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Int")) {
arg = "Integer";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Double")) {
arg = "Double";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).contains("Boolean")) {
arg = "Boolean";
} else if (arg.contains(".") && arg.substring(arg.lastIndexOf(".")).startsWith(".equals")) {
arg = "Boolean";
} else {
resolved = false;
if (!arg.contains(".") && !arg.contains("(") && !arg.contains(")")) {
typesNotResolved.add(arg);
} else if (!methodUnResolved) {
methodsNotResolved.add(arg);
methodUnResolved = true;
}
}
if (isMatrix)
arg = arg + "[]";
mInfo.params.add(arg);
// System.out.println("arg " + arg);
mInfo.isResolvedParam.add(resolved);
}
// System.out.println("Invocation : " + node.getExpression() + " " + mInfo.expression + " " + mInfo.methodName + " " + mInfo.params);
methodInvocations.add(mInfo);
return true;
}
public boolean visit(Block node) {
if (node != null) {
blockIterate(node, cu, bDeclarations);
}
return false;
}
});
}
}
use of org.eclipse.jdt.core.dom.ConstructorInvocation in project eclipse.jdt.ls by eclipse.
the class JDTUtils method resolveBinding.
private static IBinding resolveBinding(ASTNode node) {
if (node instanceof SimpleName) {
SimpleName simpleName = (SimpleName) node;
// workaround for https://bugs.eclipse.org/62605 (constructor name resolves to type, not method)
ASTNode normalized = ASTNodes.getNormalizedNode(simpleName);
if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
ClassInstanceCreation cic = (ClassInstanceCreation) normalized.getParent();
IMethodBinding constructorBinding = cic.resolveConstructorBinding();
if (constructorBinding == null) {
return null;
}
ITypeBinding declaringClass = constructorBinding.getDeclaringClass();
if (!declaringClass.isAnonymous()) {
return constructorBinding;
}
ITypeBinding superTypeDeclaration = declaringClass.getSuperclass().getTypeDeclaration();
return resolveSuperclassConstructor(superTypeDeclaration, constructorBinding);
}
return simpleName.resolveBinding();
} else if (node instanceof SuperConstructorInvocation) {
return ((SuperConstructorInvocation) node).resolveConstructorBinding();
} else if (node instanceof ConstructorInvocation) {
return ((ConstructorInvocation) node).resolveConstructorBinding();
} else if (node instanceof LambdaExpression) {
return ((LambdaExpression) node).resolveMethodBinding();
} else {
return null;
}
}
use of org.eclipse.jdt.core.dom.ConstructorInvocation in project eclipse.jdt.ls by eclipse.
the class ChangeSignatureProcessor method containsImplicitCallToSuperConstructor.
private static boolean containsImplicitCallToSuperConstructor(MethodDeclaration constructor) {
Assert.isTrue(constructor.isConstructor());
Block body = constructor.getBody();
if (body == null) {
return false;
}
if (body.statements().size() == 0) {
return true;
}
if (body.statements().get(0) instanceof ConstructorInvocation) {
return false;
}
if (body.statements().get(0) instanceof SuperConstructorInvocation) {
return false;
}
return true;
}
Aggregations