use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class RefactoringAvailabilityTester method isIntroduceFactoryAvailable.
public static boolean isIntroduceFactoryAvailable(final JavaTextSelection selection) throws JavaModelException {
final IJavaElement[] elements = selection.resolveElementAtOffset();
if (elements.length == 1 && elements[0] instanceof IMethod)
return isIntroduceFactoryAvailable((IMethod) elements[0]);
// there's no IMethod for the default constructor
if (!Checks.isAvailable(selection.resolveEnclosingElement()))
return false;
ASTNode node = selection.resolveCoveringNode();
if (node == null) {
ASTNode[] selectedNodes = selection.resolveSelectedNodes();
if (selectedNodes != null && selectedNodes.length == 1) {
node = selectedNodes[0];
if (node == null)
return false;
} else {
return false;
}
}
if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
return true;
node = ASTNodes.getNormalizedNode(node);
if (node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
return true;
return false;
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class RefactoringAvailabilityTester method isReplaceInvocationsAvailable.
public static boolean isReplaceInvocationsAvailable(final JavaTextSelection selection) throws JavaModelException {
final IJavaElement[] elements = selection.resolveElementAtOffset();
if (elements.length != 1)
return false;
IJavaElement element = elements[0];
return (element instanceof IMethod) && isReplaceInvocationsAvailable(((IMethod) element));
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class JavaElementUtil method getPackageAndSubpackages.
/**
* @param pack a package fragment
* @return an array containing the given package and all subpackages
* @throws JavaModelException if getting the all sibling packages fails
*/
public static IPackageFragment[] getPackageAndSubpackages(IPackageFragment pack) throws JavaModelException {
if (pack.isDefaultPackage())
return new IPackageFragment[] { pack };
IPackageFragmentRoot root = (IPackageFragmentRoot) pack.getParent();
IJavaElement[] allPackages = root.getChildren();
ArrayList<IPackageFragment> subpackages = new ArrayList<IPackageFragment>();
subpackages.add(pack);
String prefix = pack.getElementName() + '.';
for (int i = 0; i < allPackages.length; i++) {
IPackageFragment currentPackage = (IPackageFragment) allPackages[i];
if (currentPackage.getElementName().startsWith(prefix))
subpackages.add(currentPackage);
}
return subpackages.toArray(new IPackageFragment[subpackages.size()]);
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class MemberVisibilityAdjustor method adjustOutgoingVisibility.
/**
* Adjusts the visibilities of the outgoing references from the member represented by the specified search result groups.
*
* @param groups the search result groups representing the references
* @param monitor the progress monitor to us
* @throws JavaModelException if the visibility could not be determined
*/
private void adjustOutgoingVisibility(final SearchResultGroup[] groups, final IProgressMonitor monitor) throws JavaModelException {
try {
//$NON-NLS-1$
monitor.beginTask("", groups.length);
monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
IJavaElement element = null;
SearchMatch[] matches = null;
SearchResultGroup group = null;
for (int index = 0; index < groups.length; index++) {
group = groups[index];
element = JavaCore.create(group.getResource());
if (element instanceof ICompilationUnit) {
matches = group.getSearchResults();
for (int offset = 0; offset < matches.length; offset++) adjustOutgoingVisibility(matches[offset], new SubProgressMonitor(monitor, 1));
}
// else if (element != null)
// fStatus.merge(RefactoringStatus.createStatus(fFailureSeverity, RefactoringCoreMessages.getFormattedString
// ("MemberVisibilityAdjustor.binary.outgoing.project", new String[] { element.getJavaProject().getElementName(), getLabel
// (fReferenced)}), null, null, RefactoringStatusEntry.NO_CODE, null)); //$NON-NLS-1$
// else if (group.getResource() != null)
// fStatus.merge(RefactoringStatus.createStatus(fFailureSeverity, RefactoringCoreMessages.getFormattedString
// ("MemberVisibilityAdjustor.binary.outgoing.resource", new String[] { group.getResource().getName(), getLabel
// (fReferenced)}), null, null, RefactoringStatusEntry.NO_CODE, null)); //$NON-NLS-1$
// TW: enable when bug 78387 is fixed
monitor.worked(1);
}
} finally {
monitor.done();
}
}
use of org.eclipse.jdt.core.IJavaElement 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;
}
Aggregations