use of org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding in project che by eclipse.
the class HandleFactory method createElement.
/**
* Create handle by adding child to parent obtained by recursing into parent scopes.
*/
public IJavaElement createElement(Scope scope, int elementPosition, ICompilationUnit unit, HashSet existingElements, HashMap knownScopes) {
IJavaElement newElement = (IJavaElement) knownScopes.get(scope);
if (newElement != null)
return newElement;
switch(scope.kind) {
case Scope.COMPILATION_UNIT_SCOPE:
newElement = unit;
break;
case Scope.CLASS_SCOPE:
IJavaElement parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
switch(parentElement.getElementType()) {
case IJavaElement.COMPILATION_UNIT:
newElement = ((ICompilationUnit) parentElement).getType(new String(scope.enclosingSourceType().sourceName));
break;
case IJavaElement.TYPE:
newElement = ((IType) parentElement).getType(new String(scope.enclosingSourceType().sourceName));
break;
case IJavaElement.FIELD:
case IJavaElement.INITIALIZER:
case IJavaElement.METHOD:
IMember member = (IMember) parentElement;
if (member.isBinary()) {
return null;
} else {
newElement = member.getType(new String(scope.enclosingSourceType().sourceName), 1);
// increment occurrence count if collision is detected
if (newElement != null) {
while (!existingElements.add(newElement)) ((SourceRefElement) newElement).occurrenceCount++;
}
}
break;
}
if (newElement != null) {
knownScopes.put(scope, newElement);
}
break;
case Scope.METHOD_SCOPE:
if (scope.isLambdaScope()) {
parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
LambdaExpression expression = (LambdaExpression) scope.originalReferenceContext();
if (expression.resolvedType != null && expression.resolvedType.isValidBinding() && !(expression.descriptor instanceof ProblemMethodBinding)) {
// chain in lambda element only if resolved properly.
//newElement = new org.eclipse.jdt.internal.core.SourceLambdaExpression((JavaElement) parentElement, expression).getMethod();
newElement = LambdaFactory.createLambdaExpression((JavaElement) parentElement, expression).getMethod();
knownScopes.put(scope, newElement);
return newElement;
}
return parentElement;
}
IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
MethodScope methodScope = (MethodScope) scope;
if (methodScope.isInsideInitializer()) {
// inside field or initializer, must find proper one
TypeDeclaration type = methodScope.referenceType();
int occurenceCount = 1;
int length = type.fields == null ? 0 : type.fields.length;
for (int i = 0; i < length; i++) {
FieldDeclaration field = type.fields[i];
if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) {
switch(field.getKind()) {
case AbstractVariableDeclaration.FIELD:
case AbstractVariableDeclaration.ENUM_CONSTANT:
newElement = parentType.getField(new String(field.name));
break;
case AbstractVariableDeclaration.INITIALIZER:
newElement = parentType.getInitializer(occurenceCount);
break;
}
break;
} else if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
occurenceCount++;
}
}
} else {
// method element
AbstractMethodDeclaration method = methodScope.referenceMethod();
newElement = parentType.getMethod(new String(method.selector), Util.typeParameterSignatures(method));
if (newElement != null) {
knownScopes.put(scope, newElement);
}
}
break;
case Scope.BLOCK_SCOPE:
// standard block, no element per se
newElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
break;
}
return newElement;
}
use of org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding in project lombok by rzwitserloot.
the class PatchExtensionMethod method resolveType.
public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend methodCall, BlockScope scope) {
List<Extension> extensions = new ArrayList<Extension>();
TypeDeclaration decl = scope.classScope().referenceContext;
EclipseNode owningType = null;
for (EclipseNode typeNode = getTypeNode(decl); typeNode != null; typeNode = upToType(typeNode)) {
Annotation ann = getAnnotation(ExtensionMethod.class, typeNode);
if (ann != null) {
extensions.addAll(0, getApplicableExtensionMethods(typeNode, ann, methodCall.receiver.resolvedType));
if (owningType == null)
owningType = typeNode;
}
}
boolean skip = false;
if (methodCall.receiver instanceof ThisReference && (((ThisReference) methodCall.receiver).bits & ASTNode.IsImplicitThis) != 0)
skip = true;
if (methodCall.receiver instanceof SuperReference)
skip = true;
if (methodCall.receiver instanceof NameReference) {
Binding binding = ((NameReference) methodCall.receiver).binding;
if (binding instanceof TypeBinding)
skip = true;
}
if (!skip)
for (Extension extension : extensions) {
if (!extension.suppressBaseMethods && !(methodCall.binding instanceof ProblemMethodBinding))
continue;
for (MethodBinding extensionMethod : extension.extensionMethods) {
if (!Arrays.equals(methodCall.selector, extensionMethod.selector))
continue;
MessageSend_postponedErrors.clear(methodCall);
if (methodCall.receiver instanceof ThisReference) {
methodCall.receiver.bits &= ~ASTNode.IsImplicitThis;
}
List<Expression> arguments = new ArrayList<Expression>();
arguments.add(methodCall.receiver);
if (methodCall.arguments != null)
arguments.addAll(Arrays.asList(methodCall.arguments));
List<TypeBinding> argumentTypes = new ArrayList<TypeBinding>();
for (Expression argument : arguments) {
if (argument.resolvedType != null)
argumentTypes.add(argument.resolvedType);
// TODO: Instead of just skipping nulls entirely, there is probably a 'unresolved type' placeholder. THAT is what we ought to be adding here!
}
Expression[] originalArgs = methodCall.arguments;
methodCall.arguments = arguments.toArray(new Expression[0]);
MethodBinding fixedBinding = scope.getMethod(extensionMethod.declaringClass, methodCall.selector, argumentTypes.toArray(new TypeBinding[0]), methodCall);
if (fixedBinding instanceof ProblemMethodBinding) {
methodCall.arguments = originalArgs;
if (fixedBinding.declaringClass != null) {
PostponedInvalidMethodError.invoke(scope.problemReporter(), methodCall, fixedBinding, scope);
}
} else {
for (int i = 0, iend = arguments.size(); i < iend; i++) {
Expression arg = arguments.get(i);
if (fixedBinding.parameters[i].isArrayType() != arg.resolvedType.isArrayType())
break;
if (arg instanceof MessageSend) {
((MessageSend) arg).valueCast = arg.resolvedType;
}
if (!fixedBinding.parameters[i].isBaseType() && arg.resolvedType.isBaseType()) {
int id = arg.resolvedType.id;
// magic see TypeIds
arg.implicitConversion = TypeIds.BOXING | (id + (id << 4));
} else if (fixedBinding.parameters[i].isBaseType() && !arg.resolvedType.isBaseType()) {
int id = fixedBinding.parameters[i].id;
// magic see TypeIds
arg.implicitConversion = TypeIds.UNBOXING | (id + (id << 4));
}
}
methodCall.receiver = createNameRef(extensionMethod.declaringClass, methodCall);
methodCall.actualReceiverType = extensionMethod.declaringClass;
methodCall.binding = fixedBinding;
methodCall.resolvedType = methodCall.binding.returnType;
}
return methodCall.resolvedType;
}
}
PostponedError error = MessageSend_postponedErrors.get(methodCall);
if (error != null)
error.fire();
MessageSend_postponedErrors.clear(methodCall);
return resolvedType;
}
Aggregations