本文整理汇总了Java中org.eclipse.jdt.core.ICompilationUnit.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit.getParent方法的具体用法?Java ICompilationUnit.getParent怎么用?Java ICompilationUnit.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.getParent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TypeReferenceProcessor
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public TypeReferenceProcessor(Set<String> oldSingleImports, Set<String> oldDemandImports, CompilationUnit root, ImportRewrite impStructure, boolean ignoreLowerCaseNames, UnresolvableImportMatcher unresolvableImportMatcher) {
fOldSingleImports= oldSingleImports;
fOldDemandImports= oldDemandImports;
fImpStructure= impStructure;
fDoIgnoreLowerCaseNames= ignoreLowerCaseNames;
fUnresolvableImportMatcher= unresolvableImportMatcher;
ICompilationUnit cu= impStructure.getCompilationUnit();
fImplicitImports= new HashSet<>(3);
fImplicitImports.add(""); //$NON-NLS-1$
fImplicitImports.add("java.lang"); //$NON-NLS-1$
fImplicitImports.add(cu.getParent().getElementName());
fAnalyzer= new ScopeAnalyzer(root);
fCurrPackage= (IPackageFragment) cu.getParent();
fAllowDefaultPackageImports= cu.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true).equals(JavaCore.VERSION_1_3);
fImportsAdded= new HashSet<>();
fUnresolvedTypes= new HashMap<>();
}
示例2: appendCompilationUnitLabel
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
* Appends the label for a compilation unit. Considers the CU_* flags.
*
* @param cu the element to render
* @param flags the rendering flags. Flags with names starting with 'CU_' are considered.
*/
public void appendCompilationUnitLabel(ICompilationUnit cu, long flags) {
if (getFlag(flags, JavaElementLabels.CU_QUALIFIED)) {
IPackageFragment pack= (IPackageFragment) cu.getParent();
if (!pack.isDefaultPackage()) {
appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS));
fBuilder.append('.');
}
}
fBuilder.append(cu.getElementName());
if (getFlag(flags, JavaElementLabels.CU_POST_QUALIFIED)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentLabel((IPackageFragment) cu.getParent(), flags & QUALIFIER_FLAGS);
}
}
示例3: addEdits
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
for (int i= 0; i < decls.length; i++) {
ISourceRange range= decls[i].getSourceRange();
root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
}
return;
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
String lineDelim = "\n";
String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
示例4: getName
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Override
public String getName() {
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
try {
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
} catch(JavaModelException e) {
JavaLanguageServerPlugin.log(e);
}
return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
示例5: rename
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public WorkspaceEdit rename(RenameParams params, IProgressMonitor monitor) {
WorkspaceEdit edit = new WorkspaceEdit();
if (!preferenceManager.getPreferences().isRenameEnabled()) {
return edit;
}
try {
final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri());
IJavaElement[] elements = JDTUtils.findElementsAtSelection(unit, params.getPosition().getLine(), params.getPosition().getCharacter(), this.preferenceManager, monitor);
if (elements == null || elements.length == 0) {
return edit;
}
IJavaElement curr = null;
if (elements.length != 1) {
// they could be package fragments.
// We need to select the one that matches the package fragment of the current unit
IPackageFragment packageFragment = (IPackageFragment) unit.getParent();
IJavaElement found = Stream.of(elements).filter(e -> e.equals(packageFragment)).findFirst().orElse(null);
if (found == null) {
// this would be a binary package fragment
curr = elements[0];
} else {
curr = found;
}
} else {
curr = elements[0];
}
RenameProcessor processor = createRenameProcessor(curr);
processor.renameOccurrences(edit, params.getNewName(), monitor);
} catch (CoreException ex) {
JavaLanguageServerPlugin.logException("Problem with rename for " + params.getTextDocument().getUri(), ex);
}
return edit;
}
示例6: createCompilationUnit
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private ICompilationUnit createCompilationUnit(ICompilationUnit unit) {
try {
unit.getResource().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
if (unit.getResource().exists()) {
IJavaElement parent = unit.getParent();
if (parent instanceof IPackageFragment) {
IPackageFragment pkg = (IPackageFragment) parent;
unit = pkg.createCompilationUnit(unit.getElementName(), unit.getSource(), true, new NullProgressMonitor());
}
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
return unit;
}