本文整理汇总了Java中org.eclipse.jdt.core.ICompilationUnit.getJavaProject方法的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit.getJavaProject方法的具体用法?Java ICompilationUnit.getJavaProject怎么用?Java ICompilationUnit.getJavaProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.getJavaProject方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getImportStaticConstructsProposal
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private IJavaCompletionProposal[] getImportStaticConstructsProposal(
IInvocationContext context) {
final ICompilationUnit unit = context.getCompilationUnit();
final IJavaProject project = unit.getJavaProject();
final ImportRewrite rewrite = getImportRewrite(context.getASTRoot(),
"static apgas.Constructs.*");
final ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
proposals.add(new ConstructsImportProposal(project, rewrite));
final IJavaCompletionProposal[] propArr = new IJavaCompletionProposal[proposals
.size()];
for (int i = 0; i < proposals.size(); i++) {
propArr[i] = proposals.get(i);
}
return propArr;
}
示例2: getAddAPGASToBuildPathProposals
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private IJavaCompletionProposal[] getAddAPGASToBuildPathProposals(
IInvocationContext context) {
final ICompilationUnit unit = context.getCompilationUnit();
final IJavaProject project = unit.getJavaProject();
final String name = "static apgas.Constructs.*";
final ClasspathFixProposal[] fixProposals = ClasspathFixProcessor
.getContributedFixImportProposals(project, name, null);
final List<ImportRewrite> importRewrites = new ArrayList<ImportRewrite>();
importRewrites.add(getImportRewrite(context.getASTRoot(), name));
importRewrites.add(getImportRewrite(context.getASTRoot(), "apgas.*"));
final ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
for (final ClasspathFixProposal fixProposal : fixProposals) {
proposals.add(new APGASClasspathFixCorrelationProposal(project,
fixProposal, importRewrites));
}
final IJavaCompletionProposal[] propArr = new IJavaCompletionProposal[proposals
.size()];
for (int i = 0; i < proposals.size(); i++) {
propArr[i] = proposals.get(i);
}
return propArr;
}
示例3: getSetterComment
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static String getSetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String paramName, String bareFieldName, String lineDelimiter) throws CoreException {
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.SETTERCOMMENT;
Template template = templateSetting.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, typeName);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldType);
context.setVariable(CodeTemplateContextType.BARE_FIELD_NAME, bareFieldName);
context.setVariable(CodeTemplateContextType.PARAM, paramName);
return evaluateTemplate(context, template);
}
示例4: getGetterComment
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static String getGetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String bareFieldName, String lineDelimiter) throws CoreException {
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.GETTERCOMMENT;
Template template = templateSetting.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, typeName);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldType);
context.setVariable(CodeTemplateContextType.BARE_FIELD_NAME, bareFieldName);
return evaluateTemplate(context, template);
}
示例5: getSerialVersionProposals
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
* Determines the serial version quickfix proposals.
*
* @param context
* the invocation context
* @param location
* the problem location
* @param proposals
* the proposal collection to extend
*/
public static final void getSerialVersionProposals(final IInvocationContext context, final IProblemLocation location, final Collection<CUCorrectionProposal> proposals) {
Assert.isNotNull(context);
Assert.isNotNull(location);
Assert.isNotNull(proposals);
IProposableFix[] fixes = PotentialProgrammingProblemsFix.createMissingSerialVersionFixes(context.getASTRoot(), location);
if (fixes != null) {
proposals.add(new SerialVersionProposal(fixes[0], IProposalRelevance.MISSING_SERIAL_VERSION_DEFAULT, context, true));
ICompilationUnit unit = context.getCompilationUnit();
if (unit != null && unit.getJavaProject() != null && !ProjectsManager.DEFAULT_PROJECT_NAME.equals(unit.getJavaProject().getProject().getName())) {
proposals.add(new SerialVersionProposal(fixes[1], IProposalRelevance.MISSING_SERIAL_VERSION, context, false));
}
}
}
示例6: OverrideCompletionProposal
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public OverrideCompletionProposal(ICompilationUnit cu, String methodName, String[] paramTypes, String completionProposal) {
this.fCompilationUnit = cu;
Assert.isNotNull(cu.getJavaProject());
Assert.isNotNull(methodName);
Assert.isNotNull(paramTypes);
Assert.isNotNull(cu);
fParamTypes= paramTypes;
fMethodName= methodName;
fJavaProject= cu.getJavaProject();
}
示例7: AnonymousTypeCompletionProposal
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public AnonymousTypeCompletionProposal(ICompilationUnit cu, int replacementOffset, IType superType, String declarationSignature, boolean snippetSupport) {
Assert.isNotNull(cu.getJavaProject());
Assert.isNotNull(superType);
Assert.isNotNull(cu);
Assert.isNotNull(declarationSignature);
fCompilationUnit = cu;
fReplacementOffset = replacementOffset;
fJavaProject = cu.getJavaProject();
fDeclarationSignature = declarationSignature;
fSuperType = superType;
fSnippetSupport = snippetSupport;
}
示例8: getCatchBodyContent
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static String getCatchBodyContent(ICompilationUnit cu, String exceptionType, String variableName, String enclosingType, String enclosingMethod, String lineDelimiter) throws CoreException {
// Template template = getCodeTemplate(CodeTemplateContextType.CATCHBLOCK_ID, cu.getJavaProject());
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.CATCHBODY;
Template template = templateSetting.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, enclosingType);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, enclosingMethod);
context.setVariable(CodeTemplateContextType.EXCEPTION_TYPE, exceptionType);
context.setVariable(CodeTemplateContextType.EXCEPTION_VAR, variableName);
return evaluateTemplate(context, template);
}
示例9: getFieldComment
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static String getFieldComment(ICompilationUnit cu, String typeName, String fieldName, String lineDelimiter) throws CoreException {
Template template = CodeGenerationTemplate.FIELDCOMMENT.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, typeName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
return evaluateTemplate(context, template);
}
示例10: getScanner
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
protected IScanner getScanner(ICompilationUnit unit) {
IJavaProject project = unit.getJavaProject();
if (project.equals(fProjectCache)) {
return fScannerCache;
}
fProjectCache = project;
String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
fScannerCache = ToolFactory.createScanner(false, false, false, sourceLevel, complianceLevel);
return fScannerCache;
}
示例11: getWrongTypeNameProposals
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static void getWrongTypeNameProposals(IInvocationContext context, IProblemLocation problem,
Collection<CUCorrectionProposal> proposals) {
ICompilationUnit cu= context.getCompilationUnit();
IJavaProject javaProject= cu.getJavaProject();
String sourceLevel= javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
String compliance= javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
CompilationUnit root= context.getASTRoot();
ASTNode coveredNode= problem.getCoveredNode(root);
if (!(coveredNode instanceof SimpleName)) {
return;
}
ASTNode parentType= coveredNode.getParent();
if (!(parentType instanceof AbstractTypeDeclaration)) {
return;
}
String currTypeName= ((SimpleName) coveredNode).getIdentifier();
String newTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName());
List<AbstractTypeDeclaration> types= root.types();
for (int i= 0; i < types.size(); i++) {
AbstractTypeDeclaration curr= types.get(i);
if (parentType != curr) {
if (newTypeName.equals(curr.getName().getIdentifier())) {
return;
}
}
}
if (!JavaConventions.validateJavaTypeName(newTypeName, sourceLevel, compliance).matches(IStatus.ERROR)) {
proposals.add(new CorrectMainTypeNameProposal(cu, context, currTypeName, newTypeName, IProposalRelevance.RENAME_TYPE));
}
}
示例12: getUnusedAndUndocumentedParameterOrExceptionProposals
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static void getUnusedAndUndocumentedParameterOrExceptionProposals(IInvocationContext context,
IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
ICompilationUnit cu= context.getCompilationUnit();
IJavaProject project= cu.getJavaProject();
if (!JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true))) {
return;
}
int problemId= problem.getProblemId();
boolean isUnusedTypeParam= problemId == IProblem.UnusedTypeParameter;
boolean isUnusedParam= problemId == IProblem.ArgumentIsNeverUsed || isUnusedTypeParam;
String key= isUnusedParam ? JavaCore.COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE : JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE;
if (!JavaCore.ENABLED.equals(project.getOption(key, true))) {
return;
}
ASTNode node= problem.getCoveringNode(context.getASTRoot());
if (node == null) {
return;
}
BodyDeclaration bodyDecl= ASTResolving.findParentBodyDeclaration(node);
if (bodyDecl == null || ASTResolving.getParentMethodOrTypeBinding(bodyDecl) == null) {
return;
}
String label;
if (isUnusedTypeParam) {
label= CorrectionMessages.JavadocTagsSubProcessor_document_type_parameter_description;
} else if (isUnusedParam) {
label= CorrectionMessages.JavadocTagsSubProcessor_document_parameter_description;
} else {
node= ASTNodes.getNormalizedNode(node);
label= CorrectionMessages.JavadocTagsSubProcessor_document_exception_description;
}
ASTRewriteCorrectionProposal proposal= new AddMissingJavadocTagProposal(label, context.getCompilationUnit(), bodyDecl, node, IProposalRelevance.DOCUMENT_UNUSED_ITEM);
proposals.add(proposal);
}
示例13: isOnClassPath
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static boolean isOnClassPath(ICompilationUnit unit) {
if (unit != null && unit.getJavaProject() != null && !unit.getJavaProject().getProject().equals(JavaLanguageServerPlugin.getProjectsManager().getDefaultProject())) {
return unit.getJavaProject().isOnClasspath(unit);
}
return false;
}
示例14: checkPackageDeclaration
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private ICompilationUnit checkPackageDeclaration(String uri, ICompilationUnit unit) {
if (unit.getResource() != null && unit.getJavaProject() != null && unit.getJavaProject().getProject().getName().equals(ProjectsManager.DEFAULT_PROJECT_NAME)) {
try {
CompilationUnit astRoot = SharedASTProvider.getInstance().getAST(unit, new NullProgressMonitor());
IProblem[] problems = astRoot.getProblems();
for (IProblem problem : problems) {
if (problem.getID() == IProblem.PackageIsNotExpectedPackage) {
IResource file = unit.getResource();
boolean toRemove = file.isLinked();
if (toRemove) {
IPath path = file.getParent().getProjectRelativePath();
if (path.segmentCount() > 0 && JDTUtils.SRC.equals(path.segments()[0])) {
String packageNameResource = path.removeFirstSegments(1).toString().replace(JDTUtils.PATH_SEPARATOR, JDTUtils.PERIOD);
path = file.getLocation();
if (path != null && path.segmentCount() > 0) {
path = path.removeLastSegments(1);
String pathStr = path.toString().replace(JDTUtils.PATH_SEPARATOR, JDTUtils.PERIOD);
if (pathStr.endsWith(packageNameResource)) {
toRemove = false;
}
}
}
}
if (toRemove) {
file.delete(true, new NullProgressMonitor());
sharedASTProvider.invalidate(unit);
unit.discardWorkingCopy();
unit = JDTUtils.resolveCompilationUnit(uri);
unit.becomeWorkingCopy(new NullProgressMonitor());
triggerValidation(unit);
}
break;
}
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
return unit;
}