List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding isDefault
public final boolean isDefault()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
/** * Returns whether the code gen will use an invoke virtual for * this message send or not.// w w w . j av a 2 s . co m */ protected boolean isVirtualInvoke(MethodBinding method, MessageSend messageSend) { return !method.isStatic() && !method.isPrivate() && !messageSend.isSuperAccess() && !(method.isDefault() && this.pattern.focus != null && !CharOperation .equals(this.pattern.declaringPackageName, method.declaringClass.qualifiedPackageName())); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
public int resolveLevel(Binding binding) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof MethodBinding)) return IMPOSSIBLE_MATCH; MethodBinding method = (MethodBinding) binding; boolean skipVerif = this.pattern.findDeclarations && this.mayBeGeneric; int methodLevel = matchMethod(method, skipVerif); if (methodLevel == IMPOSSIBLE_MATCH) { if (method != method.original()) methodLevel = matchMethod(method.original(), skipVerif); if (methodLevel == IMPOSSIBLE_MATCH) { return IMPOSSIBLE_MATCH; } else {/*ww w . java 2s . co m*/ method = method.original(); } } // declaring type if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do boolean subType = !method.isStatic() && !method.isPrivate(); if (subType && this.pattern.declaringQualification != null && method.declaringClass != null && method.declaringClass.fPackage != null) { subType = CharOperation.compareWith(this.pattern.declaringQualification, method.declaringClass.fPackage.shortReadableName()) == 0; } int declaringLevel = subType ? resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass, method.selector, null, method.declaringClass.qualifiedPackageName(), method.isDefault()) : resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass); return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
protected int resolveLevel(MessageSend messageSend) { MethodBinding method = messageSend.binding; if (method == null) { return INACCURATE_MATCH; }/* ww w . j ava2 s .co m*/ if (messageSend.resolvedType == null) { // Closest match may have different argument numbers when ProblemReason is NotFound // see MessageSend#resolveType(BlockScope) // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=97322 int argLength = messageSend.arguments == null ? 0 : messageSend.arguments.length; if (this.pattern.parameterSimpleNames == null || argLength == this.pattern.parameterSimpleNames.length) { return INACCURATE_MATCH; } return IMPOSSIBLE_MATCH; } int methodLevel = matchMethod(method, false); if (methodLevel == IMPOSSIBLE_MATCH) { if (method != method.original()) methodLevel = matchMethod(method.original(), false); if (methodLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; method = method.original(); } // receiver type if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do int declaringLevel; if (isVirtualInvoke(method, messageSend) && (messageSend.actualReceiverType instanceof ReferenceBinding)) { ReferenceBinding methodReceiverType = (ReferenceBinding) messageSend.actualReceiverType; declaringLevel = resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, methodReceiverType, method.selector, method.parameters, methodReceiverType.qualifiedPackageName(), method.isDefault()); if (declaringLevel == IMPOSSIBLE_MATCH) { if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) { declaringLevel = INACCURATE_MATCH; } else { char[][][] superTypeNames = (method.isDefault() && this.pattern.focus == null) ? this.samePkgSuperDeclaringTypeNames : this.allSuperDeclaringTypeNames; if (superTypeNames != null && resolveLevelAsSuperInvocation(methodReceiverType, method.parameters, superTypeNames, true)) { declaringLevel = methodLevel // since this is an ACCURATE_MATCH so return the possibly weaker match | SUPER_INVOCATION_FLAVOR; // this is an overridden method => add flavor to returned level } } } if ((declaringLevel & FLAVORS_MASK) != 0) { // level got some flavors => return it return declaringLevel; } } else { declaringLevel = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass); } return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match }
From source file:com.google.gwt.dev.jjs.ast.AccessModifier.java
License:Apache License
public static AccessModifier fromMethodBinding(MethodBinding methodBinding) { if (methodBinding.isPublic()) { return PUBLIC; } else if (methodBinding.isProtected()) { return PROTECTED; } else if (methodBinding.isPrivate()) { return PRIVATE; }/*from w w w. ja v a 2 s . co m*/ assert methodBinding.isDefault(); return DEFAULT; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTMethod.java
License:Open Source License
public JDTMethod(JDTClass enclosingClass, MethodBinding method) { this.enclosingClass = enclosingClass; bindingRef = new WeakReference<MethodBinding>(method); name = new String(method.selector); readableName = new String(method.readableName()); isStatic = method.isStatic();//from ww w.j a va 2s .com isPublic = method.isPublic(); isConstructor = method.isConstructor(); isStaticInit = method.selector == TypeConstants.CLINIT; // TODO : check if it is right isAbstract = method.isAbstract(); isFinal = method.isFinal(); isProtected = method.isProtected(); isDefaultAccess = method.isDefault(); isDeclaredVoid = method.returnType.id == TypeIds.T_void; isVariadic = method.isVarargs(); isDefault = method.getDefaultValue() != null; bindingKey = method.computeUniqueKey(); if (method instanceof ProblemMethodBinding) { annotations = new HashMap<>(); parameters = Collections.emptyList(); returnType = JDTType.UNKNOWN_TYPE; typeParameters = Collections.emptyList(); isOverriding = false; isOverloading = false; } }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MethodLocator.java
License:Open Source License
public int resolveLevel(Binding binding) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof MethodBinding)) return IMPOSSIBLE_MATCH; MethodBinding method = (MethodBinding) binding; boolean skipVerif = this.pattern.findDeclarations && this.mayBeGeneric; int methodLevel = matchMethod(method, skipVerif); if (methodLevel == IMPOSSIBLE_MATCH) { if (method != method.original()) methodLevel = matchMethod(method.original(), skipVerif); if (methodLevel == IMPOSSIBLE_MATCH) { return IMPOSSIBLE_MATCH; } else {//from w ww . ja v a2 s . com method = method.original(); } } // declaring type if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any // declaring class will do boolean subType = !method.isStatic() && !method.isPrivate(); if (subType && this.pattern.declaringQualification != null && method.declaringClass != null && method.declaringClass.fPackage != null) { subType = CharOperation.compareWith(this.pattern.declaringQualification, method.declaringClass.fPackage.shortReadableName()) == 0; } int declaringLevel = subType ? resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass, method.selector, null, method.declaringClass.qualifiedPackageName(), method.isDefault()) : resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass); return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MethodLocator.java
License:Open Source License
protected int resolveLevel(MessageSend messageSend) { MethodBinding method = messageSend.binding; if (method == null) { return INACCURATE_MATCH; }//from ww w.j a v a 2 s. c om if (messageSend.resolvedType == null) { // Closest match may have different argument numbers when ProblemReason is NotFound // see MessageSend#resolveType(BlockScope) // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=97322 int argLength = messageSend.arguments == null ? 0 : messageSend.arguments.length; if (this.pattern.parameterSimpleNames == null || argLength == this.pattern.parameterSimpleNames.length) { return INACCURATE_MATCH; } return IMPOSSIBLE_MATCH; } int methodLevel = matchMethod(method, false); if (methodLevel == IMPOSSIBLE_MATCH) { if (method != method.original()) methodLevel = matchMethod(method.original(), false); if (methodLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; method = method.original(); } // receiver type if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do int declaringLevel; if (isVirtualInvoke(method, messageSend) && (messageSend.actualReceiverType instanceof ReferenceBinding)) { ReferenceBinding methodReceiverType = (ReferenceBinding) messageSend.actualReceiverType; declaringLevel = resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, methodReceiverType, method.selector, method.parameters, methodReceiverType.qualifiedPackageName(), method.isDefault()); if (declaringLevel == IMPOSSIBLE_MATCH) { if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) { declaringLevel = INACCURATE_MATCH; } else { char[][][] superTypeNames = (method.isDefault() && this.pattern.focus == null) ? this.samePkgSuperDeclaringTypeNames : this.allSuperDeclaringTypeNames; if (superTypeNames != null && resolveLevelAsSuperInvocation(methodReceiverType, method.parameters, superTypeNames, true)) { declaringLevel = methodLevel // since this is an ACCURATE_MATCH so return the possibly weaker match | SUPER_INVOCATION_FLAVOR; // this is an overridden method => add flavor to returned level } } } if ((declaringLevel & FLAVORS_MASK) != 0) { // level got some flavors => return it return declaringLevel; } } else { declaringLevel = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass); } return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker // match }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java
License:Open Source License
/** * Generate creation methods for a given role constructor. * for concrete R:/*from ww w .j a va 2s . c o m*/ * R _OT$createR (mySignature) { return new __OT__R(myArgs); } * for abstract R: * abstract R _OT$createR (mySignature); * If role is inherited from super-Team, repeat creation method with * same signature but creating an instance of the local role type. * * @param teamDeclaration the team class to hold the creation method * @param roleModel the role to instantiate * @param constructor use this as a template to create the creation method, may be null. * @param constructorBinding non-null representation of constructor * @param needMethodBody used to signal whether generating statements is required * @return the creation method. */ public static MethodDeclaration createCreationMethod(TypeDeclaration teamDeclaration, RoleModel roleModel, ConstructorDeclaration constructor, MethodBinding constructorBinding, boolean needMethodBody) { int start, end; int modifiers; boolean hasError = false; if (constructor != null) { if (constructor.isTSuper || constructor.hasErrors()) return null; if (constructor.isDefaultConstructor() && roleModel.hasBaseclassProblem()) hasError = true; start = constructor.sourceStart; end = constructor.sourceEnd; modifiers = constructor.modifiers; constructorBinding = constructor.binding; } else { if (TSuperHelper.isTSuper(constructorBinding)) return null; start = teamDeclaration.sourceStart; end = teamDeclaration.sourceEnd; modifiers = constructorBinding.modifiers; } int originalModifiers = -1; // creation method must access constructor, make it at least protected: if (constructorBinding != null && (constructorBinding.isDefault() || constructorBinding.isPrivate())) { originalModifiers = constructorBinding.modifiers; MethodModel.getModel(constructorBinding).storeModifiers(originalModifiers); } AstGenerator gen = new AstGenerator(start, end); gen.replaceableEnclosingClass = teamDeclaration.binding; Argument[] newArguments = null; // Arguments (construct from bindings, using dummy names): if (constructorBinding != null) { TypeBinding[] srcParams = constructorBinding.parameters; if (srcParams != null) { newArguments = AstConverter.createArgumentsFromParameters(srcParams, gen); if (srcParams.length == 1 && TypeBinding.equalsEquals(srcParams[0], roleModel.getInterfacePartBinding())) { // single argument of type of this role itself? if (constructorBinding.isPrivate() || constructorBinding.isDefault()) roleModel.getAst().scope.problemReporter() .roleConstructorHiddenByLiftingConstructor(constructor); } if (Lifting.isLiftingCtor(constructorBinding)) { gen.addNonNullAnnotation(newArguments[0], teamDeclaration.scope.environment()); } } } if (newArguments != null && constructorBinding != null && Lifting.isLiftingCtor(constructorBinding)) newArguments[0].type.setBaseclassDecapsulation(DecapsulationState.REPORTED); // if we have source arguments, improve: use correct argument names: if (newArguments != null && constructor != null) { Argument[] srcArguments = constructor.arguments; if (srcArguments != null && srcArguments.length == newArguments.length) for (int i = 0; i < srcArguments.length; i++) newArguments[i].name = srcArguments[i].name; } TypeReference[] exceptions = null; if (constructor != null) { if (constructor.thrownExceptions != null) exceptions = AstClone.copyTypeArray(constructor.thrownExceptions); } else if (constructorBinding != null) { if (constructorBinding.thrownExceptions != Binding.NO_EXCEPTIONS) exceptions = AstClone.copyExceptions(constructorBinding, gen); } else { throw new InternalCompilerError("Either constructor or constructorBinding must be nonnull"); //$NON-NLS-1$ } MethodDeclaration newMethod = internalCreateCreationMethod(teamDeclaration, roleModel, modifiers, newArguments, exceptions, needMethodBody && !hasError, start, end); if (hasError) newMethod.tagAsHavingErrors(); if (newMethod != null) { MethodModel model = MethodModel.getModel(newMethod); model._srcCtor = constructorBinding; if (originalModifiers != -1) model.storeModifiers(originalModifiers); } if (newMethod != null && constructor != null) // faked source locations (binaries have no source poss, but compiled constructor has no errors.) AstClone.copySrcLocation(constructor, newMethod); return newMethod; }