本文整理汇总了Java中org.eclipse.jdt.core.IType.getCompilationUnit方法的典型用法代码示例。如果您正苦于以下问题:Java IType.getCompilationUnit方法的具体用法?Java IType.getCompilationUnit怎么用?Java IType.getCompilationUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IType
的用法示例。
在下文中一共展示了IType.getCompilationUnit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findPathInGeneratedAnnotation
import org.eclipse.jdt.core.IType; //导入方法依赖的package包/类
/**
* @param project
* @param itype
* @return
* @throws JavaModelException
*/
private static IPath findPathInGeneratedAnnotation(IProject project, IType itype) throws JavaModelException {
ICompilationUnit cu = itype.getCompilationUnit();
List<IAnnotationBinding> annotations = resolveAnnotation(cu, Generated.class).getAnnotations();
if ((annotations != null) && (annotations.size() > 0)) {
IAnnotationBinding ab = annotations.get(0);
IMemberValuePairBinding[] attributes = ab.getAllMemberValuePairs();
for (int i = 0; i < attributes.length; i++) {
IMemberValuePairBinding attribut = attributes[i];
if (attribut.getName().equalsIgnoreCase("value")) {
Object[] o = (Object[]) attribut.getValue();
if (o != null && o.length > 0 && String.valueOf(o[0]).trim().length() > 0) {
try {
IPath p = ResourceManager.find(project, String.valueOf(o[0]).trim());
return p;
} catch (Exception e) {
ResourceManager.logException(e);
return null;
}
}
}
}
}
return null;
}
示例2: findPathInModelAnnotation
import org.eclipse.jdt.core.IType; //导入方法依赖的package包/类
/**
* @param project
* @param itype
* @return
* @throws JavaModelException
*/
public static IPath findPathInModelAnnotation(IProject project, IType itype) throws JavaModelException {
ICompilationUnit cu = itype.getCompilationUnit();
List<IAnnotationBinding> annotations = resolveAnnotation(cu, Model.class).getAnnotations();
if ((annotations != null) && (annotations.size() > 0)) {
IAnnotationBinding ab = annotations.get(0);
IMemberValuePairBinding[] attributes = ab.getAllMemberValuePairs();
for (int i = 0; i < attributes.length; i++) {
IMemberValuePairBinding attribut = attributes[i];
if (attribut.getName().equalsIgnoreCase("value")) {
Object[] o = (Object[]) attribut.getValue();
if (o != null && o.length > 0 && String.valueOf(o[0]).trim().length() > 0) {
try {
IPath p = ResourceManager.find(project, String.valueOf(o[0]).trim());
return p;
} catch (Exception e) {
ResourceManager.logException(e);
return null;
}
}
}
}
}
return null;
}
示例3: findPathInStaticField
import org.eclipse.jdt.core.IType; //导入方法依赖的package包/类
/**
* @param project
* @param itype
* @return
* @throws JavaModelException
*/
private static IPath findPathInStaticField(IProject project, IType itype) throws JavaModelException {
List<IPath> wrapper = new ArrayList<IPath>();
ICompilationUnit cu = itype.getCompilationUnit();
CompilationUnit ast = parse(cu);
ast.accept(new ASTVisitor() {
public boolean visit(VariableDeclarationFragment node) {
SimpleName simpleName = node.getName();
IBinding bding = simpleName.resolveBinding();
if (bding instanceof IVariableBinding) {
IVariableBinding binding = (IVariableBinding) bding;
String type = binding.getType().getBinaryName(); //
String name = simpleName.getFullyQualifiedName();
if ("MODEL_PATH".equals(name) && "java.nio.file.Path".equals(type)) {
Expression expression = node.getInitializer();
if (expression instanceof MethodInvocation) {
MethodInvocation mi = (MethodInvocation) expression;
if ("get".equals(mi.resolveMethodBinding().getName())
&& "java.nio.file.Path".equals(mi.resolveTypeBinding().getBinaryName())) {
StringLiteral sl = (StringLiteral) mi.arguments().get(0);
String argument = sl.getLiteralValue();
try {
IPath p = ResourceManager.find(project, argument);
wrapper.add(p);
} catch (CoreException e) {
ResourceManager.logException(e);
}
}
}
}
}
return true;
}
});
if (wrapper.size() > 0)
return wrapper.get(0);
return null;
}
示例4: findGeneratorFactoryParseInvocation
import org.eclipse.jdt.core.IType; //导入方法依赖的package包/类
public static Set<String> findGeneratorFactoryParseInvocation(IProject project, IType itype)
throws JavaModelException {
Set<String> ret = new HashSet<String>();
ICompilationUnit cu = itype.getCompilationUnit();
CompilationUnit ast = parse(cu);
ast.accept(new ASTVisitor() {
public boolean visit(MethodInvocation node) {
SimpleName simpleName = node.getName();
IBinding bding = simpleName.resolveBinding();
if (bding instanceof IMethodBinding) {
IMethodBinding imb = (IMethodBinding) bding;
if ("parse".equalsIgnoreCase(imb.getName())) {
ITypeBinding[] arguments = imb.getParameterTypes();
if (arguments.length == 1) {
if (String.class.getName().equals(arguments[0].getQualifiedName())
&& PathGenerator.class.getName().equals(imb.getReturnType().getQualifiedName())) {
int start = node.getStartPosition();
int end = node.getLength();
try {
String code = cu.getSource().substring(start, start + end);
// System.out.println(code);
} catch (JavaModelException e) {
ResourceManager.logException(e);
}
List args = node.arguments();
Expression argumentExpression = (Expression) args.get(0);
ITypeBinding typeBinding = argumentExpression.resolveTypeBinding();
if (typeBinding != null) {
if (argumentExpression instanceof StringLiteral) {
StringLiteral sl = (StringLiteral) argumentExpression;
String lv = sl.getLiteralValue();
ret.add(lv);
}
}
}
}
}
}
return true;
}
});
return ret;
}