private static IImportDeclaration getImportedType(ICompilationUnit cu, String typeName) throws CoreException { IImportDeclaration[] imports= cu.getImports(); String dotTypeName= "." + typeName; //$NON-NLS-1$ for (int i= 0; i < imports.length; i++){ if (imports[i].getElementName().endsWith(dotTypeName)) return imports[i]; } return null; }
private static boolean importsOSGIUtil(ICompilationUnit unit) throws JavaModelException { IImportDeclaration[] imports= unit.getImports(); for (int i= 0; i < imports.length; i++) { if (imports[i].getElementName().startsWith("org.eclipse.osgi.util.")) //$NON-NLS-1$ return true; } return false; }
private static boolean importsOSGIUtil(ICompilationUnit unit) throws JavaModelException { IImportDeclaration[] imports= unit.getImports(); for (int i= 0; i < imports.length; i++) { if (imports[i].getElementName().startsWith("org.eclipse.osgi.util.")) //$NON-NLS-1$ return true; } return false; }
private static IImportDeclaration getImportedType(ICompilationUnit cu, String typeName) throws CoreException { IImportDeclaration[] imports= cu.getImports(); String dotTypeName= "." + typeName; //$NON-NLS-1$ for (int i= 0; i < imports.length; i++){ if (imports[i].getElementName().endsWith(dotTypeName)) return imports[i]; } return null; }
private static boolean importsOSGIUtil(ICompilationUnit unit) throws JavaModelException { IImportDeclaration[] imports= unit.getImports(); for (int i= 0; i < imports.length; i++) { if (imports[i].getElementName().startsWith("org.eclipse.osgi.util.")) //$NON-NLS-1$ return true; } return false; } }
private static boolean importsOSGIUtil(ICompilationUnit unit) throws JavaModelException { IImportDeclaration[] imports= unit.getImports(); for (int i= 0; i < imports.length; i++) { if (imports[i].getElementName().startsWith("org.eclipse.osgi.util.")) //$NON-NLS-1$ return true; } return false; } }
private static IImportDeclaration getImportedType(ICompilationUnit cu, String typeName) throws CoreException { IImportDeclaration[] imports = cu.getImports(); String dotTypeName = "." + typeName; //$NON-NLS-1$ for (int i = 0; i < imports.length; i++) { if (imports[i].getElementName().endsWith(dotTypeName)) { return imports[i]; } } return null; }
private static IImportDeclaration getImportedType(ICompilationUnit cu, String typeName) throws CoreException { IImportDeclaration[] imports= cu.getImports(); String dotTypeName= "." + typeName; //$NON-NLS-1$ for (int i= 0; i < imports.length; i++){ if (imports[i].getElementName().endsWith(dotTypeName)) return imports[i]; } return null; }
private RefactoringStatus checkImportedTypes() throws CoreException { RefactoringStatus result = new RefactoringStatus(); IImportDeclaration[] imports = fType.getCompilationUnit().getImports(); for (int i = 0; i < imports.length; i++) { analyzeImportDeclaration(imports[i], result); } return result; }
private RefactoringStatus checkImportedTypes() throws CoreException { RefactoringStatus result= new RefactoringStatus(); IImportDeclaration[] imports= fType.getCompilationUnit().getImports(); for (int i= 0; i < imports.length; i++) analyzeImportDeclaration(imports[i], result); return result; }
private RefactoringStatus checkImportedTypes() throws CoreException { RefactoringStatus result= new RefactoringStatus(); IImportDeclaration[] imports= fType.getCompilationUnit().getImports(); for (int i= 0; i < imports.length; i++) analyzeImportDeclaration(imports[i], result); return result; }
private RefactoringStatus checkImportedTypes() throws CoreException { RefactoringStatus result= new RefactoringStatus(); IImportDeclaration[] imports= fType.getCompilationUnit().getImports(); for (int i= 0; i < imports.length; i++) analyzeImportDeclaration(imports[i], result); return result; }
/** * Creates an {@link ImportRewrite} from an {@link ICompilationUnit}. If <code>restoreExistingImports</code> * is <code>true</code>, all existing imports are kept, and new imports will be inserted at best matching locations. If * <code>restoreExistingImports</code> is <code>false</code>, the existing imports will be removed and only the * newly added imports will be created. * <p> * Note that {@link #create(CompilationUnit, boolean)} is more efficient than this method if an AST for * the compilation unit is already available. * </p> * @param cu the compilation unit to create the imports for * @param restoreExistingImports specifies if the existing imports should be kept or removed. * @return the created import rewriter. * @throws JavaModelException thrown when the compilation unit could not be accessed. */ public static ImportRewrite create(ICompilationUnit cu, boolean restoreExistingImports) throws JavaModelException { if (cu == null) { throw new IllegalArgumentException("Compilation unit must not be null"); //$NON-NLS-1$ } List existingImport= null; if (restoreExistingImports) { existingImport= new ArrayList(); IImportDeclaration[] imports= cu.getImports(); for (int i= 0; i < imports.length; i++) { IImportDeclaration curr= imports[i]; char prefix= Flags.isStatic(curr.getFlags()) ? STATIC_PREFIX : NORMAL_PREFIX; existingImport.add(prefix + curr.getElementName()); } } return new ImportRewrite(cu, null, existingImport); }
private String resolve(IMethod operation, String typename) throws JavaModelException { if (Signature.C_UNRESOLVED == Signature.getElementType(typename).charAt(0)) { final ICompilationUnit unit = operation.getCompilationUnit(); if (unit != null) { final String post = "." + Signature.toString(typename); //$NON-NLS-1$ for (final IImportDeclaration decl : unit.getImports()) { if (decl.getElementName().endsWith(post)) { return decl.getElementName(); } } } } return Signature.toString(typename); }
/** * This method needs to return fast since the QuickAssist pop up is waiting on it. */ public boolean hasAssists(IInvocationContext context) throws CoreException { IImportDeclaration[] imports = context.getCompilationUnit().getImports(); // See if we have any JUnit import for (int i = 0; i < imports.length; i++) { IImportDeclaration id = imports[i]; String name = id.getElementName(); if (name.indexOf("junit") != -1) { return true; } } // Nothing in the imports, try to make a guess based on the class name and superclass IType[] types = context.getCompilationUnit().getTypes(); for (IType type : types) { if (type.getFullyQualifiedName().contains("Test")) { return true; } } // ppp("HAS ASSISTS:" + result); return false; }
/** * Sets the correct position for new package declaration:<ul> * <li> before the first import * <li> if no imports, before the first type * <li> if no type - first thing in the CU * <li> */ protected void initializeDefaultPosition() { try { ICompilationUnit cu = getCompilationUnit(); IImportDeclaration[] imports = cu.getImports(); if (imports.length > 0) { createBefore(imports[0]); return; } IType[] types = cu.getTypes(); if (types.length > 0) { createBefore(types[0]); return; } } catch (JavaModelException e) { // cu doesn't exist: ignore } } /**
/** * Sets the correct position for new package declaration:<ul> * <li> before the first import * <li> if no imports, before the first type * <li> if no type - first thing in the CU * <li> */ protected void initializeDefaultPosition() { try { ICompilationUnit cu = getCompilationUnit(); IImportDeclaration[] imports = cu.getImports(); if (imports.length > 0) { createBefore(imports[0]); return; } IType[] types = cu.getTypes(); if (types.length > 0) { createBefore(types[0]); return; } } catch (JavaModelException e) { // cu doesn't exist: ignore } } /**
/** * Sets the correct position for new package declaration:<ul> * <li> before the first import * <li> if no imports, before the first type * <li> if no type - first thing in the CU * <li> */ protected void initializeDefaultPosition() { try { ICompilationUnit cu = getCompilationUnit(); IImportDeclaration[] imports = cu.getImports(); if (imports.length > 0) { createBefore(imports[0]); return; } IType[] types = cu.getTypes(); if (types.length > 0) { createBefore(types[0]); return; } } catch (JavaModelException e) { // cu doesn't exist: ignore } } /**
/** * Sets the correct position for new package declaration:<ul> * <li> before the first import * <li> if no imports, before the first type * <li> if no type - first thing in the CU * <li> */ @Override protected void initializeDefaultPosition() { try { ICompilationUnit cu = getCompilationUnit(); IImportDeclaration[] imports = cu.getImports(); if (imports.length > 0) { createBefore(imports[0]); return; } IType[] types = cu.getTypes(); if (types.length > 0) { createBefore(types[0]); return; } } catch (JavaModelException e) { // cu doesn't exist: ignore } } /**
/** * Sets the correct position for new package declaration:<ul> * <li> before the first import * <li> if no imports, before the first type * <li> if no type - first thing in the CU * <li> */ protected void initializeDefaultPosition() { try { ICompilationUnit cu = getCompilationUnit(); IImportDeclaration[] imports = cu.getImports(); if (imports.length > 0) { createBefore(imports[0]); return; } IType[] types = cu.getTypes(); if (types.length > 0) { createBefore(types[0]); return; } } catch (JavaModelException e) { // cu doesn't exist: ignore } } /**