Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IType


     * @param javaElement
     * @return simply element name
     */
    public static String getElementName(IJavaElement javaElement) {
        if (isAnonymousType(javaElement)) {
            IType anonType = (IType) javaElement;
            List allAnonymous = new ArrayList();
            /*
             * in order to resolve anon. class name we need to know about all other
             * anonymous classes in declaring class, therefore we need to collect all here
             */
 
View Full Code Here


                       exception on classFile.isInterface() call.
                    }*/
                    break;
                case IJavaElement.COMPILATION_UNIT :
                    ICompilationUnit cUnit = (ICompilationUnit) javaEl;
                    IType type = cUnit.findPrimaryType();
                    abstractOrInterface = type != null && type.isInterface();
                    break;
                case IJavaElement.TYPE :
                    abstractOrInterface = ((IType) javaEl).isInterface();
                    break;
                case IJavaElement.METHOD :
                    // test for "abstract" flag on method in a class
                    abstractOrInterface = Flags.isAbstract(((IMethod) javaEl)
                        .getFlags());
                    // "abstract" flags could be not exist on interface methods
                    if (!abstractOrInterface) {
                        IType ancestor = (IType) javaEl
                            .getAncestor(IJavaElement.TYPE);
                        abstractOrInterface = ancestor != null
                            && ancestor.isInterface();
                    }
                    break;
                default :
                    IType ancestor1 = (IType) javaEl
                        .getAncestor(IJavaElement.TYPE);
                    abstractOrInterface = ancestor1 != null
                        && ancestor1.isInterface();
                    break;
            }
        } catch (JavaModelException e) {
            // No point to log it here
            // BytecodeOutlinePlugin.log(e, IStatus.ERROR);
View Full Code Here

     * @return non public class (local type class) with the name from "debugType" and
     * which source was in the "parent" class. Null if no class file could be found.
     */
    private static IClassFile getLocalTypeClass(IJavaReferenceType debugType, IClassFile parent) {
        try {
            IType type = parent.getType();
            if((type.isLocal()) || (type.isMember())) {
                // local type could not be defined in local or inner classes
                return null;
            }
            // debugType.getSignature() == Lpackage/name/with/slashes/className;
            String binarySignature = debugType.getSignature();
            // get only type name from binary signature
            int idx = binarySignature.lastIndexOf('/');
            if(idx > 0 && idx < binarySignature.length() - 1){
                String name = binarySignature.substring(idx + 1);
                if(name.charAt(name.length() - 1) == ';'){
                    name = name.substring(0, name.length() - 1);
                }
                return type.getPackageFragment().getClassFile(name + ".class");
            }
        } catch (Exception e) {
            BytecodeOutlinePlugin.log(e, IStatus.ERROR);
        }
        return null;
View Full Code Here

         * @param o1 should be IType
         * @param o2 should be IType
         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
         */
        public int compare(Object o1, Object o2) {
            IType m1 = (IType) o1;
            IType m2 = (IType) o2;
            int idx1, idx2;
            try {
                ISourceRange sr1 = m1.getSourceRange();
                ISourceRange sr2 = m2.getSourceRange();
                if (sr1 == null || sr2 == null) {
                    return 0;
                }
                idx1 = sr1.getOffset();
                idx2 = sr2.getOffset();
View Full Code Here

         */
        public int compare(Object o1, Object o2) {
            if(o1 == o2){
                return 0;
            }
            IType m1 = (IType) o1;
            IType m2 = (IType) o2;
            if(is50OrHigher){
                return compare50(m1, m2);
            }

            IJavaElement firstAncestor1 = getFirstAncestor(m1);
View Full Code Here

            + File.separator;

        String fieldName = getFieldName();
        IType[] allTypes = getAllTypes(cu);
        for (int i = 0; i < allTypes.length; i++) {
            IType type = allTypes[i];
            IField field = type.getField(fieldName);
            if (field == null) {
                continue;
            }
            String constant = (String) field.getConstant();
            if(constant != null){
View Full Code Here

        if (enclName.length() == 0) {
            status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeEnterName);
            return status;
        }
        try {
            IType type = findType(root.getJavaProject(), enclName);
            if (type == null) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
                return status;
            }

            if (type.getCompilationUnit() == null) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotInCU);
                return status;
            }
            if (!JavaModelUtil.isEditable(type.getCompilationUnit())) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotEditable);
                return status;
            }

            fCurrEnclosingType = type;
View Full Code Here

                        status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown, BasicElementLabels.getURLPart(Resources.getLocationString(resource))));
                    }
                }
            }
        } else {
            IType type = getEnclosingType();
            if (type != null) {
                fCurrType = type.getType(typeName);
                if (fCurrType.exists()) {
                    status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
                    return status;
                }
            }
View Full Code Here

        try {
            String typeName = getTypeNameWithoutParameters();

            boolean isInnerClass = isEnclosingTypeSelected();

            IType createdType;
            ImportsManager imports;
            int indent = 0;

            Set<String> existingImports;

            String lineDelimiter = null;
            if (!isInnerClass) {
                lineDelimiter = StubUtility.getLineDelimiterUsed(pack.getJavaProject());

                String cuName = getCompilationUnitName(typeName);
                ICompilationUnit parentCU = pack.createCompilationUnit(cuName, "", false, new SubProgressMonitor(monitor, 2)); //$NON-NLS-1$
                // create a working copy with a new owner

                needsSave = true;
                parentCU.becomeWorkingCopy(new SubProgressMonitor(monitor, 1)); // cu is now a (primary) working copy
                connectedCU = parentCU;

                IBuffer buffer = parentCU.getBuffer();

                String simpleTypeStub = constructSimpleTypeStub();
                String cuContent = constructCUContent(parentCU, simpleTypeStub, lineDelimiter);
                buffer.setContents(cuContent);

                CompilationUnit astRoot = createASTForImports(parentCU);
                existingImports = getExistingImports(astRoot);

                imports = new ImportsManager(astRoot);
                // add an import that will be removed again. Having this import solves 14661
                imports.addImport(JavaModelUtil.concatenateName(pack.getElementName(), typeName));

                String typeContent = constructTypeStub(parentCU, imports, lineDelimiter);

                int index = cuContent.lastIndexOf(simpleTypeStub);
                if (index == -1) {
                    AbstractTypeDeclaration typeNode = (AbstractTypeDeclaration) astRoot.types().get(0);
                    int start = ((ASTNode) typeNode.modifiers().get(0)).getStartPosition();
                    int end = typeNode.getStartPosition() + typeNode.getLength();
                    buffer.replace(start, end - start, typeContent);
                } else {
                    buffer.replace(index, simpleTypeStub.length(), typeContent);
                }

                createdType = parentCU.getType(typeName);
            } else {
                IType enclosingType = getEnclosingType();

                ICompilationUnit parentCU = enclosingType.getCompilationUnit();

                needsSave = !parentCU.isWorkingCopy();
                parentCU.becomeWorkingCopy(new SubProgressMonitor(monitor, 1)); // cu is now for sure (primary) a working copy
                connectedCU = parentCU;

                CompilationUnit astRoot = createASTForImports(parentCU);
                imports = new ImportsManager(astRoot);
                existingImports = getExistingImports(astRoot);

                // add imports that will be removed again. Having the imports solves 14661
                IType[] topLevelTypes = parentCU.getTypes();
                for (int i = 0; i < topLevelTypes.length; i++) {
                    imports.addImport(topLevelTypes[i].getFullyQualifiedName('.'));
                }

                lineDelimiter = StubUtility.getLineDelimiterUsed(enclosingType);
                StringBuffer content = new StringBuffer();

                String comment = getTypeComment(parentCU, lineDelimiter);
                if (comment != null) {
                    content.append(comment);
                    content.append(lineDelimiter);
                }

                content.append(constructTypeStub(parentCU, imports, lineDelimiter));
                IJavaElement sibling = null;
                if (enclosingType.isEnum()) {
                    IField[] fields = enclosingType.getFields();
                    if (fields.length > 0) {
                        for (int i = 0, max = fields.length; i < max; i++) {
                            if (!fields[i].isEnumConstant()) {
                                sibling = fields[i];
                                break;
                            }
                        }
                    }
                } else {
                    IJavaElement[] elems = enclosingType.getChildren();
                    sibling = elems.length > 0 ? elems[0] : null;
                }

                createdType = enclosingType.createType(content.toString(), sibling, false, new SubProgressMonitor(monitor, 2));

                indent = StubUtility.getIndentUsed(enclosingType) + 1;
            }
            if (monitor.isCanceled()) {
                throw new InterruptedException();
View Full Code Here

        String initSuperclass = "java.lang.Object"; //$NON-NLS-1$
        ArrayList<String> initSuperinterfaces = new ArrayList<String>(5);

        IJavaProject project = null;
        IPackageFragment pack = null;
        IType enclosingType = null;

        if (elem != null) {
            // evaluate the enclosing type
            project = elem.getJavaProject();
            pack = (IPackageFragment) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
            IType typeInCU = (IType) elem.getAncestor(IJavaElement.TYPE);
            if (typeInCU != null) {
                if (typeInCU.getCompilationUnit() != null) {
                    enclosingType = typeInCU;
                }
            } else {
                ICompilationUnit cu = (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
                if (cu != null) {
                    enclosingType = cu.findPrimaryType();
                }
            }

            try {
                IType type = null;
                if (elem.getElementType() == IJavaElement.TYPE) {
                    type = (IType) elem;
                    if (type.exists()) {
                        String superName = SuperInterfaceSelectionDialog.getNameWithTypeParameters(type);
                        if (type.isInterface()) {
                            initSuperinterfaces.add(superName);
                        } else {
                            initSuperclass = superName;
                        }
                    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.IType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.