/** * Returns the primary type of a class file. * * @param classFile the class file * @return returns the primary type of the class file, or <code>null</code> * if is does not have one */ private IType getMainType(IClassFile classFile) { IType type= classFile.getType(); return type != null && type.exists() ? type : null; } }
private static Object computeScope(Object element) throws JavaModelException { if(element instanceof IResource) { element = JavaCore.create((IResource) element); } if(element instanceof IClassFile) { IClassFile cf = (IClassFile) element; element = cf.getType(); } return element; }
@Override public String getToolTipText() { return fClassFile.getType().getFullyQualifiedName(); }
public String getToolTipText() { return fClassFile.getType().getFullyQualifiedName(); }
private void addContainedTypes(IPackageFragment pack, List typesCollector) throws JavaModelException { IJavaElement[] children= pack.getChildren(); for (int c= 0; c < children.length; c++) { IJavaElement child= children[c]; if (child instanceof ICompilationUnit) { typesCollector.addAll(Arrays.asList(((ICompilationUnit) child).getTypes())); } else if (child instanceof IClassFile) { typesCollector.add(((IClassFile) child).getType()); } } }
private void addContainedTypes(IPackageFragment pack, List<IType> typesCollector) throws JavaModelException { IJavaElement[] children= pack.getChildren(); for (int c= 0; c < children.length; c++) { IJavaElement child= children[c]; if (child instanceof ICompilationUnit) { typesCollector.addAll(Arrays.asList(((ICompilationUnit) child).getTypes())); } else if (child instanceof IClassFile) { typesCollector.add(((IClassFile) child).getType()); } } }
private IType findTypeForName(String typeName) throws JavaModelException { if (typeName == null || typeName.length() == 0) return null; IType type = null; String fileName = typeName.replace('.', '/') + ".java"; //$NON-NLS-1$ IJavaElement element = javaProject.findElement(new Path(fileName)); if (element == null) return null; if (element instanceof IClassFile) { type = ((IClassFile) element).getType(); } else if (element instanceof ICompilationUnit) { IType[] types = ((ICompilationUnit) element).getTypes(); type = types[0]; } return type; }
private static IType convertToEnclosingOrPrimaryType(IJavaElement element) throws JavaModelException { if (element instanceof IType) return (IType)element; IType result= (IType)element.getAncestor(IJavaElement.TYPE); if (result != null) return result; if (element instanceof ICompilationUnit) return ((ICompilationUnit)element).findPrimaryType(); if (element instanceof IClassFile) return ((IClassFile)element).getType(); return null; }
private static IType convertToEnclosingOrPrimaryType(IJavaElement element) throws JavaModelException { if (element instanceof IType) return (IType)element; IType result= (IType)element.getAncestor(IJavaElement.TYPE); if (result != null) return result; if (element instanceof ICompilationUnit) return ((ICompilationUnit)element).findPrimaryType(); if (element instanceof IClassFile) return ((IClassFile)element).getType(); return null; }
private IJavaElement getTypeIfPossible(IJavaElement o, boolean silent) { switch (o.getElementType()) { case IJavaElement.COMPILATION_UNIT: if (silent) return o; else return findType((ICompilationUnit)o, silent); case IJavaElement.CLASS_FILE: return ((IClassFile)o).getType(); default: return o; } }
private IJavaElement getTypeIfPossible(IJavaElement o, boolean silent) { switch (o.getElementType()) { case IJavaElement.COMPILATION_UNIT: if (silent) return o; else return findType((ICompilationUnit)o, silent); case IJavaElement.CLASS_FILE: return ((IClassFile)o).getType(); default: return o; } }
private void processClassFile(ITypeVisitor visitor, IClassFile file, IProgressMonitor monitor) throws JavaModelException { visitor.visit(file); final IType type = file.getType(); processType(visitor, new BinaryTypeName(type), type, monitor); }
/** * Creates an IType from the given simple top level type name. */ protected IType createTypeHandle(String simpleTypeName) { Openable openable = this.currentPossibleMatch.openable; if (openable instanceof CompilationUnit) return ((CompilationUnit) openable).getType(simpleTypeName); IType binaryType = ((ClassFile) openable).getType(); String binaryTypeQualifiedName = binaryType.getTypeQualifiedName(); if (simpleTypeName.equals(binaryTypeQualifiedName)) return binaryType; // answer only top-level types, sometimes the classFile is for a member/local type // type name may be null for anonymous (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=164791) String classFileName = simpleTypeName.length() == 0 ? binaryTypeQualifiedName : simpleTypeName; IClassFile classFile = binaryType.getPackageFragment().getClassFile(classFileName + SuffixConstants.SUFFIX_STRING_class); return classFile.getType(); } protected boolean encloses(IJavaElement element) {
private static void addElementFor(IClassFile classFile, IApiComponent apiComponent, ApiScope scope) { try { IApiTypeRoot typeRoot = apiComponent.findTypeRoot(classFile.getType().getFullyQualifiedName()); if (typeRoot != null) { scope.addElement(typeRoot); } } catch (CoreException e) { ApiPlugin.log(e); } }
public void visit(IClassFile classfile) throws JavaModelException { final String vmname = classfile.getType().getFullyQualifiedName() .replace('.', '/'); final IClassCoverage coverage = nodes.getClassCoverage(vmname); if (coverage != null) { modelcoverage.putClassFile(classfile, coverage); // Add source file coverage manually in case of binary roots // as we will not see compilation units: final ISourceFileCoverage source = nodes.getSourceFileCoverage( coverage.getPackageName(), coverage.getSourceFileName()); if (source != null) { sources.add(source); } } }
private static void addElementFor(IClassFile classFile, IApiComponent apiComponent, ApiScope scope) { try { IApiTypeRoot typeRoot = apiComponent.findTypeRoot(classFile.getType().getFullyQualifiedName()); if (typeRoot != null) { scope.addElement(typeRoot); } } catch (CoreException e) { ApiPlugin.log(e); } }
/** * Find the specified (fully-qualified) type name in the specified java project. */ public static IType findType(IJavaProject javaProject, String mainTypeName) throws CoreException { IJavaElement javaElement= JavaDebugUtils.findElement(mainTypeName, javaProject); if (javaElement == null) { return null; } else if (javaElement instanceof IType) { return (IType)javaElement; } else if (javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) { String simpleName= Signature.getSimpleName(mainTypeName); return ((ICompilationUnit) javaElement).getType(simpleName); } else if (javaElement.getElementType() == IJavaElement.CLASS_FILE) { return ((IClassFile) javaElement).getType(); } return null; }
private IType[] getTypes() throws JavaModelException { IEditorInput input= fEditor.getEditorInput(); if (input instanceof IClassFileEditorInput) { return new IType[] { ((IClassFileEditorInput)input).getClassFile().getType() }; } else { return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input).getAllTypes(); } }
private IType[] getTypes() throws JavaModelException { IEditorInput input= fEditor.getEditorInput(); if (input instanceof IClassFileEditorInput) { return new IType[] { ((IClassFileEditorInput)input).getClassFile().getType() }; } else { return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input).getAllTypes(); } }
protected IType transplantHandle(IJavaElement parent, IType element) { switch (parent.getElementType()) { case IJavaElement.COMPILATION_UNIT: return ((ICompilationUnit) parent).getType(element.getElementName()); case IJavaElement.CLASS_FILE: return ((IClassFile) parent).getType(); case IJavaElement.METHOD: return ((IMethod) parent).getType(element.getElementName(), element.getOccurrenceCount()); case IJavaElement.FIELD: return ((IField) parent).getType(element.getElementName(), element.getOccurrenceCount()); case IJavaElement.INITIALIZER: return ((IInitializer) parent).getType(element.getElementName(), element.getOccurrenceCount()); case IJavaElement.TYPE: return ((IType) parent).getType(element.getElementName(), element.getOccurrenceCount()); default: throw new IllegalStateException(element.toString()); } }