Lines 955-960
Link Here
|
955 |
typesFound); |
955 |
typesFound); |
956 |
} |
956 |
} |
957 |
findTypesAndPackages(this.completionToken, scope, typesFound); |
957 |
findTypesAndPackages(this.completionToken, scope, typesFound); |
|
|
958 |
if (this.assistNodeIsConstructor && |
959 |
!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) { |
960 |
findExactConstructors(this.completionToken, scope, FakeInvocationSite); |
961 |
} |
958 |
} |
962 |
} |
959 |
} else if (!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) { |
963 |
} else if (!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) { |
960 |
findMemberTypes( |
964 |
findMemberTypes( |
Lines 1257-1262
Link Here
|
1257 |
argTypes, |
1261 |
argTypes, |
1258 |
scope, |
1262 |
scope, |
1259 |
constructorCall, |
1263 |
constructorCall, |
|
|
1264 |
false, |
1260 |
false); |
1265 |
false); |
1261 |
} |
1266 |
} |
1262 |
} else if (astNode instanceof CompletionOnQualifiedAllocationExpression) { |
1267 |
} else if (astNode instanceof CompletionOnQualifiedAllocationExpression) { |
Lines 1275-1280
Link Here
|
1275 |
argTypes, |
1280 |
argTypes, |
1276 |
scope, |
1281 |
scope, |
1277 |
allocExpression, |
1282 |
allocExpression, |
|
|
1283 |
false, |
1278 |
false); |
1284 |
false); |
1279 |
} |
1285 |
} |
1280 |
if (!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION) |
1286 |
if (!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION) |
Lines 1617-1623
Link Here
|
1617 |
if (this.completionToken == null |
1623 |
if (this.completionToken == null |
1618 |
|| CharOperation.prefixEquals(this.completionToken, refBinding.sourceName) |
1624 |
|| CharOperation.prefixEquals(this.completionToken, refBinding.sourceName) |
1619 |
|| (this.options.camelCaseMatch && CharOperation.camelCaseMatch(this.completionToken, refBinding.sourceName))) { |
1625 |
|| (this.options.camelCaseMatch && CharOperation.camelCaseMatch(this.completionToken, refBinding.sourceName))) { |
1620 |
findConstructors(refBinding, null, scope, fieldRef, false); |
1626 |
findConstructors(refBinding, null, scope, fieldRef, false, false); |
1621 |
} |
1627 |
} |
1622 |
} |
1628 |
} |
1623 |
} |
1629 |
} |
Lines 1683-1689
Link Here
|
1683 |
|
1689 |
|
1684 |
ReferenceBinding ref = (ReferenceBinding) qualifiedBinding; |
1690 |
ReferenceBinding ref = (ReferenceBinding) qualifiedBinding; |
1685 |
if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF) && ref.isClass()) { |
1691 |
if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF) && ref.isClass()) { |
1686 |
findConstructors(ref, argTypes, scope, allocExpression, false); |
1692 |
findConstructors(ref, argTypes, scope, allocExpression, false, false); |
1687 |
} |
1693 |
} |
1688 |
} else if (astNode instanceof CompletionOnJavadocParamNameReference) { |
1694 |
} else if (astNode instanceof CompletionOnJavadocParamNameReference) { |
1689 |
if (!this.requestor.isIgnored(CompletionProposal.JAVADOC_PARAM_REF)) { |
1695 |
if (!this.requestor.isIgnored(CompletionProposal.JAVADOC_PARAM_REF)) { |
Lines 2186-2192
Link Here
|
2186 |
argTypes, |
2192 |
argTypes, |
2187 |
scope, |
2193 |
scope, |
2188 |
invocationSite, |
2194 |
invocationSite, |
2189 |
true); |
2195 |
true, |
|
|
2196 |
false); |
2190 |
} |
2197 |
} |
2191 |
} |
2198 |
} |
2192 |
|
2199 |
|
Lines 2309-2314
Link Here
|
2309 |
} |
2316 |
} |
2310 |
} |
2317 |
} |
2311 |
|
2318 |
|
|
|
2319 |
private void findExactConstructors(char[] token, Scope scope, InvocationSite invocationSite) { |
2320 |
ObjectVector typesFound = new ObjectVector(); |
2321 |
|
2322 |
if (token == null || token.length == 0) |
2323 |
return; |
2324 |
|
2325 |
if (scope.enclosingSourceType() != null) { |
2326 |
findExactNestedTypesConstructors( |
2327 |
token, |
2328 |
scope.enclosingSourceType(), |
2329 |
scope, |
2330 |
invocationSite, |
2331 |
typesFound); |
2332 |
} |
2333 |
|
2334 |
if (this.unitScope != null) { |
2335 |
ReferenceBinding outerInvocationType = scope.enclosingSourceType(); |
2336 |
if(outerInvocationType != null) { |
2337 |
ReferenceBinding temp = outerInvocationType.enclosingType(); |
2338 |
while(temp != null) { |
2339 |
outerInvocationType = temp; |
2340 |
temp = temp.enclosingType(); |
2341 |
} |
2342 |
} |
2343 |
|
2344 |
int typeLength = token.length; |
2345 |
SourceTypeBinding[] types = this.unitScope.topLevelTypes; |
2346 |
|
2347 |
next : for (int i = 0, length = types.length; i < length; i++) { |
2348 |
SourceTypeBinding sourceType = types[i]; |
2349 |
|
2350 |
if (isForbidden(sourceType)) continue next; |
2351 |
|
2352 |
if (sourceType.sourceName == CompletionParser.FAKE_TYPE_NAME) continue next; |
2353 |
if (sourceType.sourceName == TypeConstants.PACKAGE_INFO_NAME) continue next; |
2354 |
|
2355 |
if (typeLength != sourceType.sourceName.length) continue next; |
2356 |
|
2357 |
if (!CharOperation.equals(token, sourceType.sourceName)) continue next; |
2358 |
|
2359 |
for (int j = typesFound.size; --j >= 0;) { |
2360 |
ReferenceBinding otherType = (ReferenceBinding) typesFound.elementAt(j); |
2361 |
|
2362 |
if (sourceType == otherType) continue next; |
2363 |
} |
2364 |
|
2365 |
typesFound.add(sourceType); |
2366 |
|
2367 |
findConstructors( |
2368 |
sourceType, |
2369 |
null, |
2370 |
scope, |
2371 |
invocationSite, |
2372 |
false, |
2373 |
true); |
2374 |
} |
2375 |
} |
2376 |
|
2377 |
SingleTypeReference convertedType = new SingleTypeReference(token, 0); |
2378 |
|
2379 |
this.problemFactory.startCheckingProblems(); |
2380 |
TypeBinding guessedType = null; |
2381 |
switch (scope.kind) { |
2382 |
case Scope.METHOD_SCOPE : |
2383 |
case Scope.BLOCK_SCOPE : |
2384 |
guessedType = convertedType.resolveType((BlockScope)scope); |
2385 |
break; |
2386 |
case Scope.CLASS_SCOPE : |
2387 |
guessedType = convertedType.resolveType((ClassScope)scope); |
2388 |
break; |
2389 |
} |
2390 |
this.problemFactory.stopCheckingProblems(); |
2391 |
if (!this.problemFactory.hasForbiddenProblems && |
2392 |
guessedType instanceof ReferenceBinding && |
2393 |
!guessedType.isTypeVariable()) { |
2394 |
|
2395 |
TypeBinding erasure = guessedType.erasure(); |
2396 |
boolean alreadyFound = false; |
2397 |
for (int j = typesFound.size; --j >= 0;) { |
2398 |
ReferenceBinding otherType = (ReferenceBinding) typesFound.elementAt(j); |
2399 |
|
2400 |
if (erasure == otherType) { |
2401 |
alreadyFound = true; |
2402 |
} |
2403 |
} |
2404 |
if (!alreadyFound) { |
2405 |
typesFound.add(erasure); |
2406 |
|
2407 |
findConstructors( |
2408 |
(ReferenceBinding)erasure, |
2409 |
null, |
2410 |
scope, |
2411 |
invocationSite, |
2412 |
false, |
2413 |
true); |
2414 |
} |
2415 |
} |
2416 |
} |
2417 |
|
2418 |
private void findExactMemberTypesConstructors( |
2419 |
char[] typeName, |
2420 |
ReferenceBinding[] memberTypes, |
2421 |
ReferenceBinding receiverType, |
2422 |
SourceTypeBinding invocationType, |
2423 |
Scope scope, |
2424 |
InvocationSite invocationSite, |
2425 |
ObjectVector typesFound) { |
2426 |
|
2427 |
// Inherited member types which are hidden by subclasses are filtered out |
2428 |
// No visibility checks can be performed without the scope & invocationSite |
2429 |
int typeLength = typeName.length; |
2430 |
next : for (int m = memberTypes.length; --m >= 0;) { |
2431 |
ReferenceBinding memberType = memberTypes[m]; |
2432 |
|
2433 |
if (isForbidden(memberType)) continue next; |
2434 |
|
2435 |
if (typeLength != memberType.sourceName.length) |
2436 |
continue next; |
2437 |
|
2438 |
if (!CharOperation.equals(typeName, memberType.sourceName)) |
2439 |
continue next; |
2440 |
|
2441 |
for (int j = typesFound.size; --j >= 0;) { |
2442 |
ReferenceBinding otherType = (ReferenceBinding) typesFound.elementAt(j); |
2443 |
|
2444 |
if (memberType == otherType) continue next; |
2445 |
} |
2446 |
|
2447 |
typesFound.add(memberType); |
2448 |
|
2449 |
findConstructors( |
2450 |
memberType, |
2451 |
null, |
2452 |
scope, |
2453 |
invocationSite, |
2454 |
false, |
2455 |
true); |
2456 |
} |
2457 |
} |
2458 |
|
2459 |
private void findExactMemberTypesContructors( |
2460 |
char[] typeName, |
2461 |
ReferenceBinding receiverType, |
2462 |
Scope scope, |
2463 |
SourceTypeBinding typeInvocation, |
2464 |
SourceTypeBinding typeToIgnore, |
2465 |
InvocationSite invocationSite, |
2466 |
ObjectVector typesFound) { |
2467 |
|
2468 |
ReferenceBinding currentType = receiverType; |
2469 |
if (typeName == null) |
2470 |
return; |
2471 |
|
2472 |
if (currentType.superInterfaces() == null) return; |
2473 |
|
2474 |
if (this.insideQualifiedReference) { // do not search up the hierarchy |
2475 |
|
2476 |
findExactMemberTypesConstructors( |
2477 |
typeName, |
2478 |
currentType.memberTypes(), |
2479 |
receiverType, |
2480 |
typeInvocation, |
2481 |
scope, |
2482 |
invocationSite, |
2483 |
typesFound); |
2484 |
return; |
2485 |
} |
2486 |
|
2487 |
ReferenceBinding[] interfacesToVisit = null; |
2488 |
int nextPosition = 0; |
2489 |
|
2490 |
do { |
2491 |
ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); |
2492 |
if (itsInterfaces != Binding.NO_SUPERINTERFACES) { |
2493 |
if (interfacesToVisit == null) { |
2494 |
interfacesToVisit = itsInterfaces; |
2495 |
nextPosition = interfacesToVisit.length; |
2496 |
} else { |
2497 |
int itsLength = itsInterfaces.length; |
2498 |
if (nextPosition + itsLength >= interfacesToVisit.length) |
2499 |
System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); |
2500 |
nextInterface : for (int a = 0; a < itsLength; a++) { |
2501 |
ReferenceBinding next = itsInterfaces[a]; |
2502 |
for (int b = 0; b < nextPosition; b++) |
2503 |
if (next == interfacesToVisit[b]) continue nextInterface; |
2504 |
interfacesToVisit[nextPosition++] = next; |
2505 |
} |
2506 |
} |
2507 |
} |
2508 |
|
2509 |
findExactMemberTypesConstructors( |
2510 |
typeName, |
2511 |
currentType.memberTypes(), |
2512 |
receiverType, |
2513 |
typeInvocation, |
2514 |
scope, |
2515 |
invocationSite, |
2516 |
typesFound); |
2517 |
|
2518 |
currentType = currentType.superclass(); |
2519 |
} while (currentType != null); |
2520 |
|
2521 |
if (interfacesToVisit != null) { |
2522 |
for (int i = 0; i < nextPosition; i++) { |
2523 |
ReferenceBinding anInterface = interfacesToVisit[i]; |
2524 |
findExactMemberTypesConstructors( |
2525 |
typeName, |
2526 |
anInterface.memberTypes(), |
2527 |
receiverType, |
2528 |
typeInvocation, |
2529 |
scope, |
2530 |
invocationSite, |
2531 |
typesFound); |
2532 |
|
2533 |
ReferenceBinding[] itsInterfaces = anInterface.superInterfaces(); |
2534 |
if (itsInterfaces != Binding.NO_SUPERINTERFACES) { |
2535 |
int itsLength = itsInterfaces.length; |
2536 |
if (nextPosition + itsLength >= interfacesToVisit.length) |
2537 |
System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); |
2538 |
nextInterface : for (int a = 0; a < itsLength; a++) { |
2539 |
ReferenceBinding next = itsInterfaces[a]; |
2540 |
for (int b = 0; b < nextPosition; b++) |
2541 |
if (next == interfacesToVisit[b]) continue nextInterface; |
2542 |
interfacesToVisit[nextPosition++] = next; |
2543 |
} |
2544 |
} |
2545 |
} |
2546 |
} |
2547 |
} |
2548 |
|
2549 |
private void findExactNestedTypesConstructors( |
2550 |
char[] typeName, |
2551 |
SourceTypeBinding currentType, |
2552 |
Scope scope, |
2553 |
InvocationSite invocationSite, |
2554 |
ObjectVector typesFound) { |
2555 |
|
2556 |
if (typeName == null) |
2557 |
return; |
2558 |
|
2559 |
int typeLength = typeName.length; |
2560 |
|
2561 |
SourceTypeBinding nextTypeToIgnore = null; |
2562 |
while (scope != null) { // done when a COMPILATION_UNIT_SCOPE is found |
2563 |
|
2564 |
switch (scope.kind) { |
2565 |
|
2566 |
case Scope.METHOD_SCOPE : |
2567 |
case Scope.BLOCK_SCOPE : |
2568 |
BlockScope blockScope = (BlockScope) scope; |
2569 |
|
2570 |
next : for (int i = 0, length = blockScope.subscopeCount; i < length; i++) { |
2571 |
|
2572 |
if (blockScope.subscopes[i] instanceof ClassScope) { |
2573 |
SourceTypeBinding localType = |
2574 |
((ClassScope) blockScope.subscopes[i]).referenceContext.binding; |
2575 |
|
2576 |
if (!localType.isAnonymousType()) { |
2577 |
if (this.isForbidden(localType)) |
2578 |
continue next; |
2579 |
|
2580 |
if (typeLength != localType.sourceName.length) |
2581 |
continue next; |
2582 |
|
2583 |
if (!CharOperation.equals(typeName, localType.sourceName)) |
2584 |
continue next; |
2585 |
|
2586 |
for (int j = typesFound.size; --j >= 0;) { |
2587 |
ReferenceBinding otherType = (ReferenceBinding) typesFound.elementAt(j); |
2588 |
|
2589 |
if (localType == otherType) continue next; |
2590 |
} |
2591 |
|
2592 |
typesFound.add(localType); |
2593 |
|
2594 |
findConstructors( |
2595 |
localType, |
2596 |
null, |
2597 |
scope, |
2598 |
invocationSite, |
2599 |
false, |
2600 |
true); |
2601 |
} |
2602 |
} |
2603 |
} |
2604 |
break; |
2605 |
|
2606 |
case Scope.CLASS_SCOPE : |
2607 |
SourceTypeBinding enclosingSourceType = scope.enclosingSourceType(); |
2608 |
findExactMemberTypesContructors( |
2609 |
typeName, |
2610 |
enclosingSourceType, |
2611 |
scope, |
2612 |
currentType, |
2613 |
nextTypeToIgnore, |
2614 |
invocationSite, |
2615 |
typesFound); |
2616 |
nextTypeToIgnore = enclosingSourceType; |
2617 |
if (typeLength == 0) |
2618 |
return; // do not search outside the class scope if no prefix was provided |
2619 |
break; |
2620 |
|
2621 |
case Scope.COMPILATION_UNIT_SCOPE : |
2622 |
return; |
2623 |
} |
2624 |
scope = scope.parent; |
2625 |
} |
2626 |
} |
2627 |
|
2312 |
private void findExceptionFromTryStatement( |
2628 |
private void findExceptionFromTryStatement( |
2313 |
char[] typeName, |
2629 |
char[] typeName, |
2314 |
ReferenceBinding exceptionType, |
2630 |
ReferenceBinding exceptionType, |
Lines 2586-2592
Link Here
|
2586 |
TypeBinding[] argTypes, |
2902 |
TypeBinding[] argTypes, |
2587 |
Scope scope, |
2903 |
Scope scope, |
2588 |
InvocationSite invocationSite, |
2904 |
InvocationSite invocationSite, |
2589 |
boolean forAnonymousType) { |
2905 |
boolean forAnonymousType, |
|
|
2906 |
boolean forExactConstructors) { |
2907 |
|
2908 |
char[] simpleTypename = currentType.sourceName; |
2590 |
|
2909 |
|
2591 |
// No visibility checks can be performed without the scope & invocationSite |
2910 |
// No visibility checks can be performed without the scope & invocationSite |
2592 |
MethodBinding[] methods = currentType.availableMethods(); |
2911 |
MethodBinding[] methods = currentType.availableMethods(); |
Lines 2662-2667
Link Here
|
2662 |
this.printDebug(proposal); |
2981 |
this.printDebug(proposal); |
2663 |
} |
2982 |
} |
2664 |
} |
2983 |
} |
|
|
2984 |
} else if (forExactConstructors) { |
2985 |
if (this.source != null |
2986 |
&& this.source.length > this.endPosition |
2987 |
&& this.source[this.endPosition] == '(') { |
2988 |
completion = simpleTypename; |
2989 |
} else { |
2990 |
completion = CharOperation.concat(simpleTypename, new char[] { '(', ')' }); |
2991 |
} |
2992 |
|
2993 |
int relevance = computeBaseRelevance(); |
2994 |
relevance += computeRelevanceForResolution(); |
2995 |
relevance += computeRelevanceForInterestingProposal(); |
2996 |
relevance += computeRelevanceForCaseMatching(simpleTypename, simpleTypename); |
2997 |
relevance += computeRelevanceForExpectingType(currentType); |
2998 |
relevance += computeRelevanceForQualification(false); |
2999 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for type in the current unit |
3000 |
relevance += R_CONSTRUCTOR; |
3001 |
|
3002 |
// Create standard proposal |
3003 |
this.noProposal = false; |
3004 |
if(!this.requestor.isIgnored(CompletionProposal.METHOD_REF) && (this.assistNodeInJavadoc & CompletionOnJavadoc.ONLY_INLINE_TAG) == 0) { |
3005 |
CompletionProposal proposal = this.createProposal(CompletionProposal.METHOD_REF, this.actualCompletionPosition); |
3006 |
proposal.setDeclarationSignature(getSignature(currentType)); |
3007 |
proposal.setSignature(getSignature(constructor)); |
3008 |
MethodBinding original = constructor.original(); |
3009 |
if(original != constructor) { |
3010 |
proposal.setOriginalSignature(getSignature(original)); |
3011 |
} |
3012 |
proposal.setDeclarationPackageName(currentType.qualifiedPackageName()); |
3013 |
proposal.setDeclarationTypeName(currentType.qualifiedSourceName()); |
3014 |
proposal.setParameterPackageNames(parameterPackageNames); |
3015 |
proposal.setParameterTypeNames(parameterTypeNames); |
3016 |
//proposal.setPackageName(null); |
3017 |
//proposal.setTypeName(null); |
3018 |
proposal.setName(currentType.sourceName()); |
3019 |
proposal.setIsContructor(true); |
3020 |
proposal.setCompletion(completion); |
3021 |
proposal.setFlags(constructor.modifiers); |
3022 |
proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); |
3023 |
proposal.setRelevance(relevance); |
3024 |
if(parameterNames != null) proposal.setParameterNames(parameterNames); |
3025 |
this.requestor.accept(proposal); |
3026 |
if(DEBUG) { |
3027 |
this.printDebug(proposal); |
3028 |
} |
3029 |
} |
2665 |
} else { |
3030 |
} else { |
2666 |
int relevance = computeBaseRelevance(); |
3031 |
int relevance = computeBaseRelevance(); |
2667 |
relevance += computeRelevanceForResolution(); |
3032 |
relevance += computeRelevanceForResolution(); |