//List<Tree> treeNodes = linearizeTree(expTrees);
if (treeNodes == null) return null;
if (indexes == null) return null;
int length = treeNodes.size();
List<EditorContext.Operation> operations = new ArrayList<EditorContext.Operation>(length);
LineMap lineMap = cu.getLineMap();
int indexesIndex = 0;
int from = indexes[indexesIndex];
int to = indexes[indexesIndex + 1];
for (int treeIndex = 0; treeIndex < length; treeIndex++) {
Tree node = treeNodes.get(treeIndex);
Tree.Kind kind = node.getKind();
EditorContext.Operation op = null;
if (kind.equals(Tree.Kind.METHOD_INVOCATION) ||
kind.equals(Tree.Kind.NEW_CLASS)) {
int opcode;
do {
do {
opcode = bytecodes[from] & 0xFF;
if (isMethodCall(opcode)) {
break;
}
from += getInstrSize(opcode, bytecodes, from);
} while (from < to);
if (from < to) {
break;
}
if ((indexesIndex + 2) < indexes.length) {
indexesIndex += 2;
from = indexes[indexesIndex];
to = indexes[indexesIndex + 1];
} else {
break;
}
} while (true);
if (from < to) { // We have the method call
if (!ci.getTreeUtilities().isSynthetic(ci.getTrees().getPath(cu, node))) {
int pos = (int) sp.getStartPosition(cu, node);
EditorContext.Position startPosition =
opCreationDelegate.createPosition(
pos,
(int) lineMap.getLineNumber(pos),
(int) lineMap.getColumnNumber(pos)
);
pos = (int) sp.getEndPosition(cu, node);
EditorContext.Position endPosition =
opCreationDelegate.createPosition(
pos,
(int) lineMap.getLineNumber(pos),
(int) lineMap.getColumnNumber(pos)
);
Tree identifier;
String methodName;
String methodClassType;
boolean getStartPosFromMethodLength = false;
if (kind.equals(Tree.Kind.NEW_CLASS)) {
identifier = ((NewClassTree) node).getIdentifier();
methodName = "<init>";
TreePath iPath = TreePath.getPath(cu, identifier);
TypeMirror type = trees.getTypeMirror(iPath);
if (type.getKind() == TypeKind.ERROR) {
// There are errors, give it up.
return null;
}
assert type.getKind() == TypeKind.DECLARED;
TypeElement te = (TypeElement) types.asElement(type);
methodClassType = ElementUtilities.getBinaryName(te);
} else {
//identifier = ((MemberSelectTree) ((MethodInvocationTree) node).getMethodSelect()).getIdentifier();
identifier = ((MethodInvocationTree) node).getMethodSelect();
if (identifier.getKind() == Tree.Kind.IDENTIFIER) {
methodName = ((IdentifierTree) identifier).getName().toString();
TreePath iPath = TreePath.getPath(cu, identifier);
TypeElement te = trees.getScope(iPath).getEnclosingClass();
if (te == null) {
// No enclosing class? Some error, give it up.
return null;
}
methodClassType = ElementUtilities.getBinaryName(te);
} else {
methodName = ((MemberSelectTree) identifier).getIdentifier().toString();
getStartPosFromMethodLength = true;
ExpressionTree exp = ((MemberSelectTree) identifier).getExpression();
TreePath expPath = TreePath.getPath(cu, exp);
TypeMirror type = trees.getTypeMirror(expPath);
if (type.getKind() == TypeKind.ERROR) {
// There are errors, give it up.
return null;
}
TypeElement te;
if (type.getKind() == TypeKind.DECLARED) {
te = (TypeElement) types.asElement(type);
} else if (type.getKind() == TypeKind.TYPEVAR) {
TypeParameterElement tpe = (TypeParameterElement) types.asElement(type);
List<? extends TypeMirror> exts = tpe.getBounds();
if (exts.size() == 1) {
type = exts.get(0);
if (type.getKind() == TypeKind.DECLARED) {
te = (TypeElement) types.asElement(type);
} else {
return null; // Unsupported
}
} else {
return null; // Unsupported
}
} else {
ErrorManager.getDefault().notify(new IllegalStateException("Unexpected type "+type+" in "+treeNodes));
return null;
}
methodClassType = ElementUtilities.getBinaryName(te);
}
}
pos = (int) sp.getEndPosition(cu, identifier);
EditorContext.Position methodEndPosition =
opCreationDelegate.createPosition(
pos,
(int) lineMap.getLineNumber(pos),
(int) lineMap.getColumnNumber(pos)
);
if (getStartPosFromMethodLength) {
pos = pos - methodName.length();
} else {
pos = (int) sp.getStartPosition(cu, identifier);
}
EditorContext.Position methodStartPosition =
opCreationDelegate.createPosition(
pos,
(int) lineMap.getLineNumber(pos),
(int) lineMap.getColumnNumber(pos)
);
/*
EditorContext.Operation op =
opCreationDelegate.createOperation(
startPosition,