本文整理汇总了Java中org.eclipse.jdt.core.IJavaElement.getElementType方法的典型用法代码示例。如果您正苦于以下问题:Java IJavaElement.getElementType方法的具体用法?Java IJavaElement.getElementType怎么用?Java IJavaElement.getElementType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IJavaElement
的用法示例。
在下文中一共展示了IJavaElement.getElementType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTarget
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
/**
* Returns the target of this resource change.
* @param elem the changed element
* @return the target of the change, or an empty string if the target is not either a project, package, or file
*/
private String getTarget(IJavaElement elem) {
if (elem == null) {
return "";
}
int type = elem.getElementType();
if (type == IJavaElement.JAVA_PROJECT) {
return "Project";
} else if (type == IJavaElement.PACKAGE_DECLARATION) {
return "Package";
} else if (type == IJavaElement.COMPILATION_UNIT) {
return "File";
}
return elem.getElementName() + "@" + elem.getElementType();
}
示例2: getName
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
/**
* Obtains the name of the specified element.
* @param elem the element
* @param type the type of the element
* @return the name string
*/
public static String getName(IJavaElement elem) {
int type = elem.getElementType();
if (type == IJavaElement.JAVA_PROJECT) {
return elem.getResource().getName();
} else if (type == IJavaElement.PACKAGE_DECLARATION) {
IPackageFragment jpackage = (IPackageFragment)elem;
return jpackage.getElementName();
} else if (type == IJavaElement.COMPILATION_UNIT) {
return elem.getResource().getName();
}
return "";
}
示例3: getTypeOfOpenJavaEditor
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
public static IType getTypeOfOpenJavaEditor() {
IJavaElement activeEditorJavaInput = EditorUtility.getActiveEditorJavaInput();
if (activeEditorJavaInput != null) {
if (activeEditorJavaInput.getElementType() == IJavaElement.COMPILATION_UNIT) {
try {
ICompilationUnit iCompilationUnit = (ICompilationUnit) activeEditorJavaInput;
String elementName = iCompilationUnit.getElementName();
elementName = elementName.substring(0,
elementName.lastIndexOf('.'));
IType[] types = iCompilationUnit.getTypes();
for (IType type : types) {
String fullyQualifiedName = type
.getFullyQualifiedName();
if (fullyQualifiedName.contains(elementName)) {
return type;
}
}
} catch (JavaModelException e1) {
e1.printStackTrace();
}
}
} else {
System.err.println("Java Editor is not open");
}
return null;
}
示例4: processType
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private void processType(ITypeVisitor visitor, BinaryTypeName btn,
IType type, IProgressMonitor monitor) throws JavaModelException {
final String binaryname = btn.toString();
monitor.subTask(binaryname);
visitor.visit(type, binaryname);
for (final IJavaElement child : type.getChildren()) {
if (monitor.isCanceled()) {
break;
}
switch (child.getElementType()) {
case IJavaElement.TYPE:
IType nestedtype = (IType) child;
processType(visitor, btn.nest(nestedtype), nestedtype, monitor);
break;
case IJavaElement.METHOD:
case IJavaElement.INITIALIZER:
case IJavaElement.FIELD:
processAnonymousInnerTypes(visitor, btn, (IMember) child, monitor);
break;
}
}
}
示例5: visit
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private void visit(IJavaElementDelta delta) {
IJavaElement el = delta.getElement();
switch (el.getElementType()) {
case IJavaElement.JAVA_MODEL:
for (IJavaElementDelta c : delta.getAffectedChildren()) {
visit(c);
}
break;
case IJavaElement.JAVA_PROJECT:
IJavaProject javaProject = (IJavaProject) el;
if (isClasspathChanged(delta)) {
detectionJob.analyze(javaProject);
}
break;
default:
break;
}
}
示例6: getDefaultPackage
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
public String getDefaultPackage() {
WPILibJavaPlugin.logInfo("Project: "+project);
String defaultPackage = null;
if (project != null) {
try {
IPackageFragmentRoot root = JavaCore.create(project)
.getPackageFragmentRoot(project.getFolder("src"));
String backupPackage = "";
for (IJavaElement child : root.getChildren()) {
if (child.getElementType()==IJavaElement.PACKAGE_FRAGMENT
&& child.getElementName().endsWith("."+ending)) {
defaultPackage = child.getElementName();
}
backupPackage = child.getElementName();
}
if (defaultPackage == null) defaultPackage = backupPackage;
} catch (JavaModelException e) {
WPILibJavaPlugin.logError("Error getting default package.", e);
}
}
if (defaultPackage != null) return defaultPackage;
else return "";
}
示例7: getMethodDeclaration
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
public static MethodDeclaration getMethodDeclaration(String methodName) {
IJavaElement javaElem = EditorUtility.getActiveEditorJavaInput();
if (javaElem.getElementType() == IJavaElement.COMPILATION_UNIT) {
ICompilationUnit iCompUnit = (ICompilationUnit) javaElem;
ASTNode astNode = Crystal.getInstance()
.getASTNodeFromCompilationUnit(iCompUnit);
if (astNode != null
&& astNode.getNodeType() == ASTNode.COMPILATION_UNIT) {
CompilationUnit compUnit = (CompilationUnit) astNode;
for (Object declaration : compUnit.types()) {
if (declaration instanceof TypeDeclaration) {
for (MethodDeclaration method : ((TypeDeclaration) declaration)
.getMethods()) {
if (methodName.contentEquals(method.getName()
.getFullyQualifiedName())) {
return method;
}
}
}
}
}
}
return null;
}
示例8: collectCodeLenses
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private void collectCodeLenses(ITypeRoot unit, IJavaElement[] elements, List<ICodeLens> lenses,
IProgressMonitor monitor) throws JavaModelException {
for (IJavaElement element : elements) {
if (monitor.isCanceled()) {
return;
}
if (element.getElementType() == IJavaElement.TYPE) {
collectCodeLenses(unit, ((IType) element).getChildren(), lenses, monitor);
} else if (element.getElementType() != IJavaElement.METHOD || JDTUtils.isHiddenGeneratedElement(element)) {
continue;
}
// if (preferenceManager.getPreferences().isReferencesCodeLensEnabled()) {
ICodeLens lens = getCodeLens(REFERENCES_TYPE, element, unit);
lenses.add(lens);
// }
// if (preferenceManager.getPreferences().isImplementationsCodeLensEnabled() &&
// element instanceof IType) {
if (element instanceof IType) {
IType type = (IType) element;
if (type.isInterface() || Flags.isAbstract(type.getFlags())) {
lens = getCodeLens(IMPLEMENTATION_TYPE, element, unit);
lenses.add(lens);
}
}
}
}
示例9: launch
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private void launch(Object[] elements, String mode) {
try {
IJavaElement[] ijes = null;
List<IJavaElement> jes = new ArrayList<IJavaElement>();
for (int i = 0; i < elements.length; i++) {
Object selected= elements[i];
if (selected instanceof IJavaElement) {
IJavaElement element= (IJavaElement) selected;
switch (element.getElementType()) {
case IJavaElement.COMPILATION_UNIT:
jes.add(element);
break;
}
}
}
ijes = new IJavaElement[jes.size()];
jes.toArray(ijes);
ILaunchConfigurationWorkingCopy wc = buildLaunchConfiguration(ijes);
if (wc==null) return;
ILaunchConfiguration config= findExistingORCreateLaunchConfiguration(wc, mode);
DebugUITools.launch(config, mode);
} catch (Exception e) {
ResourceManager.logException(e);
MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "GW4E Launcher", (Image)null, "Unable to launch. See error in Error view.", MessageDialog.ERROR, new String[] { "Close" }, 0);
dialog.open();
}
}
示例10: findElementAtCursor
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
/**
* Try to identify a nested java element of the given element from a textual
* selection in its source code. This might be possible if the given element
* is a compilation unit or class file.
*
* @param unit
* unit to search
* @param selection
* selection within this unit
* @return nested element or the unit itself
*/
private IJavaElement findElementAtCursor(IJavaElement unit,
ISelection selection) {
int pos = -1;
if (selection instanceof ITextSelection) {
pos = ((ITextSelection) selection).getOffset();
}
if (selection instanceof IMarkSelection) {
pos = ((IMarkSelection) selection).getOffset();
}
if (pos == -1)
return unit;
IJavaElement element = null;
try {
switch (unit.getElementType()) {
case IJavaElement.COMPILATION_UNIT:
element = ((ICompilationUnit) unit).getElementAt(pos);
break;
case IJavaElement.CLASS_FILE:
element = ((IClassFile) unit).getElementAt(pos);
break;
}
} catch (JavaModelException e) {
// we ignore this
}
return element == null ? unit : element;
}
示例11: getCoverageFor
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
public ICoverageNode getCoverageFor(IJavaElement element) {
final ICoverageNode coverage = coveragemap.get(element);
if (coverage != null) {
return coverage;
}
if (IJavaElement.METHOD == element.getElementType()) {
resolveMethods((IType) element.getParent());
return coveragemap.get(element);
}
return null;
}
示例12: processAnonymousInnerTypes
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private void processAnonymousInnerTypes(ITypeVisitor visitor,
BinaryTypeName btn, IMember member, IProgressMonitor monitor)
throws JavaModelException {
for (final IJavaElement element : member.getChildren()) {
if (monitor.isCanceled()) {
break;
}
if (element.getElementType() == IJavaElement.TYPE) {
final IType type = (IType) element;
processType(visitor, btn.nest(type), type, monitor);
}
}
}
示例13: visit
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private void visit(IJavaElementDelta delta) {
IJavaElement el = delta.getElement();
switch (el.getElementType()) {
case IJavaElement.JAVA_MODEL:
visitChildren(delta);
break;
case IJavaElement.JAVA_PROJECT:
if (isClasspathChanged(delta.getFlags()) && platformHolder.isCurrentPlatformProject(delta.getElement().getJavaProject())) {
notifyClasspathChanged((IJavaProject) el);
}
break;
default:
break;
}
}
示例14: organizeImportsInProject
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
/**
* Organize imports when select a project.
*
* @param proj
* the target project
* @return
*/
public WorkspaceEdit organizeImportsInProject(IProject proj) {
WorkspaceEdit rootEdit = new WorkspaceEdit();
HashSet<IJavaElement> result = new HashSet<>();
collectCompilationUnits(JavaCore.create(proj), result, null);
for (IJavaElement elem : result) {
if (elem.getElementType() == IJavaElement.COMPILATION_UNIT) {
organizeImportsInCompilationUnit((ICompilationUnit) elem, rootEdit);
}
}
return rootEdit;
}
示例15: organizeImportsInDirectory
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
/**
* Organize imports underlying a directory
*
* @param folderUri
* Selected folder URI
* @param proj
* the folder associated project
* @return
* @throws CoreException
*/
public WorkspaceEdit organizeImportsInDirectory(String folderUri, IProject proj) throws CoreException {
WorkspaceEdit rootEdit = new WorkspaceEdit();
IPackageFragment fragment = null;
if (JDTUtils.toURI(folderUri) != null) {
fragment = JDTUtils.resolvePackage(folderUri);
}
// Select an individual package
if (fragment != null) {
organizeImportsInPackageFragment(fragment, rootEdit);
} else if (proj != null) {
// Search the packages under the selected folder:
IJavaProject javaProject = JavaCore.create(proj);
IPath rootPath = ResourceUtils.filePathFromURI(folderUri);
IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
HashSet<IJavaElement> result = new HashSet<>();
for (IPackageFragmentRoot root : roots) {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
String packageRoot = root.getResource().getLocation().toString();
if (packageRoot.toLowerCase().indexOf(rootPath.toString().toLowerCase()) >= 0) {
collectCompilationUnits(javaProject, result, null);
}
}
}
for (IJavaElement elem : result) {
if (elem.getElementType() == IJavaElement.COMPILATION_UNIT) {
organizeImportsInCompilationUnit((ICompilationUnit) elem, rootEdit);
}
}
}
return rootEdit;
}