public static org.eclipse.jdt.core.dom.AbstractTypeDeclaration findTypeDeclaration(IType searchType, List<?> nodes) { for (Object object : nodes) { if (object instanceof org.eclipse.jdt.core.dom.AbstractTypeDeclaration) { org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = (org.eclipse.jdt.core.dom.AbstractTypeDeclaration) object; if (typeDeclaration.getName().toString().equals(searchType.getElementName())) return typeDeclaration; } } return null; }
/** * Returns the java project this hierarchy was created in. */ public IJavaProject javaProject() { return this.focusType.getJavaProject(); } protected static byte[] readUntil(InputStream input, byte separator) throws JavaModelException, IOException{
static String[] getSuperTypeSignatures(IType subType, IType superType) throws JavaModelException { if (superType.isInterface()) { return subType.getSuperInterfaceTypeSignatures(); } else { return new String[] {subType.getSuperclassTypeSignature()}; } }
private void computeQualifiedNameMatches(IProgressMonitor pm) { IPackageFragment fragment= fType.getPackageFragment(); if (fQualifiedNameSearchResult == null) fQualifiedNameSearchResult= new QualifiedNameSearchResult(); QualifiedNameFinder.process(fQualifiedNameSearchResult, fType.getFullyQualifiedName(), fragment.getElementName() + "." + getNewElementName(), //$NON-NLS-1$ fFilePatterns, fType.getJavaProject().getProject(), pm); }
private IType resolveType(String qualifiedTypeName) throws JavaModelException{ IType type= getDeclaringType().getJavaProject().findType(qualifiedTypeName); if (type == null) type= getDeclaringType().getJavaProject().findType(getDeclaringType().getPackageFragment().getElementName(), qualifiedTypeName); return type; }
private void handleType(IType type, IPackageFragment destination, IProgressMonitor pm) { QualifiedNameFinder.process(fQualifiedNameSearchResult, type.getFullyQualifiedName(), destination.getElementName() + "." + type.getTypeQualifiedName(), //$NON-NLS-1$ fFilePatterns, type.getJavaProject().getProject(), pm); }
public static boolean isTestImplementor(IType type) throws JavaModelException { ITypeHierarchy typeHier= type.newSupertypeHierarchy(null); IType[] superInterfaces= typeHier.getAllInterfaces(); for (int i= 0; i < superInterfaces.length; i++) { if (JUnitCorePlugin.TEST_INTERFACE_NAME.equals(superInterfaces[i].getFullyQualifiedName('.'))) { return true; } } return false; }
/** * Finds a method in a type. * Searches for a method with the same name and the same parameter count. * Parameter types are <b>not</b> compared. * @param method * @param type * @return The first found method or null, if nothing found * @throws JavaModelException */ public static IMethod findMethod(IMethod method, IType type) throws JavaModelException { return findMethod(method.getElementName(), method.getParameterTypes().length, method.isConstructor(), type.getMethods()); }
@Override public String getQualifiedName() { IType declaringType = this.method.getDeclaringType(); return declaringType.getFullyQualifiedName() + "#" + this.method.getElementName(); }
private void initialize() throws JavaModelException { fQualifiedTypeName= JavaModelUtil.concatenateName(fType.getPackageFragment().getElementName(), fType.getElementName()); fEnclosingInstanceFieldName= getInitialNameForEnclosingInstanceField(); fSourceRewrite= new CompilationUnitRewrite(fType.getCompilationUnit()); fIsInstanceFieldCreationPossible= !(JdtFlags.isStatic(fType) || fType.isAnnotation() || fType.isEnum()); fIsInstanceFieldCreationMandatory= fIsInstanceFieldCreationPossible && isInstanceFieldCreationMandatory(); fCreateInstanceField= fIsInstanceFieldCreationMandatory; }
private RefactoringStatus checkTypesImportedInCu() throws CoreException { IImportDeclaration imp= getImportedType(fType.getCompilationUnit(), getNewElementName()); if (imp == null) return null; String msg= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_imported, new Object[]{getNewElementName(), fType.getCompilationUnit().getResource().getFullPath()}); IJavaElement grandParent= imp.getParent().getParent(); if (grandParent instanceof ICompilationUnit) return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(imp)); return null; }
private static String parseTestItemFullName(IJavaElement element, TestLevel level) { switch (level) { case CLASS: case NESTED_CLASS: final IType type = (IType) element; return type.getFullyQualifiedName(); case METHOD: final IMethod method = (IMethod) element; return method.getDeclaringType().getFullyQualifiedName() + "#" + method.getElementName(); default: return element.getElementName(); } }
private boolean isPrimaryType() { String cuName= fType.getCompilationUnit().getElementName(); String typeName= fType.getElementName(); return Checks.isTopLevel(fType) && JavaCore.removeJavaLikeExtension(cuName).equals(typeName); }
private static Integer[] createOffsetArray(IType[] types) throws JavaModelException { List result= new ArrayList(); for (int i= 0; i < types.length; i++) { IType iType= types[i]; addOffset(result, iType.getNameRange().getOffset()); addOffset(result, iType.getSourceRange().getOffset() + iType.getSourceRange().getLength()); addMemberOffsetList(result, iType.getMethods()); addMemberOffsetList(result, iType.getFields()); addMemberOffsetList(result, iType.getInitializers()); } return (Integer[]) result.toArray(new Integer[result.size()]); }
protected void openCodeTempatePage(String id) { HashMap<String, String> arg= new HashMap<>(); arg.put(CodeTemplatePreferencePage.DATA_SELECT_TEMPLATE, id); PreferencesUtil.createPropertyDialogOn(getShell(), fType.getJavaProject().getProject(), CodeTemplatePreferencePage.PROP_ID, null, arg).open(); }
private IElementDescriptor getElementDescriptor(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: return Factory.packageDescriptor(element.getElementName()); case IJavaElement.TYPE: return Factory.typeDescriptor(((IType) element).getFullyQualifiedName('$')); default: return null; } }
private boolean isInnerOrAnonymousClass(IType res) { try { if (res.isClass() && (res.isAnonymous() || (Flags.isPrivate(res.getFlags())) || res.getFullyQualifiedName().indexOf("$") > 0)) //must be better way to discover if it is an inner class //$NON-NLS-1$ return true; } catch (JavaModelException e) { //ignore } return false; }
@Override CodeGenerationSettings createSettings(IType type, SourceActionDialog dialog) { ToStringGenerationSettings settings= ((GenerateToStringDialog) dialog).getGenerationSettings(); super.createSettings(type, dialog).setSettings(settings); settings.createComments= dialog.getGenerateComment(); settings.useBlocks= useBlocks(type.getJavaProject()); String version= fUnit.getJavaElement().getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true); settings.is50orHigher= !JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_5); settings.is60orHigher= !JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6); return settings; }
private boolean canEnable(IStructuredSelection selection) throws JavaModelException { if (getSelectedFields(selection) != null) return true; if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { IType type= (IType) selection.getFirstElement(); return type.getCompilationUnit() != null && !type.isInterface() && !type.isAnonymous(); } if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit)) return true; return false; }
@SuppressWarnings("squid:S1067") protected boolean acceptType(IType jdtType) throws CoreException { //fast check before doing expensive source parsing return S2eUtils.exists(jdtType) && S2eUtils.exists(jdtType.getJavaProject()) // required! && !jdtType.isAnonymous() && !jdtType.isBinary() && jdtType.getDeclaringType() == null && Flags.isPublic(jdtType.getFlags()); }