Example usage for org.eclipse.jdt.internal.compiler.lookup TypeConstants PACKAGE_INFO_NAME

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeConstants PACKAGE_INFO_NAME

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup TypeConstants PACKAGE_INFO_NAME.

Prototype

null PACKAGE_INFO_NAME

To view the source code for org.eclipse.jdt.internal.compiler.lookup TypeConstants PACKAGE_INFO_NAME.

Click Source Link

Usage

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

License:Open Source License

protected boolean seekTypesInWorkingCopies(String name, IPackageFragment pkg, int firstDot,
        boolean partialMatch, String topLevelTypeName, int acceptFlags, IJavaElementRequestor requestor,
        boolean considerSecondaryTypes) {

    if (!partialMatch) {
        HashMap typeMap = (HashMap) (this.typesInWorkingCopies == null ? null
                : this.typesInWorkingCopies.get(pkg));
        if (typeMap != null) {
            Object object = typeMap.get(topLevelTypeName);
            if (object instanceof IType) {
                IType type = getMemberType((IType) object, name, firstDot);
                if (!considerSecondaryTypes && !isPrimaryType(name, (IType) object, false))
                    return false;
                if (acceptType(type, acceptFlags, true/*a source type*/)) {
                    requestor.acceptType(type);
                    return true; // don't continue with compilation unit
                }//from   ww  w .  ja v a  2 s  . c o m
            } else if (object instanceof IType[]) {
                if (object == NO_TYPES) {
                    // all types where deleted -> type is hidden, OR it is the fake type package-info
                    String packageInfoName = String.valueOf(TypeConstants.PACKAGE_INFO_NAME);
                    if (packageInfoName.equals(name))
                        requestor.acceptType(pkg.getCompilationUnit(packageInfoName.concat(SUFFIX_STRING_java))
                                .getType(name));
                    return true;
                }
                IType[] topLevelTypes = (IType[]) object;
                for (int i = 0, length = topLevelTypes.length; i < length; i++) {
                    if (requestor.isCanceled())
                        return false;
                    IType type = getMemberType(topLevelTypes[i], name, firstDot);
                    if (acceptType(type, acceptFlags, true/*a source type*/)) {
                        requestor.acceptType(type);
                        return true; // return the first one
                    }
                }
            }
        }
    } else {
        HashMap typeMap = (HashMap) (this.typesInWorkingCopies == null ? null
                : this.typesInWorkingCopies.get(pkg));
        if (typeMap != null) {
            Iterator iterator = typeMap.values().iterator();
            while (iterator.hasNext()) {
                if (requestor.isCanceled())
                    return false;
                Object object = iterator.next();
                if (object instanceof IType) {
                    if (!considerSecondaryTypes && !isPrimaryType(name, (IType) object, true))
                        continue;
                    seekTypesInTopLevelType(name, firstDot, (IType) object, requestor, acceptFlags);
                } else if (object instanceof IType[]) {
                    IType[] topLevelTypes = (IType[]) object;
                    for (int i = 0, length = topLevelTypes.length; i < length; i++)
                        seekTypesInTopLevelType(name, firstDot, topLevelTypes[i], requestor, acceptFlags);
                }
            }
        }
    }
    return false;
}

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

License:Open Source License

/**
 * Returns the given type in the the given package if it exists,
 * otherwise <code>null</code>.
 *//*from   w w  w .jav  a 2s  . co  m*/
protected NameEnvironmentAnswer find(String typeName, String packageName) {
    if (packageName == null)
        packageName = IPackageFragment.DEFAULT_PACKAGE_NAME;
    if (this.owner != null) {
        String source = this.owner.findSource(typeName, packageName);
        if (source != null) {
            ICompilationUnit cu = new BasicCompilationUnit(source.toCharArray(),
                    CharOperation.splitOn('.', packageName.toCharArray()),
                    typeName + Util.defaultJavaExtension());
            return new NameEnvironmentAnswer(cu, null);
        }
    }
    NameLookup.Answer answer = this.nameLookup.findType(typeName, packageName, false/*exact match*/,
            NameLookup.ACCEPT_ALL, this.checkAccessRestrictions);
    if (answer != null) {
        // construct name env answer
        if (answer.type instanceof BinaryType) { // BinaryType
            try {
                return new NameEnvironmentAnswer((IBinaryType) ((BinaryType) answer.type).getElementInfo(),
                        answer.restriction);
            } catch (JavaModelException npe) {
                // fall back to using owner
            }
        } else { //SourceType
            try {
                // retrieve the requested type
                SourceTypeElementInfo sourceType = (SourceTypeElementInfo) ((SourceType) answer.type)
                        .getElementInfo();
                ISourceType topLevelType = sourceType;
                while (topLevelType.getEnclosingType() != null) {
                    topLevelType = topLevelType.getEnclosingType();
                }
                // find all siblings (other types declared in same unit, since may be used for name resolution)
                IType[] types = sourceType.getHandle().getCompilationUnit().getTypes();
                ISourceType[] sourceTypes = new ISourceType[types.length];

                // in the resulting collection, ensure the requested type is the first one
                sourceTypes[0] = sourceType;
                int length = types.length;
                for (int i = 0, index = 1; i < length; i++) {
                    ISourceType otherType = (ISourceType) ((JavaElement) types[i]).getElementInfo();
                    if (!otherType.equals(topLevelType) && index < length) // check that the index is in bounds (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=62861)
                        sourceTypes[index++] = otherType;
                }
                return new NameEnvironmentAnswer(sourceTypes, answer.restriction);
            } catch (JavaModelException jme) {
                if (jme.isDoesNotExist() && String.valueOf(TypeConstants.PACKAGE_INFO_NAME).equals(typeName)) {
                    // in case of package-info.java the type doesn't exist in the model,
                    // but the CU may still help in order to fetch package level annotations.
                    return new NameEnvironmentAnswer((ICompilationUnit) answer.type.getParent(),
                            answer.restriction);
                }
                // no usable answer
            }
        }
    }
    return null;
}

From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java

License:Open Source License

protected void createProblemFor(IResource resource, IMember javaElement, String message,
        String problemSeverity) {
    try {/*from www. j a v  a 2  s.c o m*/
        IMarker marker = resource.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
        int severity = problemSeverity.equals(JavaCore.WARNING) ? IMarker.SEVERITY_WARNING
                : IMarker.SEVERITY_ERROR;

        ISourceRange range = null;
        if (javaElement != null) {
            try {
                range = javaElement.getNameRange();
            } catch (JavaModelException e) {
                if (e.getJavaModelStatus().getCode() != IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST) {
                    throw e;
                }
                if (!CharOperation.equals(javaElement.getElementName().toCharArray(),
                        TypeConstants.PACKAGE_INFO_NAME)) {
                    throw e;
                }
                // else silently swallow the exception as the synthetic interface type package-info has no
                // source range really. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=258145
            }
        }
        int start = range == null ? 0 : range.getOffset();
        int end = range == null ? 1 : start + range.getLength();
        marker.setAttributes(
                new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IMarker.CHAR_START, IMarker.CHAR_END,
                        IMarker.SOURCE_ID },
                new Object[] { message, new Integer(severity), new Integer(start), new Integer(end),
                        JavaBuilder.SOURCE_ID });
    } catch (CoreException e) {
        throw internalException(e);
    }
}

From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java

License:Open Source License

/**
 * Creates a marker from each problem and adds it to the resource.
 * The marker is as follows://  w w w  .ja  va  2 s  .c  o  m
 *   - its type is T_PROBLEM
 *   - its plugin ID is the JavaBuilder's plugin ID
 *    - its message is the problem's message
 *    - its priority reflects the severity of the problem
 *    - its range is the problem's range
 *    - it has an extra attribute "ID" which holds the problem's id
 *   - it's {@link IMarker#SOURCE_ID} attribute is positioned to {@link JavaBuilder#SOURCE_ID} if
 *     the problem was generated by JDT; else the {@link IMarker#SOURCE_ID} attribute is
 *     carried from the problem to the marker in extra attributes, if present.
 */
protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] problems) throws CoreException {
    if (sourceFile == null || problems == null || problems.length == 0)
        return;
    // once a classpath error is found, ignore all other problems for this project so the user can see the main error
    // but still try to compile as many source files as possible to help the case when the base libraries are in source
    if (!this.keepStoringProblemMarkers)
        return; // only want the one error recorded on this source file

    HashSet managedMarkerTypes = JavaModelManager.getJavaModelManager().compilationParticipants
            .managedMarkerTypes();
    problems: for (int i = 0, l = problems.length; i < l; i++) {
        CategorizedProblem problem = problems[i];
        int id = problem.getID();
        // we may use a different resource for certain problems such as IProblem.MissingNonNullByDefaultAnnotationOnPackage
        // but at the start of the next problem we should reset it to the source file's resource
        IResource resource = sourceFile.resource;

        // handle missing classfile situation
        if (id == IProblem.IsClassPathCorrect) {
            String missingClassfileName = problem.getArguments()[0];
            if (JavaBuilder.DEBUG)
                System.out.println(Messages.bind(Messages.build_incompleteClassPath, missingClassfileName));
            boolean isInvalidClasspathError = JavaCore.ERROR
                    .equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true));
            // insert extra classpath problem, and make it the only problem for this project (optional)
            if (isInvalidClasspathError && JavaCore.ABORT.equals(
                    this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true))) {
                JavaBuilder.removeProblemsAndTasksFor(this.javaBuilder.currentProject); // make this the only problem for this project
                this.keepStoringProblemMarkers = false;
            }
            IMarker marker = this.javaBuilder.currentProject
                    .createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
            marker.setAttributes(
                    new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID,
                            IMarker.SOURCE_ID },
                    new Object[] { Messages.bind(Messages.build_incompleteClassPath, missingClassfileName),
                            new Integer(isInvalidClasspathError ? IMarker.SEVERITY_ERROR
                                    : IMarker.SEVERITY_WARNING),
                            new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID });
            // even if we're not keeping more markers, still fall through rest of the problem reporting, so that offending
            // IsClassPathCorrect problem gets recorded since it may help locate the offending reference
        }

        String markerType = problem.getMarkerType();
        boolean managedProblem = false;
        if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType)
                || (managedProblem = managedMarkerTypes.contains(markerType))) {
            if (id == IProblem.MissingNonNullByDefaultAnnotationOnPackage
                    && !(CharOperation.equals(sourceFile.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME))) {
                // for this kind of problem, marker needs to be created on the package instead of on the source file
                // see bug 372012
                char[] fileName = sourceFile.getFileName();
                int pkgEnd = CharOperation.lastIndexOf('/', fileName);
                if (pkgEnd == -1)
                    pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
                PackageFragment pkg = null;
                if (pkgEnd != -1)
                    pkg = (PackageFragment) Util.getPackageFragment(sourceFile.getFileName(), pkgEnd,
                            -1 /*no jar separator for java files*/);

                if (pkg != null) {
                    try {
                        IMarker[] existingMarkers = pkg.resource().findMarkers(
                                IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
                        int len = existingMarkers.length;
                        for (int j = 0; j < len; j++) {
                            if (((Integer) existingMarkers[j].getAttribute(IJavaModelMarker.ID))
                                    .intValue() == IProblem.MissingNonNullByDefaultAnnotationOnPackage) {
                                continue problems; // marker already present
                            }
                        }
                    } catch (CoreException e) {
                        // marker retrieval failed, cannot do much
                        if (JavaModelManager.VERBOSE) {
                            e.printStackTrace();
                        }
                    }
                    IResource tempRes = pkg.resource();
                    if (tempRes != null) {
                        resource = tempRes;
                    }
                }
            }
            IMarker marker = resource.createMarker(markerType);

            String[] attributeNames = JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES;
            int standardLength = attributeNames.length;
            String[] allNames = attributeNames;
            int managedLength = managedProblem ? 0 : 1;
            String[] extraAttributeNames = problem.getExtraMarkerAttributeNames();
            int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length;
            if (managedLength > 0 || extraLength > 0) {
                allNames = new String[standardLength + managedLength + extraLength];
                System.arraycopy(attributeNames, 0, allNames, 0, standardLength);
                if (managedLength > 0)
                    allNames[standardLength] = IMarker.SOURCE_ID;
                System.arraycopy(extraAttributeNames, 0, allNames, standardLength + managedLength, extraLength);
            }

            Object[] allValues = new Object[allNames.length];
            // standard attributes
            int index = 0;
            allValues[index++] = problem.getMessage(); // message
            allValues[index++] = problem.isError() ? S_ERROR : S_WARNING; // severity
            allValues[index++] = new Integer(id); // ID
            allValues[index++] = new Integer(problem.getSourceStart()); // start
            allValues[index++] = new Integer(problem.getSourceEnd() + 1); // end
            allValues[index++] = new Integer(problem.getSourceLineNumber()); // line
            allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments
            allValues[index++] = new Integer(problem.getCategoryID()); // category ID
            // SOURCE_ID attribute for JDT problems
            if (managedLength > 0)
                allValues[index++] = JavaBuilder.SOURCE_ID;
            // optional extra attributes
            if (extraLength > 0)
                System.arraycopy(problem.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength);

            marker.setAttributes(allNames, allValues);

            if (!this.keepStoringProblemMarkers)
                return; // only want the one error recorded on this source file
        }
    }
}

From source file:net.sf.j2s.core.builder.IncrementalImageBuilder.java

License:Open Source License

protected void addDependentsOf(IPath path, boolean isStructuralChange, StringSet qualifiedNames,
        StringSet simpleNames, StringSet rootNames) {
    path = path.setDevice(null);/*from ww  w.  jav  a  2 s  .  c  om*/
    if (isStructuralChange) {
        String last = path.lastSegment();
        if (last.length() == TypeConstants.PACKAGE_INFO_NAME.length)
            if (CharOperation.equals(last.toCharArray(), TypeConstants.PACKAGE_INFO_NAME)) {
                path = path.removeLastSegments(1); // the package-info file has changed so blame the package itself
                /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=323785, in the case of default package,
                   there is no need to blame the package itself as there can be no annotations or documentation
                   comment tags in the package-info file that can influence the rest of the package. Just bail out
                   so we don't touch null objects below.
                 */
                if (path.isEmpty())
                    return;
            }
    }

    if (isStructuralChange && !this.hasStructuralChanges) {
        this.newState.tagAsStructurallyChanged();
        this.hasStructuralChanges = true;
    }
    // the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are just 'X'
    rootNames.add(path.segment(0));
    String packageName = path.removeLastSegments(1).toString();
    boolean wasNew = qualifiedNames.add(packageName);
    String typeName = path.lastSegment();
    int memberIndex = typeName.indexOf('$');
    if (memberIndex > 0)
        typeName = typeName.substring(0, memberIndex);
    wasNew = simpleNames.add(typeName) | wasNew;
    if (wasNew && JavaBuilder.DEBUG)
        System.out.println("  will look for dependents of " //$NON-NLS-1$
                + typeName + " in " + packageName); //$NON-NLS-1$
}

From source file:net.sf.j2s.core.builder.IncrementalImageBuilder.java

License:Open Source License

protected void updateProblemsFor(SourceFile sourceFile, CompilationResult result) throws CoreException {
    if (CharOperation.equals(sourceFile.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME)) {
        IResource pkgResource = sourceFile.resource.getParent();
        pkgResource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
    }/*  ww w .ja v  a 2  s .  c  o  m*/
    IMarker[] markers = JavaBuilder.getProblemsFor(sourceFile.resource);
    CategorizedProblem[] problems = result.getProblems();
    if (problems == null && markers.length == 0)
        return;

    this.notifier.updateProblemCounts(markers, problems);
    JavaBuilder.removeProblemsFor(sourceFile.resource);
    storeProblemsFor(sourceFile, problems);
}

From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementNotifier.java

License:Open Source License

protected void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence,
        TypeDeclaration declaringType) {

    if (CharOperation.equals(TypeConstants.PACKAGE_INFO_NAME, typeDeclaration.name))
        return;/* ww w. j a v a 2  s .co  m*/

    //   AspectJ change begin
    boolean isAspect = false;
    org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration ajtypeDeclaration = new org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration(
            new org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult(
                    typeDeclaration.compilationResult.fileName, typeDeclaration.compilationResult.unitIndex,
                    typeDeclaration.compilationResult.totalUnitsKnown, 500));
    if (ajtypeDeclaration instanceof AspectDeclaration) {
        isAspect = true;
    }
    //   AspectJ change end

    // range check
    boolean isInRange = initialPosition <= typeDeclaration.declarationSourceStart
            && eofPosition >= typeDeclaration.declarationSourceEnd;

    FieldDeclaration[] fields = typeDeclaration.fields;
    AbstractMethodDeclaration[] methods = typeDeclaration.methods;
    TypeDeclaration[] memberTypes = typeDeclaration.memberTypes;
    int fieldCounter = fields == null ? 0 : fields.length;
    int methodCounter = methods == null ? 0 : methods.length;
    int memberTypeCounter = memberTypes == null ? 0 : memberTypes.length;
    int fieldIndex = 0;
    int methodIndex = 0;
    int memberTypeIndex = 0;

    if (notifyTypePresence) {
        char[][] interfaceNames = getInterfaceNames(typeDeclaration);
        int kind = TypeDeclaration.kind(typeDeclaration.modifiers);
        char[] implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT;
        if (isInRange) {
            int currentModifiers = typeDeclaration.modifiers;

            // remember deprecation so as to not lose it below
            boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0
                    || hasDeprecatedAnnotation(typeDeclaration.annotations);

            boolean isEnumInit = typeDeclaration.allocation != null
                    && typeDeclaration.allocation.enumConstant != null;
            char[] superclassName;
            if (isEnumInit) {
                currentModifiers |= ClassFileConstants.AccEnum;
                superclassName = declaringType.name;
            } else {
                superclassName = getSuperclassName(typeDeclaration);
            }
            ISourceElementRequestor.TypeInfo typeInfo = new ISourceElementRequestor.TypeInfo();
            if (typeDeclaration.allocation == null) {
                typeInfo.declarationStart = typeDeclaration.declarationSourceStart;
            } else if (isEnumInit) {
                typeInfo.declarationStart = typeDeclaration.allocation.enumConstant.sourceStart;
            } else {
                typeInfo.declarationStart = typeDeclaration.allocation.sourceStart;
            }
            typeInfo.modifiers = deprecated
                    ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated
                    : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
            typeInfo.name = typeDeclaration.name;
            typeInfo.nameSourceStart = isEnumInit ? typeDeclaration.allocation.enumConstant.sourceStart
                    : typeDeclaration.sourceStart;
            typeInfo.nameSourceEnd = sourceEnd(typeDeclaration);
            typeInfo.superclass = superclassName;
            typeInfo.superinterfaces = interfaceNames;
            typeInfo.typeParameters = getTypeParameterInfos(typeDeclaration.typeParameters);
            typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
            typeInfo.secondary = typeDeclaration.isSecondary();
            typeInfo.anonymousMember = typeDeclaration.allocation != null
                    && typeDeclaration.allocation.enclosingInstance != null;
            typeInfo.annotations = typeDeclaration.annotations;
            typeInfo.node = typeDeclaration;
            requestor.enterType(typeInfo, isAspect,
                    (isAspect ? ((AspectDeclaration) ajtypeDeclaration).isPrivileged : false)); // AspectJ change
            switch (kind) {
            case TypeDeclaration.CLASS_DECL:
                if (superclassName != null)
                    implicitSuperclassName = superclassName;
                break;
            case TypeDeclaration.INTERFACE_DECL:
                implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT;
                break;
            case TypeDeclaration.ENUM_DECL:
                implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_ENUM;
                break;
            case TypeDeclaration.ANNOTATION_TYPE_DECL:
                implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_ANNOTATION_ANNOTATION;
                break;
            }
        }
        if (this.nestedTypeIndex == this.typeNames.length) {
            // need a resize
            System.arraycopy(this.typeNames, 0, (this.typeNames = new char[this.nestedTypeIndex * 2][]), 0,
                    this.nestedTypeIndex);
            System.arraycopy(this.superTypeNames, 0,
                    (this.superTypeNames = new char[this.nestedTypeIndex * 2][]), 0, this.nestedTypeIndex);
        }
        this.typeNames[this.nestedTypeIndex] = typeDeclaration.name;
        this.superTypeNames[this.nestedTypeIndex++] = implicitSuperclassName;
    }
    while ((fieldIndex < fieldCounter) || (memberTypeIndex < memberTypeCounter)
            || (methodIndex < methodCounter)) {
        FieldDeclaration nextFieldDeclaration = null;
        AbstractMethodDeclaration nextMethodDeclaration = null;
        TypeDeclaration nextMemberDeclaration = null;

        int position = Integer.MAX_VALUE;
        int nextDeclarationType = -1;
        if (fieldIndex < fieldCounter) {
            nextFieldDeclaration = fields[fieldIndex];
            if (nextFieldDeclaration.declarationSourceStart < position) {
                position = nextFieldDeclaration.declarationSourceStart;
                nextDeclarationType = 0; // FIELD
            }
        }
        if (methodIndex < methodCounter) {
            nextMethodDeclaration = methods[methodIndex];
            if (nextMethodDeclaration.declarationSourceStart < position) {
                position = nextMethodDeclaration.declarationSourceStart;
                nextDeclarationType = 1; // METHOD
            }
        }
        if (memberTypeIndex < memberTypeCounter) {
            nextMemberDeclaration = memberTypes[memberTypeIndex];
            if (nextMemberDeclaration.declarationSourceStart < position) {
                position = nextMemberDeclaration.declarationSourceStart;
                nextDeclarationType = 2; // MEMBER
            }
        }
        switch (nextDeclarationType) {
        case 0:
            fieldIndex++;
            notifySourceElementRequestor(nextFieldDeclaration, typeDeclaration);
            break;
        case 1:
            methodIndex++;
            notifySourceElementRequestor(nextMethodDeclaration);
            break;
        case 2:
            memberTypeIndex++;
            notifySourceElementRequestor(nextMemberDeclaration, true, null);
        }
    }
    if (notifyTypePresence) {
        if (isInRange) {
            requestor.exitType(typeDeclaration.declarationSourceEnd);
        }
        nestedTypeIndex--;
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public CompilationUnit convert(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration unit,
        char[] source) {
    try {/*from  w w w.  jav  a 2  s.c o m*/
        if (unit.compilationResult.recoveryScannerData != null) {
            RecoveryScanner recoveryScanner = new RecoveryScanner(this.scanner,
                    unit.compilationResult.recoveryScannerData.removeUnused());
            this.scanner = recoveryScanner;
            this.docParser.scanner = this.scanner;
        }
        this.compilationUnitSource = source;
        this.compilationUnitSourceLength = source.length;
        this.scanner.setSource(source, unit.compilationResult);
        // GROOVY start
        /* old {
        CompilationUnit compilationUnit = new CompilationUnit(this.ast);
         } new */
        CompilationUnit compilationUnit = unit.getSpecialDomCompilationUnit(this.ast);
        if (compilationUnit == null) {
            compilationUnit = new CompilationUnit(this.ast);
        }
        // GROOVY end
        compilationUnit.setStatementsRecoveryData(unit.compilationResult.recoveryScannerData);

        // Parse comments
        int[][] comments = unit.comments;
        if (comments != null) {
            buildCommentsTable(compilationUnit, comments);
        }

        // handle the package declaration immediately
        // There is no node corresponding to the package declaration
        if (this.resolveBindings) {
            recordNodes(compilationUnit, unit);
        }
        if (unit.currentPackage != null) {
            PackageDeclaration packageDeclaration = convertPackage(unit);
            compilationUnit.setPackage(packageDeclaration);
        }
        org.eclipse.jdt.internal.compiler.ast.ImportReference[] imports = unit.imports;
        if (imports != null) {
            int importLength = imports.length;
            for (int i = 0; i < importLength; i++) {
                compilationUnit.imports().add(convertImport(imports[i]));
            }
        }

        org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = unit.types;
        if (types != null) {
            int typesLength = types.length;
            for (int i = 0; i < typesLength; i++) {
                org.eclipse.jdt.internal.compiler.ast.TypeDeclaration declaration = types[i];
                if (CharOperation.equals(declaration.name, TypeConstants.PACKAGE_INFO_NAME)) {
                    continue;
                }
                ASTNode type = convert(declaration);
                if (type == null) {
                    compilationUnit.setFlags(compilationUnit.getFlags() | ASTNode.MALFORMED);
                } else {
                    compilationUnit.types().add(type);
                }
            }
        }
        compilationUnit.setSourceRange(unit.sourceStart, unit.sourceEnd - unit.sourceStart + 1);

        int problemLength = unit.compilationResult.problemCount;
        if (problemLength != 0) {
            CategorizedProblem[] resizedProblems = null;
            final CategorizedProblem[] problems = unit.compilationResult.getProblems();
            final int realProblemLength = problems.length;
            if (realProblemLength == problemLength) {
                resizedProblems = problems;
            } else {
                System.arraycopy(problems, 0, (resizedProblems = new CategorizedProblem[realProblemLength]), 0,
                        realProblemLength);
            }
            ASTSyntaxErrorPropagator syntaxErrorPropagator = new ASTSyntaxErrorPropagator(resizedProblems);
            compilationUnit.accept(syntaxErrorPropagator);
            ASTRecoveryPropagator recoveryPropagator = new ASTRecoveryPropagator(resizedProblems,
                    unit.compilationResult.recoveryScannerData);
            compilationUnit.accept(recoveryPropagator);
            compilationUnit.setProblems(resizedProblems);
        }
        if (this.resolveBindings) {
            lookupForScopes();
        }
        compilationUnit.initCommentMapper(this.scanner);
        return compilationUnit;
    } catch (IllegalArgumentException e) {
        StringBuffer message = new StringBuffer("Exception occurred during compilation unit conversion:"); //$NON-NLS-1$
        String lineDelimiter = Util.findLineSeparator(source);
        if (lineDelimiter == null)
            lineDelimiter = System.getProperty("line.separator");//$NON-NLS-1$
        message.append(lineDelimiter);
        message.append(
                "----------------------------------- SOURCE BEGIN -------------------------------------"); //$NON-NLS-1$
        message.append(lineDelimiter);
        message.append(source);
        message.append(lineDelimiter);
        message.append("----------------------------------- SOURCE END -------------------------------------"); //$NON-NLS-1$
        Util.log(e, message.toString());
        throw e;
    }
}

From source file:org.jboss.tools.arquillian.core.internal.builder.ArquillianBuilder.java

License:Open Source License

private IMarker storeProblem(ICompilationUnit unit, String message, Integer severity, String type)
        throws CoreException {
    if (severity == null || unit == null || unit.getUnderlyingResource() == null) {
        return null;
    }/*w w  w  .j a  v a  2s  .  c  o  m*/
    IMarker marker = unit.getUnderlyingResource().createMarker(type);
    String[] attributeNames = ArquillianConstants.ARQUILLIAN_PROBLEM_MARKER_ATTRIBUTE_NAMES;
    String[] allNames = attributeNames;

    Object[] allValues = new Object[allNames.length];
    // standard attributes
    int index = 0;
    StringBuffer sb = new StringBuffer();
    sb.append("Arquillian: "); //$NON-NLS-1$
    sb.append(message);

    allValues[index++] = sb.toString(); // message
    allValues[index++] = severity;

    ISourceRange range = null;
    IMember javaElement = unit.findPrimaryType();
    if (javaElement != null) {
        try {
            range = javaElement.getNameRange();
        } catch (JavaModelException e) {
            if (e.getJavaModelStatus().getCode() != IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST) {
                throw e;
            }
            if (!CharOperation.equals(javaElement.getElementName().toCharArray(),
                    TypeConstants.PACKAGE_INFO_NAME)) {
                throw e;
            }

        }
    }
    int start = range == null ? 0 : range.getOffset();
    int end = range == null ? 1 : start + range.getLength();

    allValues[index++] = new Integer(ArquillianConstants.ARQUILLIAN_PROBLEM_ID); // ID
    allValues[index++] = new Integer(start); // start

    allValues[index++] = new Integer(end > 0 ? end + 1 : end); // end

    allValues[index++] = new Integer(CategorizedProblem.CAT_TYPE); // category
    // ID
    allValues[index++] = ArquillianConstants.SOURCE_ID;
    if (javaElement != null) {
        allValues[index++] = ((IType) javaElement).getFullyQualifiedName();
    }

    marker.setAttributes(allNames, allValues);
    return marker;
}

From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianCompilationParticipant.java

License:Open Source License

private void storeProblem(SourceFile sourceFile, String message, Integer severity) throws CoreException {
    if (severity == null) {
        return;//from  ww  w . java2 s .  c  o  m
    }
    IMarker marker = sourceFile.resource.createMarker(ArquillianConstants.MARKER_CLASS_ID);
    String[] attributeNames = ArquillianConstants.ARQUILLIAN_PROBLEM_MARKER_ATTRIBUTE_NAMES;
    String[] allNames = attributeNames;

    Object[] allValues = new Object[allNames.length];
    // standard attributes
    int index = 0;
    StringBuffer sb = new StringBuffer();
    sb.append("Arquillian: ");
    sb.append(message);

    allValues[index++] = sb.toString(); // message
    allValues[index++] = severity;

    ISourceRange range = null;
    IMember javaElement = ArquillianSearchEngine.getType(sourceFile);
    if (javaElement != null) {
        try {
            range = javaElement.getNameRange();
        } catch (JavaModelException e) {
            if (e.getJavaModelStatus().getCode() != IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST) {
                throw e;
            }
            if (!CharOperation.equals(javaElement.getElementName().toCharArray(),
                    TypeConstants.PACKAGE_INFO_NAME)) {
                throw e;
            }

        }
    }
    int start = range == null ? 0 : range.getOffset();
    int end = range == null ? 1 : start + range.getLength();

    allValues[index++] = new Integer(ArquillianConstants.ARQUILLIAN_PROBLEM_ID); // ID
    allValues[index++] = new Integer(start); // start

    allValues[index++] = new Integer(end > 0 ? end + 1 : end); // end

    allValues[index++] = new Integer(CategorizedProblem.CAT_TYPE); // category
    // ID
    allValues[index++] = ArquillianConstants.SOURCE_ID;
    if (javaElement != null) {
        allValues[index++] = ((IType) javaElement).getFullyQualifiedName();
    }

    marker.setAttributes(allNames, allValues);

}