List of usage examples for org.eclipse.jdt.core Flags isDefaultMethod
public static boolean isDefaultMethod(int flags)
AccDefaultMethod bit set. From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isDefaultMethod(IMethod method) throws JavaModelException { return Flags.isDefaultMethod(method.getFlags()); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isAbstract(IMember member) throws JavaModelException { int flags = member.getFlags(); if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) { return !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags); }/*from www . j a v a 2s . co m*/ return Flags.isAbstract(flags); }
From source file:io.sarl.eclipse.util.Jdt2Ecore.java
License:Apache License
/** Analyzing the type hierarchy of the given element, and * extract any type-related information. * * <p>The type finder could be obtained with {@link #toTypeFinder(IJavaProject)}. * * @param typeFinder - the type finder to be used for finding the type definitions. * @param finalOperations - filled with the final operations inherited by the element. * @param overridableOperations - filled with the oervrideable operations inherited by the element. * @param inheritedFields - filled with the fields inherited by the element. * @param operationsToImplement - filled with the abstract operations inherited by the element. * @param superConstructors - filled with the construstors of the super type. * @param superClass - the name of the super class. * @param superInterfaces - the super interfaces. * @return the status of the operation./*w w w .j a v a2s. c o m*/ * @throws JavaModelException if the Java model is invalid. * @see #toTypeFinder(IJavaProject) */ @SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:nestedifdepth", "checkstyle:parameternumber" }) public IStatus populateInheritanceContext(TypeFinder typeFinder, Map<ActionPrototype, IMethod> finalOperations, Map<ActionPrototype, IMethod> overridableOperations, Map<String, IField> inheritedFields, Map<ActionPrototype, IMethod> operationsToImplement, Map<ActionParameterTypes, IMethod> superConstructors, String superClass, List<String> superInterfaces) throws JavaModelException { final Set<ActionPrototype> treatedElements = new TreeSet<>(); final SARLEclipsePlugin plugin = SARLEclipsePlugin.getDefault(); final List<IStatus> statuses = new ArrayList<>(); // Get the operations that must be implemented if (operationsToImplement != null) { final SuperTypeIterator typeIterator = new SuperTypeIterator(typeFinder, true, superInterfaces); while (typeIterator.hasNext()) { final IType type = typeIterator.next(); for (final IMethod operation : type.getMethods()) { if (!Flags.isStatic(operation.getFlags()) && !Flags.isFinal(operation.getFlags()) && !operation.isLambdaMethod() && !operation.isConstructor()) { final ActionParameterTypes sig = this.actionPrototypeProvider.createParameterTypes( Flags.isVarargs(operation.getFlags()), getFormalParameterProvider(operation)); final ActionPrototype actionKey = this.actionPrototypeProvider .createActionPrototype(operation.getElementName(), sig); if (treatedElements.add(actionKey)) { if (Flags.isDefaultMethod(operation.getFlags())) { if (!overridableOperations.containsKey(actionKey)) { overridableOperations.put(actionKey, operation); } } else { if (!operationsToImplement.containsKey(actionKey)) { operationsToImplement.put(actionKey, operation); } } } } } } statuses.addAll(typeIterator.getStatuses()); } // Check on the implemented features, inherited from the super type if (isValidSuperType(superClass)) { final SuperTypeIterator typeIterator = new SuperTypeIterator(typeFinder, false, superClass); while (typeIterator.hasNext()) { final IType type = typeIterator.next(); final boolean checkForConstructors = superConstructors != null && type.getFullyQualifiedName().equals(superClass); for (final IMethod operation : type.getMethods()) { if (!Flags.isStatic(operation.getFlags()) && !operation.isLambdaMethod() && isVisible(typeFinder, type, operation)) { if (!operation.isConstructor() && !Utils.isHiddenMember(operation.getElementName())) { final ActionParameterTypes sig = this.actionPrototypeProvider.createParameterTypes( Flags.isVarargs(operation.getFlags()), getFormalParameterProvider(operation)); final ActionPrototype actionKey = this.actionPrototypeProvider .createActionPrototype(operation.getElementName(), sig); if (treatedElements.add(actionKey)) { final int flags = operation.getFlags(); if (Flags.isAbstract(flags) && !Flags.isDefaultMethod(flags)) { if (operationsToImplement != null) { operationsToImplement.put(actionKey, operation); } } else if (Flags.isFinal(flags)) { if (finalOperations != null) { finalOperations.put(actionKey, operation); } if (operationsToImplement != null) { operationsToImplement.remove(actionKey); } } else { if (overridableOperations != null) { overridableOperations.put(actionKey, operation); } if (operationsToImplement != null) { operationsToImplement.remove(actionKey); } } } } else if (checkForConstructors && operation.isConstructor() && superConstructors != null) { final ActionParameterTypes sig = this.actionPrototypeProvider.createParameterTypes( Flags.isVarargs(operation.getFlags()), getFormalParameterProvider(operation)); superConstructors.put(sig, operation); } } } if (inheritedFields != null) { for (final IField field : type.getFields()) { if (!Flags.isStatic(field.getFlags()) && !Utils.isHiddenMember(field.getElementName()) && isVisible(typeFinder, type, field)) { inheritedFields.putIfAbsent(field.getElementName(), field); } } } } statuses.addAll(typeIterator.getStatuses()); } if (statuses.isEmpty()) { return plugin.createOkStatus(); } if (statuses.size() == 1) { return statuses.get(0); } return plugin.createMultiStatus(statuses); }
From source file:org.eclipse.objectteams.otdt.debug.ui.internal.actions.OTToggleBreakpointAdapter.java
License:Open Source License
/** * Returns the methods from the selection, or an empty array * @param selection the selection to get the methods from * @return an array of the methods from the selection or an empty array *//*from w w w. j av a 2s.c o m*/ protected IMethod[] getMethods(IStructuredSelection selection, boolean isInterace) { if (selection.isEmpty()) { return new IMethod[0]; } List<IMethod> methods = new ArrayList<IMethod>(selection.size()); Iterator<?> iterator = selection.iterator(); while (iterator.hasNext()) { Object thing = iterator.next(); try { if (thing instanceof IMethod) { IMethod method = (IMethod) thing; if (isInterace) { if (Flags.isDefaultMethod(method.getFlags()) || Flags.isStatic(method.getFlags())) methods.add(method); } else if (!Flags.isAbstract(method.getFlags())) { methods.add(method); } } } catch (JavaModelException e) { } } return methods.toArray(new IMethod[methods.size()]); }
From source file:org.eclipse.objectteams.otdt.debug.ui.internal.actions.OTToggleBreakpointAdapter.java
License:Open Source License
/** * Returns the methods from the selection, or an empty array * @param selection the selection to get the methods from * @return an array of the methods from the selection or an empty array *//*from w w w .j av a 2 s. c o m*/ protected IMethod[] getInterfaceMethods(IStructuredSelection selection) { if (selection.isEmpty()) { return new IMethod[0]; } List<IMethod> methods = new ArrayList<IMethod>(selection.size()); Iterator<?> iterator = selection.iterator(); while (iterator.hasNext()) { Object thing = iterator.next(); try { if (thing instanceof IMethod) { IMethod method = (IMethod) thing; if (Flags.isDefaultMethod(method.getFlags())) { methods.add(method); } } } catch (JavaModelException e) { } } return methods.toArray(new IMethod[methods.size()]); }
From source file:org.eclipse.pde.api.tools.internal.builder.TagValidator.java
License:Open Source License
/** * Processes all of the tags for the given {@link MethodDeclaration} * /*from w ww . j a v a 2 s. c o m*/ * @param method * @param tags * @since 1.0.400 */ void processMethodNode(MethodDeclaration method, List<TagElement> tags) { int pkind = getParentKind(method); int mods = method.getModifiers(); boolean isconstructor = method.isConstructor(); boolean isstatic = Flags.isStatic(mods); Item item = getItem(); Set<String> supportedtags = getSupportedTagNames(pkind, isconstructor ? IApiJavadocTag.MEMBER_CONSTRUCTOR : IApiJavadocTag.MEMBER_METHOD); HashSet<String> processed = new HashSet<String>(); for (TagElement tag : tags) { String tagname = tag.getTagName(); if (tagname == null || !JavadocTagManager.ALL_TAGS.contains(tagname)) { continue; } if (processed.contains(tagname)) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.DUPLICATE_TAG_USE, IApiMarkerConstants.DUPLICATE_TAG_MARKER_ID, null); } else { switch (pkind) { case IApiJavadocTag.TYPE_ENUM: { if (!supportedtags.contains(tagname)) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_an_enum_method); } else if (Flags.isPrivate(mods)) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_private_enum_method); } else if (Flags.isPackageDefault(mods)) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_a_package_default_enum); } else if (!item.visible) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_not_visible_enum_method); } break; } case IApiJavadocTag.TYPE_INTERFACE: { if (!supportedtags.contains(tagname)) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_an_interface_method); } else if (!item.visible) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_not_visible_interface_method); } else if (!Flags.isDefaultMethod(mods) && JavadocTagManager.TAG_NOOVERRIDE.equals(tagname)) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_nondefault_interface_method); } break; } case IApiJavadocTag.TYPE_CLASS: { if (!supportedtags.contains(tagname)) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_a_constructor : BuilderMessages.TagValidator_a_method); } else if (Flags.isPrivate(mods)) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_private_constructor : BuilderMessages.TagValidator_private_method); } else if (Flags.isPackageDefault(mods)) { if (isstatic) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_static_package_constructor : BuilderMessages.TagValidator_a_static_package_default_method); } else { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_a_package_default_constructor : BuilderMessages.TagValidator_a_package_default_method); } } else if (JavadocTagManager.TAG_NOOVERRIDE.equals(tagname)) { if (Flags.isFinal(mods)) { if (isstatic) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_static_final_constructor : BuilderMessages.TagValidator_a_static_final_method); } else { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_final_constructor : BuilderMessages.TagValidator_a_final_method); } } else if (isstatic) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_a_static_constructor : BuilderMessages.TagValidator_a_static_method); } else if (Flags.isFinal(getParentModifiers(method))) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_constructor_in_final_class : BuilderMessages.TagValidator_a_method_in_a_final_class); } else if (!item.visible) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_not_visible_constructor : BuilderMessages.TagValidator_a_method_that_is_not_visible); } } else if (!item.visible) { createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_not_visible_constructor : BuilderMessages.TagValidator_a_method_that_is_not_visible); } break; } default: { break; } } } processed.add(tagname); } }
From source file:org.eclipse.pde.api.tools.internal.builder.TagValidator.java
License:Open Source License
/** * Checks the given annotation//from w ww. j a va 2 s . c om * * @param node the annotation */ void checkMethod(MarkerAnnotation node, MethodDeclaration parent) { String name = node.getTypeName().getFullyQualifiedName(); int pkind = getParentKind(parent); int flags = parent.getModifiers(); boolean isconstructor = parent.isConstructor(); boolean isstatic = Flags.isStatic(flags); Item item = getItem(); Set<String> supportedtags = ApiPlugin.getJavadocTagManager().getAnntationsForType(pkind, isconstructor ? IApiJavadocTag.MEMBER_CONSTRUCTOR : IApiJavadocTag.MEMBER_METHOD); if (fProcessedAnnotations.contains(name)) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.DUPLICATE_ANNOTATION_USE, IApiMarkerConstants.DUPLICATE_ANNOTATION_MARKER_ID, null); } else { switch (pkind) { case IApiJavadocTag.TYPE_ENUM: { if (!supportedtags.contains(name)) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, BuilderMessages.TagValidator_an_enum_method); } else if (Flags.isPrivate(flags)) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, BuilderMessages.TagValidator_private_enum_method); } else if (Flags.isPackageDefault(flags)) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, BuilderMessages.TagValidator_a_package_default_enum); } else if (!item.visible) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, BuilderMessages.TagValidator_not_visible_enum_method); } break; } case IApiJavadocTag.TYPE_INTERFACE: { if (!supportedtags.contains(name)) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, BuilderMessages.TagValidator_an_interface_method); } else if (!item.visible) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, BuilderMessages.TagValidator_not_visible_interface_method); } else if (!Flags.isDefaultMethod(flags) && JavadocTagManager.ANNOTATION_NOOVERRIDE.equals(name)) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, BuilderMessages.TagValidator_nondefault_interface_method); } break; } case IApiJavadocTag.TYPE_CLASS: { if (!supportedtags.contains(name)) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_a_constructor : BuilderMessages.TagValidator_a_method); } else if (Flags.isPrivate(flags)) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_private_constructor : BuilderMessages.TagValidator_private_method); } else if (Flags.isPackageDefault(flags)) { if (isstatic) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_static_package_constructor : BuilderMessages.TagValidator_a_static_package_default_method); } else { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_a_package_default_constructor : BuilderMessages.TagValidator_a_package_default_method); } } else if (JavadocTagManager.ANNOTATION_NOOVERRIDE.equals(name)) { if (Flags.isFinal(flags)) { if (isstatic) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_static_final_constructor : BuilderMessages.TagValidator_a_static_final_method); } else { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_final_constructor : BuilderMessages.TagValidator_a_final_method); } } else if (isstatic) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_a_static_constructor : BuilderMessages.TagValidator_a_static_method); } else if (Flags.isFinal(getParentModifiers(parent))) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_constructor_in_final_class : BuilderMessages.TagValidator_a_method_in_a_final_class); } else if (!item.visible) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_not_visible_constructor : BuilderMessages.TagValidator_a_method_that_is_not_visible); } } else if (!item.visible) { createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_not_visible_constructor : BuilderMessages.TagValidator_a_method_that_is_not_visible); } break; } default: { break; } } } fProcessedAnnotations.add(name); }
From source file:org.springframework.ide.eclipse.data.jdt.core.RepositoryInformation.java
License:Open Source License
/** * Returns all {@link IMethod}s that shall be considered query methods (which need to be validated). * //from w w w. j a va 2 s .c om * @return */ public Iterable<IMethod> getMethodsToValidate() { Set<IMethod> result = new HashSet<IMethod>(); try { for (IMethod method : type.getMethods()) { if (!isCrudMethod(method) && !hasQueryAnnotation(method) && !Flags.isDefaultMethod(method.getFlags())) { result.add(method); } } } catch (JavaModelException e) { SpringCore.log(e); } return result; }