use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class AbstractJavaCompletionProposal method getAdditionalProposalInfo.
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension5#getAdditionalProposalInfo(org.eclipse.core.runtime.IProgressMonitor)
*/
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
if (getProposalInfo() != null) {
String info = getProposalInfo().getInfo(monitor);
if (info != null && info.length() > 0) {
StringBuffer buffer = new StringBuffer();
HTMLPrinter.insertPageProlog(buffer, 0, getCSSStyles());
buffer.append(info);
IJavaElement element = null;
try {
element = getProposalInfo().getJavaElement();
if (element instanceof IMember) {
//TODO
// String base= JavaDocLocations.getBaseURL(element, ((IMember)element).isBinary());
// if (base != null) {
// int endHeadIdx= buffer.indexOf("</head>"); //$NON-NLS-1$
// buffer.insert(endHeadIdx, "\n<base href='" + base + "'>\n"); //$NON-NLS-1$ //$NON-NLS-2$
// }
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
HTMLPrinter.addPageEpilog(buffer);
info = buffer.toString();
return new JavadocBrowserInformationControlInput(info);
}
}
return null;
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class JavaElementImageProvider method computeJavaAdornmentFlags.
// ---- Methods to compute the adornments flags ---------------------------------
private int computeJavaAdornmentFlags(IJavaElement element, int renderFlags) {
int flags = 0;
if (showOverlayIcons(renderFlags)) {
try {
if (element instanceof IMember) {
IMember member = (IMember) element;
int modifiers = member.getFlags();
if (confirmAbstract(member) && JdtFlags.isAbstract(member))
flags |= JavaElementImageDescriptor.ABSTRACT;
if (Flags.isFinal(modifiers) || isInterfaceOrAnnotationField(member) || isEnumConstant(member, modifiers))
flags |= JavaElementImageDescriptor.FINAL;
if (Flags.isStatic(modifiers) || isInterfaceOrAnnotationFieldOrType(member) || isEnumConstant(member, modifiers))
flags |= JavaElementImageDescriptor.STATIC;
if (Flags.isDeprecated(modifiers))
flags |= JavaElementImageDescriptor.DEPRECATED;
int elementType = element.getElementType();
if (elementType == IJavaElement.METHOD) {
if (((IMethod) element).isConstructor())
flags |= JavaElementImageDescriptor.CONSTRUCTOR;
if (// collides with 'super' flag
Flags.isSynchronized(modifiers))
flags |= JavaElementImageDescriptor.SYNCHRONIZED;
if (Flags.isNative(modifiers))
flags |= JavaElementImageDescriptor.NATIVE;
if (Flags.isDefaultMethod(modifiers))
flags |= JavaElementImageDescriptor.DEFAULT_METHOD;
if (Flags.isAnnnotationDefault(modifiers))
flags |= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
}
if (member.getElementType() == IJavaElement.TYPE) {
if (JavaModelUtil.hasMainMethod((IType) member)) {
flags |= JavaElementImageDescriptor.RUNNABLE;
}
}
if (member.getElementType() == IJavaElement.FIELD) {
if (Flags.isVolatile(modifiers))
flags |= JavaElementImageDescriptor.VOLATILE;
if (Flags.isTransient(modifiers))
flags |= JavaElementImageDescriptor.TRANSIENT;
}
} else if (element instanceof ILocalVariable && Flags.isFinal(((ILocalVariable) element).getFlags())) {
flags |= JavaElementImageDescriptor.FINAL;
}
} catch (JavaModelException e) {
// do nothing. Can't compute runnable adornment or get flags
}
}
return flags;
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class JavaSearchScope method add.
/**
* Add an element to the java search scope.
* @param element The element we want to add to current java search scope
* @throws JavaModelException May happen if some Java Model info are not available
*/
public void add(IJavaElement element) throws JavaModelException {
IPath containerPath = null;
String containerPathToString = null;
PackageFragmentRoot root = null;
int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
switch(element.getElementType()) {
case IJavaElement.JAVA_MODEL:
// a workspace sope should be used
break;
case IJavaElement.JAVA_PROJECT:
add((JavaProject) element, null, includeMask, new HashSet(2), new HashSet(2), null);
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
root = (PackageFragmentRoot) element;
IPath rootPath = root.internalPath();
containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
IResource rootResource = root.resource();
String projectPath = root.getJavaProject().getPath().toString();
if (rootResource != null && rootResource.isAccessible()) {
String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
add(projectPath, relativePath, containerPathToString, false, /*not a package*/
null);
} else {
//$NON-NLS-1$
add(projectPath, "", containerPathToString, false, /*not a package*/
null);
}
break;
case IJavaElement.PACKAGE_FRAGMENT:
root = (PackageFragmentRoot) element.getParent();
projectPath = root.getJavaProject().getPath().toString();
if (root.isArchive()) {
String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
containerPath = root.getPath();
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
add(projectPath, relativePath, containerPathToString, true, /*package*/
null);
} else {
IResource resource = ((JavaElement) element).resource();
if (resource != null) {
if (resource.isAccessible()) {
containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath();
} else {
// for working copies, get resource container full path
containerPath = resource.getParent().getFullPath();
}
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
add(projectPath, relativePath, containerPathToString, true, /*package*/
null);
}
}
break;
default:
// remember sub-cu (or sub-class file) java elements
if (element instanceof IMember) {
if (this.elements == null) {
this.elements = new ArrayList();
}
this.elements.add(element);
}
root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
projectPath = root.getJavaProject().getPath().toString();
String relativePath;
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
containerPath = root.getParent().getPath();
relativePath = Util.relativePath(getPath(element, false), root.getJavaProject().getPath().segmentCount());
} else {
containerPath = root.internalPath();
relativePath = getPath(element, true).toString();
}
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
add(projectPath, relativePath, containerPathToString, false, /*not a package*/
null);
}
if (root != null)
addEnclosingProjectOrJar(root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath());
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class SourceMapper method getNameRange.
/**
* Returns the SourceRange for the name of the given element, or
* {-1, -1} if no source range is known for the name of the element.
*/
public SourceRange getNameRange(IJavaElement element) {
switch(element.getElementType()) {
case IJavaElement.METHOD:
if (((IMember) element).isBinary()) {
IJavaElement[] el = getUnqualifiedMethodHandle((IMethod) element, false);
if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
element = getUnqualifiedMethodHandle((IMethod) element, true)[0];
} else {
element = el[0];
}
}
break;
case IJavaElement.TYPE_PARAMETER:
IJavaElement parent = element.getParent();
if (parent.getElementType() == IJavaElement.METHOD) {
IMethod method = (IMethod) parent;
if (method.isBinary()) {
IJavaElement[] el = getUnqualifiedMethodHandle(method, false);
if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
method = (IMethod) getUnqualifiedMethodHandle(method, true)[0];
} else {
method = (IMethod) el[0];
}
element = method.getTypeParameter(element.getElementName());
}
}
break;
case IJavaElement.LOCAL_VARIABLE:
LocalVariableElementKey key = new LocalVariableElementKey(element.getParent(), element.getElementName());
SourceRange[] ranges = (SourceRange[]) this.parametersRanges.get(key);
if (ranges == null) {
return UNKNOWN_RANGE;
} else {
return ranges[1];
}
}
SourceRange[] ranges = (SourceRange[]) this.sourceRanges.get(element);
if (ranges == null) {
return UNKNOWN_RANGE;
} else {
return ranges[1];
}
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class IntroduceIndirectionRefactoring method adjustVisibility.
private RefactoringStatus adjustVisibility(IMember whoToAdjust, ModifierKeyword neededVisibility, boolean alsoIncreaseEnclosing, IProgressMonitor monitor) throws CoreException {
Map<IMember, IncomingMemberVisibilityAdjustment> adjustments;
if (isRewriteKept(whoToAdjust.getCompilationUnit()))
adjustments = fIntermediaryAdjustments;
else
adjustments = new HashMap<IMember, IncomingMemberVisibilityAdjustment>();
int existingAdjustments = adjustments.size();
addAdjustment(whoToAdjust, neededVisibility, adjustments);
if (alsoIncreaseEnclosing)
while (whoToAdjust.getDeclaringType() != null) {
whoToAdjust = whoToAdjust.getDeclaringType();
addAdjustment(whoToAdjust, neededVisibility, adjustments);
}
boolean hasNewAdjustments = (adjustments.size() - existingAdjustments) > 0;
if (hasNewAdjustments && ((whoToAdjust.isReadOnly() || whoToAdjust.isBinary())))
return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_update_binary_target_visibility, new String[] { JavaElementLabels.getElementLabel(whoToAdjust, JavaElementLabels.ALL_DEFAULT) }), JavaStatusContext.create(whoToAdjust));
RefactoringStatus status = new RefactoringStatus();
// Don't create a rewrite if it is not necessary
if (!hasNewAdjustments)
return status;
try {
monitor.beginTask(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting, 2);
Map<ICompilationUnit, CompilationUnitRewrite> rewrites;
if (!isRewriteKept(whoToAdjust.getCompilationUnit())) {
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(whoToAdjust.getCompilationUnit());
rewrite.setResolveBindings(false);
rewrites = new HashMap<ICompilationUnit, CompilationUnitRewrite>();
rewrites.put(whoToAdjust.getCompilationUnit(), rewrite);
status.merge(rewriteVisibility(adjustments, rewrites, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
rewrite.attachChange((CompilationUnitChange) fTextChangeManager.get(whoToAdjust.getCompilationUnit()), true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
}
} finally {
monitor.done();
}
return status;
}
Aggregations