List of usage examples for org.eclipse.jdt.core Flags isVolatile
public static boolean isVolatile(int flags)
volatile
modifier. From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isVolatile(IMember member) throws JavaModelException { return Flags.isVolatile(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 va 2s .c o m*/ 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 {//from w ww.j a v a 2 s. c o m 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./* w ww . j a v a 2 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.jem.internal.adapters.jdom.JavaFieldJDOMAdaptor.java
License:Open Source License
/** * setModifiers - set the attribute values related to modifiers here *///from w ww. j a v a 2 s.co m protected void setModifiers() { Field javaFieldTarget = (Field) getTarget(); try { String initializer = getFieldInitializerString(); if (initializer != null) javaFieldTarget.setInitializer(createBlock(javaFieldTarget.getName(), initializer)); int flags = getSourceField().getFlags(); javaFieldTarget.setFinal(Flags.isFinal(flags)); javaFieldTarget.setStatic(Flags.isStatic(flags)); javaFieldTarget.setTransient(Flags.isTransient(flags)); javaFieldTarget.setVolatile(Flags.isVolatile(flags)); // Set visibility if (Flags.isPublic(flags)) javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PUBLIC_LITERAL); else if (Flags.isPrivate(flags)) javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PRIVATE_LITERAL); else if (Flags.isProtected(flags)) javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PROTECTED_LITERAL); else javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PACKAGE_LITERAL); } catch (JavaModelException npe) { System.out.println(ResourceHandler.getString("Error_Introspecting_Flags_ERROR_", new Object[] { //$NON-NLS-1$ ((XMIResource) javaFieldTarget.eResource()).getID(javaFieldTarget), npe.getMessage() })); //= "error introspecting flags on {0}" } }
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. * //from w ww . j ava 2 s .c om * @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 getDeltaForField(IApiField field) { int access = field.getModifiers(); if (Flags.isSynthetic(access)) { // we ignore synthetic fields return;/* w w w . j a va2 s.com*/ } String name = field.getName(); IApiField field2 = this.type2.getField(name); if (field2 == null) { if (Flags.isPrivate(access) || Util.isDefault(access)) { this.addDelta(getElementType(this.type1), IDelta.REMOVED, IDelta.FIELD, this.currentDescriptorRestrictions, access, 0, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } else { boolean found = false; if (this.component2 != null) { if (this.type1.isInterface()) { Set<?> interfacesSet = getInterfacesSet(this.type2); if (interfacesSet != null) { for (Iterator<?> iterator = interfacesSet.iterator(); iterator.hasNext();) { IApiType superTypeDescriptor = (IApiType) iterator.next(); IApiField field3 = superTypeDescriptor.getField(name); if (field3 == 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.FIELD_MOVED_UP, this.currentDescriptorRestrictions, access, field3.getModifiers(), this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); found = true; break; } } } } else { List<IApiType> superclassList = getSuperclassList(this.type2); if (superclassList != null && isStatusOk()) { loop: for (Iterator<IApiType> iterator = superclassList.iterator(); iterator .hasNext();) { IApiType superTypeDescriptor = iterator.next(); IApiField field3 = superTypeDescriptor.getField(name); if (field3 == null) { continue; } else { int access3 = field3.getModifiers(); if (Flags.isPublic(access3) || Flags.isProtected(access3)) { // method has been move up in the // hierarchy - report the delta and // abort loop this.addDelta(getElementType(this.type1), IDelta.REMOVED, IDelta.FIELD_MOVED_UP, this.currentDescriptorRestrictions, access, field3.getModifiers(), this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); found = true; break loop; } } } } } } if (!found) { if ((this.visibilityModifiers == VisibilityModifiers.API) && component.hasApiDescription()) { // check if this field 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(field.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 field return; } } } } if (field.isEnumConstant()) { // report delta (removal of an enum constant - not // compatible) this.addDelta(getElementType(this.type1), IDelta.REMOVED, IDelta.ENUM_CONSTANT, this.currentDescriptorRestrictions, this.type1.getModifiers(), this.type2.getModifiers(), this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); return; } // removing a public field is a breakage this.addDelta(getElementType(this.type1), IDelta.REMOVED, IDelta.FIELD, this.currentDescriptorRestrictions, access, 0, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } } return; } int restrictions = RestrictionModifiers.NO_RESTRICTIONS; int referenceRestrictions = RestrictionModifiers.NO_RESTRICTIONS; int access2 = field2.getModifiers(); if (this.component2.hasApiDescription()) { try { IApiDescription apiDescription = this.component2.getApiDescription(); IApiAnnotations resolvedAPIDescription = apiDescription.resolveAnnotations(field2.getHandle()); if (resolvedAPIDescription != null) { restrictions = resolvedAPIDescription.getRestrictions(); } } catch (CoreException e) { // ignore } } if ((this.visibilityModifiers == VisibilityModifiers.API) && component.hasApiDescription()) { // check if this field 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(field.getHandle()); if (apiAnnotations != null) { referenceRestrictions = apiAnnotations.getRestrictions(); } } if (RestrictionModifiers.isReferenceRestriction(referenceRestrictions)) { // tagged as @noreference in the reference component if (!RestrictionModifiers.isReferenceRestriction(restrictions)) { // no longer tagged as @noreference // report a field addition if (field2.isEnumConstant()) { // report delta (addition of an enum constant - // compatible this.addDelta(getElementType(this.type2), IDelta.ADDED, IDelta.ENUM_CONSTANT, this.currentDescriptorRestrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type2), name }); } else { this.addDelta(getElementType(this.type2), IDelta.ADDED, IDelta.FIELD, this.currentDescriptorRestrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type2), name }); } return; } } else if (RestrictionModifiers.isReferenceRestriction(restrictions)) { if (((Flags.isPublic(access2) || Flags.isProtected(access2)) && (Flags.isPublic(access) || Flags.isProtected(access))) && (this.visibilityModifiers == VisibilityModifiers.API)) { // report that it is no longer an API field this.addDelta(getElementType(this.type2), IDelta.REMOVED, field2.isEnumConstant() ? IDelta.API_ENUM_CONSTANT : IDelta.API_FIELD, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type2), name }); } return; } } restrictions |= this.currentDescriptorRestrictions; if (!field.getSignature().equals(field2.getSignature())) { // report delta this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } else { // check type parameters String signature1 = field.getGenericSignature(); String signature2 = field2.getGenericSignature(); checkGenericSignature(signature1, signature2, field, field2); } boolean changeFinalToNonFinal = false; if (Flags.isProtected(access)) { if (Flags.isPrivate(access2) || Util.isDefault(access2)) { // report delta - decrease access: protected to default or // private this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.DECREASE_ACCESS, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } else if (Flags.isPublic(access2)) { // report delta - increase access: protected to public this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.INCREASE_ACCESS, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } } 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(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.DECREASE_ACCESS, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } else if (Flags.isPrivate(access) && (Flags.isProtected(access2) || Util.isDefault(access2) || Flags.isPublic(access2))) { this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.INCREASE_ACCESS, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } else if (Util.isDefault(access) && (Flags.isProtected(access2) || Flags.isPublic(access2))) { this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.INCREASE_ACCESS, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } if (Flags.isFinal(access)) { if (!Flags.isFinal(access2)) { if (!Flags.isStatic(access2)) { // report delta - final to non-final for a non static field this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.FINAL_TO_NON_FINAL_NON_STATIC, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } else if (field.getConstantValue() != null) { // report delta - final to non-final for a static field with // a compile time constant changeFinalToNonFinal = true; this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.FINAL_TO_NON_FINAL_STATIC_CONSTANT, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } else { // report delta - final to non-final for a static field with // no compile time constant this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.FINAL_TO_NON_FINAL_STATIC_NON_CONSTANT, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } } } else if (Flags.isFinal(access2)) { // report delta - non-final to final this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.NON_FINAL_TO_FINAL, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } if (Flags.isStatic(access)) { if (!Flags.isStatic(access2)) { // report delta - static to non-static this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.STATIC_TO_NON_STATIC, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } } else if (Flags.isStatic(access2)) { // report delta - non-static to static this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.NON_STATIC_TO_STATIC, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } if (Flags.isTransient(access)) { if (!Flags.isTransient(access2)) { // report delta - transient to non-transient this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TRANSIENT_TO_NON_TRANSIENT, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } } else if (Flags.isTransient(access2)) { // report delta - non-transient to transient this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.NON_TRANSIENT_TO_TRANSIENT, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } if (Flags.isVolatile(access)) { if (!Flags.isVolatile(access2)) { // report delta - volatile to non-volatile this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.VOLATILE_TO_NON_VOLATILE, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } } else if (Flags.isVolatile(access2)) { // report delta - non-volatile to volatile this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.NON_VOLATILE_TO_VOLATILE, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } if (Flags.isDeprecated(access)) { if (!Flags.isDeprecated(access2)) { this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.REMOVED, IDelta.DEPRECATION, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } } else if (Flags.isDeprecated(access2)) { // report delta - non-volatile to volatile this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.ADDED, IDelta.DEPRECATION, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name }); } if (field.getConstantValue() != null) { if (field2.getConstantValue() == null) { if (!changeFinalToNonFinal) { // report delta - removal of constant value this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.REMOVED, IDelta.VALUE, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name, String.valueOf(field.getConstantValue()) }); } } else if (!field.getConstantValue().equals(field2.getConstantValue())) { // report delta - modified constant value this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.CHANGED, IDelta.VALUE, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name, String.valueOf(field.getConstantValue()) }); } } else if (field2.getConstantValue() != null) { // report delta this.addDelta(IDelta.FIELD_ELEMENT_TYPE, IDelta.ADDED, IDelta.VALUE, restrictions, access, access2, this.type1, name, new String[] { Util.getDescriptorName(this.type1), name, String.valueOf(field2.getConstantValue()) }); } }
From source file:org.eclipse.pde.tools.internal.versioning.JavaClassVersionCompare.java
License:Open Source License
/** * checks if there is any change from <code>accessFlag2</code> to <code>accessFlag1</code> * we check changes which narrowed down the visibility of a field or method with protected or public modifier * //from w w w .jav a2 s. co m * @param accessFlag1 denotes combined modifiers of a field or method * @param accessFlag2 denotes combined modifiers of a field or method * @return <code>true</code> if visibility has been narrowed down from <code>accessFlag2</code> to <code>accessFlag1</code>, * <code>false</code> otherwise */ private boolean isModifierNarrowed(int accessFlag1, int accessFlag2) { if (Flags.isProtected(accessFlag2)) { // from protected to modifier other than public and protected if (!(Flags.isPublic(accessFlag1) || Flags.isProtected(accessFlag1))) { return true; } } else if (Flags.isPublic(accessFlag2)) { // from public to modifier other than public if (!Flags.isPublic(accessFlag1)) { return true; } } else { // only check which was protected or public return false; } // from non-final to final if (!Flags.isFinal(accessFlag2) && Flags.isFinal(accessFlag1)) { return true; } // from static to non-static if (Flags.isStatic(accessFlag2) && !Flags.isStatic(accessFlag1)) { return true; } // from non-abstract to abstract if (!Flags.isAbstract(accessFlag2) && Flags.isAbstract(accessFlag1)) { return true; } // volatile modifier changed if (Flags.isVolatile(accessFlag2) != Flags.isVolatile(accessFlag1)) { return true; } return false; }
From source file:org.eclipse.pde.tools.internal.versioning.JavaClassVersionCompare.java
License:Open Source License
/** * creates modifier string which includes multiple modifiers(e.g. "public static final") * /*from ww w .j av a 2 s .c om*/ * @param accessFlags accessFlags of field or method * @param changedFlags indicates change on accessFlags * @return modifier string */ private String createChangedModifierString(int accessFlags, int changedFlags) { StringBuffer buffer = new StringBuffer(); if (Flags.isPublic(changedFlags)) { if (Flags.isPublic(accessFlags)) { buffer.append(PUBLIC_STRING); buffer.append(SPACE); } else if (isDefault(accessFlags)) { buffer.append(DEFAULT_STRING); buffer.append(SPACE); } } if (Flags.isProtected(changedFlags)) { if (Flags.isProtected(accessFlags)) { buffer.append(PROTECTED_STRING); buffer.append(SPACE); } else if (isDefault(accessFlags)) { buffer.append(DEFAULT_STRING); buffer.append(SPACE); } } if (Flags.isPrivate(changedFlags)) { if (Flags.isPrivate(accessFlags)) { buffer.append(PRIVATE_STRING); buffer.append(SPACE); } else if (isDefault(accessFlags)) { buffer.append(DEFAULT_STRING); buffer.append(SPACE); } } if (Flags.isStatic(changedFlags)) { if (Flags.isStatic(accessFlags)) { buffer.append(STATIC_STRING); buffer.append(SPACE); } else { buffer.append(NON_STATIC_STRING); buffer.append(SPACE); } } if (Flags.isFinal(changedFlags)) { if (Flags.isFinal(accessFlags)) { buffer.append(FINAL_STRING); buffer.append(SPACE); } else { buffer.append(NON_FINAL_STRING); buffer.append(SPACE); } } if (Flags.isAbstract(changedFlags)) { if (Flags.isAbstract(accessFlags)) { buffer.append(ABSTRACT_STRING); buffer.append(SPACE); } else { buffer.append(NON_ABSTRACT_STRING); buffer.append(SPACE); } } if (Flags.isVolatile(changedFlags)) { if (Flags.isVolatile(accessFlags)) { buffer.append(VOLATILE_STRING); buffer.append(SPACE); } else { buffer.append(NON_VOLATILE_STRING); buffer.append(SPACE); } } return buffer.toString().trim(); }
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. java2 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(); }