List of usage examples for org.eclipse.jdt.core Flags isSynchronized
public static boolean isSynchronized(int flags)
synchronized
modifier. From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isSynchronized(IMember member) throws JavaModelException { return Flags.isSynchronized(member.getFlags()); }
From source file:com.codenvy.ide.ext.java.server.SourcesFromBytecodeGenerator.java
License:Open Source License
private String getModifiers(int flags, int typeFlags) { StringBuilder modifiers = new StringBuilder(); //package private modifier has no string representation if (Flags.isPublic(flags)) { modifiers.append("public "); }/*w w w . j a v a2s. c om*/ if (Flags.isProtected(flags)) { modifiers.append("protected "); } if (Flags.isPrivate(flags)) { modifiers.append("private "); } if (Flags.isStatic(flags)) { modifiers.append("static "); } if (Flags.isAbstract(flags) && !Flags.isInterface(typeFlags)) { modifiers.append("abstract "); } if (Flags.isFinal(flags)) { modifiers.append("final "); } if (Flags.isNative(flags)) { modifiers.append("native "); } if (Flags.isSynchronized(flags)) { modifiers.append("synchronized "); } if (Flags.isVolatile(flags)) { modifiers.append("volatile "); } int len = modifiers.length(); if (len == 0) return ""; modifiers.setLength(len - 1); return modifiers.toString(); }
From source file:com.redhat.ceylon.eclipse.code.explorer.JavaElementImageProvider.java
License:Open Source License
private int computeJavaAdornmentFlags(IJavaElement element, int renderFlags) { int flags = 0; if (showOverlayIcons(renderFlags)) { try {// w w w . ja va 2 s.c om if (element instanceof IMember) { IMember member = (IMember) element; int modifiers = member.getFlags(); if (Flags.isAbstract(modifiers) && confirmAbstract(member)) flags |= JavaElementImageDescriptor.ABSTRACT; if (Flags.isFinal(modifiers) || isInterfaceOrAnnotationField(member) || isEnumConstant(member, modifiers)) flags |= JavaElementImageDescriptor.FINAL; if (Flags.isStatic(modifiers) || isInterfaceOrAnnotationFieldOrType(member) || isEnumConstant(member, modifiers)) flags |= JavaElementImageDescriptor.STATIC; if (Flags.isDeprecated(modifiers)) flags |= JavaElementImageDescriptor.DEPRECATED; int elementType = element.getElementType(); if (elementType == IJavaElement.METHOD) { if (((IMethod) element).isConstructor()) flags |= JavaElementImageDescriptor.CONSTRUCTOR; if (Flags.isSynchronized(modifiers)) // collides with 'super' flag flags |= JavaElementImageDescriptor.SYNCHRONIZED; if (Flags.isNative(modifiers)) flags |= JavaElementImageDescriptor.NATIVE; } if (member.getElementType() == IJavaElement.TYPE) { if (JavaModelUtil.hasMainMethod((IType) member)) { flags |= JavaElementImageDescriptor.RUNNABLE; } } if (member.getElementType() == IJavaElement.FIELD) { if (Flags.isVolatile(modifiers)) flags |= JavaElementImageDescriptor.VOLATILE; if (Flags.isTransient(modifiers)) flags |= JavaElementImageDescriptor.TRANSIENT; } } else if (element instanceof ILocalVariable && Flags.isFinal(((ILocalVariable) element).getFlags())) { flags |= JavaElementImageDescriptor.FINAL; } } catch (JavaModelException e) { // do nothing. Can't compute runnable adornment or get flags } } return flags; }
From source file:org.eclim.plugin.jdt.command.src.ClassPrototypeCommand.java
License:Open Source License
/** * Prototypes the given member's flags.//from w w w. j a va2 s. c o m * * @param buffer The buffer to append to. * @param member The member instance. */ protected void prototypeFlags(StringBuffer buffer, IMember member) throws Exception { int flags = member.getFlags(); if (Flags.isPublic(flags)) { buffer.append("public "); } else if (Flags.isProtected(flags)) { buffer.append("protected "); } else if (Flags.isPrivate(flags)) { buffer.append("private "); } if (Flags.isStatic(flags)) { buffer.append("static "); } if (Flags.isFinal(flags)) { buffer.append("final "); } if (Flags.isAbstract(flags)) { buffer.append("abstract "); } if (Flags.isNative(flags)) { buffer.append("native "); } if (Flags.isTransient(flags)) { buffer.append("transient "); } if (Flags.isVolatile(flags)) { buffer.append("volatile "); } if (Flags.isSynchronized(flags)) { buffer.append("synchronized "); } }
From source file:org.eclipse.ajdt.internal.ui.lazystart.ImageDecorator.java
License:Open Source License
private int computeJavaAdornmentFlags(IJavaElement element) { int flags = 0; if (true && element instanceof IMember) { try {/*from w ww . ja v a2s. co m*/ IMember member = (IMember) element; if (element.getElementType() == IJavaElement.METHOD && ((IMethod) element).isConstructor()) flags |= JavaElementImageDescriptor.CONSTRUCTOR; int modifiers = member.getFlags(); if (Flags.isAbstract(modifiers) && confirmAbstract(member)) flags |= JavaElementImageDescriptor.ABSTRACT; if (Flags.isFinal(modifiers) || isInterfaceField(member)) flags |= JavaElementImageDescriptor.FINAL; if (Flags.isSynchronized(modifiers) && confirmSynchronized(member)) flags |= JavaElementImageDescriptor.SYNCHRONIZED; if (Flags.isStatic(modifiers) || isInterfaceField(member)) flags |= JavaElementImageDescriptor.STATIC; if (Flags.isDeprecated(modifiers)) flags |= JavaElementImageDescriptor.DEPRECATED; if (member.getElementType() == IJavaElement.TYPE) { if (JavaModelUtil.hasMainMethod((IType) member)) { flags |= JavaElementImageDescriptor.RUNNABLE; } } } catch (JavaModelException e) { // do nothing. Can't compute runnable adornment or get flags // can be ignored } } return flags; }
From source file:org.eclipse.jem.internal.adapters.jdom.JavaMethodJDOMAdaptor.java
License:Open Source License
/** * setModifiers - set the attribute values related to modifiers here *//* w w w .j a v a 2 s. co m*/ protected void setModifiers() { Method methodTarget = (Method) getTarget(); try { methodTarget.setFinal(Flags.isFinal(getSourceMethod().getFlags())); methodTarget.setNative(Flags.isNative(getSourceMethod().getFlags())); methodTarget.setStatic(Flags.isStatic(getSourceMethod().getFlags())); methodTarget.setSynchronized(Flags.isSynchronized(getSourceMethod().getFlags())); methodTarget.setConstructor(getSourceMethod().isConstructor()); JavaClass javaClass = getContainingJavaClass(); //Set abstract if (javaClass.getKind().getValue() == TypeKind.INTERFACE) methodTarget.setAbstract(true); else methodTarget.setAbstract(Flags.isAbstract(getSourceMethod().getFlags())); // Set visibility if (javaClass.getKind().getValue() == TypeKind.INTERFACE || Flags.isPublic(getSourceMethod().getFlags())) methodTarget.setJavaVisibility(JavaVisibilityKind.PUBLIC_LITERAL); else if (Flags.isPrivate(getSourceMethod().getFlags())) methodTarget.setJavaVisibility(JavaVisibilityKind.PRIVATE_LITERAL); else if (Flags.isProtected(getSourceMethod().getFlags())) methodTarget.setJavaVisibility(JavaVisibilityKind.PROTECTED_LITERAL); else //Visibility must be package methodTarget.setJavaVisibility(JavaVisibilityKind.PACKAGE_LITERAL); } catch (JavaModelException npe) { System.out.println(ResourceHandler.getString("Error_Introspecting_Flags_ERROR_", (new Object[] { //$NON-NLS-1$ ((XMIResource) methodTarget.eResource()).getID(methodTarget), npe.getMessage() }))); //= "error introspecting flags on {0}, exception: {1}" } }
From source file:org.eclipse.modisco.java.discoverer.internal.io.library.ClassFileParser.java
License:Open Source License
/** * Complete the MoDisco modifier with the informations of the flags. * /* www. j a v a2 s. com*/ * @param flags * the flags * @param modiscoModifier * the MoDisco Modifier * @see Flags */ private static void manageModifier(final Modifier modiscoModifier, final int flags, final IJavaElement element) { int kind = element.getElementType(); // static is applicable on types, methods, fields, and initializers. if (!modiscoModifier.isStatic()) { if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD || kind == IJavaElement.FIELD) { modiscoModifier.setStatic(Flags.isStatic(flags)); } } // native is applicable to methods if (!modiscoModifier.isNative()) { if (kind == IJavaElement.METHOD) { modiscoModifier.setNative(Flags.isNative(flags)); } } // strictfp is applicable to types and methods if (!modiscoModifier.isStrictfp()) { if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD) { modiscoModifier.setStrictfp(Flags.isStrictfp(flags)); } } // synchronized is applicable only to methods if (!modiscoModifier.isSynchronized()) { if (kind == IJavaElement.METHOD) { modiscoModifier.setSynchronized(Flags.isSynchronized(flags)); } } // transient is applicable only to fields if (!modiscoModifier.isTransient()) { if (kind == IJavaElement.FIELD) { modiscoModifier.setTransient(Flags.isTransient(flags)); } } // volatile is applicable only to fields if (!modiscoModifier.isVolatile()) { if (kind == IJavaElement.FIELD) { modiscoModifier.setVolatile(Flags.isVolatile(flags)); } } // visibility modifiers are applicable to types, methods, constructors, // and fields. if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD || kind == IJavaElement.FIELD) { if (Flags.isPrivate(flags)) { modiscoModifier.setVisibility(VisibilityKind.PRIVATE); } else if (Flags.isProtected(flags)) { modiscoModifier.setVisibility(VisibilityKind.PROTECTED); } else if (Flags.isPublic(flags)) { modiscoModifier.setVisibility(VisibilityKind.PUBLIC); } } // abstract is applicable to types and methods // final is applicable to types, methods and variables if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD) { if (Flags.isAbstract(flags)) { modiscoModifier.setInheritance(InheritanceKind.ABSTRACT); } else if (Flags.isFinal(flags)) { modiscoModifier.setInheritance(InheritanceKind.FINAL); } } }
From source file:org.eclipse.pde.api.tools.internal.comparator.ClassFileComparator.java
License:Open Source License
private void getDeltaForMethod(IApiMethod method) { int access = method.getModifiers(); if (Flags.isSynthetic(access)) { // we ignore synthetic methods return;/*from ww w . j ava 2 s . c om*/ } String name = method.getName(); String descriptor = method.getSignature(); String key = getKeyForMethod(method, this.type1); IApiMethod method2 = this.type2.getMethod(name, descriptor); String methodDisplayName = getMethodDisplayName(method, this.type1); if (method2 == null) { if (method.isClassInitializer()) { // report delta: removal of a clinit method this.addDelta(getElementType(this.type1), IDelta.REMOVED, IDelta.CLINIT, this.currentDescriptorRestrictions, access, 0, this.type1, this.type1.getName(), Util.getDescriptorName(type1)); return; } else if (Flags.isPrivate(access) || Util.isDefault(access)) { this.addDelta(getElementType(this.type1), IDelta.REMOVED, getTargetType(method), Flags.isAbstract(this.type2.getModifiers()) ? this.currentDescriptorRestrictions | RestrictionModifiers.NO_INSTANTIATE : this.currentDescriptorRestrictions, access, 0, this.type1, getKeyForMethod(method, this.type1), new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); return; } // if null we need to walk the hierarchy of descriptor2 boolean found = false; if (this.component2 != null && !method.isConstructor()) { if (this.type1.isInterface()) { Set<?> interfacesSet = getInterfacesSet(this.type2); if (interfacesSet != null && isStatusOk()) { for (Iterator<?> iterator = interfacesSet.iterator(); iterator.hasNext();) { IApiType superTypeDescriptor = (IApiType) iterator.next(); IApiMethod method3 = superTypeDescriptor.getMethod(name, descriptor); if (method3 == null) { continue; } else { // interface method can only be public // method has been move up in the hierarchy - // report the delta and abort loop this.addDelta(getElementType(this.type1), IDelta.REMOVED, IDelta.METHOD_MOVED_UP, this.currentDescriptorRestrictions, access, method3.getModifiers(), this.type1, getKeyForMethod(method3, this.type1), new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); found = true; break; } } } } else { List<?> superclassList = getSuperclassList(this.type2, true); if (superclassList != null && isStatusOk()) { loop: for (Iterator<?> iterator = superclassList.iterator(); iterator.hasNext();) { IApiType superTypeDescriptor = (IApiType) iterator.next(); IApiMethod method3 = superTypeDescriptor.getMethod(name, descriptor); if (method3 == null) { continue; } else { int access3 = method3.getModifiers(); if (Flags.isPublic(access3) || Flags.isProtected(access3)) { // method has been move up in the hierarchy // - report the delta and abort loop // TODO need to make the distinction between // methods that need to be re-implemented // and methods that don't this.addDelta(getElementType(this.type1), IDelta.REMOVED, IDelta.METHOD_MOVED_UP, this.currentDescriptorRestrictions, access, access3, this.type1, getKeyForMethod(method3, this.type1), new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); found = true; break loop; } } } } } } if (!found) { if ((this.visibilityModifiers == VisibilityModifiers.API) && component.hasApiDescription()) { // check if this method should be removed because it is // tagged as @noreference IApiDescription apiDescription = null; try { apiDescription = this.component.getApiDescription(); } catch (CoreException e) { reportStatus(e); } if (apiDescription != null) { IApiAnnotations apiAnnotations = apiDescription.resolveAnnotations(method.getHandle()); if (apiAnnotations != null) { int restrictions = apiAnnotations.getRestrictions(); if (RestrictionModifiers.isReferenceRestriction(restrictions)) { // if not found, but tagged as @noreference in // reference we don't need to report // a removed method return; } } } } if (this.type1.isAnnotation()) { this.addDelta(getElementType(this.type1), IDelta.REMOVED, method.getDefaultValue() != null ? IDelta.METHOD_WITH_DEFAULT_VALUE : IDelta.METHOD_WITHOUT_DEFAULT_VALUE, this.currentDescriptorRestrictions, access, 0, this.type1, getKeyForMethod(method, this.type1), new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } else { int restrictions = this.currentDescriptorRestrictions; if (RestrictionModifiers.isExtendRestriction(this.initialDescriptorRestrictions) && !RestrictionModifiers.isExtendRestriction(this.currentDescriptorRestrictions)) { restrictions = this.initialDescriptorRestrictions; } this.addDelta(getElementType(this.type1), IDelta.REMOVED, getTargetType(method), Flags.isAbstract(this.type2.getModifiers()) ? restrictions | RestrictionModifiers.NO_INSTANTIATE : restrictions, access, 0, this.type1, getKeyForMethod(method, this.type1), new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } return; } int restrictions = this.currentDescriptorRestrictions; if (component2.hasApiDescription()) { try { IApiDescription apiDescription = this.component2.getApiDescription(); IApiAnnotations resolvedAPIDescription = apiDescription.resolveAnnotations(method2.getHandle()); if (resolvedAPIDescription != null) { restrictions |= resolvedAPIDescription.getRestrictions(); } } catch (CoreException e) { // ignore } } int referenceRestrictions = this.initialDescriptorRestrictions; int access2 = method2.getModifiers(); if (this.component.hasApiDescription()) { // check if this method should be removed because it is tagged as // @noreference IApiDescription apiDescription = null; try { apiDescription = this.component.getApiDescription(); } catch (CoreException e) { reportStatus(e); } if (apiDescription != null) { IApiAnnotations apiAnnotations = apiDescription.resolveAnnotations(method.getHandle()); if (apiAnnotations != null) { referenceRestrictions |= apiAnnotations.getRestrictions(); } } } if ((this.visibilityModifiers == VisibilityModifiers.API) && this.component.hasApiDescription()) { if (RestrictionModifiers.isReferenceRestriction(referenceRestrictions)) { // tagged as @noreference in the reference component if (!RestrictionModifiers.isReferenceRestriction(restrictions)) { // no longer tagged as @noreference // report a method addition if (method.isConstructor()) { this.addDelta(getElementType(this.type2), IDelta.ADDED, IDelta.CONSTRUCTOR, this.currentDescriptorRestrictions, access, access2, this.type1, getKeyForMethod(method, this.type2), new String[] { Util.getDescriptorName(this.type2), methodDisplayName }); } else if (this.type2.isAnnotation()) { if (method.getDefaultValue() != null) { this.addDelta(getElementType(this.type2), IDelta.ADDED, IDelta.METHOD_WITH_DEFAULT_VALUE, this.currentDescriptorRestrictions, access, access2, this.type1, getKeyForMethod(method, this.type2), new String[] { Util.getDescriptorName(this.type2), methodDisplayName }); } else { this.addDelta(getElementType(this.type2), IDelta.ADDED, IDelta.METHOD_WITHOUT_DEFAULT_VALUE, this.currentDescriptorRestrictions, access, access2, this.type1, getKeyForMethod(method, this.type2), new String[] { Util.getDescriptorName(this.type2), methodDisplayName }); } } else { // check superclass // if null we need to walk the hierarchy of descriptor2 boolean found = false; if (this.component2 != null) { if (this.type1.isInterface()) { Set<?> interfacesSet = getInterfacesSet(this.type2); if (interfacesSet != null && isStatusOk()) { for (Iterator<?> iterator = interfacesSet.iterator(); iterator.hasNext();) { IApiType superTypeDescriptor = (IApiType) iterator.next(); IApiMethod method3 = superTypeDescriptor.getMethod(name, descriptor); if (method3 == null) { continue; } else { // interface method can only be // public // method has been move up in the // hierarchy - report the delta and // abort loop found = true; break; } } } } else { List<IApiType> superclassList = getSuperclassList(this.type2, true); if (superclassList != null) { loop: for (Iterator<IApiType> iterator = superclassList.iterator(); iterator .hasNext();) { IApiType superTypeDescriptor = iterator.next(); IApiMethod method3 = superTypeDescriptor.getMethod(name, descriptor); if (method3 == null) { continue; } else { int access3 = method3.getModifiers(); if (Flags.isPublic(access3) || Flags.isProtected(access3)) { // method has been move up in // the hierarchy - report the // delta and abort loop // TODO need to make the // distinction between methods // that need to be // re-implemented and methods // that don't found = true; break loop; } } } } } } this.addDelta(getElementType(this.type2), IDelta.ADDED, found ? IDelta.OVERRIDEN_METHOD : IDelta.METHOD, this.currentDescriptorRestrictions, access, access2, this.type1, getKeyForMethod(method, this.type2), new String[] { Util.getDescriptorName(this.type2), methodDisplayName }); } return; } } else if (RestrictionModifiers.isReferenceRestriction(restrictions)) { if (Flags.isPublic(access2) || Flags.isProtected(access2)) { // report that it is no longer an API method if (this.type2.isAnnotation()) { this.addDelta(getElementType(this.type2), IDelta.REMOVED, method.getDefaultValue() != null ? IDelta.API_METHOD_WITH_DEFAULT_VALUE : IDelta.API_METHOD_WITHOUT_DEFAULT_VALUE, this.currentDescriptorRestrictions, access, access2, this.type1, getKeyForMethod(method2, this.type2), new String[] { Util.getDescriptorName(this.type2), methodDisplayName }); } else if (Flags.isPublic(access) || Flags.isProtected(access)) { this.addDelta(getElementType(this.type2), IDelta.REMOVED, method.isConstructor() ? IDelta.API_CONSTRUCTOR : IDelta.API_METHOD, Flags.isAbstract(this.type2.getModifiers()) ? this.currentDescriptorRestrictions | RestrictionModifiers.NO_INSTANTIATE : this.currentDescriptorRestrictions, access, access2, this.type1, getKeyForMethod(method2, this.type2), new String[] { Util.getDescriptorName(this.type2), methodDisplayName }); } return; } } } if (this.component.hasApiDescription() && !method.isConstructor() && !method.isClassInitializer() && !(type1.isInterface() || type1.isAnnotation())) { if (restrictions != referenceRestrictions) { if (!Flags.isFinal(access2)) { if (RestrictionModifiers.isOverrideRestriction(restrictions) && !RestrictionModifiers.isOverrideRestriction(referenceRestrictions)) { this.addDelta(getElementType(method), IDelta.ADDED, IDelta.RESTRICTIONS, restrictions, referenceRestrictions, access, access2, this.type1, getKeyForMethod(method2, this.type2), new String[] { Util.getDescriptorName(this.type2), methodDisplayName }); } } } } String[] names1 = method.getExceptionNames(); List<String> list1 = null; if (names1 != null) { list1 = new ArrayList<String>(names1.length); for (int i = 0; i < names1.length; i++) { list1.add(names1[i]); } } String[] names2 = method2.getExceptionNames(); List<String> list2 = null; if (names2 != null) { list2 = new ArrayList<String>(names2.length); for (int i = 0; i < names2.length; i++) { list2.add(names2[i]); } } if (names1 != null) { if (names2 == null) { // check all exception in method descriptor to see if they are // checked or unchecked exceptions loop: for (Iterator<String> iterator = list1.iterator(); iterator.hasNext();) { String exceptionName = iterator.next().replace('/', '.'); if (isCheckedException(this.apiBaseline1, this.component, exceptionName)) { // report delta - removal of checked exception // TODO should we continue the loop for all remaining // exceptions this.addDelta(getElementType(method), IDelta.REMOVED, IDelta.CHECKED_EXCEPTION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName, exceptionName }); break loop; } else { // report delta - removal of unchecked exception this.addDelta(getElementType(method), IDelta.REMOVED, IDelta.UNCHECKED_EXCEPTION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName, exceptionName }); } } } else { // check if the exceptions are consistent for both descriptors List<String> removedExceptions = new ArrayList<String>(); for (Iterator<String> iterator = list1.iterator(); iterator.hasNext();) { String exceptionName = iterator.next().replace('/', '.'); if (!list2.remove(exceptionName)) { // this means that the exceptionName was not found // inside the new set of exceptions // so it has been removed removedExceptions.add(exceptionName); } } if (removedExceptions.size() != 0) { loop: for (Iterator<String> iterator = removedExceptions.iterator(); iterator.hasNext();) { String exceptionName = iterator.next().replace('/', '.'); if (isCheckedException(this.apiBaseline1, this.component, exceptionName)) { // report delta - removal of checked exception // TODO should we continue the loop for all // remaining exceptions this.addDelta(getElementType(method), IDelta.REMOVED, IDelta.CHECKED_EXCEPTION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName, exceptionName }); break loop; } else { // report delta - removal of unchecked exception this.addDelta(getElementType(method), IDelta.REMOVED, IDelta.UNCHECKED_EXCEPTION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName, exceptionName }); } } } loop: for (Iterator<String> iterator = list2.iterator(); iterator.hasNext();) { String exceptionName = iterator.next().replace('/', '.'); if (isCheckedException(this.apiBaseline2, this.component2, exceptionName)) { // report delta - addition of checked exception // TODO should we continue the loop for all remaining // exceptions this.addDelta(getElementType(method), IDelta.ADDED, IDelta.CHECKED_EXCEPTION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName, exceptionName }); break loop; } else { // report delta - addition of unchecked exception this.addDelta(getElementType(method), IDelta.ADDED, IDelta.UNCHECKED_EXCEPTION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName, exceptionName }); } } } } else if (names2 != null) { // check all exception in method descriptor to see if they are // checked or unchecked exceptions loop: for (Iterator<String> iterator = list2.iterator(); iterator.hasNext();) { String exceptionName = iterator.next().replace('/', '.'); if (isCheckedException(this.apiBaseline2, this.component2, exceptionName)) { // report delta - addition of checked exception this.addDelta(getElementType(method), IDelta.ADDED, IDelta.CHECKED_EXCEPTION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName, exceptionName }); // TODO should we continue the loop for all remaining // exceptions break loop; } else { // report delta - addition of unchecked exception this.addDelta(getElementType(method), IDelta.ADDED, IDelta.UNCHECKED_EXCEPTION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName, exceptionName }); } } } if (Flags.isVarargs(access)) { if (!Flags.isVarargs(access2)) { // report delta: conversion from T... to T[] - break // compatibility this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.VARARGS_TO_ARRAY, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (Flags.isVarargs(access2)) { // report delta: conversion from T[] to T... compatible this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.ARRAY_TO_VARARGS, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } if (Flags.isProtected(access)) { if (Flags.isPrivate(access2) || Util.isDefault(access2)) { // report delta - decrease access: protected to default or // private this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.DECREASE_ACCESS, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } else if (Flags.isPublic(access2)) { // report delta - increase access: protected to public this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.INCREASE_ACCESS, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (Flags.isPublic(access) && (Flags.isProtected(access2) || Flags.isPrivate(access2) || Util.isDefault(access2))) { // report delta - decrease access: public to protected, default or // private this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.DECREASE_ACCESS, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } else if (Util.isDefault(access) && (Flags.isPublic(access2) || Flags.isProtected(access2))) { this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.INCREASE_ACCESS, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } else if (Flags.isPrivate(access) && (Util.isDefault(access2) || Flags.isPublic(access2) || Flags.isProtected(access2))) { this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.INCREASE_ACCESS, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } if (Flags.isAbstract(access)) { if (!Flags.isAbstract(access2)) { // report delta - changed from abstract to non-abstract this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.ABSTRACT_TO_NON_ABSTRACT, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (Flags.isAbstract(access2)) { // report delta - changed from non-abstract to abstract this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.NON_ABSTRACT_TO_ABSTRACT, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } if (Flags.isFinal(access)) { if (!Flags.isFinal(access2)) { // report delta - changed from final to non-final this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.FINAL_TO_NON_FINAL, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (Flags.isFinal(access2)) { int res = restrictions; if (!RestrictionModifiers.isOverrideRestriction(res)) { if (RestrictionModifiers.isExtendRestriction(this.currentDescriptorRestrictions)) { res = this.currentDescriptorRestrictions; } else if (RestrictionModifiers.isExtendRestriction(this.initialDescriptorRestrictions)) { res = this.initialDescriptorRestrictions; } if (RestrictionModifiers.isOverrideRestriction(referenceRestrictions)) { // it is ok to remove @nooverride and add final at the same // time res = referenceRestrictions; } } // only report this delta is the method was visible this.addDelta(getElementType(method2), IDelta.CHANGED, IDelta.NON_FINAL_TO_FINAL, res, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type2), getMethodDisplayName(method2, this.type2) }); } if (Flags.isStatic(access)) { if (!Flags.isStatic(access2)) { // report delta: change from static to non-static this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.STATIC_TO_NON_STATIC, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (Flags.isStatic(access2)) { // report delta: change from non-static to static this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.NON_STATIC_TO_STATIC, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } if (Flags.isNative(access)) { if (!Flags.isNative(access2)) { // report delta: change from native to non-native this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.NATIVE_TO_NON_NATIVE, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (Flags.isNative(access2)) { // report delta: change from non-native to native this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.NON_NATIVE_TO_NATIVE, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } if (Flags.isSynchronized(access)) { if (!Flags.isSynchronized(access2)) { // report delta: change from synchronized to non-synchronized this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.SYNCHRONIZED_TO_NON_SYNCHRONIZED, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (Flags.isSynchronized(access2)) { // report delta: change from non-synchronized to synchronized this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.NON_SYNCHRONIZED_TO_SYNCHRONIZED, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } if (Flags.isDeprecated(access)) { if (!Flags.isDeprecated(access2)) { this.addDelta(getElementType(method), IDelta.REMOVED, IDelta.DEPRECATION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (Flags.isDeprecated(access2)) { // report delta - non-volatile to volatile this.addDelta(getElementType(method), IDelta.ADDED, IDelta.DEPRECATION, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } // check type parameters String signature1 = method.getGenericSignature(); String signature2 = method2.getGenericSignature(); checkGenericSignature(signature1, signature2, method, method2); if (method.getDefaultValue() == null) { if (method2.getDefaultValue() != null) { // report delta : default value has been added - compatible this.addDelta(getElementType(method), IDelta.ADDED, IDelta.ANNOTATION_DEFAULT_VALUE, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } } else if (method2.getDefaultValue() == null) { // report delta : default value has been removed - incompatible this.addDelta(getElementType(method), IDelta.REMOVED, IDelta.ANNOTATION_DEFAULT_VALUE, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } else if (!method.getDefaultValue().equals(method2.getDefaultValue())) { // report delta: default value has changed this.addDelta(getElementType(method), IDelta.CHANGED, IDelta.ANNOTATION_DEFAULT_VALUE, restrictions, access, access2, this.type1, key, new String[] { Util.getDescriptorName(this.type1), methodDisplayName }); } }
From source file:org.seasar.s2junit4plugin.wizard.S2JUnit4StubUtility.java
License:Apache License
/** * Generates a stub. Given a template method, a stub with the same signature * will be constructed so it can be added to a type. * @param destTypeName The name of the type to which the method will be added to (Used for the constructor) * @param method A method template (method belongs to different type than the parent) * @param settings Options as defined above (GENSTUB_*) * @param imports Imports required by the sub are added to the imports structure * @return The ynformatted stub//from w ww. j ava2 s. co m * @throws JavaModelException */ public static String genStub(ICompilationUnit compilationUnit, String destTypeName, IMethod method, GenStubSettings settings, String extraAnnotations, ImportsManager imports) throws CoreException { IType declaringtype = method.getDeclaringType(); StringBuffer buf = new StringBuffer(); String[] paramTypes = method.getParameterTypes(); String[] paramNames = method.getParameterNames(); String[] excTypes = method.getExceptionTypes(); String retTypeSig = method.getReturnType(); int lastParam = paramTypes.length - 1; String comment = null; if (settings.createComments) { if (method.isConstructor()) { comment = CodeGeneration.getMethodComment(compilationUnit, destTypeName, method.getElementName(), paramNames, excTypes, null, null, "\n"); //$NON-NLS-1$ } else { if (settings.methodOverwrites) { comment = CodeGeneration.getMethodComment(compilationUnit, destTypeName, method.getElementName(), paramNames, excTypes, retTypeSig, method, "\n"); //$NON-NLS-1$ } else { comment = CodeGeneration.getMethodComment(compilationUnit, destTypeName, method.getElementName(), paramNames, excTypes, retTypeSig, null, "\n"); //$NON-NLS-1$ } } } if (comment != null) { buf.append(comment).append('\n'); } if (extraAnnotations != null) { buf.append(extraAnnotations).append('\n'); } int flags = method.getFlags(); if (Flags.isPublic(flags) || (declaringtype.isInterface() && !settings.noBody)) { buf.append("public "); //$NON-NLS-1$ } else if (Flags.isProtected(flags)) { buf.append("protected "); //$NON-NLS-1$ } else if (Flags.isPrivate(flags)) { buf.append("private "); //$NON-NLS-1$ } if (Flags.isSynchronized(flags)) { buf.append("synchronized "); //$NON-NLS-1$ } if (Flags.isVolatile(flags)) { buf.append("volatile "); //$NON-NLS-1$ } if (Flags.isStrictfp(flags)) { buf.append("strictfp "); //$NON-NLS-1$ } if (Flags.isStatic(flags)) { buf.append("static "); //$NON-NLS-1$ } if (method.isConstructor()) { buf.append(destTypeName); } else { String retTypeFrm = Signature.toString(retTypeSig); if (!isBuiltInType(retTypeSig)) { resolveAndAdd(retTypeSig, declaringtype, imports); } buf.append(Signature.getSimpleName(retTypeFrm)); buf.append(' '); buf.append(method.getElementName()); } buf.append('('); for (int i = 0; i <= lastParam; i++) { String paramTypeSig = paramTypes[i]; String paramTypeFrm = Signature.toString(paramTypeSig); if (!isBuiltInType(paramTypeSig)) { resolveAndAdd(paramTypeSig, declaringtype, imports); } buf.append(Signature.getSimpleName(paramTypeFrm)); buf.append(' '); buf.append(paramNames[i]); if (i < lastParam) { buf.append(", "); //$NON-NLS-1$ } } buf.append(')'); int lastExc = excTypes.length - 1; if (lastExc >= 0) { buf.append(" throws "); //$NON-NLS-1$ for (int i = 0; i <= lastExc; i++) { String excTypeSig = excTypes[i]; String excTypeFrm = Signature.toString(excTypeSig); resolveAndAdd(excTypeSig, declaringtype, imports); buf.append(Signature.getSimpleName(excTypeFrm)); if (i < lastExc) { buf.append(", "); //$NON-NLS-1$ } } } if (settings.noBody) { buf.append(";\n\n"); //$NON-NLS-1$ } else { buf.append(" {\n\t"); //$NON-NLS-1$ if (!settings.callSuper) { if (retTypeSig != null && !retTypeSig.equals(Signature.SIG_VOID)) { buf.append('\t'); if (!isBuiltInType(retTypeSig) || Signature.getArrayCount(retTypeSig) > 0) { buf.append("return null;\n\t"); //$NON-NLS-1$ } else if (retTypeSig.equals(Signature.SIG_BOOLEAN)) { buf.append("return false;\n\t"); //$NON-NLS-1$ } else { buf.append("return 0;\n\t"); //$NON-NLS-1$ } } } else { buf.append('\t'); if (!method.isConstructor()) { if (!Signature.SIG_VOID.equals(retTypeSig)) { buf.append("return "); //$NON-NLS-1$ } buf.append("super."); //$NON-NLS-1$ buf.append(method.getElementName()); } else { buf.append("super"); //$NON-NLS-1$ } buf.append('('); for (int i = 0; i <= lastParam; i++) { buf.append(paramNames[i]); if (i < lastParam) { buf.append(", "); //$NON-NLS-1$ } } buf.append(");\n\t"); //$NON-NLS-1$ } buf.append("}\n\n"); //$NON-NLS-1$ } return buf.toString(); }