Example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccSynthetic

List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccSynthetic

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccSynthetic.

Prototype

int AccSynthetic

To view the source code for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccSynthetic.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryMethod.java

License:Open Source License

public String[] getParameterNames() throws JavaModelException {
    if (this.parameterNames != null)
        return this.parameterNames;

    // force source mapping if not already done
    IType type = (IType) getParent();/*from ww w.j  a  v  a 2 s .c  om*/
    SourceMapper mapper = getSourceMapper();
    if (mapper != null) {
        char[][] paramNames = mapper.getMethodParameterNames(this);

        // map source and try to find parameter names
        if (paramNames == null) {
            IBinaryType info = (IBinaryType) ((BinaryType) getDeclaringType()).getElementInfo();
            char[] source = mapper.findSource(type, info);
            if (source != null) {
                mapper.mapSource(type, source, info);
            }
            paramNames = mapper.getMethodParameterNames(this);
        }

        // if parameter names exist, convert parameter names to String array
        if (paramNames != null) {
            String[] names = new String[paramNames.length];
            for (int i = 0; i < paramNames.length; i++) {
                names[i] = new String(paramNames[i]);
            }
            return this.parameterNames = names;
        }
    }

    // try to see if we can retrieve the names from the attached javadoc
    IBinaryMethod info = (IBinaryMethod) getElementInfo();
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316937
    // Use Signature#getParameterCount() only if the argument names are not already available.
    int paramCount = Signature.getParameterCount(new String(info.getMethodDescriptor()));
    if (this.isConstructor()) {
        final IType declaringType = this.getDeclaringType();
        if (declaringType.isMember() && !Flags.isStatic(declaringType.getFlags())) {
            paramCount--; // remove synthetic argument from constructor param count
        } else if (declaringType.isEnum()) {
            if (paramCount >= 2) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=436347
                paramCount -= 2;
        }
    }

    if (paramCount != 0) {
        // don't try to look for javadoc for synthetic methods
        int modifiers = getFlags();
        if ((modifiers & ClassFileConstants.AccSynthetic) != 0) {
            return this.parameterNames = getRawParameterNames(paramCount);
        }
        JavadocContents javadocContents = null;
        IType declaringType = getDeclaringType();
        JavaModelManager.PerProjectInfo projectInfo = manager.getPerProjectInfoCheckExistence();
        synchronized (projectInfo.javadocCache) {
            javadocContents = (JavadocContents) projectInfo.javadocCache.get(declaringType);
            if (javadocContents == null) {
                projectInfo.javadocCache.put(declaringType, BinaryType.EMPTY_JAVADOC);
            }
        }

        String methodDoc = null;
        if (javadocContents == null) {
            long timeOut = 50; // default value
            try {
                String option = getJavaProject()
                        .getOption(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, true);
                if (option != null) {
                    timeOut = Long.parseLong(option);
                }
            } catch (NumberFormatException e) {
                // ignore
            }
            if (timeOut == 0) {
                // don't try to fetch the values and don't cache either (https://bugs.eclipse.org/bugs/show_bug.cgi?id=329671)
                return getRawParameterNames(paramCount);
            }
            final class ParametersNameCollector {
                String javadoc;

                public void setJavadoc(String s) {
                    this.javadoc = s;
                }

                public String getJavadoc() {
                    return this.javadoc;
                }
            }
            /*
             * The declaring type is not in the cache yet. The thread wil retrieve the javadoc contents
             */
            final ParametersNameCollector nameCollector = new ParametersNameCollector();
            Thread collect = new Thread() {
                public void run() {
                    try {
                        // this call has a side-effect on the per project info cache
                        nameCollector.setJavadoc(BinaryMethod.this.getAttachedJavadoc(null));
                    } catch (JavaModelException e) {
                        // ignore
                    }
                    synchronized (nameCollector) {
                        nameCollector.notify();
                    }
                }
            };
            collect.start();
            synchronized (nameCollector) {
                try {
                    nameCollector.wait(timeOut);
                } catch (InterruptedException e) {
                    // ignore
                }
            }
            methodDoc = nameCollector.getJavadoc();
        } else if (javadocContents != BinaryType.EMPTY_JAVADOC) {
            // need to extract the part relative to the binary method since javadoc contains the javadoc for the declaring type
            try {
                methodDoc = javadocContents.getMethodDoc(this);
            } catch (JavaModelException e) {
                javadocContents = null;
            }
        }
        if (methodDoc != null) {
            int indexOfOpenParen = methodDoc.indexOf('(');
            // Annotations may have parameters, so make sure we are parsing the actual method parameters.
            if (info.getAnnotations() != null) {
                while (indexOfOpenParen != -1
                        && !isOpenParenForMethod(methodDoc, getElementName(), indexOfOpenParen)) {
                    indexOfOpenParen = methodDoc.indexOf('(', indexOfOpenParen + 1);
                }
            }
            if (indexOfOpenParen != -1) {
                final int indexOfClosingParen = methodDoc.indexOf(')', indexOfOpenParen);
                if (indexOfClosingParen != -1) {
                    final char[] paramsSource = CharOperation.replace(
                            methodDoc.substring(indexOfOpenParen + 1, indexOfClosingParen).toCharArray(),
                            "&nbsp;".toCharArray(), //$NON-NLS-1$
                            new char[] { ' ' });
                    final char[][] params = splitParameters(paramsSource, paramCount);
                    final int paramsLength = params.length;
                    String[] names = new String[paramsLength];
                    for (int i = 0; i < paramsLength; i++) {
                        final char[] param = params[i];
                        int indexOfSpace = CharOperation.lastIndexOf(' ', param);
                        if (indexOfSpace != -1) {
                            names[i] = String.valueOf(param, indexOfSpace + 1, param.length - indexOfSpace - 1);
                        } else {
                            names[i] = "arg" + i; //$NON-NLS-1$
                        }
                    }
                    return this.parameterNames = names;
                }
            }
        }
        // let's see if we can retrieve them from the debug infos
        char[][] argumentNames = info.getArgumentNames();
        if (argumentNames != null && argumentNames.length == paramCount) {
            String[] names = new String[paramCount];
            for (int i = 0; i < paramCount; i++) {
                names[i] = new String(argumentNames[i]);
            }
            return this.parameterNames = names;
        }
    }
    // If still no parameter names, produce fake ones, but don't cache them (https://bugs.eclipse.org/bugs/show_bug.cgi?id=329671)
    return getRawParameterNames(paramCount);
    //   throw new UnsupportedOperationException();
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java

License:Open Source License

/**
 * Create a JDT MethodDeclaration that represents a groovy MethodNode
 *//*from  www  . j  ava2s. com*/
private MethodDeclaration createMethodDeclaration(ClassNode classNode, MethodNode methodNode, boolean isEnum,
        CompilationResult compilationResult) {
    if (classNode.isAnnotationDefinition()) {
        AnnotationMethodDeclaration methodDeclaration = new AnnotationMethodDeclaration(compilationResult);
        int modifiers = methodNode.getModifiers();
        modifiers &= ~(ClassFileConstants.AccSynthetic | ClassFileConstants.AccTransient);
        methodDeclaration.annotations = transformAnnotations(methodNode.getAnnotations());
        methodDeclaration.modifiers = modifiers;
        if (methodNode.hasAnnotationDefault()) {
            methodDeclaration.modifiers |= ClassFileConstants.AccAnnotationDefault;
        }
        methodDeclaration.selector = methodNode.getName().toCharArray();
        fixupSourceLocationsForMethodDeclaration(methodDeclaration, methodNode);
        ClassNode returnType = methodNode.getReturnType();
        methodDeclaration.returnType = createTypeReferenceForClassNode(returnType);
        return methodDeclaration;
    } else {
        MethodDeclaration methodDeclaration = new MethodDeclaration(compilationResult);

        // TODO refactor - extract method
        GenericsType[] generics = methodNode.getGenericsTypes();
        // generic method
        if (generics != null && generics.length != 0) {
            methodDeclaration.typeParameters = new TypeParameter[generics.length];
            for (int tp = 0; tp < generics.length; tp++) {
                TypeParameter typeParameter = new TypeParameter();
                typeParameter.name = generics[tp].getName().toCharArray();
                ClassNode[] upperBounds = generics[tp].getUpperBounds();
                if (upperBounds != null) {
                    // FIXASC Positional info for these references?
                    typeParameter.type = createTypeReferenceForClassNode(upperBounds[0]);
                    typeParameter.bounds = (upperBounds.length > 1 ? new TypeReference[upperBounds.length - 1]
                            : null);
                    for (int b = 1, max = upperBounds.length; b < max; b++) {
                        typeParameter.bounds[b - 1] = createTypeReferenceForClassNode(upperBounds[b]);
                        typeParameter.bounds[b - 1].bits |= ASTNode.IsSuperType;
                    }
                }
                methodDeclaration.typeParameters[tp] = typeParameter;
            }
        }

        boolean isMain = false;
        // Note: modifiers for the MethodBinding constructed for this declaration will be created marked with
        // AccVarArgs if the bitset for the type reference in the final argument is marked IsVarArgs
        int modifiers = methodNode.getModifiers();
        modifiers &= ~(ClassFileConstants.AccSynthetic | ClassFileConstants.AccTransient);
        methodDeclaration.annotations = transformAnnotations(methodNode.getAnnotations());
        methodDeclaration.modifiers = modifiers;
        methodDeclaration.selector = methodNode.getName().toCharArray();
        // Need to capture the rule in Verifier.adjustTypesIfStaticMainMethod(MethodNode node)
        // if (node.getName().equals("main") && node.isStatic()) {
        // Parameter[] params = node.getParameters();
        // if (params.length == 1) {
        // Parameter param = params[0];
        // if (param.getType() == null || param.getType()==ClassHelper.OBJECT_TYPE) {
        // param.setType(ClassHelper.STRING_TYPE.makeArray());
        // ClassNode returnType = node.getReturnType();
        // if(returnType == ClassHelper.OBJECT_TYPE) {
        // node.setReturnType(ClassHelper.VOID_TYPE);
        // }
        // }
        // }
        Parameter[] params = methodNode.getParameters();
        ClassNode returnType = methodNode.getReturnType();

        // source of 'static main(args)' would become 'static Object main(Object args)' - so transform here
        if ((modifiers & ClassFileConstants.AccStatic) != 0 && params != null && params.length == 1
                && methodNode.getName().equals("main")) {
            Parameter p = params[0];
            if (p.getType() == null || p.getType().getName().equals(ClassHelper.OBJECT)) {
                String name = p.getName();
                params = new Parameter[1];
                params[0] = new Parameter(ClassHelper.STRING_TYPE.makeArray(), name);
                if (returnType.getName().equals(ClassHelper.OBJECT)) {
                    returnType = ClassHelper.VOID_TYPE;
                }
            }
        }

        methodDeclaration.arguments = createArguments(params, isMain);
        methodDeclaration.returnType = createTypeReferenceForClassNode(returnType);
        methodDeclaration.thrownExceptions = createTypeReferencesForClassNodes(methodNode.getExceptions());
        fixupSourceLocationsForMethodDeclaration(methodDeclaration, methodNode);
        return methodDeclaration;
    }
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java

License:Open Source License

/**
 * Create a JDT representation of a groovy MethodNode - but with some parameters defaulting
 *///from w  w w  .ja v a2 s .c  om
private MethodDeclaration genMethodDeclarationVariant(MethodNode methodNode, Argument[] alternativeArguments,
        TypeReference returnType, CompilationResult compilationResult) {
    MethodDeclaration methodDeclaration = new MethodDeclaration(compilationResult);
    int modifiers = methodNode.getModifiers();
    modifiers &= ~(ClassFileConstants.AccSynthetic | ClassFileConstants.AccTransient);
    methodDeclaration.annotations = transformAnnotations(methodNode.getAnnotations());
    methodDeclaration.modifiers = modifiers;
    methodDeclaration.selector = methodNode.getName().toCharArray();
    methodDeclaration.arguments = alternativeArguments;
    methodDeclaration.returnType = returnType;
    fixupSourceLocationsForMethodDeclaration(methodDeclaration, methodNode);
    return methodDeclaration;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

private void addDefaultAbstractMethods() {
    if ((this.tagBits & TagBits.KnowsDefaultAbstractMethods) != 0)
        return;/*  w w w . j  a v a2  s.  com*/

    this.tagBits |= TagBits.KnowsDefaultAbstractMethods;
    if (isClass() && isAbstract()) {
        if (this.scope.compilerOptions().targetJDK >= ClassFileConstants.JDK1_2)
            return; // no longer added for post 1.2 targets

        ReferenceBinding[] itsInterfaces = superInterfaces();
        if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
            MethodBinding[] defaultAbstracts = null;
            int defaultAbstractsCount = 0;
            ReferenceBinding[] interfacesToVisit = itsInterfaces;
            int nextPosition = interfacesToVisit.length;
            for (int i = 0; i < nextPosition; i++) {
                ReferenceBinding superType = interfacesToVisit[i];
                if (superType.isValidBinding()) {
                    MethodBinding[] superMethods = superType.methods();
                    nextAbstractMethod: for (int m = superMethods.length; --m >= 0;) {
                        MethodBinding method = superMethods[m];
                        // explicitly implemented ?
                        if (implementsMethod(method))
                            continue nextAbstractMethod;
                        if (defaultAbstractsCount == 0) {
                            defaultAbstracts = new MethodBinding[5];
                        } else {
                            // already added as default abstract ?
                            for (int k = 0; k < defaultAbstractsCount; k++) {
                                MethodBinding alreadyAdded = defaultAbstracts[k];
                                if (CharOperation.equals(alreadyAdded.selector, method.selector)
                                        && alreadyAdded.areParametersEqual(method))
                                    continue nextAbstractMethod;
                            }
                        }
                        MethodBinding defaultAbstract = new MethodBinding(
                                method.modifiers | ExtraCompilerModifiers.AccDefaultAbstract
                                        | ClassFileConstants.AccSynthetic,
                                method.selector, method.returnType, method.parameters, method.thrownExceptions,
                                this);
                        if (defaultAbstractsCount == defaultAbstracts.length)
                            System.arraycopy(defaultAbstracts, 0,
                                    defaultAbstracts = new MethodBinding[2 * defaultAbstractsCount], 0,
                                    defaultAbstractsCount);
                        defaultAbstracts[defaultAbstractsCount++] = defaultAbstract;
                    }

                    if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
                        int itsLength = itsInterfaces.length;
                        if (nextPosition + itsLength >= interfacesToVisit.length)
                            System.arraycopy(interfacesToVisit, 0,
                                    interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0,
                                    nextPosition);
                        nextInterface: for (int a = 0; a < itsLength; a++) {
                            ReferenceBinding next = itsInterfaces[a];
                            for (int b = 0; b < nextPosition; b++)
                                if (next == interfacesToVisit[b])
                                    continue nextInterface;
                            interfacesToVisit[nextPosition++] = next;
                        }
                    }
                }
            }
            if (defaultAbstractsCount > 0) {
                int length = this.methods.length;
                System.arraycopy(this.methods, 0,
                        this.methods = new MethodBinding[length + defaultAbstractsCount], 0, length);
                System.arraycopy(defaultAbstracts, 0, this.methods, length, defaultAbstractsCount);
                // re-sort methods
                length = length + defaultAbstractsCount;
                if (length > 1)
                    ReferenceBinding.sortMethods(this.methods, 0, length);
                // this.tagBits |= TagBits.AreMethodsSorted; -- already set in #methods()
            }
        }
    }
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding addSyntheticFieldForInnerclass(LocalVariableBinding actualOuterLocalVariable) {
    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(actualOuterLocalVariable);
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(
                CharOperation.concat(TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX, actualOuterLocalVariable.name),
                actualOuterLocalVariable.type,
                ClassFileConstants.AccPrivate | ClassFileConstants.AccFinal | ClassFileConstants.AccSynthetic,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size());
        this.synthetics[SourceTypeBinding.FIELD_EMUL].put(actualOuterLocalVariable, synthField);
    }/*from   ww  w.  ja  v  a2s.com*/

    // ensure there is not already such a field defined by the user
    boolean needRecheck;
    int index = 1;
    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(TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX,
                            actualOuterLocalVariable.name, ("$" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$
                    needRecheck = true;
                    break;
                }
            }
        }
    } while (needRecheck);
    return synthField;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding addSyntheticFieldForInnerclass(ReferenceBinding enclosingType) {
    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(enclosingType);
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(
                CharOperation.concat(TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX,
                        String.valueOf(enclosingType.depth()).toCharArray()),
                enclosingType,//  ww w. ja v  a  2s.com
                ClassFileConstants.AccDefault | ClassFileConstants.AccFinal | ClassFileConstants.AccSynthetic,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size());
        this.synthetics[SourceTypeBinding.FIELD_EMUL].put(enclosingType, synthField);
    }
    // ensure there is not already such a field defined by the user
    boolean needRecheck;
    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) {
                    if (this.scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_5) {
                        synthField.name = CharOperation.concat(synthField.name, "$".toCharArray()); //$NON-NLS-1$
                        needRecheck = true;
                    } else {
                        this.scope.problemReporter().duplicateFieldInType(this, fieldDecl);
                    }
                    break;
                }
            }
        }
    } while (needRecheck);
    return synthField;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding addSyntheticFieldForClassLiteral(TypeBinding targetType, BlockScope blockScope) {
    if (this.synthetics == null)
        this.synthetics = new HashMap[MAX_SYNTHETICS];
    if (this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL] == null)
        this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL] = new HashMap(5);

    // use a different table than FIELDS, given there might be a collision between emulation of X.this$0 and X.class.
    FieldBinding synthField = (FieldBinding) this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL]
            .get(targetType);/*  w  w w.  jav a  2  s.c  o  m*/
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(
                CharOperation.concat(TypeConstants.SYNTHETIC_CLASS,
                        String.valueOf(this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].size())
                                .toCharArray()),
                blockScope.getJavaLangClass(),
                ClassFileConstants.AccDefault | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].size());
        this.synthetics[SourceTypeBinding.CLASS_LITERAL_EMUL].put(targetType, synthField);
    }
    // ensure there is not already such a field defined by the user
    FieldBinding existingField;
    if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
        TypeDeclaration typeDecl = blockScope.referenceType();
        FieldDeclaration[] typeDeclarationFields = typeDecl.fields;
        int max = typeDeclarationFields == null ? 0 : typeDeclarationFields.length;
        for (int i = 0; i < max; i++) {
            FieldDeclaration fieldDecl = typeDeclarationFields[i];
            if (fieldDecl.binding == existingField) {
                blockScope.problemReporter().duplicateFieldInType(this, fieldDecl);
                break;
            }
        }
    }
    return synthField;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding addSyntheticFieldForAssert(BlockScope blockScope) {
    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,
                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$
    }/*  w ww .  j a  va 2 s.  co  m*/
    // 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;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding addSyntheticFieldForEnumValues() {
    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("enumConstantValues"); //$NON-NLS-1$
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(TypeConstants.SYNTHETIC_ENUM_VALUES,
                this.scope.createArrayType(this, 1),
                ClassFileConstants.AccPrivate | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic
                        | ClassFileConstants.AccFinal,
                this, Constant.NotAConstant, this.synthetics[SourceTypeBinding.FIELD_EMUL].size());
        this.synthetics[SourceTypeBinding.FIELD_EMUL].put("enumConstantValues", synthField); //$NON-NLS-1$
    }/*  w  ww. j a  va  2s .c o m*/
    // 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;
            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(TypeConstants.SYNTHETIC_ENUM_VALUES,
                            ("_" + String.valueOf(index++)).toCharArray()); //$NON-NLS-1$
                    needRecheck = true;
                    break;
                }
            }
        }
    } while (needRecheck);
    return synthField;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public SyntheticFieldBinding addSyntheticFieldForSwitchEnum(char[] fieldName, String key) {
    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);/*w w  w . j a  va2s  .c o m*/
    if (synthField == null) {
        synthField = new SyntheticFieldBinding(fieldName, this.scope.createArrayType(TypeBinding.INT, 1),
                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;
}