Java Code Examples for org.eclipse.jdt.core.ICompilationUnit#getPrimary()

The following examples show how to use org.eclipse.jdt.core.ICompilationUnit#getPrimary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GotoTypeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void gotoType(IType type) {
	ICompilationUnit cu= (ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT);
	IJavaElement element= null;
	if (cu != null) {
		element= cu.getPrimary();
	}
	else {
		element= type.getAncestor(IJavaElement.CLASS_FILE);
	}
	if (element != null) {
		PackageExplorerPart view= PackageExplorerPart.openInActivePerspective();
		if (view != null) {
			view.selectReveal(new StructuredSelection(element));
			if (!element.equals(getSelectedElement(view))) {
				MessageDialog.openInformation(fPackageExplorer.getSite().getShell(),
					getDialogTitle(),
					Messages.format(PackagesMessages.PackageExplorer_element_not_present, JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT)));
			}
		}
	}
}
 
Example 2
Source File: LanguageServerWorkingCopyOwner.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IBuffer createBuffer(ICompilationUnit workingCopy) {
	ICompilationUnit original= workingCopy.getPrimary();
	IResource resource= original.getResource();
	if (resource instanceof IFile) {
		return new DocumentAdapter(workingCopy, (IFile)resource);
	}
	return DocumentAdapter.Null;
}
 
Example 3
Source File: RenameAnalyzeUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
static ICompilationUnit findWorkingCopyForCu(ICompilationUnit[] newWorkingCopies, ICompilationUnit cu){
	ICompilationUnit original= cu == null ? null : cu.getPrimary();
	for (int i= 0; i < newWorkingCopies.length; i++) {
		if (newWorkingCopies[i].getPrimary().equals(original)) {
			return newWorkingCopies[i];
		}
	}
	return null;
}
 
Example 4
Source File: RenameAnalyzeUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static ICompilationUnit findWorkingCopyForCu(ICompilationUnit[] newWorkingCopies, ICompilationUnit cu){
	ICompilationUnit original= cu == null ? null : cu.getPrimary();
	for (int i= 0; i < newWorkingCopies.length; i++) {
		if (newWorkingCopies[i].getPrimary().equals(original))
			return newWorkingCopies[i];
	}
	return null;
}
 
Example 5
Source File: InlineMethodRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IFile getFile(ICompilationUnit unit) {
	unit= unit.getPrimary();
	IResource resource= unit.getResource();
	if (resource != null && resource.getType() == IResource.FILE)
		return (IFile)resource;
	return null;
}
 
Example 6
Source File: ReplaceInvocationsRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IFile getFile(ICompilationUnit unit) {
	unit= unit.getPrimary();
	IResource resource= unit.getResource();
	if (resource != null && resource.getType() == IResource.FILE)
		return (IFile)resource;
	return null;
}
 
Example 7
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void integrateSolution(CleanUpChange solution, ICompilationUnit source) {
	ICompilationUnit primary= source.getPrimary();

	List<CleanUpChange> changes= fSolutions.get(primary);
	if (changes == null) {
		changes= new ArrayList<CleanUpChange>();
		fSolutions.put(primary, changes);
	}
	changes.add(solution);
}
 
Example 8
Source File: CustomBufferFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IBuffer createBuffer(IOpenable owner) {
	if (owner instanceof ICompilationUnit) {
		ICompilationUnit unit= (ICompilationUnit) owner;
		ICompilationUnit original= unit.getPrimary();
		IResource resource= original.getResource();
		if (resource instanceof IFile) {
			return new DocumentAdapter(unit, (IFile) resource);
		}

	}
	return DocumentAdapter.NULL;
}
 
Example 9
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IResource getUnderlyingResource() {
	Object input= getInput();
	if (input instanceof ICompilationUnit) {
		ICompilationUnit cu= (ICompilationUnit) input;
		cu= cu.getPrimary();
		return cu.getResource();
	} else if (input instanceof IClassFile) {
		return ((IClassFile) input).getResource();
	}
	return null;
}
 
Example 10
Source File: JavaElementResourceMapping.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static ResourceMapping create(ICompilationUnit unit) {
	if (unit == null) {
		return null;
	}
	return new CompilationUnitResourceMapping(unit.getPrimary());
}
 
Example 11
Source File: JavaElementResourceMapping.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static ResourceMapping create(ICompilationUnit unit) {
	if (unit == null)
		return null;
	return new CompilationUnitResourceMapping(unit.getPrimary());
}