List of usage examples for org.eclipse.jdt.core IMember getDeclaringType
IType getDeclaringType();
null if this member is not declared in a type (for example, a top-level type). From source file:at.bestsolution.fxide.jdt.corext.util.JavaModelUtil.java
License:Open Source License
/** * Evaluates if a member in the focus' element hierarchy is visible from * elements in a package./*from ww w . j a v a 2 s . c om*/ * @param member The member to test the visibility for * @param pack The package of the focus element focus * @return returns <code>true</code> if the member is visible from the package * @throws JavaModelException thrown when the member can not be accessed */ public static boolean isVisibleInHierarchy(IMember member, IPackageFragment pack) throws JavaModelException { int type = member.getElementType(); if (type == IJavaElement.INITIALIZER || (type == IJavaElement.METHOD && member.getElementName().startsWith("<"))) { //$NON-NLS-1$ return false; } int otherflags = member.getFlags(); IType declaringType = member.getDeclaringType(); if (Flags.isPublic(otherflags) || Flags.isProtected(otherflags) || (declaringType != null && isInterfaceOrAnnotation(declaringType))) { return true; } else if (Flags.isPrivate(otherflags)) { return false; } IPackageFragment otherpack = (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT); return (pack != null && pack.equals(otherpack)); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isStatic(IMember member) throws JavaModelException { if (isNestedInterfaceOrAnnotation(member)) return true; if (member.getElementType() != IJavaElement.METHOD && isInterfaceOrAnnotationMember(member)) return true; if (isEnum(member) && (member.getElementType() == IJavaElement.FIELD || member.getDeclaringType() != null)) return true; return Flags.isStatic(member.getFlags()); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
private static boolean isInterfaceOrAnnotationMember(IMember member) throws JavaModelException { return member.getDeclaringType() != null && JavaModelUtil.isInterfaceOrAnnotation(member.getDeclaringType()); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
private static boolean isNestedInterfaceOrAnnotation(IMember member) throws JavaModelException { return member.getElementType() == IJavaElement.TYPE && member.getDeclaringType() != null && JavaModelUtil.isInterfaceOrAnnotation((IType) member); }
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
private String getVariableSubstitution(IMember context, String variableName) throws JavaModelException { IType type;/*from ww w.j a v a 2s . com*/ if (context instanceof IMethod) { String subst = getMethodSubstitions((IMethod) context).getSubstitution(variableName); if (subst != null) { return subst; } type = context.getDeclaringType(); } else { type = (IType) context; } String subst = getTypeSubstitions(type).getSubstitution(variableName); if (subst != null) { return subst; } IJavaElement parent = type.getParent(); if (parent instanceof IMethod) { return getVariableSubstitution((IMethod) parent, variableName); } else if (type.getDeclaringType() != null) { return getVariableSubstitution(type.getDeclaringType(), variableName); } return variableName; // not a type variable }
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
private String getVariableErasure(IMember context, String variableName) throws JavaModelException { IType type;/* ww w . j a v a 2s .c o m*/ if (context instanceof IMethod) { String subst = getMethodSubstitions((IMethod) context).getErasure(variableName); if (subst != null) { return subst; } type = context.getDeclaringType(); } else { type = (IType) context; } String subst = getTypeSubstitions(type).getErasure(variableName); if (subst != null) { return subst; } IJavaElement parent = type.getParent(); if (parent instanceof IMethod) { return getVariableErasure((IMethod) parent, variableName); } else if (type.getDeclaringType() != null) { return getVariableErasure(type.getDeclaringType(), variableName); } return variableName; // not a type variable }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private static String getJavaFxPropertyDoc(IMember member) throws JavaModelException { // XXX: should not do this by default (but we don't have settings for Javadoc, see https://bugs.eclipse.org/424283 ) if (member instanceof IMethod) { String name = member.getElementName(); boolean isGetter = name.startsWith("get") && name.length() > 3; //$NON-NLS-1$ boolean isBooleanGetter = name.startsWith("is") && name.length() > 2; //$NON-NLS-1$ boolean isSetter = name.startsWith("set") && name.length() > 3; //$NON-NLS-1$ if (isGetter || isBooleanGetter || isSetter) { String propertyName = firstToLower(name.substring(isBooleanGetter ? 2 : 3)); IType type = member.getDeclaringType(); IMethod method = type.getMethod(propertyName + "Property", new String[0]); //$NON-NLS-1$ if (method.exists()) { String content = getHTMLContentFromSource(method); if (content != null) { if (isSetter) { content = Messages.format(JavaDocMessages.JavadocContentAccess2_setproperty_message, new Object[] { propertyName, content }); } else { content = Messages.format(JavaDocMessages.JavadocContentAccess2_getproperty_message, new Object[] { propertyName, content }); }/* www. j av a 2 s .c o m*/ } return content; } } else if (name.endsWith("Property")) { //$NON-NLS-1$ String propertyName = name.substring(0, name.length() - 8); IType type = member.getDeclaringType(); IField field = type.getField(propertyName); if (field.exists()) { return getHTMLContentFromSource(field); } } } return null; }
From source file:com.google.gwt.eclipse.core.refactoring.GWTRenameParticipant.java
License:Open Source License
@Override protected boolean initialize(Object element) { if (element instanceof IType || element instanceof IMethod || element instanceof IField) { GWTRefactoringSupport support = getRefactoringSupport(); IMember oldMember = (IMember) element; support.setOldElement(oldMember); try {//from w w w.ja va 2s . co m /* * We can't trust our RenameArgument's getNewName() to always return the * correct new name. When the user sets the new name in the Rename * refactoring dialog, clicks Next to go to the Preview page, then * clicks Back and changes the new name, getNewName() returns the * original name, not the updated one. This appears to be a bug in the * JDT, which affects other built-in rename participants such as * BreakpointRenameTypeParticipant. It does not affect the core JDT * refactorings, though, since they are executed directly from * JavaRenameRefactoring and not as loaded rename participants. * * The workaround here is to instead go directly to the refactoring * processor and query it for the new element, which will have the right * name. * * TODO: file this as a JDT bug? */ JavaRenameProcessor processor = getRenameProcessor(); IJavaElement newElement = (IJavaElement) processor.getNewElement(); IType declaringType = oldMember.getDeclaringType(); String newElementName = newElement.getElementName(); /* * Compute the new method by using the declaring type of the old method. * Otherwise when a RenameVirtualMethodProcessor instance is passed in, * we will end up looking at the topmost declaration of the method * instead of the one we actually want because * RenameVirtualMethodProcessor.getNewElement() actually points to the * topmost declaration. */ if (element instanceof IField) { newElement = declaringType.getField(newElementName); } else if (element instanceof IMethod) { IMethod method = (IMethod) newElement; newElement = declaringType.getMethod(newElementName, method.getParameterTypes()); } else { assert (element instanceof IType); } support.setNewElement(newElement); support.setUpdateReferences(getArguments().getUpdateReferences()); return true; } catch (CoreException e) { GWTPluginLog.logError(e); } } return false; }
From source file:com.redhat.ceylon.eclipse.code.explorer.JavaElementImageProvider.java
License:Open Source License
/** * Returns an image descriptor for a java element. This is the base image, no overlays. * @param element the element//w ww .j a v a2s . c o m * @param renderFlags the image flags * @return returns the image descriptor */ public ImageDescriptor getBaseImageDescriptor(IJavaElement element, int renderFlags) { try { switch (element.getElementType()) { case IJavaElement.INITIALIZER: return JavaPluginImages.DESC_MISC_PRIVATE; // 23479 case IJavaElement.METHOD: { IMethod method = (IMethod) element; IType declType = method.getDeclaringType(); int flags = method.getFlags(); if (declType.isEnum() && isDefaultFlag(flags) && method.isConstructor()) return JavaPluginImages.DESC_MISC_PRIVATE; return getMethodImageDescriptor(JavaModelUtil.isInterfaceOrAnnotation(declType), flags); } case IJavaElement.FIELD: { IMember member = (IMember) element; IType declType = member.getDeclaringType(); return getFieldImageDescriptor(JavaModelUtil.isInterfaceOrAnnotation(declType), member.getFlags()); } case IJavaElement.LOCAL_VARIABLE: return JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE; case IJavaElement.PACKAGE_DECLARATION: return JavaPluginImages.DESC_OBJS_PACKDECL; case IJavaElement.IMPORT_DECLARATION: return JavaPluginImages.DESC_OBJS_IMPDECL; case IJavaElement.IMPORT_CONTAINER: return JavaPluginImages.DESC_OBJS_IMPCONT; case IJavaElement.TYPE: { IType type = (IType) element; IType declType = type.getDeclaringType(); boolean isInner = declType != null; boolean isInInterfaceOrAnnotation = isInner && JavaModelUtil.isInterfaceOrAnnotation(declType); return getTypeImageDescriptor(isInner, isInInterfaceOrAnnotation, type.getFlags(), useLightIcons(renderFlags)); } case IJavaElement.PACKAGE_FRAGMENT_ROOT: { IPackageFragmentRoot root = (IPackageFragmentRoot) element; IPath attach = root.getSourceAttachmentPath(); if (root.getKind() == IPackageFragmentRoot.K_BINARY) { if (root.isArchive()) { if (root.isExternal()) { if (attach == null) { return JavaPluginImages.DESC_OBJS_EXTJAR; } else { return JavaPluginImages.DESC_OBJS_EXTJAR_WSRC; } } else { if (attach == null) { return JavaPluginImages.DESC_OBJS_JAR; } else { return JavaPluginImages.DESC_OBJS_JAR_WSRC; } } } else { if (attach == null) { return JavaPluginImages.DESC_OBJS_CLASSFOLDER; } else { return JavaPluginImages.DESC_OBJS_CLASSFOLDER_WSRC; } } } else { return JavaPluginImages.DESC_OBJS_PACKFRAG_ROOT; } } case IJavaElement.PACKAGE_FRAGMENT: return getPackageFragmentIcon(element); case IJavaElement.COMPILATION_UNIT: return JavaPluginImages.DESC_OBJS_CUNIT; case IJavaElement.CLASS_FILE: /* this is too expensive for large packages try { IClassFile cfile= (IClassFile)element; if (cfile.isClass()) return JavaPluginImages.IMG_OBJS_CFILECLASS; return JavaPluginImages.IMG_OBJS_CFILEINT; } catch(JavaModelException e) { // fall through; }*/ return JavaPluginImages.DESC_OBJS_CFILE; case IJavaElement.JAVA_PROJECT: IJavaProject jp = (IJavaProject) element; if (jp.getProject().isOpen()) { IProject project = jp.getProject(); IWorkbenchAdapter adapter = (IWorkbenchAdapter) project.getAdapter(IWorkbenchAdapter.class); if (adapter != null) { ImageDescriptor result = adapter.getImageDescriptor(project); if (result != null) return result; } return DESC_OBJ_PROJECT; } return DESC_OBJ_PROJECT_CLOSED; case IJavaElement.JAVA_MODEL: return JavaPluginImages.DESC_OBJS_JAVA_MODEL; case IJavaElement.TYPE_PARAMETER: return JavaPluginImages.DESC_OBJS_TYPEVARIABLE; case IJavaElement.ANNOTATION: return JavaPluginImages.DESC_OBJS_ANNOTATION; default: // ignore. Must be a new, yet unknown Java element // give an advanced IWorkbenchAdapter the chance IWorkbenchAdapter wbAdapter = (IWorkbenchAdapter) element.getAdapter(IWorkbenchAdapter.class); if (wbAdapter != null && !(wbAdapter instanceof JavaWorkbenchAdapter)) { // avoid recursion ImageDescriptor imageDescriptor = wbAdapter.getImageDescriptor(element); if (imageDescriptor != null) { return imageDescriptor; } } return JavaPluginImages.DESC_OBJS_GHOST; } } catch (JavaModelException e) { if (e.isDoesNotExist()) return JavaPluginImages.DESC_OBJS_UNKNOWN; JavaPlugin.log(e); return JavaPluginImages.DESC_OBJS_GHOST; } }
From source file:com.redhat.ceylon.eclipse.code.explorer.JavaElementImageProvider.java
License:Open Source License
private static boolean confirmAbstract(IMember element) throws JavaModelException { // never show the abstract symbol on interfaces or members in interfaces if (element.getElementType() == IJavaElement.TYPE) { return !JavaModelUtil.isInterfaceOrAnnotation((IType) element); }//from w ww . j a va 2 s .co m return !JavaModelUtil.isInterfaceOrAnnotation(element.getDeclaringType()); }