本文整理汇总了Java中org.eclipse.jdt.core.util.IClassFileReader.getSourceFileAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java IClassFileReader.getSourceFileAttribute方法的具体用法?Java IClassFileReader.getSourceFileAttribute怎么用?Java IClassFileReader.getSourceFileAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.util.IClassFileReader
的用法示例。
在下文中一共展示了IClassFileReader.getSourceFileAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.eclipse.jdt.core.util.IClassFileReader; //导入方法依赖的package包/类
/**
* Answers whether children should be visited.
* <p>
* If the associated resource is a class file which has been changed, record it.
* </p>
*/
@Override
public boolean visit(IResourceDelta delta) {
if (delta == null || 0 == (delta.getKind() & IResourceDelta.CHANGED)) {
return false;
}
IResource resource = delta.getResource();
if (resource != null) {
switch (resource.getType()) {
case IResource.FILE:
if (0 == (delta.getFlags() & IResourceDelta.CONTENT)) {
return false;
}
if (CLASS_FILE_EXTENSION.equals(resource.getFullPath().getFileExtension())) {
IPath localLocation = resource.getLocation();
if (localLocation != null) {
String path = localLocation.toOSString();
IClassFileReader reader = ToolFactory.createDefaultClassFileReader(path,
IClassFileReader.CLASSFILE_ATTRIBUTES);
if (reader != null) {
// this name is slash-delimited
String qualifiedName = new String(reader.getClassName());
boolean hasBlockingErrors = false;
try {
// If the user doesn't want to replace
// classfiles containing
// compilation errors, get the source
// file associated with
// the class file and query it for
// compilation errors
IJavaProject pro = JavaCore.create(resource.getProject());
ISourceAttribute sourceAttribute = reader.getSourceFileAttribute();
String sourceName = null;
if (sourceAttribute != null) {
sourceName = new String(sourceAttribute.getSourceFileName());
}
IResource sourceFile = getSourceFile(pro, qualifiedName, sourceName);
if (sourceFile != null) {
IMarker[] problemMarkers = null;
problemMarkers = sourceFile.findMarkers(
IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
IResource.DEPTH_INFINITE);
for (IMarker problemMarker : problemMarkers) {
if (problemMarker.getAttribute(IMarker.SEVERITY,
-1) == IMarker.SEVERITY_ERROR) {
hasBlockingErrors = true;
break;
}
}
}
} catch (CoreException e) {
logger.log(Level.SEVERE, "Failed to visit classes: " + e.getMessage(), e);
}
if (!hasBlockingErrors) {
changedFiles.add(resource);
// dot-delimit the name
fullyQualifiedNames.add(qualifiedName.replace('/', '.'));
}
}
}
}
return false;
default:
return true;
}
}
return true;
}
示例2: buildJavaToClassMap
import org.eclipse.jdt.core.util.IClassFileReader; //导入方法依赖的package包/类
private Map<String, ArrayList<IResource>> buildJavaToClassMap(IContainer container, IProgressMonitor monitor) throws CoreException {
if (container == null || !container.isAccessible())
return new HashMap<String, ArrayList<IResource>>(0);
/*
* XXX: Bug 6584: Need a way to get class files for a java file (or CU)
*/
IClassFileReader cfReader= null;
IResource[] members= container.members();
Map<String, ArrayList<IResource>> map= new HashMap<String, ArrayList<IResource>>(members.length);
for (int i= 0; i < members.length; i++) {
if (isClassFile(members[i])) {
IFile classFile= (IFile)members[i];
URI location= classFile.getLocationURI();
if (location != null) {
InputStream contents= null;
try {
contents= EFS.getStore(location).openInputStream(EFS.NONE, monitor);
cfReader= ToolFactory.createDefaultClassFileReader(contents, IClassFileReader.CLASSFILE_ATTRIBUTES);
} finally {
try {
if (contents != null)
contents.close();
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR,
Messages.format(JarPackagerMessages.JarFileExportOperation_errorCannotCloseConnection, BasicElementLabels.getURLPart(Resources.getLocationString(classFile))),
e));
}
}
if (cfReader != null) {
ISourceAttribute sourceAttribute= cfReader.getSourceFileAttribute();
if (sourceAttribute == null) {
/*
* Can't fully build the map because one or more
* class file does not contain the name of its
* source file.
*/
addWarning(Messages.format(
JarPackagerMessages.JarFileExportOperation_classFileWithoutSourceFileAttribute,
BasicElementLabels.getURLPart(Resources.getLocationString(classFile))), null);
return null;
}
String javaName= new String(sourceAttribute.getSourceFileName());
ArrayList<IResource> classFiles= map.get(javaName);
if (classFiles == null) {
classFiles= new ArrayList<IResource>(3);
map.put(javaName, classFiles);
}
classFiles.add(classFile);
}
}
}
}
return map;
}