当前位置: 首页>>代码示例>>Java>>正文


Java IJavaElement类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.IJavaElement的典型用法代码示例。如果您正苦于以下问题:Java IJavaElement类的具体用法?Java IJavaElement怎么用?Java IJavaElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IJavaElement类属于org.eclipse.jdt.core包,在下文中一共展示了IJavaElement类的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();
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:24,代码来源:ResourceMacro.java

示例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 "";
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:22,代码来源:ResourceMacro.java

示例3: createResourceRemovedMacro

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
/**
 * Creates a macro corresponding to the removed delta of the change.
 * @param time the time when the change occurred
 * @param delta the removed delta of the change
 * @return the created resource macro
 */
private ResourceMacro createResourceRemovedMacro(long time, IJavaElementDelta delta) {
    IJavaElement elem = delta.getElement();
    String path = elem.getPath().toString();
    if (path == null) {
        return null;
    }
    
    String type = "Removed";
    if ((delta.getFlags() & IJavaElementDelta.F_MOVED_TO) != 0) {
        if (isRenamed(delta.getElement(), delta.getMovedToElement())) {
            type = "RenamedTo";
        } else {
            type = "MovedTo";
        }
    }
    
    return new ResourceMacro(time, type, path, elem);
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:25,代码来源:ResourceChangedManager.java

示例4: createResourceAddedMacro

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
/**
 * Creates a macro corresponding to the added delta of the change.
 * @param time the time when the change occurred
 * @param delta the added delta of the change
 * @return the created resource macro
 */
private ResourceMacro createResourceAddedMacro(long time, IJavaElementDelta delta) {
    IJavaElement elem = delta.getElement();
    String path = elem.getPath().toString();
    if (path == null) {
        return null;
    }
    
    String type = "Added";
    if ((delta.getFlags() & IJavaElementDelta.F_MOVED_FROM) != 0) {
        if (isRenamed(delta.getElement(), delta.getMovedFromElement())) {
            type = "RenamedFrom";
        } else {
            type = "MovedFrom";
        }
    }
    
    return new ResourceMacro(time, type, path, elem);
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:25,代码来源:ResourceChangedManager.java

示例5: isHiddenGeneratedElement

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
public static boolean isHiddenGeneratedElement(IJavaElement element) {
	// generated elements are tagged with javax.annotation.Generated and
	// they need to be filtered out
	if (element instanceof IAnnotatable) {
		try {
			IAnnotation[] annotations = ((IAnnotatable) element).getAnnotations();
			if (annotations.length != 0) {
				for (IAnnotation annotation : annotations) {
					if (isSilencedGeneratedAnnotation(annotation)) {
						return true;
					}
				}
			}
		} catch (JavaModelException e) {
			// ignore
		}
	}
	return false;
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:20,代码来源:JDTUtils.java

示例6: performFinish

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
@Override
public boolean performFinish()
{
	boolean res = super.performFinish();
	if( res )
	{
		final IJavaElement newElement = getCreatedElement();

		IWorkingSet[] workingSets = fFirstPage.getWorkingSets();
		if( workingSets.length > 0 )
		{
			PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(newElement, workingSets);
		}
		BasicNewResourceWizard.selectAndReveal(fSecondPage.getJavaProject().getProject(), getWorkbench()
			.getActiveWorkbenchWindow());
	}
	return res;
}
 
开发者ID:equella,项目名称:Equella,代码行数:19,代码来源:NewPluginWizard.java

示例7: ClassDetails

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
public ClassDetails(IClassFile classFile, String jarFileName, String packageName, boolean isUserDefined) {
	LOGGER.debug("Extracting methods from "+classFile.getElementName());

	try {
		this.javaDoc=getJavaDoc(classFile);	
		intialize(classFile,jarFileName,packageName, isUserDefined);
		for (IJavaElement iJavaElement : classFile.getChildren()) {
			if (iJavaElement instanceof IType) {
				IType iType = (IType) iJavaElement;
				for (IMethod iMethod : iType.getMethods()) {
					addMethodsToClass(iMethod);
				}
			}
		}
	} catch (JavaModelException e) {
		LOGGER.error("Error occurred while fetching methods from class"+cName);
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:19,代码来源:ClassDetails.java

示例8: resolveClassFile

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
private static IClassFile resolveClassFile(String uriString) {
    if (uriString == null || uriString.isEmpty()) {
        return null;
    }
    try {
        URI uri = new URI(uriString);
        if (uri != null && JDT_SCHEME.equals(uri.getScheme()) && "contents".equals(uri.getAuthority())) {
            String handleId = uri.getQuery();
            IJavaElement element = JavaCore.create(handleId);
            IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
            return cf;
        }
    } catch (URISyntaxException e) {
        // ignore
    }
    return null;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:18,代码来源:JdtSourceLookUpProvider.java

示例9: getSourceFile

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
/**
 * Returns the source file associated with the given type, or <code>null</code>
 * if no source file could be found.
 *
 * @param project
 *            the java project containing the classfile
 * @param qualifiedName
 *            fully qualified name of the type, slash delimited
 * @param sourceAttribute
 *            debug source attribute, or <code>null</code> if none
 */
private IResource getSourceFile(IJavaProject project, String qualifiedName, String sourceAttribute) {
    String name = null;
    IJavaElement element = null;
    try {
        if (sourceAttribute == null) {
            element = findElement(qualifiedName, project);
        } else {
            int i = qualifiedName.lastIndexOf('/');
            if (i > 0) {
                name = qualifiedName.substring(0, i + 1);
                name = name + sourceAttribute;
            } else {
                name = sourceAttribute;
            }
            element = project.findElement(new Path(name));
        }
        if (element instanceof ICompilationUnit) {
            ICompilationUnit cu = (ICompilationUnit) element;
            return cu.getCorrespondingResource();
        }
    } catch (CoreException e) {
        logger.log(Level.INFO, "Failed to get source file with exception" + e.getMessage(), e);
    }
    return null;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:37,代码来源:JavaHotCodeReplaceProvider.java

示例10: findElement

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
/**
 * Returns the class file or compilation unit containing the given fully
 * qualified name in the specified project. All registered java like file
 * extensions are considered.
 *
 * @param qualifiedTypeName
 *            fully qualified type name
 * @param project
 *            project to search in
 * @return class file or compilation unit or <code>null</code>
 * @throws CoreException
 *             if an exception occurs
 */
public static IJavaElement findElement(String qualifiedTypeName, IJavaProject project) throws CoreException {
    String path = qualifiedTypeName;

    final String[] javaLikeExtensions = JavaCore.getJavaLikeExtensions();
    int pos = path.indexOf('$');
    if (pos != -1) {
        path = path.substring(0, pos);
    }
    path = path.replace('.', IPath.SEPARATOR);
    path += "."; //$NON-NLS-1$
    for (String ext : javaLikeExtensions) {
        IJavaElement element = project.findElement(new Path(path + ext));
        if (element != null) {
            return element;
        }
    }
    return null;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:32,代码来源:JavaHotCodeReplaceProvider.java

示例11: getCompilerOptions

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
/**
 * Returns the compiler options used for creating the refactoring AST.
 * <p>
 * Turns all errors, warnings and infos into ignore and disables task tags.
 * The customizable set of compiler options only contains additional Eclipse
 * options. The standard JDK compiler options can't be changed anyway.
 *
 * @param element
 *            an element (not the Java model)
 * @return compiler options
 */
public static Map<String, String> getCompilerOptions(IJavaElement element) {
	IJavaProject project = element.getJavaProject();
	Map<String, String> options = project.getOptions(true);
	for (Iterator<String> iter = options.keySet().iterator(); iter.hasNext();) {
		String key = iter.next();
		String value = options.get(key);
		if (JavaCore.ERROR.equals(value) || JavaCore.WARNING.equals(value) || JavaCore.INFO.equals(value)) {
			// System.out.println("Ignoring - " + key);
			options.put(key, JavaCore.IGNORE);
		}
	}
	options.put(JavaCore.COMPILER_PB_MAX_PER_UNIT, "0"); //$NON-NLS-1$
	options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
	return options;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:RefactoringASTParser.java

示例12: computeDefinitionNavigation

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) {
	try {
		IJavaElement element = JDTUtils.findElementAtSelection(unit, line, column, this.preferenceManager, monitor);
		if (element == null) {
			return null;
		}
		ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
		IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
		if (compilationUnit != null || (cf != null && cf.getSourceRange() != null)  ) {
			return JDTUtils.toLocation(element);
		}
		if (element instanceof IMember && ((IMember) element).getClassFile() != null) {
			return JDTUtils.toLocation(((IMember) element).getClassFile());
		}
	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.logException("Problem computing definition for" +  unit.getElementName(), e);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:NavigateToDefinitionHandler.java

示例13: internalGetContentReader

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
/**
 * Gets a reader for an package fragment's Javadoc comment content from the source attachment.
 * The content does contain only the text from the comment without the Javadoc leading star characters.
 * Returns <code>null</code> if the package fragment does not contain a Javadoc comment or if no source is available.
 * @param fragment The package fragment to get the Javadoc of.
 * @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
 * does not contain a Javadoc comment or if no source is available
 * @throws JavaModelException is thrown when the package fragment's javadoc can not be accessed
 * @since 3.4
 */
private static Reader internalGetContentReader(IPackageFragment fragment) throws JavaModelException {
	IPackageFragmentRoot root= (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);

	//1==> Handle the case when the documentation is present in package-info.java or package-info.class file
	boolean isBinary= root.getKind() == IPackageFragmentRoot.K_BINARY;
	ITypeRoot packageInfo;
	if (isBinary) {
		packageInfo= fragment.getClassFile(PACKAGE_INFO_CLASS);
	} else {
		packageInfo= fragment.getCompilationUnit(PACKAGE_INFO_JAVA);
	}
	if (packageInfo != null && packageInfo.exists()) {
		String source = packageInfo.getSource();
		//the source can be null for some of the class files
		if (source != null) {
			Javadoc javadocNode = getPackageJavadocNode(fragment, source);
			if (javadocNode != null) {
				int start = javadocNode.getStartPosition();
				int length = javadocNode.getLength();
				return new JavaDocCommentReader(source, start, start + length - 1);
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:JavadocContentAccess.java

示例14: run

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
@Override
	public void run() {
		ITypeBinding typeBinding = Crystal.getInstance().getTypeBindingFromName(fullyQualifiedName);
		if(typeBinding!=null){
			//get all types & names of fields & methods & class/interface
			IJavaElement javaElement = typeBinding.getJavaElement();
			if (javaElement != null && ASTUtils.isFromSource(typeBinding)) {
				try {
//					EditorUtility.openInEditor(javaElement, true);
					/*
					 * code above causes a bug that if several classes are in
					 * the same java file, always open the first one no matter
					 * which one the user chooses
					 */
					JavaUI.openInEditor(javaElement);
//					IEditorPart javaEditor = JavaUI.openInEditor(javaElement);
//					JavaUI.revealInEditor(javaEditor, javaElement);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		super.run();
	}
 
开发者ID:aroog,项目名称:code,代码行数:25,代码来源:OpenTypeAction.java

示例15: highlightInEditor

import org.eclipse.jdt.core.IJavaElement; //导入依赖的package包/类
public static void highlightInEditor(ASTNode enclosingDeclaration , ASTNode expressionNode){
	if(TraceToCodeUIAction.highlightCode){
		IJavaElement javaElement = getIJavaElement(enclosingDeclaration);
		if (javaElement != null) {
			try {

				EditorUtility.openInEditor(javaElement);
				IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
				if (part instanceof ITextEditor) {
					((ITextEditor) part).selectAndReveal(expressionNode.getStartPosition(), expressionNode.getLength());
				
				}
			} catch (PartInitException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:20,代码来源:TraceUtility.java


注:本文中的org.eclipse.jdt.core.IJavaElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。