本文整理汇总了Java中org.netbeans.api.java.source.CompilationInfo类的典型用法代码示例。如果您正苦于以下问题:Java CompilationInfo类的具体用法?Java CompilationInfo怎么用?Java CompilationInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationInfo类属于org.netbeans.api.java.source包,在下文中一共展示了CompilationInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: FixImport
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
public FixImport(FileObject file, String fqn, ElementHandle<Element> toImport, String sortText, boolean isValid, CompilationInfo info, @NullAllowed TreePath replacePath, @NullAllowed String replaceSuffix,
boolean doOrganize) {
super(file, fqn, toImport, sortText, isValid);
if (replacePath != null) {
this.replacePathHandle = TreePathHandle.create(replacePath, info);
this.suffix = replaceSuffix;
while (replacePath != null && replacePath.getLeaf().getKind() != Kind.IMPORT) {
replacePath = replacePath.getParentPath();
}
this.statik = replacePath != null ? ((ImportTree) replacePath.getLeaf()).isStatic() : false;
} else {
this.replacePathHandle = null;
this.suffix = null;
this.statik = false;
}
this.doOrganize = doOrganize;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ImportClass.java
示例2: IdxProperty
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
/** Creates new IndexedProperty just one of the methods indexedGetterMethod
* and indexedSetterMethod may be null.
* @param patternAnalyser patternAnalyser which creates this Property.
* @param getterMethod getterMethod may be <CODE>null</CODE>.
* @param setterMethod setterMethod may be <CODE>null</CODE>.
* @param indexedGetterMethod getterMethod of the property or <CODE>null</CODE>.
* @param indexedSetterMethod setterMethod of the property or <CODE>null</CODE>.
* @throws IntrospectionException If specified methods do not follow beans Property rules.
*/
public IdxProperty( CompilationInfo ci,
ExecutableElement getterMethod, ExecutableElement setterMethod,
ExecutableElement indexedGetterMethod, ExecutableElement indexedSetterMethod )
throws IntrospectionException {
super ( ci, getterMethod, setterMethod );
this.indexedGetterMethod = indexedGetterMethod;
this.indexedSetterMethod = indexedSetterMethod;
indexedType = findIndexedPropertyType(ci);
if (this.type == null && this.indexedType != null) {
this.type = ci.getTypes().getArrayType(this.indexedType);
}
name = findIndexedPropertyName();
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:TmpPattern.java
示例3: AddParameterOrLocalFix
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
public AddParameterOrLocalFix(CompilationInfo info,
TypeMirror type, String name,
ElementKind kind,
int /*!!!Position*/ unresolvedVariable) {
this.file = info.getFileObject();
if (type.getKind() == TypeKind.NULL || type.getKind() == TypeKind.NONE) {
TypeElement te = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
if (te != null) {
type = te.asType();
this.type = TypeMirrorHandle.create(type);
} else {
this.type = null;
}
} else {
this.type = TypeMirrorHandle.create(type);
}
this.name = name;
this.kind = kind;
TreePath treePath = info.getTreeUtilities().pathFor(unresolvedVariable + 1);
tpHandle = new TreePathHandle[1];
tpHandle[0] = TreePathHandle.create(treePath, info);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:AddParameterOrLocalFix.java
示例4: computeUnary
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private static List<? extends TypeMirror> computeUnary(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
UnaryTree tree = (UnaryTree) parent.getLeaf();
if (tree.getExpression() == error) {
List<? extends TypeMirror> parentTypes = resolveType(types, info, parent.getParentPath(), tree, offset, null, null);
if (parentTypes != null) {
//may contain only "void", ignore:
if (parentTypes.size() != 1) {
return parentTypes;
}
if (parentTypes.get(0).getKind() != TypeKind.VOID) {
return parentTypes;
}
}
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.INT));
}
return null;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CreateElementUtilities.java
示例5: getCandidateFQNs
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
public ComputeImports getCandidateFQNs(CompilationInfo info, FileObject file, String simpleName, Data<Void> data) {
//compute imports:
ComputeImports imp = new ComputeImports(info);
setComputeImports(imp);
ComputeImports.Pair<Map<String, List<Element>>, Map<String, List<Element>>> rawCandidates;
try {
imp = imp.computeCandidatesEx();
} finally {
setComputeImports(null);
}
if (isCancelled()) {
ErrorHintsProvider.LOG.log(Level.FINE, "ImportClassEnabler.getCandidateFQNs cancelled, returning."); //NOI18N
return null;
}
return imp;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ImportClass.java
示例6: ignoreWhitespaces
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
static int[] ignoreWhitespaces(CompilationInfo ci, int start, int end) {
TokenSequence<JavaTokenId> ts = ci.getTokenHierarchy().tokenSequence(JavaTokenId.language());
if (ts == null) {
return new int[]{start, end};
}
ts.move(start);
if (ts.moveNext()) {
boolean wasMoveNext = true;
while (WHITESPACES.contains(ts.token().id()) && (wasMoveNext = ts.moveNext())) {
;
}
if (wasMoveNext && ts.offset() > start) {
start = ts.offset();
}
}
ts.move(end);
while (ts.movePrevious() && WHITESPACES.contains(ts.token().id()) && ts.offset() < end) {
end = ts.offset();
}
return new int[]{start, end};
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TreeUtils.java
示例7: createConstant
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
/**
* Creates an 'introduce constant' fix.
*
* Note: the fix will not reference CompilationInfo and will remember only handles to TreePaths.
*
* @param resolved the path for expression or variable declaration to convert
* @param info compilation context
* @param value the actual expression or a variable initializer.
* @param guessedName proposed name
* @param numDuplicates number of other duplicates
* @param offset offset for the hint
* @param variableRewrite if variable name should be changed (?)
* @param cancel cancel flag
* @return
*/
static IntroduceFieldFix createConstant(TreePath resolved, CompilationInfo info, TreePath value, String guessedName, int numDuplicates, int offset, boolean variableRewrite, AtomicBoolean cancel) {
CodeStyle cs = CodeStyle.getDefault(info.getFileObject());
boolean isConstant = checkConstantExpression(info, value);
TreePath constantTarget = isConstant ? findAcceptableConstantTarget(info, resolved) : null;
if (!isConstant || constantTarget == null || cancel.get()) {
return null;
}
TreePathHandle h = TreePathHandle.create(resolved, info);
String varName;
if (variableRewrite) {
varName = guessedName;
} else {
String proposed = Utilities.toConstantName(guessedName);
varName = Utilities.makeNameUnique(info, info.getTrees().getScope(constantTarget), proposed, cs.getStaticFieldNamePrefix(), cs.getStaticFieldNameSuffix());
}
ClassTree clazz = (ClassTree)constantTarget.getLeaf();
Element el = info.getTrees().getElement(constantTarget);
if (el == null || !(el.getKind().isClass() || el.getKind().isInterface())) {
return null;
}
IntroduceConstantFix fix = new IntroduceConstantFix(h, info.getJavaSource(), varName, numDuplicates, offset, TreePathHandle.create(constantTarget, info));
fix.setTargetIsInterface(clazz.getKind() == Tree.Kind.INTERFACE);
return fix;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:IntroduceConstantFix.java
示例8: isPolymorphicSignature
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private static boolean isPolymorphicSignature(CompilationInfo info, TreePath path) {
TypeElement polymorphicEl= info.getElements().getTypeElement("java.lang.invoke.MethodHandle.PolymorphicSignature"); // NOI18N
if (polymorphicEl == null) {
// unsuitable platform
return false;
}
TypeMirror polyType = polymorphicEl.asType();
Element target = info.getTrees().getElement(path);
if (target == null || target.getKind() != ElementKind.METHOD) {
return false;
}
if (target.getEnclosingElement() == null || !target.getEnclosingElement().getKind().isClass()) {
return false;
}
ExecutableElement ee = (ExecutableElement)target;
TypeElement parent = (TypeElement)target.getEnclosingElement();
if (!parent.getQualifiedName().toString().startsWith("java.lang.invoke.")) { // NOI18N
return false;
}
for (AnnotationMirror am : ee.getAnnotationMirrors()) {
if (info.getTypes().isSameType(polyType, am.getAnnotationType())) {
return true;
}
}
return false;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:TooStrongCast.java
示例9: handleAssignment
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private List<ErrorDescription> handleAssignment(CompilationInfo info, TreePath treePath) {
AssignmentTree at = (AssignmentTree) treePath.getLeaf();
String declarationName = getName(at.getVariable());
String actualName = getName(at.getExpression());
if (isConflicting(info, declarationName, actualName)) {
long start = info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), at.getVariable());
long end = info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), at.getVariable());
if (start != (-1) && end != (-1)) {
return Collections.singletonList(ErrorDescriptionFactory.createErrorDescription(getSeverity().toEditorSeverity(), "Suspicious names combination", info.getFileObject(), (int) start, (int) end));
}
}
return null;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:SuspiciousNamesCombination.java
示例10: findIdentifierSpanImpl
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private static Token<JavaTokenId> findIdentifierSpanImpl(CompilationInfo info, IdentifierTree tree, CompilationUnitTree cu, SourcePositions positions) {
int start = (int)positions.getStartPosition(cu, tree);
int endPosition = (int)positions.getEndPosition(cu, tree);
if (start == (-1) || endPosition == (-1))
return null;
TokenHierarchy<?> th = info.getTokenHierarchy();
TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());
if (ts.move(start) == Integer.MAX_VALUE) {
return null;
}
if (ts.moveNext()) {
if (ts.offset() >= start) {
Token<JavaTokenId> t = ts.token();
return t;
}
}
return null;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Utilities.java
示例11: doFilter
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private boolean doFilter(CompilationInfo info, Map<String, List<Element>> candidates) {
List<Element> cands = candidates.get(simpleName);
if (cands == null || cands.isEmpty())
return false;
List<TypeElement> toRemove = new ArrayList<TypeElement>();
for (TypeElement te : ElementFilter.typesIn(cands)) {
if (!acceptedKinds.isEmpty() && !acceptedKinds.contains(te.getKind())) {
toRemove.add(te);
continue;
}
if (!notAcceptedKinds.isEmpty() && notAcceptedKinds.contains(te.getKind())) {
toRemove.add(te);
continue;
}
}
return cands.removeAll(toRemove);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ComputeImports.java
示例12: findExactStatement
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private StatementTree findExactStatement(CompilationInfo info, BlockTree block, int offset, boolean start) {
if (offset == (-1)) return null;
SourcePositions sp = info.getTrees().getSourcePositions();
CompilationUnitTree cut = info.getCompilationUnit();
for (StatementTree t : block.getStatements()) {
long pos = start ? sp.getStartPosition(info.getCompilationUnit(), t) : sp.getEndPosition( cut, t);
if (offset == pos) {
return t;
}
}
return null;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:AssignResultToVariable.java
示例13: createHtmlHeader
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private String createHtmlHeader(CompilationInfo info, VariableElement e, boolean isDeprecated,boolean isInherited, boolean fqn) {
StringBuilder sb = new StringBuilder();
if ( isDeprecated ) {
sb.append("<s>"); // NOI18N
}
if( isInherited ) {
sb.append( "<font color=" + ui.getInheritedColor() + ">" ); // NOI18N
}
sb.append(Utils.escape(e.getSimpleName().toString()));
if ( isDeprecated ) {
sb.append("</s>"); // NOI18N
}
if ( e.getKind() != ElementKind.ENUM_CONSTANT ) {
sb.append( " : " ); // NOI18N
sb.append( "<font color=" + ui.getTypeColor() + ">" ); // NOI18N
sb.append(print(info, e.asType(), fqn));
sb.append("</font>"); // NOI18N
}
return sb.toString();
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ElementScanningTask.java
示例14: isClassException
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
public static boolean isClassException(CompilationInfo compilationInfo,
TypeElement classElem) {
String throwableFullName = "java.lang.Throwable"; //NOI18N
TypeElement throwable = compilationInfo.getElements()
.getTypeElement(throwableFullName);
if (throwable == null) {
String msg = "junit: TestUtil.isClassException(...) " //NOI18N
+ "could not find TypeElement for " //NOI18N
+ throwableFullName;
Logger.getLogger("global").log(Level.SEVERE, msg); //NOI18N
return false;
}
return compilationInfo.getTypes().isSubtype(classElem.asType(),
throwable.asType());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JUnitTestUtil.java
示例15: CreateEnumConstant
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
public CreateEnumConstant(CompilationInfo info, String name, Set<Modifier> modifiers, TypeElement target, TypeMirror proposedType, FileObject targetFile) {
this.name = name;
this.inFQN = target.getQualifiedName().toString();
this.cpInfo = info.getClasspathInfo();
this.targetFile = targetFile;
this.target = ElementHandle.create(target);
if (proposedType.getKind() == TypeKind.NULL) {
TypeElement tel = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
if (tel != null) {
proposedType = tel.asType();
this.proposedType = TypeMirrorHandle.create(proposedType);
} else {
this.proposedType = null;
}
} else {
this.proposedType = TypeMirrorHandle.create(proposedType);
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CreateEnumConstant.java
示例16: isInSerializableOrExternalizable
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
/**
* Also returns true on error / undecidable situation, so the filtering
* will probably accept serial methods and will not mark them as unused, if
* the class declaration is errneous.
*
* @param info the compilation context
* @param e the class member (the enclosing element will be tested)
* @return true, if in serializable/externalizable or unknown
*/
private static boolean isInSerializableOrExternalizable(CompilationInfo info, Element e) {
Element encl = e.getEnclosingElement();
if (encl == null || !encl.getKind().isClass()) {
return true;
}
TypeMirror m = encl.asType();
if (m == null || m.getKind() != TypeKind.DECLARED) {
return true;
}
Element serEl = info.getElements().getTypeElement("java.io.Serializable"); // NOI18N
Element extEl = info.getElements().getTypeElement("java.io.Externalizable"); // NOI18N
if (serEl == null || extEl == null) {
return true;
}
if (info.getTypes().isSubtype(m, serEl.asType())) {
return true;
}
if (info.getTypes().isSubtype(m, extEl.asType())) {
return true;
}
return false;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:SemanticHighlighterBase.java
示例17: addPackageContent
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private void addPackageContent(PackageElement pe, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
CompilationInfo controller = jdctx.javac;
Element srcEl = jdctx.handle.resolve(controller);
Elements elements = controller.getElements();
Types types = controller.getTypes();
Trees trees = controller.getTrees();
TreeUtilities tu = controller.getTreeUtilities();
ElementUtilities eu = controller.getElementUtilities();
TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
for(Element e : pe.getEnclosedElements()) {
if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
String name = e.getSimpleName().toString();
if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
&& trees.isAccessible(scope, (TypeElement)e)
&& isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)
&& !Utilities.isExcluded(eu.getElementName(e, true))) {
items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
}
}
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:JavadocCompletionQuery.java
示例18: resolveHandles
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
/**
*/
private <T extends Element> List<T> resolveHandles(
CompilationInfo compInfo,
List<ElementHandle<T>> handles) {
if (handles == null) {
return null;
}
if (handles.isEmpty()) {
return Collections.<T>emptyList();
}
List<T> elements = new ArrayList<T>(handles.size());
for (ElementHandle<T> handle : handles) {
T element = handle.resolve(compInfo);
if (element != null) {
elements.add(element);
} else {
ErrorManager.getDefault().log(
ErrorManager.WARNING,
"JUnit: Could not resolve element handle " //NOI18N
+ handle.getBinaryName());
}
}
return elements;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AbstractTestGenerator.java
示例19: InnerToOuterRefactoringUI
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
/** Creates a new instance of InnerToOuterRefactoringUI
* @param selectedElements Elements the refactoring action was invoked on.
*/
private InnerToOuterRefactoringUI(TreePathHandle sourceType, CompilationInfo info) {
refactoring = new InnerToOuterRefactoring(sourceType);
refactoring.setReferenceName("outer"); //NOI18N
Element temp = sourceType.resolveElement(info);
className = temp.getSimpleName().toString();
disableDeclareFields = temp.getModifiers().contains(Modifier.STATIC) || temp.getKind() !=ElementKind.CLASS;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:InnerToOuterRefactoringUI.java
示例20: prepareCreateMethodFix
import org.netbeans.api.java.source.CompilationInfo; //导入依赖的package包/类
private static List<Fix> prepareCreateMethodFix(CompilationInfo info, TreePath invocation, Set<Modifier> modifiers, TypeElement target, String simpleName, List<? extends ExpressionTree> arguments, List<? extends TypeMirror> returnTypes) {
//return type:
//XXX: should reasonably consider all the found type candidates, not only the one:
TypeMirror returnType = returnTypes != null ? Utilities.resolveTypeForDeclaration(info, returnTypes.get(0)) : null;
//currently, we cannot handle error types, TYPEVARs and WILDCARDs:
if (returnType != null && Utilities.containsErrorsRecursively(returnType)) {
return Collections.<Fix>emptyList();
}
//create method:
MethodArguments formalArguments = Utilities.resolveArguments(info, invocation, arguments, target, returnType);
//currently, we cannot handle error types, TYPEVARs and WILDCARDs:
if (formalArguments == null) {
return Collections.<Fix>emptyList();
}
//IZ 111048 -- don't offer anything if target file isn't writable
if(!Utilities.isTargetWritable(target, info))
return Collections.<Fix>emptyList();
FileObject targetFile = SourceUtils.getFile(ElementHandle.create(target), info.getClasspathInfo());
if (targetFile == null)
return Collections.<Fix>emptyList();
return Collections.<Fix>singletonList(new CreateMethodFix(info, simpleName, modifiers, target, returnType, formalArguments.parameterTypes, formalArguments.parameterNames, formalArguments.typeParameterTypes, formalArguments.typeParameterNames, targetFile));
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:CreateElement.java
注:本文中的org.netbeans.api.java.source.CompilationInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论