本文整理汇总了Java中org.netbeans.api.java.source.CompilationInfo类的典型用法代码示例。如果您正苦于以下问题:Java CompilationInfo类的具体用法?Java CompilationInfo怎么用?Java CompilationInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationInfo类属于org.netbeans.api.java.source包,在下文中一共展示了CompilationInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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};
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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());
}
示例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);
}
}