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


Java JavaModelUtil类代码示例

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


JavaModelUtil类属于org.eclipse.jdt.internal.corext.util包,在下文中一共展示了JavaModelUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getImportName

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
public static String getImportName(IBinding binding) {
	ITypeBinding declaring= null;
	switch (binding.getKind()) {
	case IBinding.TYPE:
		return getRawQualifiedName((ITypeBinding) binding);
	case IBinding.PACKAGE:
		return binding.getName() + ".*"; //$NON-NLS-1$
	case IBinding.METHOD:
		declaring= ((IMethodBinding) binding).getDeclaringClass();
		break;
	case IBinding.VARIABLE:
		declaring= ((IVariableBinding) binding).getDeclaringClass();
		if (declaring == null) {
			return binding.getName(); // array.length
		}

		break;
	default:
		return binding.getName();
	}
	return JavaModelUtil.concatenateName(getRawQualifiedName(declaring), binding.getName());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:Bindings.java

示例2: removePureTypeAnnotations

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
/**
 * Removes all {@link Annotation} whose only {@link Target} is {@link ElementType#TYPE_USE} from
 * <code>node</code>'s <code>childListProperty</code>.
 * <p>
 * In a combination of {@link ElementType#TYPE_USE} and {@link ElementType#TYPE_PARAMETER}
 * the latter is ignored, because this is implied by the former and creates no ambiguity.</p>
 *
 * @param node ASTNode
 * @param childListProperty child list property
 * @param rewrite rewrite that removes the nodes
 * @param editGroup the edit group in which to collect the corresponding text edits, or null if
 *            ungrouped
 */
public static void removePureTypeAnnotations(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) {
	CompilationUnit root= (CompilationUnit) node.getRoot();
	if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject())) {
		return;
	}
	ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty);
	@SuppressWarnings("unchecked")
	List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty);
	for (ASTNode child : children) {
		if (child instanceof Annotation) {
			Annotation annotation= (Annotation) child;
			if (isPureTypeAnnotation(annotation)) {
				listRewrite.remove(child, editGroup);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:31,代码来源:TypeAnnotationRewrite.java

示例3: addOverrideAnnotation

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
/**
 * Adds <code>@Override</code> annotation to <code>methodDecl</code> if not already present and
 * if requested by code style settings or compiler errors/warnings settings.
 *
 * @param settings the code generation style settings, may be <code>null</code>
 * @param project the Java project used to access the compiler settings
 * @param rewrite the ASTRewrite
 * @param imports the ImportRewrite
 * @param methodDecl the method declaration to add the annotation to
 * @param isDeclaringTypeInterface <code>true</code> if the type declaring the method overridden
 *            by <code>methodDecl</code> is an interface
 * @param group the text edit group, may be <code>null</code>
 */
public static void addOverrideAnnotation(CodeGenerationSettings settings, IJavaProject project, ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration methodDecl,
		boolean isDeclaringTypeInterface, TextEditGroup group) {
	if (!JavaModelUtil.is50OrHigher(project)) {
		return;
	}
	if (isDeclaringTypeInterface) {
		String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
		if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
		{
			return; // not allowed in 1.5
		}
		if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true)))
		{
			return; // user doesn't want to use 1.6 style
		}
	}
	if ((settings != null && settings.overrideAnnotation) || !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, true))) {
		createOverrideAnnotation(rewrite, imports, methodDecl, group);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:34,代码来源:StubUtility2.java

示例4: uniteWithSupertypes

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
private void uniteWithSupertypes(IType anchor, IType type) throws JavaModelException {
	IType[] supertypes = fHierarchy.getSupertypes(type);
	for (int i = 0; i < supertypes.length; i++) {
		IType supertype = supertypes[i];
		IType superRep = fUnionFind.find(supertype);
		if (superRep == null) {
			//Type doesn't declare method, but maybe supertypes?
			uniteWithSupertypes(anchor, supertype);
		} else {
			//check whether method in supertype is really overridden:
			IMember superMethod = fTypeToMethod.get(supertype);
			if (JavaModelUtil.isVisibleInHierarchy(superMethod, anchor.getPackageFragment())) {
				IType rep = fUnionFind.find(anchor);
				fUnionFind.union(rep, superRep);
				// current type is no root anymore
				fRootTypes.remove(anchor);
				uniteWithSupertypes(supertype, supertype);
			} else {
				//Not overridden -> overriding chain ends here.
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:RippleMethodFinder.java

示例5: getFieldTypeFiltered

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
public IType getFieldTypeFiltered(IField field) {
    String signature;
    try {
        signature = field.getTypeSignature();
        IType primaryType = field.getTypeRoot().findPrimaryType();
        String name = JavaModelUtil.getResolvedTypeName(signature, primaryType);

        if (name == null || isFiltered(name)) {
            return null;
        }
        return field.getJavaProject().findType(name);
    } catch (JavaModelException e) {
        DataHierarchyPlugin.logError("getUnfilteredFieldType() failed for field: " + field, e);
    }
    return null;
}
 
开发者ID:iloveeclipse,项目名称:datahierarchy,代码行数:17,代码来源:FieldReferencesRequestor.java

示例6: createNewMethodDeclarationNode

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
private MethodDeclaration createNewMethodDeclarationNode(MemberActionInfo info, TypeVariableMaplet[] mapping, CompilationUnitRewrite rewriter, MethodDeclaration oldMethod) throws JavaModelException {
	Assert.isTrue(!info.isFieldInfo());
	IMethod method= (IMethod) info.getMember();
	ASTRewrite rewrite= rewriter.getASTRewrite();
	AST ast= rewrite.getAST();
	MethodDeclaration newMethod= ast.newMethodDeclaration();
	copyBodyOfPushedDownMethod(rewrite, method, oldMethod, newMethod, mapping);
	newMethod.setConstructor(oldMethod.isConstructor());
	copyExtraDimensions(oldMethod, newMethod);
	if (info.copyJavadocToCopiesInSubclasses())
		copyJavadocNode(rewrite, oldMethod, newMethod);
	final IJavaProject project= rewriter.getCu().getJavaProject();
	if (info.isNewMethodToBeDeclaredAbstract() && JavaModelUtil.is50OrHigher(project) && JavaPreferencesSettings.getCodeGenerationSettings(project).overrideAnnotation) {
		final MarkerAnnotation annotation= ast.newMarkerAnnotation();
		annotation.setTypeName(ast.newSimpleName("Override")); //$NON-NLS-1$
		newMethod.modifiers().add(annotation);
	}
	copyAnnotations(oldMethod, newMethod);
	newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, info.getNewModifiersForCopyInSubclass(oldMethod.getModifiers())));
	newMethod.setName(ast.newSimpleName(oldMethod.getName().getIdentifier()));
	copyReturnType(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping);
	copyParameters(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping);
	copyThrownExceptions(oldMethod, newMethod);
	copyTypeParameters(oldMethod, newMethod);
	return newMethod;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:PushDownRefactoringProcessor.java

示例7: createCleanUp

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean convertForLoops, boolean convertIterableForLoops, boolean makeFinal) {
	if (!JavaModelUtil.is50OrHigher(compilationUnit.getJavaElement().getJavaProject()))
		return null;

	if (!convertForLoops && !convertIterableForLoops)
		return null;

	List<ConvertLoopOperation> operations= new ArrayList<ConvertLoopOperation>();
	ControlStatementFinder finder= new ControlStatementFinder(convertForLoops, convertIterableForLoops, makeFinal, operations);
	compilationUnit.accept(finder);

	if (operations.isEmpty())
		return null;

	CompilationUnitRewriteOperation[] ops= operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
	return new ConvertLoopFix(FixMessages.ControlStatementsFix_change_name, compilationUnit, ops, null);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:ConvertLoopFix.java

示例8: hasFocusMethod

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
protected boolean hasFocusMethod(IType type) {
	if (fFocus == null) {
		return true;
	}
	if (type.equals(fFocus.getDeclaringType())) {
		return true;
	}

	try {
		IMethod method= findMethod(fFocus, type);
		if (method != null) {
			// check visibility
			IPackageFragment pack= (IPackageFragment) fFocus.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
			if (JavaModelUtil.isVisibleInHierarchy(method, pack)) {
				return true;
			}
		}
	} catch (JavaModelException e) {
		// ignore
		JavaPlugin.log(e);
	}
	return false;

}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:25,代码来源:HierarchyInformationControl.java

示例9: createExtractedSuperType

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
/**
 * Creates the new extracted supertype.
 *
 * @param superType
 *            the super type, or <code>null</code> if no super type (ie.
 *            <code>java.lang.Object</code>) is available
 * @param monitor
 *            the progress monitor
 * @return a status describing the outcome of the operation
 * @throws CoreException
 *             if an error occurs
 */
protected final RefactoringStatus createExtractedSuperType(final IType superType, final IProgressMonitor monitor) throws CoreException {
	Assert.isNotNull(monitor);
	fSuperSource= null;
	final RefactoringStatus status= new RefactoringStatus();
	try {
		monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing, 20);
		final IType declaring= getDeclaringType();
		final CompilationUnitRewrite declaringRewrite= new CompilationUnitRewrite(fOwner, declaring.getCompilationUnit());
		final AbstractTypeDeclaration declaringDeclaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(declaring, declaringRewrite.getRoot());
		if (declaringDeclaration != null) {
			final String name= JavaModelUtil.getRenamedCUName(declaring.getCompilationUnit(), fTypeName);
			final ICompilationUnit original= declaring.getPackageFragment().getCompilationUnit(name);
			final ICompilationUnit copy= getSharedWorkingCopy(original.getPrimary(), new SubProgressMonitor(monitor, 10));
			fSuperSource= createSuperTypeSource(copy, superType, declaringDeclaration, status, new SubProgressMonitor(monitor, 10));
			if (fSuperSource != null) {
				copy.getBuffer().setContents(fSuperSource);
				JavaModelUtil.reconcile(copy);
			}
		}
	} finally {
		monitor.done();
	}
	return status;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:37,代码来源:ExtractSupertypeProcessor.java

示例10: findElement

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
/**
 * Returns the updated java element for the old java element.
 *
 * @param element Old Java element
 * @return Updated Java element
 */
private IJavaElement findElement(IJavaElement element) {

	if (element == null)
		return null;

	IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager();
	ICompilationUnit unit= manager.getWorkingCopy(getEditorInput());

	if (unit != null) {
		try {
			JavaModelUtil.reconcile(unit);
			IJavaElement[] findings= unit.findElements(element);
			if (findings != null && findings.length > 0)
				return findings[0];

		} catch (JavaModelException x) {
			JavaPlugin.log(x.getStatus());
			// nothing found, be tolerant and go on
		}
	}

	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:CompilationUnitEditor.java

示例11: findTypeInfos

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
private static List<TypeNameMatch> findTypeInfos(String typeName, IType contextType, IProgressMonitor pm) throws JavaModelException {
	IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaProject[]{contextType.getJavaProject()}, true);
	IPackageFragment currPackage= contextType.getPackageFragment();
	ArrayList<TypeNameMatch> collectedInfos= new ArrayList<TypeNameMatch>();
	TypeNameMatchCollector requestor= new TypeNameMatchCollector(collectedInfos);
	int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
	new SearchEngine().searchAllTypeNames(null, matchMode, typeName.toCharArray(), matchMode, IJavaSearchConstants.TYPE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, pm);

	List<TypeNameMatch> result= new ArrayList<TypeNameMatch>();
	for (Iterator<TypeNameMatch> iter= collectedInfos.iterator(); iter.hasNext();) {
		TypeNameMatch curr= iter.next();
		IType type= curr.getType();
		if (type != null) {
			boolean visible=true;
			try {
				visible= JavaModelUtil.isVisible(type, currPackage);
			} catch (JavaModelException e) {
				//Assume visibile if not available
			}
			if (visible) {
				result.add(curr);
			}
		}
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:27,代码来源:TypeContextChecker.java

示例12: handleContainerEntry

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (initializer == null || container == null) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
		return null;
	}
	String containerName= container.getDescription();
	IStatus status= initializer.getAttributeStatus(containerPath, jproject, JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_not_supported, containerName));
		return null;
	}
	IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_read_only, containerName));
		fIsReadOnly= true;
		return entry;
	}
	Assert.isNotNull(entry);
	return entry;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:NativeLibrariesPropertyPage.java

示例13: canModifyAccessRules

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
private static boolean canModifyAccessRules(IBinding binding) {
	IJavaElement element= binding.getJavaElement();
	if (element == null)
		return false;

	IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element);
	if (root == null)
		return false;

	try {
		IClasspathEntry classpathEntry= root.getRawClasspathEntry();
		if (classpathEntry == null)
			return false;
		if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
			return true;
		if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
			ClasspathContainerInitializer classpathContainerInitializer= JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0));
			IStatus status= classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject());
			return status.isOK();
		}
	} catch (JavaModelException e) {
		return false;
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:26,代码来源:ReorgCorrectionsSubProcessor.java

示例14: addExclusionPatterns

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
private void addExclusionPatterns(IClasspathEntry newEntry, List<IClasspathEntry> existing, Set<IClasspathEntry> modifiedEntries) {
	IPath entryPath= newEntry.getPath();
	for (int i= 0; i < existing.size(); i++) {
		IClasspathEntry curr= existing.get(i);
		IPath currPath= curr.getPath();
		if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE && currPath.isPrefixOf(entryPath)) {
			IPath[] exclusionFilters= curr.getExclusionPatterns();
			if (!JavaModelUtil.isExcludedPath(entryPath, exclusionFilters)) {
				IPath pathToExclude= entryPath.removeFirstSegments(currPath.segmentCount()).addTrailingSeparator();
				IPath[] newExclusionFilters= new IPath[exclusionFilters.length + 1];
				System.arraycopy(exclusionFilters, 0, newExclusionFilters, 0, exclusionFilters.length);
				newExclusionFilters[exclusionFilters.length]= pathToExclude;

				IClasspathEntry updated= JavaCore.newSourceEntry(currPath, newExclusionFilters, curr.getOutputLocation());
				existing.set(i, updated);
				modifiedEntries.add(updated);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:NewSourceFolderWizardPage.java

示例15: createNewMethodDeclarationNode

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入依赖的package包/类
private MethodDeclaration createNewMethodDeclarationNode(MemberActionInfo info, TypeVariableMaplet[] mapping, CompilationUnitRewrite rewriter, MethodDeclaration oldMethod) throws JavaModelException {
	Assert.isTrue(!info.isFieldInfo());
	IMethod method= (IMethod) info.getMember();
	ASTRewrite rewrite= rewriter.getASTRewrite();
	AST ast= rewrite.getAST();
	MethodDeclaration newMethod= ast.newMethodDeclaration();
	copyBodyOfPushedDownMethod(rewrite, method, oldMethod, newMethod, mapping);
	newMethod.setConstructor(oldMethod.isConstructor());
	newMethod.setExtraDimensions(oldMethod.getExtraDimensions());
	if (info.copyJavadocToCopiesInSubclasses())
		copyJavadocNode(rewrite, oldMethod, newMethod);
	final IJavaProject project= rewriter.getCu().getJavaProject();
	if (info.isNewMethodToBeDeclaredAbstract() && JavaModelUtil.is50OrHigher(project) && JavaPreferencesSettings.getCodeGenerationSettings(project).overrideAnnotation) {
		final MarkerAnnotation annotation= ast.newMarkerAnnotation();
		annotation.setTypeName(ast.newSimpleName("Override")); //$NON-NLS-1$
		newMethod.modifiers().add(annotation);
	}
	copyAnnotations(oldMethod, newMethod);
	newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, info.getNewModifiersForCopyInSubclass(oldMethod.getModifiers())));
	newMethod.setName(ast.newSimpleName(oldMethod.getName().getIdentifier()));
	copyReturnType(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping);
	copyParameters(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping);
	copyThrownExceptions(oldMethod, newMethod);
	copyTypeParameters(oldMethod, newMethod);
	return newMethod;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:27,代码来源:PushDownRefactoringProcessor.java


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