當前位置: 首頁>>代碼示例>>Java>>正文


Java ICompilationUnit.getJavaProject方法代碼示例

本文整理匯總了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;
}
 
開發者ID:x10-lang,項目名稱:apgas,代碼行數:17,代碼來源:APGASQuickfixProcessor.java

示例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;
}
 
開發者ID:x10-lang,項目名稱:apgas,代碼行數:26,代碼來源:APGASQuickfixProcessor.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:19,代碼來源:StubUtility.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:18,代碼來源:StubUtility.java

示例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));
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:26,代碼來源:SerialVersionSubProcessor.java

示例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();
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:12,代碼來源:OverrideCompletionProposal.java

示例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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:14,代碼來源:AnonymousTypeCompletionProposal.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:16,代碼來源:StubUtility.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:13,代碼來源:StubUtility.java

示例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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:13,代碼來源:RenameProcessor.java

示例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));
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:38,代碼來源:ReorgCorrectionsSubProcessor.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:41,代碼來源:JavadocTagsSubProcessor.java

示例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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:7,代碼來源:JDTUtils.java

示例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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:42,代碼來源:DocumentLifeCycleHandler.java


注:本文中的org.eclipse.jdt.core.ICompilationUnit.getJavaProject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。