當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。