Java Code Examples for org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#AccPublic
The following examples show how to use
org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#AccPublic .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HandleBuilder.java From EasyMPermission with MIT License | 6 votes |
public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; MethodDeclaration out = new MethodDeclaration( ((CompilationUnitDeclaration) type.top().get()).compilationResult); out.selector = builderMethodName.toCharArray(); out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); out.typeParameters = copyTypeParams(typeParams, source); AllocationExpression invoke = new AllocationExpression(); invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)}; out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; }
Example 2
Source File: CodeSnippetScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public MethodBinding findMethodForArray(ArrayBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) { ReferenceBinding object = getJavaLangObject(); MethodBinding methodBinding = object.getExactMethod(selector, argumentTypes, null); if (methodBinding != null) { // handle the method clone() specially... cannot be protected or throw exceptions if (argumentTypes == Binding.NO_PARAMETERS && CharOperation.equals(selector, TypeConstants.CLONE)) return new MethodBinding((methodBinding.modifiers & ~ClassFileConstants.AccProtected) | ClassFileConstants.AccPublic, TypeConstants.CLONE, methodBinding.returnType, argumentTypes, null, object); if (canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this)) return methodBinding; } // answers closest approximation, may not check argumentTypes or visibility methodBinding = findMethod(object, selector, argumentTypes, invocationSite, false); if (methodBinding == null) return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound); if (methodBinding.isValidBinding()) { MethodBinding compatibleMethod = computeCompatibleMethod(methodBinding, argumentTypes, invocationSite, Scope.FULL_INFERENCE); if (compatibleMethod == null) return new ProblemMethodBinding(methodBinding, selector, argumentTypes, ProblemReasons.NotFound); methodBinding = compatibleMethod; if (!canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this)) return new ProblemMethodBinding(methodBinding, selector, methodBinding.parameters, ProblemReasons.NotVisible); } return methodBinding; }
Example 3
Source File: SyntheticMethodBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Construct enum special methods: values or valueOf methods */ public SyntheticMethodBinding(SourceTypeBinding declaringEnum, char[] selector) { this.declaringClass = declaringEnum; this.selector = selector; this.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved); LookupEnvironment environment = declaringEnum.scope.environment(); this.thrownExceptions = Binding.NO_EXCEPTIONS; if (selector == TypeConstants.VALUES) { this.returnType = environment.createArrayType(environment.convertToParameterizedType(declaringEnum), 1); this.parameters = Binding.NO_PARAMETERS; this.purpose = SyntheticMethodBinding.EnumValues; } else if (selector == TypeConstants.VALUEOF) { this.returnType = environment.convertToParameterizedType(declaringEnum); this.parameters = new TypeBinding[]{ declaringEnum.scope.getJavaLangString() }; this.purpose = SyntheticMethodBinding.EnumValueOf; } SyntheticMethodBinding[] knownAccessMethods = ((SourceTypeBinding)this.declaringClass).syntheticMethods(); int methodId = knownAccessMethods == null ? 0 : knownAccessMethods.length; this.index = methodId; if (declaringEnum.isStrictfp()) { this.modifiers |= ClassFileConstants.AccStrictfp; } }
Example 4
Source File: Util.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the outer most enclosing type's visibility for the given TypeDeclaration * and visibility based on compiler options. */ public static int computeOuterMostVisibility(TypeDeclaration typeDeclaration, int visibility) { while (typeDeclaration != null) { switch (typeDeclaration.modifiers & ExtraCompilerModifiers.AccVisibilityMASK) { case ClassFileConstants.AccPrivate: visibility = ClassFileConstants.AccPrivate; break; case ClassFileConstants.AccDefault: if (visibility != ClassFileConstants.AccPrivate) { visibility = ClassFileConstants.AccDefault; } break; case ClassFileConstants.AccProtected: if (visibility == ClassFileConstants.AccPublic) { visibility = ClassFileConstants.AccProtected; } break; } typeDeclaration = typeDeclaration.enclosingType; } return visibility; }
Example 5
Source File: SingletonEclipseHandler.java From tutorials with MIT License | 6 votes |
private void addFactoryMethod(EclipseNode singletonClass, TypeDeclaration astNode, TypeReference typeReference, TypeDeclaration innerClass, FieldDeclaration field) { MethodDeclaration factoryMethod = new MethodDeclaration(astNode.compilationResult); factoryMethod.modifiers = AccStatic | ClassFileConstants.AccPublic; factoryMethod.returnType = typeReference; factoryMethod.sourceStart = astNode.sourceStart; factoryMethod.sourceEnd = astNode.sourceEnd; factoryMethod.selector = "getInstance".toCharArray(); factoryMethod.bits = ECLIPSE_DO_NOT_TOUCH_FLAG; long pS = factoryMethod.sourceStart; long pE = factoryMethod.sourceEnd; long p = (long) pS << 32 | pE; FieldReference ref = new FieldReference(field.name, p); ref.receiver = new SingleNameReference(innerClass.name, p); ReturnStatement statement = new ReturnStatement(ref, astNode.sourceStart, astNode.sourceEnd); factoryMethod.statements = new Statement[]{statement}; EclipseHandlerUtil.injectMethod(singletonClass, factoryMethod); }
Example 6
Source File: Javadoc.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns whether a type can be seen at a given visibility level or not. * * @param visibility Level of visiblity allowed to see references * @param modifiers modifiers of java element to be seen * @return true if the type can be seen, false otherwise */ boolean canBeSeen(int visibility, int modifiers) { if (modifiers < 0) return true; switch (modifiers & ExtraCompilerModifiers.AccVisibilityMASK) { case ClassFileConstants.AccPublic : return true; case ClassFileConstants.AccProtected: return (visibility != ClassFileConstants.AccPublic); case ClassFileConstants.AccDefault: return (visibility == ClassFileConstants.AccDefault || visibility == ClassFileConstants.AccPrivate); case ClassFileConstants.AccPrivate: return (visibility == ClassFileConstants.AccPrivate); } return true; }
Example 7
Source File: HandleBuilder.java From EasyMPermission with MIT License | 5 votes |
public EclipseNode makeBuilderClass(EclipseNode tdParent, String builderClassName, TypeParameter[] typeParams, ASTNode source) { TypeDeclaration parent = (TypeDeclaration) tdParent.get(); TypeDeclaration builder = new TypeDeclaration(parent.compilationResult); builder.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; builder.modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; builder.typeParameters = copyTypeParams(typeParams, source); builder.name = builderClassName.toCharArray(); builder.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return injectType(tdParent, builder); }
Example 8
Source File: EclipseJavaUtilListSetSingularizer.java From EasyMPermission with MIT License | 5 votes |
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; md.modifiers = ClassFileConstants.AccPublic; List<Statement> statements = new ArrayList<Statement>(); statements.add(createConstructBuilderVarIfNeeded(data, builderType, false)); FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); thisDotField.receiver = new ThisReference(0, 0); MessageSend thisDotFieldDotAdd = new MessageSend(); thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(data.getSingularName(), 0L)}; thisDotFieldDotAdd.receiver = thisDotField; thisDotFieldDotAdd.selector = "add".toCharArray(); statements.add(thisDotFieldDotAdd); if (returnStatement != null) statements.add(returnStatement); md.statements = statements.toArray(new Statement[statements.size()]); TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType); Argument param = new Argument(data.getSingularName(), 0, paramType, 0); md.arguments = new Argument[] {param}; md.returnType = returnType; md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); data.setGeneratedByRecursive(md); injectMethod(builderType, md); }
Example 9
Source File: ReferenceBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Answer true if the receiver has public visibility */ public final boolean isPublic() { return (this.modifiers & ClassFileConstants.AccPublic) != 0; }
Example 10
Source File: SourceTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public FieldBinding addSyntheticFieldForAssert(BlockScope blockScope) { if (!isPrototype()) throw new IllegalStateException(); if (this.synthetics == null) this.synthetics = new HashMap[MAX_SYNTHETICS]; if (this.synthetics[SourceTypeBinding.FIELD_EMUL] == null) this.synthetics[SourceTypeBinding.FIELD_EMUL] = new HashMap(5); FieldBinding synthField = (FieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL].get("assertionEmulation"); //$NON-NLS-1$ if (synthField == null) { synthField = new SyntheticFieldBinding( TypeConstants.SYNTHETIC_ASSERT_DISABLED, TypeBinding.BOOLEAN, (isInterface() ? ClassFileConstants.AccPublic : ClassFileConstants.AccDefault) | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic | ClassFileConstants.AccFinal, this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size()); this.synthetics[SourceTypeBinding.FIELD_EMUL].put("assertionEmulation", synthField); //$NON-NLS-1$ } // ensure there is not already such a field defined by the user // ensure there is not already such a field defined by the user boolean needRecheck; int index = 0; do { needRecheck = false; FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = this.scope.referenceContext; int max = (typeDecl.fields == null) ? 0 : typeDecl.fields.length; for (int i = 0; i < max; i++) { FieldDeclaration fieldDecl = typeDecl.fields[i]; if (fieldDecl.binding == existingField) { synthField.name = CharOperation.concat( TypeConstants.SYNTHETIC_ASSERT_DISABLED, ("_" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$ needRecheck = true; break; } } } } while (needRecheck); return synthField; }
Example 11
Source File: MethodScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Error management: * keep null for all the errors that prevent the method to be created * otherwise return a correct method binding (but without the element * that caused the problem) : i.e. Incorrect thrown exception */ MethodBinding createMethod(AbstractMethodDeclaration method) { // is necessary to ensure error reporting this.referenceContext = method; method.scope = this; SourceTypeBinding declaringClass = referenceType().binding; int modifiers = method.modifiers | ExtraCompilerModifiers.AccUnresolved; if (method.isConstructor()) { if (method.isDefaultConstructor()) modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { if (declaringClass.isInterface()) {// interface or annotation type if (method.isDefaultMethod() || method.isStatic()) { modifiers |= ClassFileConstants.AccPublic; // default method is not abstract } else { modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } } method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); } this.isStatic = method.binding.isStatic(); Argument[] argTypes = method.arguments; int argLength = argTypes == null ? 0 : argTypes.length; long sourceLevel = compilerOptions().sourceLevel; if (argLength > 0) { Argument argument = argTypes[--argLength]; if (argument.isVarArgs() && sourceLevel >= ClassFileConstants.JDK1_5) method.binding.modifiers |= ClassFileConstants.AccVarargs; if (CharOperation.equals(argument.name, ConstantPool.This)) { problemReporter().illegalThisDeclaration(argument); } while (--argLength >= 0) { argument = argTypes[argLength]; if (argument.isVarArgs() && sourceLevel >= ClassFileConstants.JDK1_5) problemReporter().illegalVararg(argument, method); if (CharOperation.equals(argument.name, ConstantPool.This)) { problemReporter().illegalThisDeclaration(argument); } } } if (method.receiver != null) { if (sourceLevel <= ClassFileConstants.JDK1_7) { problemReporter().illegalSourceLevelForThis(method.receiver); } if (method.receiver.annotations != null) { method.bits |= ASTNode.HasTypeAnnotations; } } TypeParameter[] typeParameters = method.typeParameters(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level. if (typeParameters == null || typeParameters.length == 0) { method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature; } return method.binding; }
Example 12
Source File: CodeSnippetSkeleton.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public int getModifiers() { return ClassFileConstants.AccPublic; }
Example 13
Source File: CodeSnippetSkeleton.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public int getModifiers() { return ClassFileConstants.AccPublic; }
Example 14
Source File: MethodScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Spec : 8.4.3 & 9.4 */ private void checkAndSetModifiersForConstructor(MethodBinding methodBinding) { int modifiers = methodBinding.modifiers; final ReferenceBinding declaringClass = methodBinding.declaringClass; if ((modifiers & ExtraCompilerModifiers.AccAlternateModifierProblem) != 0) problemReporter().duplicateModifierForMethod(declaringClass, (AbstractMethodDeclaration) this.referenceContext); if ((((ConstructorDeclaration) this.referenceContext).bits & ASTNode.IsDefaultConstructor) != 0) { // certain flags are propagated from declaring class onto constructor final int DECLARING_FLAGS = ClassFileConstants.AccEnum|ClassFileConstants.AccPublic|ClassFileConstants.AccProtected; final int VISIBILITY_FLAGS = ClassFileConstants.AccPrivate|ClassFileConstants.AccPublic|ClassFileConstants.AccProtected; int flags; if ((flags = declaringClass.modifiers & DECLARING_FLAGS) != 0) { if ((flags & ClassFileConstants.AccEnum) != 0) { modifiers &= ~VISIBILITY_FLAGS; modifiers |= ClassFileConstants.AccPrivate; // default constructor is implicitly private in enum } else { modifiers &= ~VISIBILITY_FLAGS; modifiers |= flags; // propagate public/protected } } } // after this point, tests on the 16 bits reserved. int realModifiers = modifiers & ExtraCompilerModifiers.AccJustFlag; // check for abnormal modifiers final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected | ClassFileConstants.AccStrictfp); if (declaringClass.isEnum() && (((ConstructorDeclaration) this.referenceContext).bits & ASTNode.IsDefaultConstructor) == 0) { final int UNEXPECTED_ENUM_CONSTR_MODIFIERS = ~(ClassFileConstants.AccPrivate | ClassFileConstants.AccStrictfp); if ((realModifiers & UNEXPECTED_ENUM_CONSTR_MODIFIERS) != 0) { problemReporter().illegalModifierForEnumConstructor((AbstractMethodDeclaration) this.referenceContext); modifiers &= ~ExtraCompilerModifiers.AccJustFlag | ~UNEXPECTED_ENUM_CONSTR_MODIFIERS; } else if ((((AbstractMethodDeclaration) this.referenceContext).modifiers & ClassFileConstants.AccStrictfp) != 0) { // must check the parse node explicitly problemReporter().illegalModifierForMethod((AbstractMethodDeclaration) this.referenceContext); } modifiers |= ClassFileConstants.AccPrivate; // enum constructor is implicitly private } else if ((realModifiers & UNEXPECTED_MODIFIERS) != 0) { problemReporter().illegalModifierForMethod((AbstractMethodDeclaration) this.referenceContext); modifiers &= ~ExtraCompilerModifiers.AccJustFlag | ~UNEXPECTED_MODIFIERS; } else if ((((AbstractMethodDeclaration) this.referenceContext).modifiers & ClassFileConstants.AccStrictfp) != 0) { // must check the parse node explicitly problemReporter().illegalModifierForMethod((AbstractMethodDeclaration) this.referenceContext); } // check for incompatible modifiers in the visibility bits, isolate the visibility bits int accessorBits = realModifiers & (ClassFileConstants.AccPublic | ClassFileConstants.AccProtected | ClassFileConstants.AccPrivate); if ((accessorBits & (accessorBits - 1)) != 0) { problemReporter().illegalVisibilityModifierCombinationForMethod(declaringClass, (AbstractMethodDeclaration) this.referenceContext); // need to keep the less restrictive so disable Protected/Private as necessary if ((accessorBits & ClassFileConstants.AccPublic) != 0) { if ((accessorBits & ClassFileConstants.AccProtected) != 0) modifiers &= ~ClassFileConstants.AccProtected; if ((accessorBits & ClassFileConstants.AccPrivate) != 0) modifiers &= ~ClassFileConstants.AccPrivate; } else if ((accessorBits & ClassFileConstants.AccProtected) != 0 && (accessorBits & ClassFileConstants.AccPrivate) != 0) { modifiers &= ~ClassFileConstants.AccPrivate; } } // // if the receiver's declaring class is a private nested type, then make sure the receiver is not private (causes problems for inner type emulation) // if (declaringClass.isPrivate() && (modifiers & ClassFileConstants.AccPrivate) != 0) // modifiers &= ~ClassFileConstants.AccPrivate; methodBinding.modifiers = modifiers; }
Example 15
Source File: ConstructorDeclarationPattern.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void decodeIndexKey(char[] key) { int last = key.length - 1; int slash = CharOperation.indexOf(SEPARATOR, key, 0); this.declaringSimpleName = CharOperation.subarray(key, 0, slash); int start = slash + 1; slash = CharOperation.indexOf(SEPARATOR, key, start); last = slash - 1; boolean isDefaultConstructor = key[last] == '#'; if (isDefaultConstructor) { this.parameterCount = -1; } else { this.parameterCount = 0; int power = 1; for (int i = last; i >= start; i--) { if (i == last) { this.parameterCount = key[i] - '0'; } else { power *= 10; this.parameterCount += power * (key[i] - '0'); } } } slash = slash + 3; last = slash - 1; int typeModifiersWithExtraFlags = key[last-1] + (key[last]<<16); this.declaringTypeModifiers = decodeModifers(typeModifiersWithExtraFlags); this.extraFlags = decodeExtraFlags(typeModifiersWithExtraFlags); // initialize optional fields this.declaringPackageName = null; this.modifiers = 0; this.signature = null; this.parameterTypes = null; this.parameterNames = null; boolean isMemberType = (this.extraFlags & ExtraFlags.IsMemberType) != 0; if (!isMemberType) { start = slash + 1; if (this.parameterCount == -1) { slash = key.length; last = slash - 1; } else { slash = CharOperation.indexOf(SEPARATOR, key, start); } last = slash - 1; this.declaringPackageName = CharOperation.subarray(key, start, slash); start = slash + 1; if (this.parameterCount == 0) { slash = slash + 3; last = slash - 1; this.modifiers = key[last-1] + (key[last]<<16); } else if (this.parameterCount > 0){ slash = CharOperation.indexOf(SEPARATOR, key, start); last = slash - 1; boolean hasParameterStoredAsSignature = (this.extraFlags & ExtraFlags.ParameterTypesStoredAsSignature) != 0; if (hasParameterStoredAsSignature) { this.signature = CharOperation.subarray(key, start, slash); CharOperation.replace(this.signature , '\\', SEPARATOR); } else { this.parameterTypes = CharOperation.splitOn(PARAMETER_SEPARATOR, key, start, slash); } start = slash + 1; slash = CharOperation.indexOf(SEPARATOR, key, start); last = slash - 1; if (slash != start) { this.parameterNames = CharOperation.splitOn(PARAMETER_SEPARATOR, key, start, slash); } slash = slash + 3; last = slash - 1; this.modifiers = key[last-1] + (key[last]<<16); } else { this.modifiers = ClassFileConstants.AccPublic; } } removeInternalFlags(); // remove internal flags }
Example 16
Source File: SourceTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public SyntheticFieldBinding addSyntheticFieldForSwitchEnum(char[] fieldName, String key) { if (!isPrototype()) throw new IllegalStateException(); if (this.synthetics == null) this.synthetics = new HashMap[MAX_SYNTHETICS]; if (this.synthetics[SourceTypeBinding.FIELD_EMUL] == null) this.synthetics[SourceTypeBinding.FIELD_EMUL] = new HashMap(5); SyntheticFieldBinding synthField = (SyntheticFieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL].get(key); if (synthField == null) { synthField = new SyntheticFieldBinding( fieldName, this.scope.createArrayType(TypeBinding.INT,1), (isInterface() ? (ClassFileConstants.AccPublic | ClassFileConstants.AccFinal) : ClassFileConstants.AccPrivate) | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic, this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size()); this.synthetics[SourceTypeBinding.FIELD_EMUL].put(key, synthField); } // ensure there is not already such a field defined by the user boolean needRecheck; int index = 0; do { needRecheck = false; FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = this.scope.referenceContext; FieldDeclaration[] fieldDeclarations = typeDecl.fields; int max = fieldDeclarations == null ? 0 : fieldDeclarations.length; for (int i = 0; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.binding == existingField) { synthField.name = CharOperation.concat( fieldName, ("_" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$ needRecheck = true; break; } } } } while (needRecheck); return synthField; }
Example 17
Source File: EclipseJavaUtilMapSingularizer.java From EasyMPermission with MIT License | 4 votes |
private void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; md.modifiers = ClassFileConstants.AccPublic; String pN = new String(data.getPluralName()); char[] keyFieldName = (pN + "$key").toCharArray(); char[] valueFieldName = (pN + "$value").toCharArray(); List<Statement> statements = new ArrayList<Statement>(); statements.add(createConstructBuilderVarIfNeeded(data, builderType, true)); char[] entryName = "$lombokEntry".toCharArray(); TypeReference forEachType = new QualifiedTypeReference(JAVA_UTIL_MAP_ENTRY, NULL_POSS); forEachType = addTypeArgs(2, true, builderType, forEachType, data.getTypeArgs()); MessageSend keyArg = new MessageSend(); keyArg.receiver = new SingleNameReference(entryName, 0L); keyArg.selector = "getKey".toCharArray(); MessageSend addKey = new MessageSend(); FieldReference thisDotKeyField = new FieldReference(keyFieldName, 0L); thisDotKeyField.receiver = new ThisReference(0, 0); addKey.receiver = thisDotKeyField; addKey.selector = new char[] {'a', 'd', 'd'}; addKey.arguments = new Expression[] {keyArg}; MessageSend valueArg = new MessageSend(); valueArg.receiver = new SingleNameReference(entryName, 0L); valueArg.selector = "getValue".toCharArray(); MessageSend addValue = new MessageSend(); FieldReference thisDotValueField = new FieldReference(valueFieldName, 0L); thisDotValueField.receiver = new ThisReference(0, 0); addValue.receiver = thisDotValueField; addValue.selector = new char[] {'a', 'd', 'd'}; addValue.arguments = new Expression[] {valueArg}; LocalDeclaration elementVariable = new LocalDeclaration(entryName, 0, 0); elementVariable.type = forEachType; ForeachStatement forEach = new ForeachStatement(elementVariable, 0); MessageSend invokeEntrySet = new MessageSend(); invokeEntrySet.selector = new char[] { 'e', 'n', 't', 'r', 'y', 'S', 'e', 't'}; invokeEntrySet.receiver = new SingleNameReference(data.getPluralName(), 0L); forEach.collection = invokeEntrySet; Block forEachContent = new Block(0); forEachContent.statements = new Statement[] {addKey, addValue}; forEach.action = forEachContent; statements.add(forEach); if (returnStatement != null) statements.add(returnStatement); md.statements = statements.toArray(new Statement[statements.size()]); TypeReference paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs()); Argument param = new Argument(data.getPluralName(), 0, paramType, 0); md.arguments = new Argument[] {param}; md.returnType = returnType; md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("putAll", new String(data.getPluralName())).toCharArray(); data.setGeneratedByRecursive(md); injectMethod(builderType, md); }
Example 18
Source File: MethodBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final boolean isPublic() { return (this.modifiers & ClassFileConstants.AccPublic) != 0; }
Example 19
Source File: EclipseGuavaSingularizer.java From EasyMPermission with MIT License | 4 votes |
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { boolean mapMode = isMap(); char[] keyName = !mapMode ? data.getSingularName() : (new String(data.getSingularName()) + "$key").toCharArray(); char[] valueName = !mapMode ? null : (new String(data.getSingularName()) + "$value").toCharArray(); MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; md.modifiers = ClassFileConstants.AccPublic; List<Statement> statements = new ArrayList<Statement>(); statements.add(createConstructBuilderVarIfNeeded(data, builderType)); FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); thisDotField.receiver = new ThisReference(0, 0); MessageSend thisDotFieldDotAdd = new MessageSend(); if (mapMode) { thisDotFieldDotAdd.arguments = new Expression[] { new SingleNameReference(keyName, 0L), new SingleNameReference(valueName, 0L)}; } else { thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(keyName, 0L)}; } thisDotFieldDotAdd.receiver = thisDotField; thisDotFieldDotAdd.selector = (mapMode ? "put" : "add").toCharArray(); statements.add(thisDotFieldDotAdd); if (returnStatement != null) statements.add(returnStatement); md.statements = statements.toArray(new Statement[statements.size()]); if (mapMode) { TypeReference keyType = cloneParamType(0, data.getTypeArgs(), builderType); Argument keyParam = new Argument(keyName, 0, keyType, 0); TypeReference valueType = cloneParamType(1, data.getTypeArgs(), builderType); Argument valueParam = new Argument(valueName, 0, valueType, 0); md.arguments = new Argument[] {keyParam, valueParam}; } else { TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType); Argument param = new Argument(keyName, 0, paramType, 0); md.arguments = new Argument[] {param}; } md.returnType = returnType; md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName(mapMode ? "put" : "add", new String(data.getSingularName())).toCharArray(); data.setGeneratedByRecursive(md); injectMethod(builderType, md); }
Example 20
Source File: FieldBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final boolean isPublic() { return (this.modifiers & ClassFileConstants.AccPublic) != 0; }